forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.jsx
60 lines (53 loc) · 1.52 KB
/
group.jsx
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
55
56
57
58
59
60
import React, { Component, cloneElement } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Item from './item';
/**
* Menu.Group
* @order 5
*/
export default class Group extends Component {
static menuChildType = 'group';
static propTypes = {
root: PropTypes.object,
className: PropTypes.string,
/**
* 标签内容
*/
label: PropTypes.node,
/**
* 菜单项
*/
children: PropTypes.node,
parentMode: PropTypes.oneOf(['inline', 'popup']),
}
render() {
const { root, className, label, children, parentMode, ...others } = this.props;
const { prefix } = root.props;
const newClassName = cx({
[`${prefix}menu-group-label`]: true,
[className]: !!className
});
const newChildren = children.map(child => {
const { className } = child.props;
const newChildClassName = cx({
[`${prefix}menu-group-item`]: true,
[className]: !!className
});
return cloneElement(child, {
parentMode,
className: newChildClassName
});
});
return [
<Item
key="menu-group-label"
className={newClassName}
replaceClassName
root={root}
parentMode={parentMode}
{...others}>{label}</Item>,
...newChildren
];
}
}