Skip to content

Commit

Permalink
Merge pull request #3 from storybookjs/feat/status-badge
Browse files Browse the repository at this point in the history
feat: status badge
  • Loading branch information
darleendenno authored Sep 1, 2021
2 parents 4184677 + 46a0813 commit 71e7f10
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { StatusBadge } from './StatusBadge';
import { CallState } from '../../types';

export default {
title: 'StatusBadge',
component: StatusBadge,
paramaters: { layout: 'padded' },
};

export const Pass = {
args: { status: CallState.DONE },
};

export const Runs = {
args: { status: CallState.PENDING },
};

export const Fail = {
args: { status: CallState.ERROR },
};
43 changes: 43 additions & 0 deletions addons/interactions/src/components/StatusBadge/StatusBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { styled, typography } from '@storybook/theming';
import { CallState } from '../../types';
import { theme } from '../../theme';

export interface StatusBadgeProps {
status: `${CallState}`;
}
const {
colors: {
pure: { green, red, ochre },
},
} = theme;

const StyledBadge = styled.div(({ status }: StatusBadgeProps) => {
const backgroundColor = {
[CallState.DONE]: green,
[CallState.ERROR]: red,
[CallState.PENDING]: ochre,
}[status];
return {
padding: '4px 8px',
borderRadius: '4px',
backgroundColor: backgroundColor,
color: 'white',
fontFamily: typography.fonts.base,
textTransform: 'uppercase',
fontSize: typography.size.s1,
letterSpacing: 3,
fontWeight: 500,
width: 65,
textAlign: 'center',
};
});

export const StatusBadge: React.FC<StatusBadgeProps> = ({ status }) => {
const badgeText = {
[CallState.DONE]: 'Pass',
[CallState.ERROR]: 'Fail',
[CallState.PENDING]: 'Runs',
}[status];
return <StyledBadge status={status}>{badgeText}</StyledBadge>;
};

0 comments on commit 71e7f10

Please sign in to comment.