Skip to content

CascaderProps 重构 #480

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

Merged
merged 58 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b0b982c
feat: 优化代码
crazyair Apr 2, 2024
c5d5c13
feat: 优化代码
crazyair Apr 2, 2024
b3a30f8
feat: 优化代码
crazyair Apr 3, 2024
eb08674
feat: 优化类型
crazyair Apr 3, 2024
2addbfa
feat: 优化类型
crazyair Apr 3, 2024
50ad29f
feat: 优化类型
crazyair Apr 3, 2024
83e1977
Merge remote-tracking branch 'origin/fix-code' into fix-type-2
crazyair Apr 3, 2024
7d68b45
feat: merge
crazyair Apr 3, 2024
db85cbc
feat: 修复
crazyair Apr 3, 2024
658a6ff
feat: test
crazyair Apr 3, 2024
e2f36b7
feat: test
crazyair Apr 3, 2024
1ace0bb
feat: 移除 T
crazyair Apr 8, 2024
5f7760b
feat: 移除 T
crazyair Apr 8, 2024
c489fab
feat: 移除 T
crazyair Apr 8, 2024
6f4ca0b
feat: 移除 T
crazyair Apr 8, 2024
4d03ead
feat: add
crazyair Apr 8, 2024
92bc0ce
feat: t
crazyair Apr 8, 2024
61a078e
feat: onChange
crazyair Apr 8, 2024
dc975a2
feat: onChange
crazyair Apr 8, 2024
616af03
feat: type
crazyair Apr 8, 2024
629415b
feat: type
crazyair Apr 8, 2024
2756811
feat: type
crazyair Apr 8, 2024
95f20a9
feat: merge master
crazyair Apr 8, 2024
bbe30bb
feat: demo
crazyair Apr 9, 2024
72f46a6
feat: type
crazyair Apr 9, 2024
9009044
feat: type
crazyair Apr 9, 2024
64976d4
feat: 删除 demo.tsx
crazyair Apr 9, 2024
d069bef
feat: 删除 any
crazyair Apr 9, 2024
8b37f4c
feat: review
crazyair Apr 9, 2024
be3167e
feat: review
crazyair Apr 9, 2024
f67367f
feat: review
crazyair Apr 9, 2024
fd79828
feat: review
crazyair Apr 9, 2024
eb3c7a9
feat: 优化类型
crazyair Apr 9, 2024
1a659ba
feat: test
crazyair Apr 9, 2024
e8d1073
feat: test
crazyair Apr 9, 2024
805a0ca
feat: test
crazyair Apr 9, 2024
d609529
feat: test
crazyair Apr 9, 2024
480bc7f
feat: test
crazyair Apr 9, 2024
3788a4c
Merge remote-tracking branch 'origin/master' into fix-type-2
crazyair Apr 9, 2024
b4c4d2f
feat: test
crazyair Apr 9, 2024
3c26844
feat: test
crazyair Apr 9, 2024
e479c1a
feat: null
crazyair Apr 9, 2024
737022c
feat: type
crazyair Apr 9, 2024
737bc53
feat: review
crazyair Apr 9, 2024
fbfb82d
feat: 优化类型,可以只写 filedNames
crazyair Apr 9, 2024
f239c08
feat: add Multiple 泛型
crazyair Apr 10, 2024
11ad874
feat: 优化写法
crazyair Apr 10, 2024
adcd01a
feat: add test
crazyair Apr 10, 2024
1b22f74
feat: 代码优化
crazyair Apr 10, 2024
53af749
feat: 代码优化
crazyair Apr 10, 2024
b739c73
feat: review
crazyair Apr 10, 2024
16bf1e4
feat: review
crazyair Apr 10, 2024
4f6f37d
feat: review
crazyair Apr 10, 2024
4c48b34
feat: review
crazyair Apr 10, 2024
548993e
feat: list type
crazyair Apr 11, 2024
0efa259
feat: ingore
crazyair Apr 12, 2024
d0c9e38
feat: any
crazyair Apr 12, 2024
b947106
feat: any
crazyair Apr 12, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ coverage
.dumi/tmp
.dumi/tmp-production
dist
.vscode
4 changes: 3 additions & 1 deletion examples/adjust-overflow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useState } from 'react';
import type { BuildInPlacements } from '@rc-component/trigger/lib/interface';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -60,7 +62,7 @@ const addressOptions = [
const MyCascader = ({ builtinPlacements }: { builtinPlacements?: BuildInPlacements }) => {
const [inputValue, setInputValue] = useState('');

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down
4 changes: 3 additions & 1 deletion examples/animation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -58,7 +60,7 @@ const addressOptions = [
const Demo = () => {
const [inputValue, setInputValue] = useState('');

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2, 'value'>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down
4 changes: 3 additions & 1 deletion examples/change-on-select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const options = [
{
Expand Down Expand Up @@ -61,7 +63,7 @@ const options = [
},
];

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
};

Expand Down
10 changes: 6 additions & 4 deletions examples/custom-arrow-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
const addressOptions: CascaderProps<Option2>['options'] = [
{
label: '福建',
value: 'fj',
Expand Down Expand Up @@ -96,12 +98,12 @@ const Demo = () => {
},
]);

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};

const onChangeDynamic = (value, selectedOptions) => {
const onChangeDynamic: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setDynamicInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down Expand Up @@ -146,7 +148,7 @@ const Demo = () => {
</i>
);

const loadData = selectedOptions => {
const loadData: CascaderProps<Option2>['loadData'] = selectedOptions => {
const targetOption = selectedOptions[selectedOptions.length - 1];
targetOption.loading = true;
// 动态加载下级数据
Expand Down
6 changes: 4 additions & 2 deletions examples/custom-field-name.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option } from './utils';

const addressOptions = [
const addressOptions: Option[] = [
{
name: '福建',
code: 'fj',
Expand Down Expand Up @@ -59,7 +61,7 @@ const addressOptions = [
const Demo = () => {
const [inputValue, setInputValue] = useState('');

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option, 'code'>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.name).join(', '));
};
Expand Down
39 changes: 16 additions & 23 deletions examples/debug.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import '../assets/index.less';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
const addressOptions: Option2[] = [
// ...new Array(20).fill(null).map((_, i) => ({ label: String(i), value: `99${i}` })),
{
label: <span>空孩子</span>,
Expand Down Expand Up @@ -88,7 +89,7 @@ const addressOptions = [
const Demo = () => {
const [multiple, setMultiple] = React.useState(true);

const onChange = (value: any, selectedOptions: any) => {
const onChange = (value: string[], selectedOptions: Option2[]) => {
console.log('[DEBUG] onChange - value:', value);
console.log('[DEBUG] onChange - selectedOptions:', selectedOptions);
};
Expand All @@ -105,27 +106,19 @@ const Demo = () => {
/>
Multiple
</label>
<Cascader
style={{ width: 200 }}
options={addressOptions}
onChange={onChange}
checkable={multiple}
allowClear
// defaultValue={multiple ? [defaultValue] : defaultValue}
// defaultValue={[['not', 'yet'], ['exist']]}
// defaultValue={[['empty']]}
defaultValue={['fj', 'fuzhou']}
showSearch
// showSearch={{ limit: 1 }}
// open
// tagRender={props => {
// console.log(props);
// return props.label as any;
// }}
// direction="rtl"
// searchValue="福a"
// changeOnSelect
/>
{multiple ? (
<Cascader style={{ width: 200 }} checkable defaultValue={[['fj'], ['fuzhou']]} showSearch />
) : (
<Cascader
style={{ width: 200 }}
options={addressOptions}
onChange={onChange}
checkable={false}
allowClear
defaultValue={['fj', 'fuzhou']}
showSearch
/>
)}
</>
);
};
Expand Down
8 changes: 5 additions & 3 deletions examples/default-expand-single-option.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable @typescript-eslint/no-shadow */
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const options = [
{
Expand Down Expand Up @@ -41,12 +43,12 @@ const options = [
const App = () => {
const [inputValue, setInputValue] = useState('');

const [value, setValue] = useState([]);
const [value, setValue] = useState<string[]>([]);

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2, 'value'>['onChange'] = (value, selectedOptions) => {
const lastSelected = selectedOptions[selectedOptions.length - 1];
if (lastSelected.children && lastSelected.children.length === 1) {
value.push(lastSelected.children[0].value);
value.push(lastSelected.children[0].value as string);
setInputValue(selectedOptions.map(o => o.label).join(', '));
setValue(value);
return;
Expand Down
4 changes: 3 additions & 1 deletion examples/defaultValue.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -93,7 +95,7 @@ const defaultOptions = [
const Demo = () => {
const [inputValue, setInputValue] = useState(defaultOptions.map(o => o.label).join(', '));

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down
4 changes: 3 additions & 1 deletion examples/dropdown-render.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -59,7 +61,7 @@ const addressOptions = [
const Demo = () => {
const [inputValue, setInputValue] = useState('');

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down
6 changes: 4 additions & 2 deletions examples/dynamic-options.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand All @@ -19,12 +21,12 @@ const Demo = () => {
const [inputValue, setInputValue] = useState('');
const [options, setOptions] = useState(addressOptions);

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log('OnChange:', value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};

const loadData = selectedOptions => {
const loadData: CascaderProps<Option2>['loadData'] = selectedOptions => {
console.log('onLoad:', selectedOptions);
const targetOption = selectedOptions[selectedOptions.length - 1];
targetOption.loading = true;
Expand Down
4 changes: 3 additions & 1 deletion examples/hover.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -82,7 +84,7 @@ const addressOptions = [
const Demo = () => {
const [inputValue, setInputValue] = useState('');

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down
13 changes: 10 additions & 3 deletions examples/multiple.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
/* eslint-disable @typescript-eslint/no-shadow */
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const { SHOW_CHILD } = Cascader;

const optionLists = [
Expand All @@ -20,12 +24,14 @@ const optionLists = [

const Demo = () => {
const [options, setOptions] = React.useState(optionLists);
const [value, setValue] = useState<string[][]>([]);

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2, 'value', true>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setValue(value);
};

const loadData = selectedOptions => {
const loadData: CascaderProps<Option2, 'value'>['loadData'] = selectedOptions => {
const targetOption = selectedOptions[selectedOptions.length - 1];
targetOption.loading = true;

Expand Down Expand Up @@ -55,6 +61,7 @@ const Demo = () => {
options={options}
showCheckedStrategy={SHOW_CHILD}
loadData={loadData}
value={value}
onChange={onChange}
changeOnSelect
/>
Expand Down
8 changes: 6 additions & 2 deletions examples/panel.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-shadow */
import React from 'react';
import '../assets/index.less';
import Cascader from '../src';
Expand Down Expand Up @@ -56,7 +57,9 @@ const addressOptions = [
];

export default () => {
const [value, setValue] = React.useState([]);
const [value, setValue] = React.useState<string[]>([]);

const [value2, setValue2] = React.useState<string[][]>([]);

return (
<>
Expand All @@ -79,10 +82,11 @@ export default () => {

<Cascader.Panel
checkable
value={value}
value={value2}
options={addressOptions}
onChange={nextValue => {
console.log('Change:', nextValue);
setValue2(nextValue);
}}
/>

Expand Down
4 changes: 3 additions & 1 deletion examples/rc-form.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import arrayTreeFilter from 'array-tree-filter';
import Form, { Field } from 'rc-field-form';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import React from 'react';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -58,7 +60,7 @@ const addressOptions = [
];

const CascaderInput = (props: any) => {
const onChange = value => {
const onChange: CascaderProps<Option2>['onChange'] = value => {
if (props.onChange) {
props.onChange(value);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import '../assets/index.less';
import type { CascaderProps } from '../src';
import Cascader from '../src';
import type { Option2 } from './utils';

const addressOptions = [
{
Expand Down Expand Up @@ -59,7 +61,7 @@ const addressOptions = [
const Demo = () => {
const [inputValue, setInputValue] = useState('');

const onChange = (value, selectedOptions) => {
const onChange: CascaderProps<Option2>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
setInputValue(selectedOptions.map(o => o.label).join(', '));
};
Expand Down
Loading