diff --git a/components/checkbox/__docs__/demo/all-check/index.tsx b/components/checkbox/__docs__/demo/all-check/index.tsx
index 1b6bcd378f..6d2b6dd4fd 100644
--- a/components/checkbox/__docs__/demo/all-check/index.tsx
+++ b/components/checkbox/__docs__/demo/all-check/index.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Checkbox, Divider } from '@alifd/next';
+import type { CheckboxProps, GroupProps } from '@alifd/next/lib/checkbox';
const CheckboxGroup = Checkbox.Group;
@@ -12,13 +13,13 @@ const App = () => {
const [indeterminate, setIndeterminate] = React.useState(true);
const [checkAll, setCheckAll] = React.useState(false);
- const onChange = list => {
+ const onChange: GroupProps['onChange'] = (list: string[]) => {
setCheckedList(list);
setIndeterminate(!!list.length && list.length < plainOptions.length);
setCheckAll(list.length === plainOptions.length);
};
- const onCheckAllChange = (checked, e) => {
+ const onCheckAllChange: CheckboxProps['onChange'] = (checked, e) => {
setCheckedList(e.target.checked ? plainOptions : []);
setIndeterminate(false);
setCheckAll(e.target.checked);
diff --git a/components/checkbox/__docs__/demo/control/index.tsx b/components/checkbox/__docs__/demo/control/index.tsx
index 986b656c67..5d7a9974a2 100644
--- a/components/checkbox/__docs__/demo/control/index.tsx
+++ b/components/checkbox/__docs__/demo/control/index.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Checkbox } from '@alifd/next';
+import { type GroupProps } from '@alifd/next/lib/checkbox';
const list = [
{
@@ -18,26 +19,16 @@ const list = [
];
class ControlApp extends React.Component {
- constructor(props) {
- super(props);
-
- this.state = {
- value: 'orange',
- };
-
- this.onChange = this.onChange.bind(this);
- }
+ state = {
+ value: 'orange',
+ };
- onChange(value) {
+ onChange: GroupProps['onChange'] = value => {
this.setState({
value: value,
});
console.log('onChange', value);
- }
-
- onClick(e) {
- console.log('onClick', e);
- }
+ };
render() {
return (
diff --git a/components/checkbox/__docs__/demo/dataSource/index.tsx b/components/checkbox/__docs__/demo/dataSource/index.tsx
index 3a0192677c..33c8112540 100644
--- a/components/checkbox/__docs__/demo/dataSource/index.tsx
+++ b/components/checkbox/__docs__/demo/dataSource/index.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Checkbox } from '@alifd/next';
+import { type GroupProps } from '@alifd/next/lib/checkbox';
const list = [
{
@@ -20,15 +21,11 @@ const list = [
];
class App extends React.Component {
- constructor(props) {
- super(props);
-
- this.state = {
- value: 'apple',
- };
- }
+ state = {
+ value: 'apple',
+ };
- onChange = value => {
+ onChange: GroupProps['onChange'] = value => {
this.setState({
value: value,
});
@@ -36,12 +33,7 @@ class App extends React.Component {
render() {
return (
-
+
);
}
}
diff --git a/components/checkbox/__docs__/demo/group/index.tsx b/components/checkbox/__docs__/demo/group/index.tsx
index af18e679a4..ce3df04a38 100644
--- a/components/checkbox/__docs__/demo/group/index.tsx
+++ b/components/checkbox/__docs__/demo/group/index.tsx
@@ -1,23 +1,18 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Checkbox } from '@alifd/next';
+import { type GroupProps } from '@alifd/next/lib/checkbox';
class App extends React.Component {
- constructor(props) {
- super(props);
+ state = {
+ value: 'orange',
+ };
- this.state = {
- value: 'orange',
- };
-
- this.onChange = this.onChange.bind(this);
- }
-
- onChange(value) {
+ onChange: GroupProps['onChange'] = value => {
this.setState({
value: value,
});
- }
+ };
render() {
return (
diff --git a/components/checkbox/__docs__/demo/indeterminate/index.tsx b/components/checkbox/__docs__/demo/indeterminate/index.tsx
index 8af9451534..c7069f50f0 100644
--- a/components/checkbox/__docs__/demo/indeterminate/index.tsx
+++ b/components/checkbox/__docs__/demo/indeterminate/index.tsx
@@ -3,15 +3,11 @@ import ReactDOM from 'react-dom';
import { Checkbox, Button } from '@alifd/next';
class IndeterminateApp extends React.Component {
- constructor(props) {
- super(props);
-
- this.state = {
- checked: false,
- indeterminate: true,
- disabled: false,
- };
- }
+ state = {
+ checked: false,
+ indeterminate: true,
+ disabled: false,
+ };
toggle = () => {
if (this.state.indeterminate) {
diff --git a/components/checkbox/__docs__/demo/isPreview/index.tsx b/components/checkbox/__docs__/demo/isPreview/index.tsx
index 54372ad59c..11b62cec06 100644
--- a/components/checkbox/__docs__/demo/isPreview/index.tsx
+++ b/components/checkbox/__docs__/demo/isPreview/index.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Checkbox, Switch } from '@alifd/next';
+import { type CheckboxProps, type GroupProps } from '@alifd/next/lib/checkbox';
class App extends React.Component {
state = {
@@ -20,10 +21,10 @@ class App extends React.Component {
});
};
- renderChecked = (checked, props) =>
+ renderChecked: CheckboxProps['renderPreview'] = (checked, props) =>
checked ? {props.children} : null;
- renderPreview = (previewed, props) =>
+ renderPreview: GroupProps['renderPreview'] = previewed =>
previewed.length
? previewed.map((Item, index) => (
diff --git a/components/checkbox/__docs__/demo/uncontrol/index.tsx b/components/checkbox/__docs__/demo/uncontrol/index.tsx
index f4cbdc7677..14eb902b08 100644
--- a/components/checkbox/__docs__/demo/uncontrol/index.tsx
+++ b/components/checkbox/__docs__/demo/uncontrol/index.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Checkbox } from '@alifd/next';
+import { type GroupProps } from '@alifd/next/lib/checkbox';
const { Group: CheckboxGroup } = Checkbox;
const list = [
@@ -21,15 +22,9 @@ const list = [
];
class UnControlApp extends React.Component {
- constructor(props) {
- super(props);
-
- this.onChange = this.onChange.bind(this);
- }
-
- onChange(selectedItems) {
+ onChange: GroupProps['onChange'] = selectedItems => {
console.log('onChange callback', selectedItems);
- }
+ };
render() {
return (
diff --git a/components/checkbox/__docs__/index.en-us.md b/components/checkbox/__docs__/index.en-us.md
index 7defeb1fd2..6c5c70286b 100644
--- a/components/checkbox/__docs__/index.en-us.md
+++ b/components/checkbox/__docs__/index.en-us.md
@@ -13,41 +13,67 @@ Checkbox
### When to Use
Checkbox is used to verify which options you want selected from a group. If you have only a single option, do not use the checkbox, use the on/off switch.
+
## API
### Checkbox
-| Param | Description | Type | Default Value |
-| ------------------------ |---------------------------- | ------------ | ------------- |
-| id | checkbox id, mounted on input | String | - |
-| checked | Set the status to be checked | Boolean | - |
-| defaultChecked | Set the default status to be checked | Boolean | false |
-| disabled | Set the status to be disabled | Boolean | - |
-| label | Set the label by property | String | - |
-| indeterminate | The intermediate state of the Checkbox will only affect the style of the Checkbox and does not affect its checked property. | Boolean | - |
-| defaultIndeterminate | Set the default status to intermediate, it will only affect the style of the Checkbox and does not affect its checked property. | Boolean | false |
-| onChange | Callback function triggered when the state changes
**signatures**: Function(checked: Boolean, e: Event) => void **params**: _checked_: {Boolean} The checked value of the underlying checkbox input _e_: {Event} Dom event object | Function | func.noop |
-| onMouseEnter | Callback function triggered when the mouse pointer enters the element.
**signatures**: Function(e: Event) => void **params**: _e_: {Event} Dom event object | Function | func.noop |
-| onMouseLeave | Callback function triggered when the mouse pointer leaves the element.
**signatures**: Function(e: Event) => void **params**: _e_: {Event} Dom event object | Function | func.noop |
-|value | The value of the Checkbox | String/Number/Boolean | - |
+| Param | Description | Type | Default Value | Required | Supported Version |
+| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | ------------- | -------- | ----------------- |
+| className | ClassName | string | - | | - |
+| id | Checkbox id, mounted on the input | string | - | | - |
+| style | Custom inline style | React.CSSProperties | - | | - |
+| checked | Checked status | boolean | - | | - |
+| value | Checkbox value | IValue | - | | - |
+| name | Name | string | - | | - |
+| defaultChecked | Default checked status | boolean | false | | - |
+| disabled | Disabled | boolean | - | | - |
+| label | Label | React.ReactNode | - | | - |
+| indeterminate | Checkbox middle status, only affects the style of Checkbox, and does not affect its checked property | boolean | - | | - |
+| defaultIndeterminate | Checkbox default middle status, only affects the style of Checkbox, and does not affect its checked property | boolean | false | | - |
+| onChange | Status change event | (checked: boolean, e: React.ChangeEvent) => void | - | | - |
+| onMouseEnter | Mouse enter event | (e: React.MouseEvent) => void | - | | - |
+| onMouseLeave | Mouse leave event | (e: React.MouseEvent) => void | - | | - |
+| isPreview | Is preview | boolean | false | | 1.19 |
+| renderPreview | Custom rendering content
**signature**: **params**: _checked_: Is checked _props_: All props **return**: Custom rendering content | (checked: boolean, props: CheckboxProps) => React.ReactNode | - | | 1.19 |
### Checkbox.Group
-| params | desc | type | default |
-| ---------------- | --------------------------------------------------- | -------- | ------------- |
-| disabled | Set the status of all checkbox in group to be checked | Boolean | - |
-| dataSource | Optional list, data item can be String or Object, for example `['apple', 'pear', 'orange']` or `[{value: 'apple', label: 'Apple',}, {value: 'pear', label: 'Pear'}, {value: 'orange', label: 'Orange'}]` | Array<any> | \[] |
-| value | The values of selected optional list | Array/String/Number/Boolean | - |
-| defaultValue | The values of default selected optional list | Array/String/Number/Boolean | - |
-| children | To set nested checkbox by children components | Array<ReactElement> | - |
-| onChange | Callback function triggered when the selected value changes
**signatures**: Function(value: Array, e: Event) => void **params**: _value_: {Array} values of selected optional list _e_: {Event} Dom event object | Function | () => { } |
-| direction | The direction of item's aligning - hoz: horizontal (default) - ver: vertical