|
|
@ -1,47 +1,46 @@ |
|
|
|
import { Switch, SxProps, Theme } from '@mui/material'; |
|
|
|
import { |
|
|
|
import { FC, useMemo } from 'react'; |
|
|
|
FormControlLabel as MUIFormControlLabel, |
|
|
|
|
|
|
|
styled, |
|
|
|
|
|
|
|
Switch as MUISwitch, |
|
|
|
|
|
|
|
} from '@mui/material'; |
|
|
|
|
|
|
|
import { FC, ReactElement, useMemo } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
import { GREY } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
import { GREY } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
|
|
|
|
import { BodyText } from './Text'; |
|
|
|
import { BodyText } from './Text'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const SwitchFormControlLabel = styled(MUIFormControlLabel)({ |
|
|
|
|
|
|
|
height: '3.5em', |
|
|
|
|
|
|
|
marginLeft: 0, |
|
|
|
|
|
|
|
width: '100%', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const SwitchWithLabel: FC<SwitchWithLabelProps> = ({ |
|
|
|
const SwitchWithLabel: FC<SwitchWithLabelProps> = ({ |
|
|
|
checked: isChecked, |
|
|
|
checked: isChecked, |
|
|
|
flexBoxProps: { sx: flexBoxSx, ...restFlexBoxProps } = {}, |
|
|
|
formControlLabelProps, |
|
|
|
id: switchId, |
|
|
|
id: switchId, |
|
|
|
label, |
|
|
|
label, |
|
|
|
name: switchName, |
|
|
|
name: switchName, |
|
|
|
onChange, |
|
|
|
onChange, |
|
|
|
switchProps, |
|
|
|
switchProps, |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const combinedFlexBoxSx = useMemo<SxProps<Theme>>( |
|
|
|
const labelElement = useMemo<ReactElement>( |
|
|
|
() => ({ |
|
|
|
|
|
|
|
'& > :first-child': { |
|
|
|
|
|
|
|
flexGrow: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...flexBoxSx, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
[flexBoxSx], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const labelElement = useMemo( |
|
|
|
|
|
|
|
() => |
|
|
|
() => |
|
|
|
typeof label === 'string' ? ( |
|
|
|
typeof label === 'string' ? ( |
|
|
|
<BodyText inheritColour color={`${GREY}9F`}> |
|
|
|
<BodyText inheritColour color={`${GREY}AF`}> |
|
|
|
{label} |
|
|
|
{label} |
|
|
|
</BodyText> |
|
|
|
</BodyText> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
label |
|
|
|
<>{label}</> |
|
|
|
), |
|
|
|
), |
|
|
|
[label], |
|
|
|
[label], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<FlexBox row {...restFlexBoxProps} sx={combinedFlexBoxSx}> |
|
|
|
<SwitchFormControlLabel |
|
|
|
{labelElement} |
|
|
|
componentsProps={{ typography: { flexGrow: 1 } }} |
|
|
|
<Switch |
|
|
|
control={ |
|
|
|
|
|
|
|
<MUISwitch |
|
|
|
checked={isChecked} |
|
|
|
checked={isChecked} |
|
|
|
edge="end" |
|
|
|
edge="end" |
|
|
|
id={switchId} |
|
|
|
id={switchId} |
|
|
@ -49,7 +48,11 @@ const SwitchWithLabel: FC<SwitchWithLabelProps> = ({ |
|
|
|
onChange={onChange} |
|
|
|
onChange={onChange} |
|
|
|
{...switchProps} |
|
|
|
{...switchProps} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</FlexBox> |
|
|
|
} |
|
|
|
|
|
|
|
label={labelElement} |
|
|
|
|
|
|
|
labelPlacement="start" |
|
|
|
|
|
|
|
{...formControlLabelProps} |
|
|
|
|
|
|
|
/> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|