Zha*_* Yi 3 reactjs material-ui
material-ui 引入了一种使用类名来设置组件样式的方法。我有一个按钮组件,如下所示。它使用createStyles和withStyles将样式注入classes到组件中。但我不知道如何设置焦点样式Button。
import Button from '@material-ui/core/Button';
const styles = createStyles({
button: {
minHeight: '3rem',
lineHeight: '3rem',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around',
fontSize: '0.8rem',
fontFamily: 'Roboto',
color: '#008091',
border: '2px solid #008091',
borderRadius: '0.375rem',
marginRight: '1rem',
marginTop: '2rem',
marginBottom: '2rem',
minWidth: '180px',
textAlign: 'center',
fontWeight: 700,
margin: '1rem 0',
padding: 0
},
selected: {
backgroundColor: '#008091',
color: 'white'
}
});
interface Props {
classes: { [className in keyof typeof styles]: string };
style?: React.CSSProperties;
text: string;
selected?: boolean;
onClick: (event: React.MouseEvent<HTMLElement>) => void;
}
const TextButton = ({ classes, style, text, onClick, selected }: Props) => {
return (
<Button
className={selected ? classNames(classes.button, classes.selected) : classes.button}
style={style}
onClick={onClick}
>
{text}
</Button>
);
};
Run Code Online (Sandbox Code Playgroud)
伪选择器可以通过以下方式添加:
const styles = createStyles({
button: {
// main styles,
"&:focus": {
color: "red"
}
}
});
Run Code Online (Sandbox Code Playgroud)