Skip to content

Commit 444099a

Browse files
committed
docs: base usage of tree data
1 parent 8f7d782 commit 444099a

File tree

4 files changed

+111
-8
lines changed

4 files changed

+111
-8
lines changed

docs/zh/v1/guide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ export default function App() {
6868

6969
<<< @/../src/pages/base_flat_data.tsx
7070
<DemoIframe url="/base_flat_data" />
71+
72+
## 基础使用-树形数据
73+
74+
<<< @/../src/pages/base_tree_data.tsx
75+
<DemoIframe url="/base_tree_data" />

src/PageLayout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export default function PageLayout(props: {}) {
5959
.main-menu a{
6060
text-decoration: none;
6161
}
62+
.main-menu a.active{
63+
font-weight: bold;
64+
}
6265
.main-menu a:hover{
6366
text-decoration: underline;
6467
}

src/pages/base_flat_data.tsx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
1-
import { createFlatData } from './_data'
21
import { useHeTree, sortFlatData } from "he-tree-react";
32
import { useState } from 'react';
43

54
export default function BasePage() {
65
const keys = { idKey: 'id', parentIdKey: 'parent_id' };
7-
const [data, setdata] = useState(() => sortFlatData(createFlatData(), keys));
6+
const [data, setdata] = useState(() => sortFlatData([
7+
{
8+
id: 1,
9+
parent_id: null,
10+
name: "Root Category",
11+
},
12+
{
13+
id: 2,
14+
parent_id: 1,
15+
name: "Technology",
16+
},
17+
{
18+
id: 5,
19+
parent_id: 2,
20+
name: "Hardware",
21+
},
22+
{
23+
id: 10,
24+
parent_id: 5,
25+
name: "Computer Components",
26+
},
27+
{
28+
id: 4,
29+
parent_id: 2,
30+
name: "Programming",
31+
},
32+
{
33+
id: 8,
34+
parent_id: 4,
35+
name: "Python",
36+
},
37+
{
38+
id: 3,
39+
parent_id: 1,
40+
name: "Science",
41+
},
42+
{
43+
id: 7,
44+
parent_id: 3,
45+
name: "Biology",
46+
},
47+
{
48+
id: 6,
49+
parent_id: 3,
50+
name: "Physics",
51+
},
52+
], keys));
853
const { renderHeTree } = useHeTree({
954
...keys,
1055
data,
@@ -14,7 +59,7 @@ export default function BasePage() {
1459
{node.name}
1560
</div>,
1661
})
17-
return <div style={{ width: '300px', border: '1px solid #ccc', padding: '10px' }}>
18-
{renderHeTree()}
62+
return <div>
63+
{renderHeTree({ style: { width: '300px', border: '1px solid #555', padding: '20px' } })}
1964
</div>
2065
}

src/pages/base_tree_data.tsx

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,59 @@
1-
import { createTreeData } from './_data'
2-
import { useHeTree } from "../../lib/index";
1+
import { useHeTree } from "he-tree-react";
32
import { useState } from 'react';
43

54
export default function BasePage() {
6-
const [data, setdata] = useState(createTreeData);
5+
const [data, setdata] = useState(() => [
6+
{
7+
id: 1,
8+
name: "Root Category",
9+
children: [
10+
{
11+
id: 2,
12+
name: "Technology",
13+
children: [
14+
{
15+
id: 5,
16+
name: "Hardware",
17+
children: [
18+
{
19+
id: 10,
20+
name: "Computer Components",
21+
children: [],
22+
},
23+
],
24+
},
25+
{
26+
id: 4,
27+
name: "Programming",
28+
children: [
29+
{
30+
id: 8,
31+
name: "Python",
32+
children: [],
33+
},
34+
],
35+
},
36+
],
37+
},
38+
{
39+
id: 3,
40+
name: "Science",
41+
children: [
42+
{
43+
id: 7,
44+
name: "Biology",
45+
children: [],
46+
},
47+
{
48+
id: 6,
49+
name: "Physics",
50+
children: [],
51+
},
52+
],
53+
},
54+
],
55+
},
56+
]);
757
const { renderHeTree } = useHeTree({
858
data,
959
dataType: 'tree',
@@ -14,6 +64,6 @@ export default function BasePage() {
1464
</div>,
1565
})
1666
return <div>
17-
{renderHeTree()}
67+
{renderHeTree({ style: { width: '300px', border: '1px solid #555', padding: '20px' } })}
1868
</div>
1969
}

0 commit comments

Comments
 (0)