Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(sidebar): toggle sidebar when in fullscreen mode
  • Loading branch information
yannbf committed Jul 1, 2021
1 parent c74836d commit 7c0170a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
8 changes: 4 additions & 4 deletions lib/api/src/modules/layout.ts
Expand Up @@ -156,14 +156,14 @@ export const init: ModuleFn = ({ store, provider, singleStory }) => {
if (singleStory) return { layout: state.layout };

const { showPanel, isFullscreen } = state.layout;
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.showNav;
const shouldToggleFullScreen = showPanel === false && value === false;
const showNav = typeof toggled !== 'undefined' ? toggled : !state.layout.showNav;
const shouldToggleFullScreen = showPanel === false && showNav === false;

return {
layout: {
...state.layout,
showNav: value,
isFullscreen: shouldToggleFullScreen ? true : isFullscreen,
showNav,
isFullscreen: shouldToggleFullScreen ? true : !showNav && isFullscreen,
},
};
},
Expand Down
33 changes: 13 additions & 20 deletions lib/ui/src/components/preview/tools/menu.tsx
Expand Up @@ -5,32 +5,25 @@ import { Addon } from '@storybook/addons';

const menuMapper = ({ api, state }: Combo) => ({
isVisible: state.layout.showNav,
toggle: api.toggleNav,
toggle: () => api.toggleNav(),
});

export const menuTool: Addon = {
title: 'menu',
id: 'menu',
match: ({ viewMode }) => viewMode === 'story',
render: () => (
<>
<Consumer filter={menuMapper}>
{({ isVisible, toggle }) =>
!isVisible && (
<>
<IconButton
aria-label="Show sidebar"
key="menu"
onClick={toggle as any}
title="Show sidebar"
>
<Icons icon="menu" />
</IconButton>
<Separator />
</>
)
}
</Consumer>
</>
<Consumer filter={menuMapper}>
{({ isVisible, toggle }) =>
!isVisible && (
<>
<IconButton aria-label="Show sidebar" key="menu" onClick={toggle} title="Show sidebar">
<Icons icon="menu" />
</IconButton>
<Separator />
</>
)
}
</Consumer>
),
};

0 comments on commit 7c0170a

Please sign in to comment.