Skip to content

Commit

Permalink
Merge pull request storybookjs#15459 from storybookjs/fix/sidebar-tog…
Browse files Browse the repository at this point in the history
…gle-fullscreen

UI: Fix sidebar toggle in fullscreen mode
  • Loading branch information
shilman authored Jul 2, 2021
2 parents 79d10cd + 7c0170a commit f929ef5
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 f929ef5

Please sign in to comment.