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 { import {
Checkbox as MUICheckbox, Checkbox as MUICheckbox,
checkboxClasses as muiCheckboxClasses, checkboxClasses as muiCheckboxClasses,
CheckboxProps as MUICheckboxProps,
} from '@mui/material'; } from '@mui/material';
import { FC } from 'react'; import { FC } from 'react';
import { GREY } from '../lib/consts/DEFAULT_THEME'; import { GREY } from '../lib/consts/DEFAULT_THEME';
type CheckboxProps = MUICheckboxProps;
const Checkbox: FC<CheckboxProps> = ({ sx, ...checkboxProps }) => ( const Checkbox: FC<CheckboxProps> = ({ sx, ...checkboxProps }) => (
<MUICheckbox <MUICheckbox
{...{ {...{
@ -24,6 +21,4 @@ const Checkbox: FC<CheckboxProps> = ({ sx, ...checkboxProps }) => (
/> />
); );
export type { CheckboxProps };
export default Checkbox; 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< type OnCheckboxChange = Exclude<CheckboxProps['onChange'], undefined>;
import('../components/Checkbox').CheckboxProps['onChange'],
undefined
>;
type ListOptionalProps<T extends unknown = unknown> = { type ListOptionalProps<T extends unknown = unknown> = {
allowCheckAll?: boolean; allowCheckAll?: boolean;

Loading…
Cancel
Save