({ label, value, onChange, disabled = false })
| 3 | import { FormControl, Switch, Typography } from '@mui/material' |
| 4 | |
| 5 | export const SwitchInput = ({ label, value, onChange, disabled = false }) => { |
| 6 | const [myValue, setMyValue] = useState(value !== undefined ? !!value : false) |
| 7 | |
| 8 | useEffect(() => { |
| 9 | setMyValue(value !== undefined ? !!value : false) |
| 10 | }, [value]) |
| 11 | |
| 12 | return ( |
| 13 | <> |
| 14 | <FormControl |
| 15 | sx={{ mt: 1, width: '100%', display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }} |
| 16 | size='small' |
| 17 | > |
| 18 | {label && <Typography>{label}</Typography>} |
| 19 | <Switch |
| 20 | disabled={disabled} |
| 21 | checked={myValue} |
| 22 | onChange={(event) => { |
| 23 | setMyValue(event.target.checked) |
| 24 | onChange(event.target.checked) |
| 25 | }} |
| 26 | /> |
| 27 | </FormControl> |
| 28 | </> |
| 29 | ) |
| 30 | } |
| 31 | |
| 32 | SwitchInput.propTypes = { |
| 33 | label: PropTypes.string, |
nothing calls this directly
no test coverage detected