|
1 | 1 | import type { CollapseProps } from 'rc-collapse'; |
2 | | -import Collapse, { Panel } from 'rc-collapse'; |
| 2 | +import Collapse from 'rc-collapse'; |
3 | 3 | import * as React from 'react'; |
4 | 4 | import '../../assets/index.less'; |
| 5 | +import type { ItemType } from '../../src/interface'; |
5 | 6 | import motion from './_util/motionUtil'; |
6 | 7 |
|
7 | 8 | const initLength = 3; |
@@ -50,38 +51,60 @@ const App: React.FC = () => { |
50 | 51 |
|
51 | 52 | const time = random(); |
52 | 53 |
|
53 | | - const panelItems = Array.from<object, React.ReactNode>({ length: initLength }, (_, i) => { |
| 54 | + const panelItems = Array.from<object, ItemType>({ length: initLength }, (_, i) => { |
54 | 55 | const key = i + 1; |
55 | | - return ( |
56 | | - <Panel header={`This is panel header ${key}`} key={key}> |
57 | | - <p>{text.repeat(time)}</p> |
58 | | - </Panel> |
59 | | - ); |
| 56 | + return { |
| 57 | + key, |
| 58 | + header: `This is panel header ${key}`, |
| 59 | + children: <p>{text.repeat(time)}</p>, |
| 60 | + }; |
60 | 61 | }).concat( |
61 | | - <Panel header={`This is panel header ${initLength + 1}`} key={initLength + 1}> |
62 | | - <Collapse defaultActiveKey="1" expandIcon={expandIcon}> |
63 | | - <Panel header="This is panel nest panel" key="1" id="header-test"> |
64 | | - <p>{text}</p> |
65 | | - </Panel> |
66 | | - </Collapse> |
67 | | - </Panel>, |
68 | | - <Panel header={`This is panel header ${initLength + 2}`} key={initLength + 2}> |
69 | | - <Collapse defaultActiveKey="1"> |
70 | | - <Panel header="This is panel nest panel" key="1" id="another-test"> |
71 | | - <form> |
72 | | - <label htmlFor="test">Name: </label> |
73 | | - <input type="text" id="test" /> |
74 | | - </form> |
75 | | - </Panel> |
76 | | - </Collapse> |
77 | | - </Panel>, |
78 | | - <Panel |
79 | | - header={`This is panel header ${initLength + 3}`} |
80 | | - key={initLength + 3} |
81 | | - extra={<span>Extra Node</span>} |
82 | | - > |
83 | | - <p>Panel with extra</p> |
84 | | - </Panel>, |
| 62 | + { |
| 63 | + key: initLength + 1, |
| 64 | + header: `This is panel header ${initLength + 1}`, |
| 65 | + children: ( |
| 66 | + <Collapse |
| 67 | + defaultActiveKey="1" |
| 68 | + expandIcon={expandIcon} |
| 69 | + items={[ |
| 70 | + { |
| 71 | + key: '1', |
| 72 | + header: 'This is panel nest panel', |
| 73 | + id: 'header-test', |
| 74 | + children: <p>{text}</p>, |
| 75 | + }, |
| 76 | + ]} |
| 77 | + /> |
| 78 | + ), |
| 79 | + }, |
| 80 | + { |
| 81 | + key: initLength + 2, |
| 82 | + header: `This is panel header ${initLength + 2}`, |
| 83 | + children: ( |
| 84 | + <Collapse |
| 85 | + defaultActiveKey="1" |
| 86 | + items={[ |
| 87 | + { |
| 88 | + key: '1', |
| 89 | + header: 'This is panel nest panel', |
| 90 | + id: 'another-test', |
| 91 | + children: ( |
| 92 | + <form> |
| 93 | + <label htmlFor="test">Name: </label> |
| 94 | + <input type="text" id="test" /> |
| 95 | + </form> |
| 96 | + ), |
| 97 | + }, |
| 98 | + ]} |
| 99 | + /> |
| 100 | + ), |
| 101 | + }, |
| 102 | + { |
| 103 | + key: initLength + 3, |
| 104 | + header: `This is panel header ${initLength + 3}`, |
| 105 | + extra: <span>Extra Node</span>, |
| 106 | + children: <p>Panel with extra</p>, |
| 107 | + }, |
85 | 108 | ); |
86 | 109 |
|
87 | 110 | const handleCollapsibleChange = (e: React.ChangeEvent<HTMLSelectElement>) => { |
@@ -129,9 +152,8 @@ const App: React.FC = () => { |
129 | 152 | expandIcon={expandIcon} |
130 | 153 | openMotion={motion} |
131 | 154 | collapsible={collapsible} |
132 | | - > |
133 | | - {panelItems} |
134 | | - </Collapse> |
| 155 | + items={panelItems} |
| 156 | + /> |
135 | 157 | </> |
136 | 158 | ); |
137 | 159 | }; |
|
0 commit comments