42 lines
946 B
TypeScript
42 lines
946 B
TypeScript
import type { CheckboxProps as AntCheckboxProps } from 'antd';
|
|
import { Checkbox as AntCheckbox, Form } from 'antd';
|
|
import type { CheckboxChangeEvent } from 'antd/lib/checkbox';
|
|
import type { BaseElementProps } from './types';
|
|
|
|
const { Item: FormItem } = Form;
|
|
|
|
type ElementProps = BaseElementProps<boolean> & {
|
|
text: string;
|
|
};
|
|
|
|
export default function Checkbox({
|
|
value,
|
|
setValue,
|
|
status,
|
|
isValid,
|
|
help,
|
|
text,
|
|
...props
|
|
}: ElementProps) {
|
|
function handleChange(e: CheckboxChangeEvent) {
|
|
setValue(e.target.checked);
|
|
}
|
|
|
|
return (
|
|
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
|
<AntCheckbox
|
|
checked={value}
|
|
onChange={handleChange}
|
|
disabled={status === 'Disabled'}
|
|
{...props}
|
|
>
|
|
{text}
|
|
</AntCheckbox>
|
|
</FormItem>
|
|
);
|
|
}
|
|
|
|
type CheckboxProps = AntCheckboxProps & Pick<ElementProps, 'text'>;
|
|
|
|
export type { CheckboxProps };
|