将道具传递给makeStyles()不适用于CSS combinators
应与CSS combinators
步骤:
export interface StyleProps {
width: string; //Tried number but same
}
const useStyles = makeStyles<Theme, StyleProps>((theme) => ({
card: {
//Some other styles ...
'&:hover $filledBar': props => ({
width: props.width, //This doesn't work
transition: '0.4s ease-out'
})
},
filledBar: {
position: 'absolute',
top: '0rem',
zIndex: 3,
width: '0rem',
height: '100%',
background: 'linear-gradient(90deg, rgba(0,154,217,1) 0%, rgba(217,147,0,1) 65%, rgba(255,186,0,1) 100%)',
transition: '0.6s ease-out',
},
}));
const styleProps: StyleProps = { width: '12rem' } //Tried number but same
const classes = useStyles(styleProps);
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
答案 0 :(得分:0)
我遇到了类似的问题,并像这样解决了:
const useStyles = makeStyles((theme) => ({
card: (props: StyleProps) => ({
//Some other styles ...
'&:hover $filledBar': {
width: props.width,
transition: '0.4s ease-out'
}
}),
filledBar: {
position: 'absolute',
top: '0rem',
zIndex: 3,
width: '0rem',
height: '100%',
background: 'linear-gradient(90deg, rgba(0,154,217,1) 0%, rgba(217,147,0,1) 65%, rgba(255,186,0,1) 100%)',
transition: '0.6s ease-out',
},
}));```