Skip to content

Commit f12f15a

Browse files
authored
docs(filterrules): add more data example (#415)
1 parent 46d8ac7 commit f12f15a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { useState } from 'react';
2+
import { Alert, Input } from 'antd';
3+
import { FilterRules } from 'dt-react-component';
4+
import { IComponentProps } from 'dt-react-component/filterRules';
5+
6+
import { INIT_ROW_VALUES, IRow, MORE_INIT_DATA } from './constants';
7+
8+
const MyInput = ({ rowValues: { input }, rowKey, onChange }: IComponentProps<IRow>) => (
9+
<Input value={input} onChange={(e) => onChange?.(rowKey, { input: e.target.value })} />
10+
);
11+
12+
export default () => {
13+
const [data, setData] = useState(MORE_INIT_DATA);
14+
15+
return (
16+
<>
17+
<Alert
18+
message="可以通过操作按钮增加删除数据,切换且或节点内容"
19+
style={{ marginBottom: 16 }}
20+
/>
21+
<FilterRules<IRow>
22+
component={(props) => <MyInput {...props} />}
23+
value={data}
24+
onChange={(value: any) => setData(value)}
25+
initValues={INIT_ROW_VALUES}
26+
/>
27+
</>
28+
);
29+
};

src/filterRules/demos/constants.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,40 @@ export const INIT_DATA = {
1212
},
1313
};
1414

15+
export const MORE_INIT_DATA = {
16+
key: shortid(),
17+
level: 1,
18+
type: 1,
19+
children: [
20+
{
21+
rowValues: {
22+
input: '',
23+
},
24+
key: shortid(),
25+
level: 1,
26+
},
27+
{
28+
key: shortid(),
29+
type: 2,
30+
level: 2,
31+
children: [
32+
{
33+
key: shortid(),
34+
level: 2,
35+
rowValues: {
36+
input: '',
37+
},
38+
},
39+
{
40+
key: shortid(),
41+
rowValues: {
42+
input: '',
43+
},
44+
level: 2,
45+
},
46+
],
47+
},
48+
],
49+
};
50+
1551
export type IRow = typeof INIT_ROW_VALUES;

src/filterRules/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ demo:
1717
## 示例
1818

1919
<code src="./demos/basic.tsx" >受控方式使用</code>
20+
<code src="./demos/basicMore.tsx" >多条数据的使用</code>
2021
<code src="./demos/basicUnController.tsx" >非受控方式使用</code>
2122
<code src="./demos/basicCheck.tsx" >查看数据</code>
2223

0 commit comments

Comments
 (0)