-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42c6704
commit 98f9f1c
Showing
4 changed files
with
29 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,35 @@ | ||
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']; | ||
export const StatusIcon: React.FC<StatusIconProps> = ({ status }) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<StyledStatusIcon | ||
data-testid={`icon-${status}`} | ||
status={status} | ||
icon={icon} | ||
className={className} | ||
/> | ||
<> | ||
{status === CallStates.DONE && <CheckIcon color={theme.color.positive} />} | ||
{status === CallStates.ERROR && <StopAltIcon color={theme.color.negative} />} | ||
{status === CallStates.ACTIVE && <PlayIcon color={theme.color.secondary} />} | ||
{status === CallStates.WAITING && ( | ||
<WarningContainer> | ||
<CircleIcon color={transparentize(0.5, '#CCCCCC')} size={6} /> | ||
</WarningContainer> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters