fix(striker-ui): add CheckboxWithLabel

main
Tsu-ba-me 2 years ago
parent 6c8807b284
commit d6a9510fda
  1. 5
      striker-ui/components/Checkbox.tsx
  2. 30
      striker-ui/components/CheckboxWithLabel.tsx
  3. 1
      striker-ui/types/Checkbox.d.ts
  4. 12
      striker-ui/types/CheckboxWithLabel.d.ts
  5. 5
      striker-ui/types/List.d.ts

@ -1,14 +1,11 @@
import {
Checkbox as MUICheckbox,
checkboxClasses as muiCheckboxClasses,
CheckboxProps as MUICheckboxProps,
} from '@mui/material';
import { FC } from 'react';
import { GREY } from '../lib/consts/DEFAULT_THEME';
type CheckboxProps = MUICheckboxProps;
const Checkbox: FC<CheckboxProps> = ({ sx, ...checkboxProps }) => (
<MUICheckbox
{...{
@ -24,6 +21,4 @@ const Checkbox: FC<CheckboxProps> = ({ sx, ...checkboxProps }) => (
/>
);
export type { CheckboxProps };
export default Checkbox;

@ -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'];
};

@ -1,7 +1,4 @@
type OnCheckboxChange = Exclude<
import('../components/Checkbox').CheckboxProps['onChange'],
undefined
>;
type OnCheckboxChange = Exclude<CheckboxProps['onChange'], undefined>;
type ListOptionalProps<T extends unknown = unknown> = {
allowCheckAll?: boolean;

Loading…
Cancel
Save