Skip to content

Commit

Permalink
Fix hover behavior and search view
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Aug 1, 2024
1 parent 81b6775 commit c6ebc2c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 69 deletions.
7 changes: 5 additions & 2 deletions code/core/src/manager/components/sidebar/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { matchesKeyCode, matchesModifiers } from '../../keybinding';

import { statusMapping } from '../../utils/status';
import { UseSymbol } from './IconSymbols';
import { StatusLabel } from './StatusButton';

const { document } = global;

Expand All @@ -31,6 +32,7 @@ const ResultRow = styled.li<{ isHighlighted: boolean }>(({ theme, isHighlighted
cursor: 'pointer',
display: 'flex',
alignItems: 'start',
justifyContent: 'space-between',
textAlign: 'left',
color: 'inherit',
fontSize: `${theme.typography.size.s2}px`,
Expand All @@ -54,6 +56,7 @@ const IconWrapper = styled.div({
});

const ResultRowContent = styled.div({
flex: 1,
display: 'flex',
flexDirection: 'column',
});
Expand Down Expand Up @@ -181,7 +184,7 @@ const Result: FC<
const nameMatch = matches.find((match: Match) => match.key === 'name');
const pathMatches = matches.filter((match: Match) => match.key === 'path');

const [i] = item.status ? statusMapping[item.status] : [];
const [icon] = item.status ? statusMapping[item.status] : [];

return (
<ResultRow {...props} onClick={click}>
Expand Down Expand Up @@ -216,7 +219,7 @@ const Result: FC<
))}
</Path>
</ResultRowContent>
{item.status ? i : null}
{item.status ? <StatusLabel status={item.status}>{icon}</StatusLabel> : null}
</ResultRow>
);
});
Expand Down
63 changes: 63 additions & 0 deletions code/core/src/manager/components/sidebar/StatusButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { Theme } from '@emotion/react';
import { IconButton } from '@storybook/core/components';
import { styled } from '@storybook/core/theming';
import type { API_StatusValue } from '@storybook/types';
import { transparentize } from 'polished';

const withStatusColor = ({ theme, status }: { theme: Theme; status: API_StatusValue }) => {
const defaultColor =
theme.base === 'light'
? transparentize(0.3, theme.color.defaultText)
: transparentize(0.6, theme.color.defaultText);

return {
color: {
pending: defaultColor,
success: theme.color.positive,
error: theme.color.negative,
warn: theme.color.warning,
unknown: defaultColor,
}[status],
};
};

export const StatusLabel = styled.div<{ status: API_StatusValue }>(withStatusColor, {
margin: 3,
});

export const StatusButton = styled(IconButton)<{
height?: number;
width?: number;
status: API_StatusValue;
selectedItem?: boolean;
}>(
withStatusColor,
({ theme, height, width }) => ({
transition: 'none',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
width: width || 28,
height: height || 28,

'&:hover': {
color: theme.color.secondary,
},

'&:focus': {
color: theme.color.secondary,
borderColor: theme.color.secondary,

'&:not(:focus-visible)': {
borderColor: 'transparent',
},
},
}),
({ theme, selectedItem }) =>
selectedItem && {
'&:hover': {
boxShadow: `inset 0 0 0 2px ${theme.color.secondary}`,
background: 'rgba(255, 255, 255, 0.2)',
},
}
);
66 changes: 10 additions & 56 deletions code/core/src/manager/components/sidebar/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,62 +43,13 @@ import { useLayout } from '../layout/LayoutProvider';
import { IconSymbols, UseSymbol } from './IconSymbols';
import { CollapseIcon } from './components/CollapseIcon';
import { StatusContext, useStatusSummary } from './StatusContext';
import { StatusButton } from './StatusButton';

const Container = styled.div<{ hasOrphans: boolean }>((props) => ({
marginTop: props.hasOrphans ? 20 : 0,
marginBottom: 20,
}));

export const Action = styled(IconButton)<{
height?: number;
width?: number;
status: API_StatusValue;
selectedItem?: boolean;
}>(
({ theme, height, width, status }) => {
const defaultColor =
theme.base === 'light'
? transparentize(0.3, theme.color.defaultText)
: transparentize(0.6, theme.color.defaultText);

return {
transition: 'none',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
width: width || 28,
height: height || 28,
color: {
pending: defaultColor,
success: theme.color.positive,
error: theme.color.negative,
warn: theme.color.warning,
unknown: defaultColor,
}[status],

'&:hover': {
color: theme.color.secondary,
},

'&:focus': {
color: theme.color.secondary,
borderColor: theme.color.secondary,

'&:not(:focus-visible)': {
borderColor: 'transparent',
},
},
};
},
({ theme, selectedItem }) =>
selectedItem && {
'&:hover': {
boxShadow: `inset 0 0 0 2px ${theme.color.secondary}`,
background: 'rgba(255, 255, 255, 0.2)',
},
}
);

const CollapseButton = styled.button(({ theme }) => ({
all: 'unset',
display: 'flex',
Expand Down Expand Up @@ -126,6 +77,11 @@ export const LeafNodeStyleWrapper = styled.div(({ theme }) => ({
minHeight: 28,
borderRadius: 4,

'&:hover, &:focus': {
background: transparentize(0.93, theme.color.secondary),
outline: 'none',
},

'&[data-selected="true"]': {
color: theme.color.lightest,
background: theme.color.secondary,
Expand Down Expand Up @@ -249,7 +205,6 @@ const Node = React.memo<NodeProps>(function Node({
closeOnOutsideClick
onClick={(event) => event.stopPropagation()}
placement="bottom"
style={{ position: 'absolute', right: 0, top: 0 }}
tooltip={() => (
<TooltipLinkList
links={Object.entries(status || {})
Expand All @@ -275,9 +230,9 @@ const Node = React.memo<NodeProps>(function Node({
/>
)}
>
<Action type="button" status={statusValue} selectedItem={isSelected}>
<StatusButton type="button" status={statusValue} selectedItem={isSelected}>
{icon}
</Action>
</StatusButton>
</WithTooltip>
) : null}
</LeafNodeStyleWrapper>
Expand Down Expand Up @@ -406,14 +361,13 @@ const Node = React.memo<NodeProps>(function Node({
closeOnOutsideClick
onClick={(event) => event.stopPropagation()}
placement="bottom"
style={{ position: 'absolute', right: 0, top: 0 }}
tooltip={({ onHide }) => <TooltipLinkList links={createLinks(onHide)} />}
>
<Action type="button" status={itemStatus}>
<StatusButton type="button" status={itemStatus}>
<svg key="icon" viewBox="0 0 6 6" width="6" height="6" type="dot">
<UseSymbol type="dot" />
</svg>
</Action>
</StatusButton>
</WithTooltip>
)}
</LeafNodeStyleWrapper>
Expand Down
11 changes: 0 additions & 11 deletions code/core/src/manager/components/sidebar/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ const BranchNode = styled.button<{
gap: 6,
paddingTop: 5,
paddingBottom: 4,

'&:hover, &:focus': {
background: transparentize(0.93, theme.color.secondary),
outline: 'none',
},
}));

const LeafNode = styled.a<{ depth?: number }>(({ theme, depth = 0 }) => ({
Expand All @@ -61,17 +56,11 @@ const LeafNode = styled.a<{ depth?: number }>(({ theme, depth = 0 }) => ({
paddingLeft: `${22 + depth * 18}px`,
paddingTop: 5,
paddingBottom: 4,
paddingRight: 28,
fontSize: `${theme.typography.size.s2}px`,
textDecoration: 'none',
overflowWrap: 'break-word',
wordWrap: 'break-word',
wordBreak: 'break-word',

'&:hover, &:focus': {
background: transparentize(0.93, theme.color.secondary),
outline: 'none',
},
}));

export const RootNode = styled.div(({ theme }) => ({
Expand Down

0 comments on commit c6ebc2c

Please sign in to comment.