import { FormControlLabel, Switch } from "@material-ui/core"; import { makeStyles } from "@saleor/macaw-ui"; import React from "react"; const useStyles = makeStyles( () => ({ labelText: { fontSize: 14, }, }), { name: "ControlledSwitch" }, ); interface ControlledSwitchProps { checked: boolean; disabled?: boolean; label: string | React.ReactNode; name: string; secondLabel?: string | React.ReactNode; uncheckedLabel?: string | React.ReactNode; onChange?(event: React.ChangeEvent); } export const ControlledSwitch: React.FC = props => { const { checked, disabled, onChange, label, name, secondLabel, uncheckedLabel, } = props; const classes = useStyles(props); return ( onChange({ target: { name, value: !checked } } as any) } checked={checked} color="primary" name={name} /> } label={
{uncheckedLabel ? ( checked ? ( label ) : ( uncheckedLabel ) ) : typeof label === "string" ? ( {label} ) : ( label )}
{secondLabel ? secondLabel : null}
} disabled={disabled} /> ); }; ControlledSwitch.displayName = "ControlledSwitch"; export default ControlledSwitch;