UNPKG

4.12 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import React, { Component } from 'react';
7import classnames from 'classnames';
8import PropTypes from 'prop-types';
9import ConfigProvider from '../config-provider';
10
11export default function Base(props) {
12 var _class, _temp;
13
14 var componentName = props.componentName;
15 var Shell = (_temp = _class = function (_Component) {
16 _inherits(Shell, _Component);
17
18 function Shell() {
19 _classCallCheck(this, Shell);
20
21 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
22 }
23
24 Shell.prototype.getChildContext = function getChildContext() {
25 var collapse = this.props.collapse;
26
27
28 return {
29 isCollapse: collapse
30 };
31 };
32
33 Shell.prototype.render = function render() {
34 var _classnames;
35
36 var _props = this.props,
37 prefix = _props.prefix,
38 className = _props.className,
39 miniable = _props.miniable,
40 device = _props.device,
41 direction = _props.direction,
42 children = _props.children,
43 collapse = _props.collapse,
44 triggerProps = _props.triggerProps,
45 onCollapseChange = _props.onCollapseChange,
46 component = _props.component,
47 align = _props.align,
48 fixed = _props.fixed,
49 others = _objectWithoutProperties(_props, ['prefix', 'className', 'miniable', 'device', 'direction', 'children', 'collapse', 'triggerProps', 'onCollapseChange', 'component', 'align', 'fixed']);
50
51 var Tag = component;
52
53 var cls = classnames((_classnames = {}, _classnames[prefix + 'shell-' + componentName.toLowerCase()] = true, _classnames[prefix + 'shell-collapse'] = !!collapse, _classnames[prefix + 'shell-mini'] = miniable, _classnames[prefix + 'shell-nav-' + align] = componentName === 'Navigation' && direction === 'hoz' && align, _classnames[className] = !!className, _classnames));
54
55 var newChildren = children;
56 if (componentName === 'Content') {
57 newChildren = React.createElement(
58 'div',
59 { className: prefix + 'shell-content-inner' },
60 children
61 );
62 }
63
64 if (componentName === 'Page') {
65 return children;
66 }
67
68 return React.createElement(
69 Tag,
70 _extends({ className: cls }, others),
71 newChildren
72 );
73 };
74
75 return Shell;
76 }(Component), _class.displayName = componentName, _class._typeMark = 'Shell_' + componentName, _class.propTypes = _extends({}, ConfigProvider.propTypes, {
77 prefix: PropTypes.string,
78 collapse: PropTypes.bool,
79 miniable: PropTypes.bool,
80 component: PropTypes.string,
81 trigger: PropTypes.node,
82 triggerProps: PropTypes.object,
83 direction: PropTypes.oneOf(['hoz', 'ver']),
84 align: PropTypes.oneOf(['left', 'right', 'center']),
85 /**
86 * 弹层显示或隐藏时触发的回调函数
87 * @param {Boolean} collapse 弹层是否显示
88 */
89 onCollapseChange: PropTypes.func,
90 /**
91 * 是否固定,仅对 Shell.Navigation Shell.ToolDock 生效,且需要在在 Shell fixedHeader时生效
92 */
93 fixed: PropTypes.bool
94 }), _class.defaultProps = {
95 prefix: 'next-',
96 component: 'div',
97 onCollapseChange: function onCollapseChange() {},
98 fixed: false
99 }, _class.childContextTypes = {
100 isCollapse: PropTypes.bool
101 }, _temp);
102 Shell.displayName = 'Shell';
103
104
105 return ConfigProvider.config(Shell);
106}
\No newline at end of file