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

Addon-toolbars: Show name if there is no icon #11475

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions addons/toolbars/src/components/MenuToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';
import { useGlobals } from '@storybook/api';
import { Icons, IconButton, WithTooltip, TooltipLinkList } from '@storybook/components';
import { Icons, IconButton, WithTooltip, TooltipLinkList, TabButton } from '@storybook/components';
import { NormalizedToolbarArgType } from '../types';

export type MenuToolbarProps = NormalizedToolbarArgType & { id: string };
Expand All @@ -15,6 +15,7 @@ export const MenuToolbar: FC<MenuToolbarProps> = ({
const selectedValue = globals[id];
const active = selectedValue != null;
const selectedItem = active && items.find((item) => item.value === selectedValue);
const selectedIcon = (selectedItem && selectedItem.icon) || icon;

return (
<WithTooltip
Expand All @@ -39,9 +40,13 @@ export const MenuToolbar: FC<MenuToolbarProps> = ({
}}
closeOnClick
>
<IconButton key={name} active={active} title={description}>
<Icons icon={(selectedItem && selectedItem.icon) || icon} />
</IconButton>
{selectedIcon ? (
<IconButton key={name} active={active} title={description}>
<Icons icon={selectedIcon} />
</IconButton>
) : (
<TabButton active={active}>{name}</TabButton>
)}
</WithTooltip>
);
};