1 | # rc-collapse
|
2 |
|
3 | rc-collapse ui component for react
|
4 |
|
5 | [![NPM version][npm-image]][npm-url] [![build status][github-actions-image]][github-actions-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url]
|
6 |
|
7 | [npm-image]: http://img.shields.io/npm/v/rc-collapse.svg?style=flat-square
|
8 | [npm-url]: http://npmjs.org/package/rc-collapse
|
9 | [github-actions-image]: https://github.com/react-component/collapse/workflows/CI/badge.svg
|
10 | [github-actions-url]: https://github.com/react-component/collapse/actions
|
11 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/collapse/master.svg?style=flat-square
|
12 | [codecov-url]: https://app.codecov.io/gh/react-component/collapse
|
13 | [download-image]: https://img.shields.io/npm/dm/rc-collapse.svg?style=flat-square
|
14 | [download-url]: https://npmjs.org/package/rc-collapse
|
15 |
|
16 | ## Live Demo
|
17 |
|
18 | http://react-component.github.io/collapse/
|
19 |
|
20 | ## Install
|
21 |
|
22 | [![rc-collapse](https://nodei.co/npm/rc-collapse.png)](https://npmjs.org/package/rc-collapse)
|
23 |
|
24 | ## Usage
|
25 |
|
26 | ```js
|
27 | var Collapse = require('rc-collapse');
|
28 | var Panel = Collapse.Panel;
|
29 | var React = require('react');
|
30 | var ReactDOM = require('react-dom');
|
31 | require('rc-collapse/assets/index.css');
|
32 |
|
33 | var App = (
|
34 | <Collapse accordion={true}>
|
35 | <Panel header="hello" headerClass="my-header-class">
|
36 | this is panel content
|
37 | </Panel>
|
38 | <Panel header="title2">this is panel content2 or other</Panel>
|
39 | </Collapse>
|
40 | );
|
41 | ReactDOM.render(App, container);
|
42 | ```
|
43 |
|
44 | ## Features
|
45 |
|
46 | - support ie8,ie8+,chrome,firefox,safari
|
47 |
|
48 | ## API
|
49 |
|
50 | ### Collapse props
|
51 |
|
52 | <table class="table table-bordered table-striped">
|
53 | <thead>
|
54 | <tr>
|
55 | <th style="width: 100px;">name</th>
|
56 | <th style="width: 50px;">type</th>
|
57 | <th>default</th>
|
58 | <th>description</th>
|
59 | </tr>
|
60 | </thead>
|
61 | <tbody>
|
62 | <tr>
|
63 | <td>activeKey</td>
|
64 | <td>String|Array<String></td>
|
65 | <th>The first panel key</th>
|
66 | <td>current active Panel key</td>
|
67 | </tr>
|
68 | <tr>
|
69 | <td>className</td>
|
70 | <td>String or object</td>
|
71 | <th></th>
|
72 | <td>custom className to apply</td>
|
73 | </tr>
|
74 | <tr>
|
75 | <td>defaultActiveKey</td>
|
76 | <td>String|Array<String></td>
|
77 | <th>null</th>
|
78 | <td>default active key</td>
|
79 | </tr>
|
80 | <tr>
|
81 | <td>destroyInactivePanel</td>
|
82 | <td>Boolean</td>
|
83 | <th>false</th>
|
84 | <td>If destroy the panel which not active, default false. </td>
|
85 | </tr>
|
86 | <tr>
|
87 | <td>accordion</td>
|
88 | <td>Boolean</td>
|
89 | <th>false</th>
|
90 | <td>accordion mode, default is null, is collapse mode</td>
|
91 | </tr>
|
92 | <tr>
|
93 | <td>onChange</td>
|
94 | <td>Function(key)</td>
|
95 | <th>noop</th>
|
96 | <td>called when collapse Panel is changed</td>
|
97 | </tr>
|
98 | <tr>
|
99 | <td>expandIcon</td>
|
100 | <td>(props: PanelProps) => ReactNode</td>
|
101 | <th></th>
|
102 | <td>specific the custom expand icon.</td>
|
103 | </tr>
|
104 | <tr>
|
105 | <td>collapsible</td>
|
106 | <td>'header' | 'icon' | 'disabled'</td>
|
107 | <th>-</th>
|
108 | <td>specify whether the panel of children is collapsible or the area of collapsible.</td>
|
109 | </tr>
|
110 | <tr>
|
111 | <td>items</td>
|
112 | <td>
|
113 | <a href="./src/interface.ts#ItemType">interface.ts#ItemType</a>
|
114 | </td>
|
115 | <th>-</th>
|
116 | <td>collapse items content</td>
|
117 | </tr>
|
118 | </tbody>
|
119 | </table>
|
120 |
|
121 | If `accordion` is null or false, every panel can open. Opening another panel will not close any of the other panels. `activeKey` should be an string, if passing an array (the first item in the array will be used).
|
122 |
|
123 | If `accordion` is true, only one panel can be open. Opening another panel will cause the previously opened panel to close. `activeKey` should be an string, if passing an array (the first item in the array will be used).
|
124 |
|
125 | ### Collapse.Panel props
|
126 |
|
127 | > **deprecated** use `items` instead, will be removed in `v4.0.0`
|
128 |
|
129 | <table class="table table-bordered table-striped">
|
130 | <thead>
|
131 | <tr>
|
132 | <th style="width: 100px;">name</th>
|
133 | <th style="width: 50px;">type</th>
|
134 | <th>default</th>
|
135 | <th>description</th>
|
136 | </tr>
|
137 | </thead>
|
138 | <tbody>
|
139 | <tr>
|
140 | <td>header</td>
|
141 | <td>String or node</td>
|
142 | <th></th>
|
143 | <td>header content of Panel</td>
|
144 | </tr>
|
145 | <tr>
|
146 | <td>headerClass</td>
|
147 | <td>String</td>
|
148 | <th>' '</th>
|
149 | <td>custom className to apply to header</td>
|
150 | </tr>
|
151 | <tr>
|
152 | <td>showArrow</td>
|
153 | <td>boolean</td>
|
154 | <th>true</th>
|
155 | <td>show arrow beside header</td>
|
156 | </tr>
|
157 | <tr>
|
158 | <td>className</td>
|
159 | <td>String or object</td>
|
160 | <th></th>
|
161 | <td>custom className to apply</td>
|
162 | </tr>
|
163 | <tr>
|
164 | <td>style</td>
|
165 | <td>object</td>
|
166 | <th></th>
|
167 | <td>custom style</td>
|
168 | </tr>
|
169 | <tr>
|
170 | <td>openMotion</td>
|
171 | <td>object</td>
|
172 | <th></th>
|
173 | <td>set the animation of open behavior, [more](https://github.com/react-component/motion). Different with v2, closed pane use a `rc-collapse-content-hidden` class to set `display: none` for hidden.</td>
|
174 | </tr>
|
175 | <tr>
|
176 | <td>forceRender</td>
|
177 | <td>boolean</td>
|
178 | <th>false</th>
|
179 | <td>forced render of content in panel, not lazy render after clicking on header</td>
|
180 | </tr>
|
181 | <tr>
|
182 | <td>extra</td>
|
183 | <td>String | ReactNode</td>
|
184 | <th></th>
|
185 | <td>Content to render in the right of the panel header</td>
|
186 | </tr>
|
187 | <tr>
|
188 | <td>collapsible</td>
|
189 | <td>'header' | 'icon' | 'disabled'</td>
|
190 | <th>-</th>
|
191 | <td>specify whether the panel be collapsible or the area of collapsible.</td>
|
192 | </tr>
|
193 | </tbody>
|
194 | </table>
|
195 |
|
196 | > `disabled` is removed since 3.0.0, please use `collapsible=disabled` replace it.
|
197 |
|
198 | #### key
|
199 |
|
200 | If `key` is not provided, the panel's index will be used instead.
|
201 |
|
202 | #### KeyBoard Event
|
203 |
|
204 | By default, Collapse will listen `onKeyDown`(<3.7.0 `onKeyPress`) event with `enter` key to toggle panel's active state when `collapsible` is not `disabled`. If you want to disable this behavior, you can prevent the event from bubbling like this:
|
205 |
|
206 | ```jsx
|
207 | const App = () => {
|
208 | const items: CollapseProps['items'] = [
|
209 | {
|
210 | label: <input onKeyDown={(e) => e.stopPropagation()} />,
|
211 | children: 'content',
|
212 | },
|
213 | {
|
214 | label: (
|
215 | <div onKeyDown={(e) => e.stopPropagation()}>
|
216 | <CustomComponent />
|
217 | </div>
|
218 | ),
|
219 | children: 'content',
|
220 | },
|
221 | {
|
222 | label: 'title 2',
|
223 | children: 'content 2',
|
224 | collapsible: 'disabled',
|
225 | },
|
226 | {
|
227 | label: 'title 3',
|
228 | children: 'content 3',
|
229 | onItemClick: console.log,
|
230 | },
|
231 | ];
|
232 |
|
233 | return <Collapse items={items} />;
|
234 | };
|
235 | ```
|
236 |
|
237 | ## Development
|
238 |
|
239 | ```bash
|
240 | npm install
|
241 | npm start
|
242 | ```
|
243 |
|
244 | ## Test Case
|
245 |
|
246 | ```bash
|
247 | npm test
|
248 | ```
|
249 |
|
250 | ## Coverage
|
251 |
|
252 | ```bash
|
253 | npm test -- --coverage
|
254 | ```
|
255 |
|
256 | ## License
|
257 |
|
258 | rc-collapse is released under the MIT license.
|