Remove overly strict children propType validation. fixes #641
parent
0bd7eb8cb0
commit
e2ed42bd3b
|
@ -9,42 +9,11 @@ const Layout = ({ className, children, theme }) => (
|
|||
</div>
|
||||
);
|
||||
|
||||
const ALLOWED_THEMED = [
|
||||
'Themed Panel',
|
||||
'Themed NavDrawer|Themed Panel',
|
||||
'Themed NavDrawer|Themed Panel|Themed Sidebar',
|
||||
'Themed Panel|Themed Sidebar'
|
||||
];
|
||||
|
||||
function getChildName (child) {
|
||||
if (child.type) {
|
||||
return child.type.displayName || 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_THEMED.indexOf(names))) {
|
||||
return new Error(
|
||||
'`' + componentName + '` '
|
||||
+ 'should have a Panel for a child, optionally preceded by a NavDrawer and/or followed by a Sidebar.'
|
||||
);
|
||||
}
|
||||
},
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.element),
|
||||
PropTypes.element
|
||||
]),
|
||||
className: PropTypes.string,
|
||||
theme: PropTypes.shape({
|
||||
layout: PropTypes.string
|
||||
|
|
|
@ -32,32 +32,8 @@ var Layout = function Layout(_ref) {
|
|||
);
|
||||
};
|
||||
|
||||
var ALLOWED_THEMED = ['Themed Panel', 'Themed NavDrawer|Themed Panel', 'Themed NavDrawer|Themed Panel|Themed Sidebar', 'Themed Panel|Themed Sidebar'];
|
||||
|
||||
function getChildName(child) {
|
||||
if (child.type) {
|
||||
return child.type.displayName || child.type.name || child.type;
|
||||
}
|
||||
if (!child.constructor || !child.constructor.name) {
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
return child.constructor.name;
|
||||
}
|
||||
|
||||
Layout.propTypes = {
|
||||
children: function children(props, propName, componentName) {
|
||||
// Accept only [NavDrawer]Pane[Sidebar]
|
||||
var children = props[propName];
|
||||
if (_react2.default.Children.count(children) > 3) {
|
||||
return new Error('`' + componentName + '` ' + 'should have a Pane for a child, optionally preceded and/or followed by a Drawer.');
|
||||
}
|
||||
|
||||
var names = _react2.default.Children.map(children, getChildName).join('|');
|
||||
if (!~ALLOWED_THEMED.indexOf(names)) {
|
||||
return new Error('`' + componentName + '` ' + 'should have a Panel for a child, optionally preceded by a NavDrawer and/or followed by a Sidebar.');
|
||||
}
|
||||
},
|
||||
|
||||
children: _react.PropTypes.oneOfType([_react.PropTypes.arrayOf(_react.PropTypes.element), _react.PropTypes.element]),
|
||||
className: _react.PropTypes.string,
|
||||
theme: _react.PropTypes.shape({
|
||||
layout: _react.PropTypes.string
|
||||
|
|
Loading…
Reference in New Issue