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
73 lines (68 loc) · 2.05 KB
/
Copy pathindex.js
File metadata and controls
73 lines (68 loc) · 2.05 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
64
65
66
67
68
69
70
71
72
73
import React, { Children, PropTypes } from 'react';
import cx from 'classnames';
/**
* Sidebar: Styleguide sidebar with drop drown sections.
*/
const Sidebar = ({ children, header, mobileNavOpen, toggleNavOnClick }) => {
// TODO: 57px is the height of SidebarItem.
// Get the height from a json file generated with:
// https://github.com/nahody/postcss-export-vars
const heightMenu = Children.count(children) * 57;
return (
<div className="a0r-sidebar">
<header className="a0r-sidebar-header">
{header || (
<h1 className="default-title">
<a className="default-link" href="/">
<img
src="https://cdn.auth0.com/styleguide/latest/img/badge.svg"
alt="Auth0 logo"
width="30"
/>
</a>
</h1>
)}
<button
type="button"
className={cx('menu-toggle', { 'is-close': mobileNavOpen })}
onClick={toggleNavOnClick}
>
<span className="sr-only">Toggle navigation</span>
<span className="icon-bar" />
<span className="icon-bar" />
<span className="icon-bar" />
<span className="icon-bar" />
</button>
</header>
<nav className="a0r-sidebar-menu">
<ul
className={cx('menu-list', { 'is-opened': mobileNavOpen })}
style={{ height: `${heightMenu}px` }}
>{children}</ul>
</nav>
</div>
);
};
Sidebar.propTypes = {
/**
* Element to replace the default header content.
*/
header: PropTypes.node,
/**
* The content of the menu. This is usually used to pass SidebarItem and SidebarSubitem elements.
*/
children: PropTypes.node.isRequired,
/**
* Controls whether the navigation is opened or not, only used for mobile.
*/
mobileNavOpen: PropTypes.bool,
/**
* Callback fired when on mobile the Toggle Navigation button is pressed.
*/
toggleNavOnClick: PropTypes.func
};
Sidebar.defaultProps = {
open: false,
toggleNavOnClick: () => {}
};
export default Sidebar;