import { Checkbox, Col, Divider, Input, Row } from 'antd'; import { memo, useEffect, useState } from 'react'; import type { CheckboxValueType } from 'antd/es/checkbox/Group'; import { useIntl } from 'umi'; import { useSelections } from 'ahooks'; type CustomCheckGroupProps = { value: CheckboxValueType[]; onChange: (value: CheckboxValueType[]) => void; options: { label: string; value: string }[]; }; const CustomCheckGroup = ({ value, onChange, options }: CustomCheckGroupProps) => { const { formatMessage } = useIntl(); const [filterValue, setFilterValue] = useState(options); const { selected, allSelected, isSelected, toggle, toggleAll, partiallySelected } = useSelections( filterValue.map((item) => item.value), value, ); useEffect(() => { onChange?.(selected); }, [selected, onChange]); return ( <> setFilterValue( options.filter((item) => item.label.toLocaleLowerCase().includes(event.target.value.toLocaleLowerCase()), ), ) } style={{ margin: '10px 0' }} /> {allSelected ? ( {formatMessage({ id: 'component.check.all' })} ) : ( formatMessage({ id: 'component.check.all' }) )}
{filterValue?.map((option) => ( toggle(option.value)}> {selected?.indexOf(option.value) !== -1 ? {option.label} : option.label} ))}
); }; export default memo(CustomCheckGroup);