【发布时间】:2020-11-16 22:37:54
【问题描述】:
这是 Material-UI TextField 样式,使用来自 Material-UI 本身的 withStyles:
export const STextField = withStyles({
root: {
background: 'white',
'& label.Mui-focused': {
color: 'white'
},
'& .MuiInput-underline:after': {
borderBottomColor: 'white'
},
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: 'white'
},
'&:hover fieldset': {
borderColor: 'white'
},
'&.Mui-focused fieldset': {
borderColor: 'white'
}
}
}
})(TextField);
而且效果很好。
有没有什么方法可以使用styled-components制作相同的样式?
我试过了:
export const STextField = styled(TextField)`
.MuiTextField-root {
background: 'white'
& label.Mui-focused: {
color: 'white'
},
& .MuiInput-underline:after: {
borderBottomColor: 'white'
},
& .MuiOutlinedInput-root: {
& fieldset: {
borderColor: 'white'
},
&:hover fieldset: {
borderColor: 'white'
},
&.Mui-focused fieldset: {
borderColor: 'white'
}
}
`;
但它制作的风格不一样。
我可能遗漏了一些额外的语法,感谢任何帮助!
【问题讨论】:
标签: javascript reactjs material-ui styled-components