jiti-meet/react/features/base/ui/components/web/Checkbox.tsx

177 lines
4.6 KiB
TypeScript
Raw Normal View History

2022-09-13 07:36:00 +00:00
import { Theme } from '@mui/material';
import React from 'react';
2022-09-13 07:36:00 +00:00
import { makeStyles } from 'tss-react/mui';
import { isMobileBrowser } from '../../../environment/utils';
import Icon from '../../../icons/components/Icon';
import { IconCheck } from '../../../icons/svg';
import { withPixelLineHeight } from '../../../styles/functions.web';
interface ICheckboxProps {
/**
* Whether the input is checked or not.
*/
checked: boolean;
/**
* Class name for additional styles.
*/
className?: string;
/**
* Whether the input is disabled or not.
*/
disabled?: boolean;
/**
* The label of the input.
*/
label: string;
/**
* The name of the input.
*/
name?: string;
/**
* Change callback.
*/
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
}
2022-09-13 07:36:00 +00:00
const useStyles = makeStyles()((theme: Theme) => {
return {
formControl: {
...withPixelLineHeight(theme.typography.bodyLongRegular),
color: theme.palette.text01,
display: 'inline-flex',
alignItems: 'center',
'&.is-mobile': {
...withPixelLineHeight(theme.typography.bodyLongRegularLarge)
}
},
activeArea: {
display: 'grid',
placeContent: 'center',
width: '24px',
height: '24px',
backgroundColor: 'transparent',
marginRight: '15px',
position: 'relative',
cursor: 'pointer',
'& input[type="checkbox"]': {
appearance: 'none',
backgroundColor: 'transparent',
margin: 0,
font: 'inherit',
color: theme.palette.icon03,
width: '18px',
height: '18px',
border: `2px solid ${theme.palette.icon03}`,
borderRadius: '3px',
cursor: 'pointer',
display: 'grid',
placeContent: 'center',
'&::before': {
content: 'url("")',
width: '18px',
height: '18px',
opacity: 0,
backgroundColor: theme.palette.action01,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
border: 0,
borderRadius: '3px',
transition: '.2s'
},
'&:checked::before': {
opacity: 1
},
'&:disabled': {
backgroundColor: theme.palette.ui03,
borderColor: theme.palette.ui04,
'&::before': {
backgroundColor: theme.palette.ui04
}
},
'&:checked+.checkmark': {
opacity: 1
}
},
'& .checkmark': {
position: 'absolute',
left: '3px',
top: '3px',
opacity: 0,
transition: '.2s'
},
'&.is-mobile': {
width: '40px',
height: '40px',
'& input[type="checkbox"]': {
width: '24px',
height: '24px',
'&::before': {
width: '24px',
height: '24px'
}
},
'& .checkmark': {
left: '11px',
top: '10px'
}
}
}
};
});
const Checkbox = ({
checked,
className,
disabled,
label,
name,
onChange
}: ICheckboxProps) => {
2022-09-13 07:36:00 +00:00
const { classes: styles, cx, theme } = useStyles();
const isMobile = isMobileBrowser();
2022-09-13 07:36:00 +00:00
return (
<div className = { cx(styles.formControl, isMobile && 'is-mobile', className) }>
<label className = { cx(styles.activeArea, isMobile && 'is-mobile') }>
<input
checked = { checked }
disabled = { disabled }
name = { name }
onChange = { onChange }
type = 'checkbox' />
<Icon
className = 'checkmark'
color = { disabled ? theme.palette.icon03 : theme.palette.icon01 }
size = { 18 }
src = { IconCheck } />
2022-09-13 07:36:00 +00:00
</label>
<label>{label}</label>
</div>
);
};
export default Checkbox;