Skip to content

Commit

Permalink
feat: move state of sidebar visibility to the local store
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Krysiak authored and Wojciech Krysiak committed Sep 18, 2020
1 parent 6dd31d2 commit 221fcfa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
35 changes: 27 additions & 8 deletions src/frontend/components/app/sidebar/sidebar.tsx
@@ -1,6 +1,7 @@
import React from 'react'
import styled from 'styled-components'
import { useSelector } from 'react-redux'
import { Box, cssClass } from '@admin-bro/design-system'
import { Box, cssClass, themeGet } from '@admin-bro/design-system'

import { BrandingOptions } from 'src/admin-bro-options.interface'
import ResourceJSON from 'src/backend/decorators/resource-json.interface'
Expand All @@ -16,6 +17,29 @@ type Props = {
isVisible: boolean;
}

const StyledSidebar = styled(Box)`
transition: left 0.3s;
top: 0;
bottom: 0;
&.hidden {
left: -${themeGet('sizes', 'sidebarWidth')};
}
&.visible {
left: 0;
}
`

StyledSidebar.defaultProps = {
position: ['absolute', 'absolute', 'absolute', 'absolute', 'inherit'],
width: 'sidebarWidth',
borderRight: 'default',
display: 'flex',
flexDirection: 'column',
zIndex: 1000,
bg: 'white',
}

const Sidebar: React.FC<Props> = (props) => {
const { isVisible } = props
const [branding, resources, pages]: [BrandingOptions, ResourceJSON[], PageJSON[]] = useSelector(
Expand All @@ -25,21 +49,16 @@ const Sidebar: React.FC<Props> = (props) => {
)

return (
<Box
<StyledSidebar
className={isVisible ? 'visible' : 'hidden'}
position={['absolute', 'absolute', 'absolute', 'absolute', 'inherit']}
width="sidebarWidth"
borderRight="default"
display="flex"
flexDirection="column"
>
<SidebarBranding branding={branding} />
<Box flexGrow={1} className={cssClass('Resources')}>
<SidebarResourceSection resources={resources} />
</Box>
<SidebarPages pages={pages} />
{branding?.softwareBrothers && <SidebarFooter />}
</Box>
</StyledSidebar>
)
}

Expand Down
5 changes: 3 additions & 2 deletions src/frontend/components/application.tsx
@@ -1,5 +1,5 @@
/* eslint-disable react/no-children-prop */
import React, { useState } from 'react'
import React from 'react'
import { Switch, Route } from 'react-router-dom'
import { createGlobalStyle } from 'styled-components'
import { Box, Overlay, Reset } from '@admin-bro/design-system'
Expand All @@ -12,6 +12,7 @@ import Notice from './app/notice'
import {
Dashboard, ResourceAction, RecordAction, Page, BulkAction, Resource,
} from './routes'
import { useLocalStorage } from '../hooks'

const GlobalStyle = createGlobalStyle`
html, body, #app {
Expand All @@ -24,7 +25,7 @@ const GlobalStyle = createGlobalStyle`
`

const App: React.FC = () => {
const [sidebarVisible, toggleSidebar] = useState(false)
const [sidebarVisible, toggleSidebar] = useLocalStorage('sidebarVisible', false)
const h = new ViewHelpers()

const resourceId = ':resourceId'
Expand Down

0 comments on commit 221fcfa

Please sign in to comment.