UNPKG

2.82 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _typeof from 'babel-runtime/helpers/typeof';
3import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
4import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
5import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
6import _inherits from 'babel-runtime/helpers/inherits';
7
8var _class, _temp;
9
10import React, { Component, cloneElement } from 'react';
11import PropTypes from 'prop-types';
12import cx from 'classnames';
13import Item from './item';
14
15/**
16 * Menu.Group
17 * @order 5
18 */
19var Group = (_temp = _class = function (_Component) {
20 _inherits(Group, _Component);
21
22 function Group() {
23 _classCallCheck(this, Group);
24
25 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
26 }
27
28 Group.prototype.render = function render() {
29 var _cx;
30
31 var _props = this.props,
32 root = _props.root,
33 className = _props.className,
34 label = _props.label,
35 children = _props.children,
36 parentMode = _props.parentMode,
37 others = _objectWithoutProperties(_props, ['root', 'className', 'label', 'children', 'parentMode']);
38
39 var prefix = root.props.prefix;
40
41
42 var newClassName = cx((_cx = {}, _cx[prefix + 'menu-group-label'] = true, _cx[className] = !!className, _cx));
43
44 var newChildren = children.map(function (child) {
45 var _cx2;
46
47 // to fix https://github.com/alibaba-fusion/next/issues/952
48 if (typeof child !== 'function' && (typeof child === 'undefined' ? 'undefined' : _typeof(child)) !== 'object') {
49 return child;
50 }
51 var className = child.props.className;
52
53 var newChildClassName = cx((_cx2 = {}, _cx2[prefix + 'menu-group-item'] = true, _cx2[className] = !!className, _cx2));
54
55 return cloneElement(child, {
56 parentMode: parentMode,
57 className: newChildClassName
58 });
59 });
60
61 return [React.createElement(
62 Item,
63 _extends({
64 key: 'menu-group-label',
65 className: newClassName,
66 replaceClassName: true,
67 root: root,
68 parentMode: parentMode
69 }, others),
70 label
71 )].concat(newChildren);
72 };
73
74 return Group;
75}(Component), _class.menuChildType = 'group', _class.propTypes = {
76 root: PropTypes.object,
77 className: PropTypes.string,
78 /**
79 * 标签内容
80 */
81 label: PropTypes.node,
82 /**
83 * 菜单项
84 */
85 children: PropTypes.node,
86 parentMode: PropTypes.oneOf(['inline', 'popup'])
87}, _temp);
88Group.displayName = 'Group';
89export { Group as default };
\No newline at end of file