From 8b3fdc907c76638ba40daa41d29ef48c46e9f75f Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Mon, 3 Dec 2018 16:26:43 -0200 Subject: [PATCH] fix(docz-theme-default): overlay logic --- .../src/components/shared/Sidebar/index.tsx | 28 +++++++++++-------- .../src/components/ui/Render/index.tsx | 7 ++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/docz-theme-default/src/components/shared/Sidebar/index.tsx b/packages/docz-theme-default/src/components/shared/Sidebar/index.tsx index c4e3bf333..e3064b19a 100644 --- a/packages/docz-theme-default/src/components/shared/Sidebar/index.tsx +++ b/packages/docz-theme-default/src/components/shared/Sidebar/index.tsx @@ -122,7 +122,7 @@ interface SidebarState { menus: MenuItem[] | null searching: boolean lastVal: string - showing: boolean + hidden: boolean } interface SidebarProps { @@ -134,11 +134,17 @@ class SidebarBase extends Component { lastVal: '', menus: null, searching: false, - showing: true, + hidden: true, } public componentDidUpdate(pProps: SidebarProps, pState: SidebarState): void { - if (pState.showing !== this.state.showing) { + const { isDesktop } = this.props + const { hidden } = this.state + + if (pProps.isDesktop !== isDesktop && !hidden && isDesktop) { + this.setState({ hidden: true }) + } + if (pState.hidden !== this.state.hidden) { this.addOverlayClass() } } @@ -148,7 +154,7 @@ class SidebarBase extends Component { } public render(): React.ReactNode { - const { showing } = this.state + const { hidden } = this.state return ( @@ -157,13 +163,13 @@ class SidebarBase extends Component { return ( - + - + {menus.length === 0 ? ( @@ -189,7 +195,7 @@ class SidebarBase extends Component { @@ -201,8 +207,8 @@ class SidebarBase extends Component { private addOverlayClass = () => { const { isDesktop } = this.props - const { showing } = this.state - const method = showing ? 'add' : 'remove' + const { hidden } = this.state + const method = !hidden ? 'add' : 'remove' if (window && typeof window !== 'undefined' && !isDesktop) { document.documentElement!.classList[method]('with-overlay') @@ -236,7 +242,7 @@ class SidebarBase extends Component { private handleSidebarToggle = () => { if (this.props.isDesktop) return - this.setState({ showing: !this.state.showing }) + this.setState({ hidden: !this.state.hidden }) } } diff --git a/packages/docz-theme-default/src/components/ui/Render/index.tsx b/packages/docz-theme-default/src/components/ui/Render/index.tsx index 9477d3b8e..4fc65d4f2 100644 --- a/packages/docz-theme-default/src/components/ui/Render/index.tsx +++ b/packages/docz-theme-default/src/components/ui/Render/index.tsx @@ -160,11 +160,8 @@ class RenderBase extends Component { showEditor: Boolean(this.props.showEditor), } - public componentDidUpdate( - prevProps: RenderProps, - prevState: RenderState - ): void { - if (prevState.fullscreen !== this.state.fullscreen) { + public componentDidUpdate(pProps: RenderProps, pState: RenderState): void { + if (pState.fullscreen !== this.state.fullscreen) { this.toggleBodyOverlayClass() } }