使用Material-UI主题,如何设置环绕复选框组件的单选按钮标签的样式?我是否只能在makestyles
组件上使用FormControlLabel
?
此图像正是我要实现的(即,深色背景是选中的选项,白色背景是未选中的选项)
import React from "react";
import ThemeProvider from "@material-ui/styles/ThemeProvider";
import { createMuiTheme } from "@material-ui/core/styles";
import Radio from "@material-ui/core/Radio";
import RadioGroup from "@material-ui/core/RadioGroup";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import FormControl from "@material-ui/core/FormControl";
const muiTheme = createMuiTheme({});
const theme = {
...muiTheme,
overrides: {
MuiFormControlLabel: {
root: {
marginLeft: 0,
marginRight: 0,
backgroundColor: "#F0F3E9",
color: "#283F3D",
height: 68,
marginBottom: "5px",
// my guess this is wrong syntax
"&$checked": {
backgroundColor: "red",
color: "blue"
}
}
}
}
};
function CheckboxLabels() {
return (
<ThemeProvider theme={theme}>
<FormControl component="fieldset" fullWidth>
<RadioGroup aria-label="preferred postal address">
<FormControlLabel
value="HomeAddress"
control={<Radio icon="" checkedIcon="" />}
label="Home Address"
/>
<FormControlLabel
value="WorkAddress"
control={<Radio icon="" checkedIcon="" />}
label="Work Address"
/>
</RadioGroup>
</FormControl>
</ThemeProvider>
);
}
export default CheckboxLabels;