forked from auth0/styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (58 loc) · 1.51 KB
/
Copy pathindex.js
File metadata and controls
63 lines (58 loc) · 1.51 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
55
56
57
58
59
60
61
62
63
import React, { cloneElement, Children, PropTypes } from 'react';
import cx from 'classnames';
const SidebarItem = ({ text, wrapper, arrow, icon, children, open }) => {
const heightMenu = (Children.count(children) * 45) - 1;
const WrapperItemChildren = () => (
<span className="menu-item-link">
{icon && <span className={`menu-item-icon icon-budicon-${icon}`} />}
<span className="text">{text}</span>
{arrow && <i className="icon-budicon-519 pull-right" />}
</span>
);
return (
<li className={`a0r-sidebar-menu-item ${open ? 'active' : ''}`}>
{cloneElement(wrapper, { children: <WrapperItemChildren /> })}
{children
? (
<ul
className={cx('menu-sublist', { 'is-opened': open })}
style={{ height: `${heightMenu}px` }}
>
{children}
</ul>
)
: null
}
</li>
);
};
SidebarItem.propTypes = {
/**
* Text of the item.
*/
text: PropTypes.string.isRequired,
/**
* Wrapper element around the inner content of the item.
*/
wrapper: PropTypes.node,
/**
* Enable arrow icon.
*/
arrow: PropTypes.bool,
/**
* Show Item with an icon from Budicon.
*/
icon: PropTypes.number,
/**
* The content of the menu. This is usually used to pass SidebarSubitem elements.
*/
children: PropTypes.node,
/**
* Controls whether the subitems are showed or not.
*/
open: PropTypes.bool
};
SidebarItem.defaultProps = {
wrapper: <span />
};
export default SidebarItem;