Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Checkbox): upgrade checkbox ts #4688

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/checkbox/__docs__/demo/all-check/index.tsx
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
Expand Down
21 changes: 6 additions & 15 deletions components/checkbox/__docs__/demo/control/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand All @@ -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 (
Expand Down
20 changes: 6 additions & 14 deletions components/checkbox/__docs__/demo/dataSource/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand All @@ -20,28 +21,19 @@ 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,
});
};

render() {
return (
<Checkbox.Group
dataSource={list}
size="small"
value={this.state.value}
onChange={this.onChange}
/>
<Checkbox.Group dataSource={list} value={this.state.value} onChange={this.onChange} />
);
}
}
Expand Down
17 changes: 6 additions & 11 deletions components/checkbox/__docs__/demo/group/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
14 changes: 5 additions & 9 deletions components/checkbox/__docs__/demo/indeterminate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions components/checkbox/__docs__/demo/isPreview/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -20,10 +21,10 @@ class App extends React.Component {
});
};

renderChecked = (checked, props) =>
renderChecked: CheckboxProps['renderPreview'] = (checked, props) =>
checked ? <span>{props.children}</span> : <span>null</span>;

renderPreview = (previewed, props) =>
renderPreview: GroupProps['renderPreview'] = previewed =>
previewed.length
? previewed.map((Item, index) => (
<span key={`${index}-checkbox`} style={{ marginRight: 10 }}>
Expand Down
11 changes: 3 additions & 8 deletions components/checkbox/__docs__/demo/uncontrol/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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 (
Expand Down
Loading
Loading