forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayout.js
More file actions
54 lines (47 loc) · 1.3 KB
/
Layout.js
File metadata and controls
54 lines (47 loc) · 1.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import classnames from 'classnames';
import style from './style';
const Layout = ({ className, children }) => (
<div data-react-toolbox='layout' className={classnames(style.root, className)}>
{children}
</div>
);
const ALLOWED = [
'Panel',
'NavDrawer|Panel',
'NavDrawer|Panel|Sidebar',
'Panel|Sidebar'
];
function getChildName (child) {
if (child.type) {
return child.type.name || child.type;
}
if (!child.constructor || !child.constructor.name) {
return 'UNKNOWN';
}
return child.constructor.name;
}
Layout.propTypes = {
children (props, propName, componentName) {
// Accept only [NavDrawer]Pane[Sidebar]
const children = props[propName];
if (React.Children.count(children) > 3) {
return new Error(
'`' + componentName + '` '
+ 'should have a Pane for a child, optionally preceded and/or followed by a Drawer.'
);
}
const names = React.Children.map(children, getChildName).join('|');
if (!(~ALLOWED.indexOf(names))) {
return new Error(
'`' + componentName + '` '
+ 'should have a Panel for a child, optionally preceded by a NavDrawer and/or followed by a Sidebar.'
);
}
},
className: React.PropTypes.string
};
Layout.defaultProps = {
className: ''
};
export default Layout;