Skip to content

Commit

Permalink
Merge pull request #25822 from storybookjs/charles-fix-toolbars-icons
Browse files Browse the repository at this point in the history
UI: Update deprecated Icons with the new @storybook/icons in addons
  • Loading branch information
cdedreuille authored Feb 8, 2024
2 parents ea81001 + 404365b commit a4c7fd0
Show file tree
Hide file tree
Showing 38 changed files with 274 additions and 227 deletions.
2 changes: 1 addition & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
Expand Down
8 changes: 2 additions & 6 deletions code/addons/a11y/src/components/Report/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Fragment, useState } from 'react';

import { styled } from '@storybook/theming';
import { Icons } from '@storybook/components';

import type { Result } from 'axe-core';
import { Info } from './Info';
Expand All @@ -11,6 +10,7 @@ import { Tags } from './Tags';

import type { RuleType } from '../A11YPanel';
import HighlightToggle from './HighlightToggle';
import { ChevronSmallDownIcon } from '@storybook/icons';

const Wrapper = styled.div(({ theme }) => ({
display: 'flex',
Expand All @@ -21,10 +21,7 @@ const Wrapper = styled.div(({ theme }) => ({
},
}));

const Icon = styled(Icons)({
height: 10,
width: 10,
minWidth: 10,
const Icon = styled(ChevronSmallDownIcon)({
marginRight: 10,
transition: 'transform 0.1s ease-in-out',
verticalAlign: 'inherit',
Expand Down Expand Up @@ -75,7 +72,6 @@ export const Item = (props: ItemProps) => {
<Wrapper>
<HeaderBar onClick={() => onToggle(!open)} role="button">
<Icon
icon="arrowdown"
style={{
transform: `rotate(${open ? 0 : -90}deg)`,
}}
Expand Down
2 changes: 1 addition & 1 deletion code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"devDependencies": {
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@storybook/components": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/instrumenter": "workspace:*",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
Expand Down
8 changes: 2 additions & 6 deletions code/addons/interactions/src/components/List.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment, useState } from 'react';
import { styled, themes, convert } from '@storybook/theming';
import { Icons, type IconsProps } from '@storybook/components';
import { ChevronSmallDownIcon } from '@storybook/icons';

const ListWrapper = styled.ul({
listStyle: 'none',
Expand All @@ -18,10 +18,7 @@ const Wrapper = styled.div({
},
});

const Icon = styled(Icons)<IconsProps>({
height: 10,
width: 10,
minWidth: 10,
const Icon = styled(ChevronSmallDownIcon)({
color: convert(themes.light).textMutedColor,
marginRight: 10,
transition: 'transform 0.1s ease-in-out',
Expand Down Expand Up @@ -68,7 +65,6 @@ export const ListItem: React.FC<ListItemProps> = ({ item }) => {
<Wrapper>
<HeaderBar onClick={() => onToggle(!open)} role="button">
<Icon
icon="arrowdown"
color={convert(themes.light).appBorderColor}
style={{
transform: `rotate(${open ? 0 : -90}deg)`,
Expand Down
71 changes: 32 additions & 39 deletions code/addons/interactions/src/components/StatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
import React from 'react';
import { Icons, type IconsProps } from '@storybook/components';
import { type Call, CallStates } from '@storybook/instrumenter';
import { styled } from '@storybook/theming';
import { styled, useTheme } from '@storybook/theming';

import { transparentize } from 'polished';
import localTheme from '../theme';
import { CheckIcon, CircleIcon, PlayIcon, StopAltIcon } from '@storybook/icons';

export interface StatusIconProps {
status: Call['status'];
useSymbol?: IconsProps['useSymbol'];
className?: string;
}

const {
colors: {
pure: { gray },
},
} = localTheme;

const StyledStatusIcon = styled(Icons)<StatusIconProps>(({ theme, status }) => {
const color = {
[CallStates.DONE]: theme.color.positive,
[CallStates.ERROR]: theme.color.negative,
[CallStates.ACTIVE]: theme.color.secondary,
[CallStates.WAITING]: transparentize(0.5, gray[500]),
}[status];
return {
width: status === CallStates.WAITING ? 6 : 12,
height: status === CallStates.WAITING ? 6 : 12,
color,
justifySelf: 'center',
};
const WarningContainer = styled.div({
width: 14,
height: 14,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
});

export const StatusIcon: React.FC<StatusIconProps> = ({ status, className }) => {
const icon = {
[CallStates.DONE]: 'check',
[CallStates.ERROR]: 'stopalt',
[CallStates.ACTIVE]: 'play',
[CallStates.WAITING]: 'circle',
}[status] as IconsProps['icon'];
return (
<StyledStatusIcon
data-testid={`icon-${status}`}
status={status}
icon={icon}
className={className}
/>
);
export const StatusIcon: React.FC<StatusIconProps> = ({ status }) => {
const theme = useTheme();

switch (status) {
case CallStates.DONE: {
return <CheckIcon color={theme.color.positive} data-testid="icon-done" />;
}
case CallStates.ERROR: {
return <StopAltIcon color={theme.color.negative} data-testid="icon-error" />;
}
case CallStates.ACTIVE: {
return <PlayIcon color={theme.color.secondary} data-testid="icon-active" />;
}
case CallStates.WAITING: {
return (
<WarningContainer data-testid="icon-waiting">
<CircleIcon color={transparentize(0.5, '#CCCCCC')} size={6} />
</WarningContainer>
);
}
default: {
return null;
}
}
};
1 change: 1 addition & 0 deletions code/addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
Expand Down
8 changes: 2 additions & 6 deletions code/addons/jest/src/components/Result.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Fragment, useState } from 'react';
import { styled, themes, convert } from '@storybook/theming';
import { Icons } from '@storybook/components';
// eslint-disable-next-line import/no-named-as-default
import Message from './Message';
import { ChevronSmallDownIcon } from '@storybook/icons';

const Wrapper = styled.div<{ status: string }>(({ theme, status }) => ({
display: 'flex',
Expand Down Expand Up @@ -30,10 +30,7 @@ const HeaderBar = styled.div<{ status: string }>(({ theme, status }) => ({
},
}));

const Icon = styled(Icons)(({ theme }) => ({
height: 10,
width: 10,
minWidth: 10,
const Icon = styled(ChevronSmallDownIcon)(({ theme }) => ({
color: theme.textMutedColor,
marginRight: 10,
transition: 'transform 0.1s ease-in-out',
Expand Down Expand Up @@ -66,7 +63,6 @@ export function Result(props: ResultProps) {
<HeaderBar onClick={onToggle} role="button" status={status}>
{status === `failed` ? (
<Icon
icon="arrowdown"
color={convert(themes.light).textMutedColor}
style={{
transform: `rotate(${isOpen ? 0 : -90}deg)`,
Expand Down
2 changes: 1 addition & 1 deletion code/addons/measure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/types": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/outline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/types": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/themes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
Expand Down
6 changes: 5 additions & 1 deletion code/addons/toolbars/src/components/ToolbarMenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ interface ToolbarMenuButtonProps {
onClick?: () => void;
}

// We can't remove the Icons component just yet because there's no way for now to import icons
// in the preview directly. Before having a better solution, we are going to keep the Icons component
// for now and remove the deprecated warning.

export const ToolbarMenuButton: FC<ToolbarMenuButtonProps> = ({
active,
title,
Expand All @@ -19,7 +23,7 @@ export const ToolbarMenuButton: FC<ToolbarMenuButtonProps> = ({
}) => {
return (
<IconButton active={active} title={description} onClick={onClick}>
{icon && <Icons icon={icon} />}
{icon && <Icons icon={icon} __suppressDeprecationWarning={true} />}
{title ? `\xa0${title}` : null}
</IconButton>
);
Expand Down
2 changes: 1 addition & 1 deletion code/addons/viewport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@storybook/components": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion code/ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
useTheme,
} from '@storybook/theming';
import { useArgs, DocsContext as DocsContextProps } from '@storybook/preview-api';
import { Symbols } from '@storybook/components';
import type { PreviewWeb } from '@storybook/preview-api';
import type { ReactRenderer } from '@storybook/react';
import type { Channel } from '@storybook/channels';
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@storybook/csf": "^0.1.2",
"@storybook/docs-tools": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.3",
"@storybook/icons": "^1.2.5",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
Expand Down
14 changes: 8 additions & 6 deletions code/ui/blocks/src/components/ArgsTable/ArgValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React, { useState } from 'react';
import memoize from 'memoizerific';
import uniq from 'lodash/uniq.js';
import { styled } from '@storybook/theming';
import { WithTooltipPure, Icons, SyntaxHighlighter, codeCommon } from '@storybook/components';
import { WithTooltipPure, SyntaxHighlighter, codeCommon } from '@storybook/components';
import type { PropSummaryValue } from './types';
import { ChevronSmallDownIcon, ChevronSmallUpIcon } from '@storybook/icons';

interface ArgValueProps {
value?: PropSummaryValue;
Expand Down Expand Up @@ -86,10 +87,11 @@ const Detail = styled.div<{ width: string }>(({ theme, width }) => ({
},
}));

const ArrowIcon = styled(Icons)({
height: 10,
width: 10,
minWidth: 10,
const ChevronUpIcon = styled(ChevronSmallUpIcon)({
marginLeft: 4,
});

const ChevronDownIcon = styled(ChevronSmallDownIcon)({
marginLeft: 4,
});

Expand Down Expand Up @@ -176,7 +178,7 @@ const ArgSummary: FC<ArgSummaryProps> = ({ value, initialExpandedArgs }) => {
>
<Expandable className="sbdocs-expandable">
<span>{summaryAsString}</span>
<ArrowIcon icon={isOpen ? 'arrowup' : 'arrowdown'} />
{isOpen ? <ChevronUpIcon /> : <ChevronDownIcon />}
</Expandable>
</WithTooltipPure>
);
Expand Down
21 changes: 17 additions & 4 deletions code/ui/blocks/src/components/ArgsTable/SectionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FC } from 'react';
import React, { useState } from 'react';
import { transparentize, lighten } from 'polished';
import { styled } from '@storybook/theming';
import { Icons } from '@storybook/components';
import { ChevronDownIcon, ChevronRightIcon } from '@storybook/icons';

type Level = 'section' | 'subsection';

Expand All @@ -14,7 +14,21 @@ export interface SectionRowProps {
colSpan: number;
}

const ExpanderIcon = styled(Icons)(({ theme }) => ({
const ExpanderIconDown = styled(ChevronDownIcon)(({ theme }) => ({
marginRight: 8,
marginLeft: -10,
marginTop: -2, // optical alignment
height: 12,
width: 12,
color:
theme.base === 'light'
? transparentize(0.25, theme.color.defaultText)
: transparentize(0.3, theme.color.defaultText),
border: 'none',
display: 'inline-block',
}));

const ExpanderIconRight = styled(ChevronRightIcon)(({ theme }) => ({
marginRight: 8,
marginLeft: -10,
marginTop: -2, // optical alignment
Expand Down Expand Up @@ -100,7 +114,6 @@ export const SectionRow: FC<SectionRowProps> = ({
// @ts-expect-error (Converted from ts-ignore)
const itemCount = children?.length || 0;
const caption = level === 'subsection' ? `${itemCount} item${itemCount !== 1 ? 's' : ''}` : '';
const icon = expanded ? 'arrowdown' : 'arrowright';

const helperText = `${expanded ? 'Hide' : 'Show'} ${
level === 'subsection' ? itemCount : label
Expand All @@ -114,7 +127,7 @@ export const SectionRow: FC<SectionRowProps> = ({
{helperText}
</ClickIntercept>
<FlexWrapper>
<ExpanderIcon icon={icon} />
{expanded ? <ExpanderIconDown /> : <ExpanderIconRight />}
{label}
</FlexWrapper>
</Level>
Expand Down
10 changes: 5 additions & 5 deletions code/ui/blocks/src/components/IconGallery.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Icons as ExampleIcon } from '@storybook/components';
import { IconItem, IconGallery } from './IconGallery';
import { AddIcon, FaceHappyIcon, HomeIcon, SubtractIcon } from '@storybook/icons';

export default {
component: IconGallery,
Expand All @@ -9,16 +9,16 @@ export default {
export const DefaultStyle = () => (
<IconGallery>
<IconItem name="add">
<ExampleIcon icon="add" />
<AddIcon />
</IconItem>
<IconItem name="subtract">
<ExampleIcon icon="subtract" />
<SubtractIcon />
</IconItem>
<IconItem name="home">
<ExampleIcon icon="home" />
<HomeIcon />
</IconItem>
<IconItem name="facehappy">
<ExampleIcon icon="facehappy" />
<FaceHappyIcon />
</IconItem>
<IconItem name="bar">
<img src="https://storybook.js.org/images/placeholders/50x50.png" alt="example" />
Expand Down
Loading

0 comments on commit a4c7fd0

Please sign in to comment.