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