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: Button for toggling addons panel #17714

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
3 changes: 2 additions & 1 deletion lib/ui/src/components/preview/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PreviewProps } from './utils/types';
import { copyTool } from './tools/copy';
import { ejectTool } from './tools/eject';
import { menuTool } from './tools/menu';
import { addonsTool } from './tools/addons';

export const getTools = (getFn: API['getElements']) => Object.values(getFn<Addon>(types.TOOL));

Expand Down Expand Up @@ -108,7 +109,7 @@ export const createTabsTool = (tabs: Addon[]): Addon => ({
});

export const defaultTools: Addon[] = [zoomTool];
export const defaultToolsExtra: Addon[] = [fullScreenTool, ejectTool, copyTool];
export const defaultToolsExtra: Addon[] = [addonsTool, fullScreenTool, ejectTool, copyTool];

const useTools = (
getElements: API['getElements'],
Expand Down
31 changes: 31 additions & 0 deletions lib/ui/src/components/preview/tools/addons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { IconButton, Icons } from '@storybook/components';
import { Consumer, Combo } from '@storybook/api';
import { Addon } from '@storybook/addons';

const menuMapper = ({ api, state }: Combo) => ({
isVisible: state.layout.showPanel,
singleStory: state.singleStory,
panelPosition: state.layout.panelPosition,
toggle: () => api.togglePanel(),
});

export const addonsTool: Addon = {
title: 'addons',
id: 'addons',
match: ({ viewMode }) => viewMode === 'story',
render: () => (
<Consumer filter={menuMapper}>
{({ isVisible, toggle, singleStory, panelPosition }) =>
!singleStory &&
!isVisible && (
<>
<IconButton aria-label="Show addons" key="addons" onClick={toggle} title="Show addons">
<Icons icon={panelPosition === 'bottom' ? 'bottombar' : 'sidebaralt'} />
</IconButton>
</>
)
}
</Consumer>
),
};