import React, { useMemo } from 'react'; import { Checkbox as CheckboxSource, Tag } from 'antd'; import { CheckboxGroupProps, CheckboxOptionType } from 'antd/es/checkbox'; import { CheckableTagProps } from 'antd/es/tag/CheckableTag'; import { toOptions } from '../tool'; import { TOptionsProps, THTMLProps, TInputNotRequired } from '../types'; export type TCheckboxProps = Omit & TOptionsProps; /** * 多选框 */ export const Checkbox: React.FC = ({ options = [], ...props }) => { const checkboxOptions = useMemo(() => toOptions(options), [JSON.stringify(options)]); return ; }; export type TCheckboxTagProps = Omit, 'options'> & TOptionsProps & TInputNotRequired; /** * Tag 多选框 */ export const CheckboxTag: React.FC = ({ options = [], value = [], onChange, ...props }) => { const checkboxTagOptions = useMemo(() => toOptions(options), [JSON.stringify(options)]); return (
{checkboxTagOptions.map(({ value: val, label, ...props }) => ( onChange?.(checked ? [...value, val] : value.filter((i: any) => i !== val))} {...props} > {label} ))}
); };