Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Fix sidebar toggle in fullscreen mode #15459

Merged
merged 1 commit into from Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
),
};