mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
74492676f7
* fix: fix Checkbox.Group type * fix: fix Checkbox.Group type * fix: fix Checkbox.Group type * fix: remove type * fix: any
36 lines
1022 B
TypeScript
36 lines
1022 B
TypeScript
import React, { useState } from 'react';
|
|
import { Checkbox, Divider } from 'antd';
|
|
import type { CheckboxProps } from 'antd';
|
|
|
|
const CheckboxGroup = Checkbox.Group;
|
|
|
|
const plainOptions = ['Apple', 'Pear', 'Orange'];
|
|
const defaultCheckedList = ['Apple', 'Orange'];
|
|
|
|
const App: React.FC = () => {
|
|
const [checkedList, setCheckedList] = useState<string[]>(defaultCheckedList);
|
|
|
|
const checkAll = plainOptions.length === checkedList.length;
|
|
const indeterminate = checkedList.length > 0 && checkedList.length < plainOptions.length;
|
|
|
|
const onChange = (list: string[]) => {
|
|
setCheckedList(list);
|
|
};
|
|
|
|
const onCheckAllChange: CheckboxProps['onChange'] = (e) => {
|
|
setCheckedList(e.target.checked ? plainOptions : []);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
|
|
Check all
|
|
</Checkbox>
|
|
<Divider />
|
|
<CheckboxGroup options={plainOptions} value={checkedList} onChange={onChange} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|