parent
6c8807b284
commit
d6a9510fda
5 changed files with 44 additions and 9 deletions
@ -0,0 +1,30 @@ |
||||
import { FormControlLabel } from '@mui/material'; |
||||
import { FC, useMemo } from 'react'; |
||||
|
||||
import Checkbox from './Checkbox'; |
||||
import { BodyText } from './Text'; |
||||
|
||||
const CheckboxWithLabel: FC<CheckboxWithLabelProps> = ({ |
||||
checkboxProps, |
||||
checked, |
||||
formControlLabelProps, |
||||
label, |
||||
onChange, |
||||
}) => { |
||||
const labelElement = useMemo( |
||||
() => (typeof label === 'string' ? <BodyText>{label}</BodyText> : label), |
||||
[label], |
||||
); |
||||
|
||||
return ( |
||||
<FormControlLabel |
||||
{...formControlLabelProps} |
||||
control={ |
||||
<Checkbox {...checkboxProps} checked={checked} onChange={onChange} /> |
||||
} |
||||
label={labelElement} |
||||
/> |
||||
); |
||||
}; |
||||
|
||||
export default CheckboxWithLabel; |
@ -0,0 +1 @@ |
||||
type CheckboxProps = import('@mui/material').CheckboxProps; |
@ -0,0 +1,12 @@ |
||||
type CheckboxWithLabelOptionalProps = Partial< |
||||
Pick<CheckboxProps, 'checked' | 'onChange'> |
||||
> & { |
||||
checkboxProps?: Partial<CheckboxProps>; |
||||
formControlLabelProps?: Partial< |
||||
import('@mui/material').FormControlLabelProps |
||||
>; |
||||
}; |
||||
|
||||
type CheckboxWithLabelProps = CheckboxWithLabelOptionalProps & { |
||||
label: import('@mui/material').FormControlLabelProps['label']; |
||||
}; |
Loading…
Reference in new issue