Skip to content

Commit

Permalink
Merge pull request #11564 from storybookjs/fix/color-border-in-menu
Browse files Browse the repository at this point in the history
FIX the color of the menu separator
  • Loading branch information
ndelangen authored Jul 20, 2020
2 parents 526e0d2 + e4f25c4 commit 661e915
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
73 changes: 57 additions & 16 deletions lib/ui/src/components/sidebar/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,64 @@
import React from 'react';
import React, { Fragment, FunctionComponent } from 'react';

import { TooltipLinkList } from '@storybook/components';
import { MenuItemIcon } from './Menu';
import { WithTooltip, TooltipLinkList, Icons } from '@storybook/components';
import { styled } from '@storybook/theming';
import { MenuItemIcon, SidebarMenu, MenuButton, SidebarMenuList } from './Menu';
import { useMenu } from '../../containers/menu';

export default {
component: MenuItemIcon,
title: 'UI/Sidebar/Menu',
decorators: [
(StoryFn: FunctionComponent) => (
<Fragment>
<StoryFn />
</Fragment>
),
],
};

export const all = () => (
<TooltipLinkList
links={[
{ title: 'has icon', left: <MenuItemIcon icon="check" />, id: 'icon' },
{
title: 'has imgSrc',
left: <MenuItemIcon imgSrc="https://via.placeholder.com/20" />,
id: 'img',
},
{ title: 'has neither', left: <MenuItemIcon />, id: 'non' },
]}
/>
);
const fakemenu = [
{ title: 'has icon', left: <MenuItemIcon icon="check" />, id: 'icon' },
{
title: 'has imgSrc',
left: <MenuItemIcon imgSrc="https://via.placeholder.com/20" />,
id: 'img',
},
{ title: 'has neither', left: <MenuItemIcon />, id: 'non' },
];

export const Items = () => <TooltipLinkList links={fakemenu} />;

export const Real = () => <SidebarMenu menu={fakemenu} isHighlighted />;

const DoubleThemeRenderingHack = styled.div({
'#root > div:first-child > &': {
textAlign: 'right',
},
});

export const Expanded = () => {
const menu = useMenu(
// @ts-ignore
{ getShortcutKeys: () => ({}), versionUpdateAvailable: () => false },
false,
false,
false,
false
);
return (
<DoubleThemeRenderingHack>
<WithTooltip
placement="top"
trigger="click"
closeOnClick
startOpen
tooltip={({ onHide }) => <SidebarMenuList onHide={onHide} menu={menu} />}
>
<MenuButton outline small containsIcon highlighted={false} title="Shortcuts">
<Icons icon="ellipsis" />
</MenuButton>
</WithTooltip>
</DoubleThemeRenderingHack>
);
};
4 changes: 2 additions & 2 deletions lib/ui/src/components/sidebar/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const MenuItemIcon = ({ icon, imgSrc }: ListItemIconProps) => {
return <Placeholder />;
};

const MenuButton = styled(Button)<MenuButtonProps>(({ highlighted, theme }) => ({
export const MenuButton = styled(Button)<MenuButtonProps>(({ highlighted, theme }) => ({
position: 'relative',
overflow: 'visible',
padding: 7,
Expand All @@ -62,7 +62,7 @@ const MenuButton = styled(Button)<MenuButtonProps>(({ highlighted, theme }) => (

type ClickHandler = ComponentProps<typeof TooltipLinkList>['links'][number]['onClick'];

const SidebarMenuList: FunctionComponent<{
export const SidebarMenuList: FunctionComponent<{
menu: MenuList;
onHide: () => void;
}> = ({ menu, onHide }) => {
Expand Down
9 changes: 6 additions & 3 deletions lib/ui/src/containers/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo } from 'react';

import { Badge } from '@storybook/components';
import { API } from '@storybook/api';
import { color } from '@storybook/theming';
import { useTheme, Theme } from '@storybook/theming';

import { shortcutToHumanString } from '@storybook/api/shortcut';
import { MenuItemIcon } from '../components/sidebar/Menu';
Expand All @@ -23,6 +23,7 @@ export const useMenu = (
showNav: boolean,
enableShortcuts: boolean
) => {
const theme = useTheme<Theme>();
const shortcutKeys = api.getShortcutKeys();

const about = useMemo(
Expand Down Expand Up @@ -53,7 +54,9 @@ export const useMenu = (
onClick: () => api.navigateToSettingsPage('/settings/shortcuts'),
right: shortcutToHumanStringIfEnabled(shortcutKeys.shortcutsPage, enableShortcuts),
left: <MenuItemIcon />,
style: { borderBottom: `4px solid ${color.mediumlight}` },
style: {
borderBottom: `4px solid ${theme.appBorderColor}`,
},
}),
[api, shortcutToHumanStringIfEnabled, enableShortcuts, shortcutKeys]
);
Expand Down Expand Up @@ -162,7 +165,7 @@ export const useMenu = (
id: 'collapse',
title: 'Collapse all',
onClick: () => api.collapseAll(),
right: shortcutToHumanString(shortcutKeys.collapseAll),
right: enableShortcuts ? shortcutToHumanString(shortcutKeys.collapseAll) : '',
left: <MenuItemIcon />,
}),
[api, shortcutToHumanStringIfEnabled, enableShortcuts, shortcutKeys]
Expand Down

0 comments on commit 661e915

Please sign in to comment.