-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathPanelList.js
39 lines (35 loc) · 839 Bytes
/
PanelList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// @flow
import * as React from 'react';
type Props = {
children: Array<any>,
activeIndex: number,
customStyle: {
Panel: () => void
}
};
export default class PanelList extends React.PureComponent<Props> {
render() {
const {
children,
activeIndex,
customStyle
} = this.props;
if (!children || activeIndex === undefined) {
return null;
}
let props = {};
if (customStyle && customStyle.Panel) {
props = {...props, CustomPanelStyle: customStyle.Panel}
}
// to prevent the type of one children is object type
const result = React.Children.toArray(children).map((child, index) => (
React.cloneElement(child, {
key: index,
active: index === activeIndex,
index,
...props
})
));
return <div>{result}</div>
}
}