From 221fcfa375f489eda94a4f5aa71529f008dcce42 Mon Sep 17 00:00:00 2001 From: Wojciech Krysiak Date: Fri, 18 Sep 2020 10:05:10 +0200 Subject: [PATCH] feat: move state of sidebar visibility to the local store --- .../components/app/sidebar/sidebar.tsx | 35 ++++++++++++++----- src/frontend/components/application.tsx | 5 +-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/frontend/components/app/sidebar/sidebar.tsx b/src/frontend/components/app/sidebar/sidebar.tsx index c14ce1b83..ad476bde4 100644 --- a/src/frontend/components/app/sidebar/sidebar.tsx +++ b/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' @@ -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) => { const { isVisible } = props const [branding, resources, pages]: [BrandingOptions, ResourceJSON[], PageJSON[]] = useSelector( @@ -25,13 +49,8 @@ const Sidebar: React.FC = (props) => { ) return ( - @@ -39,7 +58,7 @@ const Sidebar: React.FC = (props) => { {branding?.softwareBrothers && } - + ) } diff --git a/src/frontend/components/application.tsx b/src/frontend/components/application.tsx index 0e7b7258f..b7568e102 100644 --- a/src/frontend/components/application.tsx +++ b/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' @@ -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 { @@ -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'