-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
36 lines (32 loc) · 1.03 KB
/
index.js
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
/** @jsx jsx */
import React, { useState } from 'react';
import { Global } from '@emotion/core';
import { jsx, Box } from 'theme-ui';
import { useMenus } from 'docz';
import { groupBy } from 'lodash';
import * as styles from './styles';
import { NavLink } from '../NavLink';
export const Sidebar = React.forwardRef((props, ref) => {
const [query] = useState('');
const menus = useMenus({ query });
const menuGroups = groupBy(menus, 'parent');
return (
<>
<Box onClick={props.onClick} sx={styles.overlay(props)}>
{props.open && <Global styles={styles.global} />}
</Box>
<Box ref={ref} sx={styles.wrapper(props)} data-testid="sidebar">
{Object.entries(menuGroups).map(([parent, menuItems]) => (
<div key={parent}>
<div sx={styles.menuHeader}>{parent}</div>
{menuItems.map(menuItem => (
<NavLink key={menuItem.id} item={menuItem}>
{menuItem.name}
</NavLink>
))}
</div>
))}
</Box>
</>
);
});