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

fix(menu): active state for iconbutton #21666

Merged
merged 1 commit into from
Mar 22, 2023
Merged
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
86 changes: 49 additions & 37 deletions code/ui/manager/src/components/sidebar/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentProps, FC } from 'react';
import React, { useMemo } from 'react';
import React, { useMemo, useState } from 'react';

import { styled } from '@storybook/theming';
import { transparentize } from 'polished';
Expand All @@ -20,43 +20,48 @@ const Icon = styled(Icons)(sharedStyles, ({ theme }) => ({
color: theme.color.secondary,
}));

export const SidebarIconButton: FC<ComponentProps<typeof Button> & { highlighted: boolean }> =
styled(IconButton)<
ComponentProps<typeof Button> & {
highlighted: boolean;
}
>(({ highlighted, theme }) => ({
position: 'relative',
overflow: 'visible',
color: theme.textMutedColor,
marginTop: 0,
zIndex: 1,
export const SidebarIconButton: FC<
ComponentProps<typeof Button> & { highlighted: boolean; active: boolean }
> = styled(IconButton)<
ComponentProps<typeof Button> & {
highlighted: boolean;
active: boolean;
}
>(({ highlighted, active, theme }) => ({
position: 'relative',
overflow: 'visible',
color: theme.textMutedColor,
marginTop: 0,
zIndex: 1,

...(highlighted && {
'&:before, &:after': {
content: '""',
position: 'absolute',
top: 6,
right: 6,
width: 5,
height: 5,
zIndex: 2,
borderRadius: '50%',
background: theme.background.app,
border: `1px solid ${theme.background.app}`,
boxShadow: `0 0 0 2px ${theme.background.app}`,
},
'&:after': {
background: theme.color.positive,
border: `1px solid rgba(0, 0, 0, 0.1)`,
boxShadow: `0 0 0 2px ${theme.background.app}`,
},
...(highlighted && {
'&:before, &:after': {
content: '""',
position: 'absolute',
top: 6,
right: 6,
width: 5,
height: 5,
zIndex: 2,
borderRadius: '50%',
background: theme.background.app,
border: `1px solid ${theme.background.app}`,
boxShadow: `0 0 0 2px ${theme.background.app}`,
},
'&:after': {
background: theme.color.positive,
border: `1px solid rgba(0, 0, 0, 0.1)`,
boxShadow: `0 0 0 2px ${theme.background.app}`,
},

'&:hover:after, &:focus-visible:after': {
boxShadow: `0 0 0 2px ${transparentize(0.88, theme.color.secondary)}`,
},
}),
}));
'&:hover:after, &:focus-visible:after': {
boxShadow: `0 0 0 2px ${transparentize(0.88, theme.color.secondary)}`,
},
}),
...(active && {
color: theme.color.secondary,
}),
}));

const Img = styled.img(sharedStyles);
const Placeholder = styled.div(sharedStyles);
Expand Down Expand Up @@ -104,13 +109,20 @@ export const SidebarMenu: FC<{
menu: MenuList;
isHighlighted?: boolean;
}> = ({ menu, isHighlighted }) => {
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
return (
<WithTooltip
placement="top"
closeOnOutsideClick
tooltip={({ onHide }) => <SidebarMenuList onHide={onHide} menu={menu} />}
onVisibleChange={setIsTooltipVisible}
>
<SidebarIconButton title="Shortcuts" aria-label="Shortcuts" highlighted={isHighlighted}>
<SidebarIconButton
title="Shortcuts"
aria-label="Shortcuts"
highlighted={isHighlighted}
active={isTooltipVisible}
>
<Icons icon="cog" />
</SidebarIconButton>
</WithTooltip>
Expand Down