-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSidebar.jsx
More file actions
68 lines (62 loc) · 2.01 KB
/
Sidebar.jsx
File metadata and controls
68 lines (62 loc) · 2.01 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
import React, { Fragment } from 'react'
import { NavLink as RouterLink, useLocation } from 'react-router-dom'
import { translate } from 'twake-i18n'
import CloudIcon from 'cozy-ui/transpiled/react/Icons/Cloud'
import CompassIcon from 'cozy-ui/transpiled/react/Icons/Compass'
import Nav, {
NavLink,
NavItem,
NavIcon,
NavText
} from 'cozy-ui/transpiled/react/Nav'
import Sidebar from 'cozy-ui/transpiled/react/Sidebar'
import withBreakpoints from 'cozy-ui/transpiled/react/helpers/withBreakpoints'
import config from '@/config/index.json'
import { SidebarCategories } from '@/ducks/apps/Containers'
import isNavigationEnabled from '@/lib/isNavigationEnabled'
const configMap = {
discover: {
icon: CompassIcon,
labelKey: 'nav.discover'
},
myapps: {
icon: CloudIcon,
labelKey: 'nav.myapps'
}
}
export const StoreSidebar = React.memo(({ t, breakpoints = {} }) => {
const location = useLocation()
const { isMobile, isTablet } = breakpoints
if (config.enabledPages.length === 1 && (isMobile || isTablet)) return null
if (!isNavigationEnabled(location.search)) return null
return (
<Sidebar>
<Nav>
{config.enabledPages.map(name => {
if (configMap[name]) {
return (
<Fragment key={name}>
<NavItem>
<RouterLink
to={`/${name}`}
className={({ isActive }) =>
isActive
? `${NavLink.activeClassName} ${NavLink.className}`
: NavLink.className
}
>
<NavIcon icon={configMap[name].icon} />
<NavText>{t(configMap[name].labelKey)}</NavText>
</RouterLink>
</NavItem>
<SidebarCategories parent={`/${name}`} />
</Fragment>
)
}
})}
</Nav>
</Sidebar>
)
})
StoreSidebar.displayName = 'Sidebar'
export default translate()(withBreakpoints()(StoreSidebar))