We haven't extended these components from Material-UI. We've just added our style over their components.
You will find the styles for this component insrc/assets/jss/nextjs-material-kit/customCheckboxRadioSwitch.js
.
Let's take a look at each one of them, and how to use our styles.
import React from "react";
import classNames from "classnames";
// material-ui components
import { makeStyles } from "@material-ui/core/styles";
import Checkbox from "@material-ui/core/Checkbox";
import FormControlLabel from "@material-ui/core/FormControlLabel";
// @material-ui/icons
import Check from "@material-ui/icons/Check";
import styles from "/styles/jss/nextjs-material-kit/customCheckboxRadioSwitch.js";
const useStyles = makeStyles(styles);
export default function CheckboxRadioSwitch(){
const [checked, setChecked] = React.useState([24, 22]);
const classes = useStyles();
const wrapperDiv = classNames(
classes.checkboxAndRadio,
classes.checkboxAndRadioHorizontal
);
const handleToggle = value => {
const currentIndex = checked.indexOf(value);
const newChecked = [...checked];
if (currentIndex === -1) {
newChecked.push(value);
} else {
newChecked.splice(currentIndex, 1);
}
setChecked(newChecked);
};
return (
<div>
<div className={wrapperDiv}>
<FormControlLabel
control={
<Checkbox
tabIndex={-1}
onClick={() => handleToggle(21)}
checkedIcon={<Check className={classes.checkedIcon} />}
icon={<Check className={classes.uncheckedIcon} />}
classes={{ checked: classes.checked }}
/>
}
classes={{ label: classes.label }}
label="Unchecked"
/>
</div>
<div className={wrapperDiv}>
<FormControlLabel
control={
<Checkbox
tabIndex={-1}
onClick={() => handleToggle(22)}
checked={
checked.indexOf(22) !== -1 ? true : false
}
checkedIcon={<Check className={classes.checkedIcon} />}
icon={<Check className={classes.uncheckedIcon} />}
classes={{ checked: classes.checked }}
/>
}
classes={{ label: classes.label }}
label="Checked"
/>
</div>
<div className={wrapperDiv}>
<FormControlLabel
disabled
control={
<Checkbox
tabIndex={-1}
checkedIcon={<Check className={classes.checkedIcon} />}
icon={<Check className={classes.uncheckedIcon} />}
classes={{ checked: classes.checked }}
/>
}
classes={{
label: classes.label,
disabled: classes.disabledCheckboxAndRadio
}}
label="Disabled Unchecked"
/>
</div>
<div className={wrapperDiv}>
<FormControlLabel
disabled
control={
<Checkbox
tabIndex={-1}
checked={
checked.indexOf(24) !== -1 ? true : false
}
checkedIcon={<Check className={classes.checkedIcon} />}
icon={<Check className={classes.uncheckedIcon} />}
classes={{ checked: classes.checked }}
/>
}
classes={{
label: classes.label,
disabled: classes.disabledCheckboxAndRadio
}}
label="Disabled Checked"
/>
</div>
</div>
);
}
import React from "react";
import classNames from "classnames";
// material-ui components
import { makeStyles } from "@material-ui/core/styles";
import Radio from "@material-ui/core/Radio";
import FormControlLabel from "@material-ui/core/FormControlLabel";
// @material-ui/icons
import FiberManualRecord from "@material-ui/icons/FiberManualRecord";
import styles from "/styles/jss/nextjs-material-kit/customCheckboxRadioSwitch.js";
const useStyles = makeStyles(styles);
export default function CheckboxRadioSwitch(){
const [selectedEnabled, setSelectedEnabled] = React.useState("b");
const classes = useStyles();
const wrapperDiv = classNames(
classes.checkboxAndRadio,
classes.checkboxAndRadioHorizontal
);
return (
<div>
<div className={wrapperDiv}>
<FormControlLabel
control={
<Radio
checked={selectedEnabled === "a"}
onChange={() => setSelectedEnabled("a")}
value="a"
name="radio button enabled"
aria-label="A"
icon={
<FiberManualRecord
className={classes.radioUnchecked}
/>
}
checkedIcon={
<FiberManualRecord className={classes.radioChecked} />
}
classes={{
checked: classes.radio
}}
/>
}
classes={{
label: classes.label
}}
label="First Radio"
/>
</div>
<div className={wrapperDiv}>
<FormControlLabel
control={
<Radio
checked={selectedEnabled === "b"}
onChange={() => setSelectedEnabled("b")}
value="b"
name="radio button enabled"
aria-label="B"
icon={
<FiberManualRecord
className={classes.radioUnchecked}
/>
}
checkedIcon={
<FiberManualRecord className={classes.radioChecked} />
}
classes={{
checked: classes.radio
}}
/>
}
classes={{
label: classes.label
}}
label="Second Radio"
/>
</div>
<div className={wrapperDiv}>
<FormControlLabel
disabled
control={
<Radio
checked={false}
value="a"
name="radio button disabled"
aria-label="B"
icon={
<FiberManualRecord
className={classes.radioUnchecked}
/>
}
checkedIcon={
<FiberManualRecord className={classes.radioChecked} />
}
classes={{
checked: classes.radio
}}
/>
}
classes={{
label: classes.label,
disabled: classes.disabledCheckboxAndRadio
}}
label="Disabled Unchecked Radio"
/>
</div>
<div className={wrapperDiv}>
<FormControlLabel
disabled
control={
<Radio
checked={true}
value="b"
name="radio button disabled"
aria-label="B"
icon={
<FiberManualRecord
className={classes.radioUnchecked}
/>
}
checkedIcon={
<FiberManualRecord className={classes.radioChecked} />
}
classes={{
checked: classes.radio
}}
/>
}
classes={{
label: classes.label,
disabled: classes.disabledCheckboxAndRadio
}}
label="Disabled Checked Radio"
/>
</div>
</div>
);
}
import React from "react";
// material-ui components
import { makeStyles } from "@material-ui/core/styles";
import Switch from "@material-ui/core/Switch";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import styles from "/styles/jss/nextjs-material-kit/customCheckboxRadioSwitch.js";
const useStyles = makeStyles(styles);
export default function CheckboxRadioSwitch(){
const classes = useStyles();
const [checkedA, setCheckedA] = React.useState(true);
const [checkedB, setCheckedB] = React.useState(false);
return (
<div>
<div>
<FormControlLabel
control={
<Switch
checked={checkedA}
onChange={event => setCheckedA(event.target.checked)}
value="checkedA"
classes={{
switchBase: classes.switchBase,
checked: classes.switchChecked,
thumb: classes.switchIcon,
iconChecked: classes.switchIconChecked,
track: classes.switchBar
}}
/>
}
classes={{
label: classes.label
}}
label="Toggle is on"
/>
</div>
<div>
<FormControlLabel
control={
<Switch
checked={checkedB}
onChange={event => setCheckedB(event.target.checked)}
value="checkedB"
classes={{
switchBase: classes.switchBase,
checked: classes.switchChecked,
thumb: classes.switchIcon,
iconChecked: classes.switchIconChecked,
track: classes.switchBar
}}
/>
}
classes={{
label: classes.label
}}
label="Toggle is off"
/>
</div>
</div>
);
}