Skip to content

Commit

Permalink
Merge pull request #821 from securityscorecard/Mnau-mnau@UXD-1247
Browse files Browse the repository at this point in the history
feat(StatusPill): add component
  • Loading branch information
Mnau-mnau authored Sep 22, 2023
2 parents f1739ab + 3a96af2 commit 3469bc3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .betterer/.betterer.results
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`no more deprecated components`] = {
"../src/components/FlexContainer/index.ts:1246547685": [
[0, 0, 59, "\'./FlexContainer\' import is restricted from being used by a pattern. FlexContainer is deprecated. Please use Layout primitives instead.", "3330215570"]
],
"../src/components/index.ts:3052257943": [
"../src/components/index.ts:3583195122": [
[18, 0, 32, "\'./FlexContainer\' import is restricted from being used by a pattern. FlexContainer is deprecated. Please use Layout primitives instead.", "726759703"]
]
}`
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/StatusDot/StatusDot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';

import { getRadii, pxToRem } from '../../utils';

const StatusDotColors = {
export const StatusDotColors = {
good: '100, 244, 81',
bad: '242, 46, 67',
neutral: '84, 129, 217',
Expand Down
19 changes: 19 additions & 0 deletions src/components/StatusPill/StatusPill.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { Meta, Story } from '@storybook/react/types-6-0';

import StatusPill from './StatusPill';
import { Inline } from '../layout';

export default {
title: 'components/StatusPill',
component: StatusPill,
} as Meta;

export const Default: Story = () => (
<Inline gap="lg">
<StatusPill color="good" label="Good" />
<StatusPill color="bad" label="Bad" />
<StatusPill color="neutral" label="Neutral" />
<StatusPill color="inactive" label="Inactive" />
</Inline>
);
44 changes: 44 additions & 0 deletions src/components/StatusPill/StatusPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import Styled from 'styled-components';
import PropTypes from 'prop-types';

import { StatusDot } from '../StatusDot/index';
import { StatusDotColors } from '../StatusDot/StatusDot';
import { StatusPillProps } from './StatusPill.types';
import PillLabel from '../Pill/PillLabel';
import { SpaceSizes } from '../../theme';
import { Inline, Padbox } from '../layout';
import { PaddingTypes } from '../layout/Padbox/Padbox.enums';
import { getColor, getRadii, pxToRem } from '../../utils';

const StyledPillWrapper = Styled(Padbox)`
display: inline-block;
height: ${pxToRem(24)};
min-width: 0;
border-radius: ${getRadii('round')};
border: 1px solid ${getColor('neutral.200')};
background-color: ${getColor('neutral.0')};
padding-right: ${pxToRem(6)};
padding-top: ${pxToRem(3)};
`;

const StatusPill: React.FC<StatusPillProps> = ({
color = 'inactive',
label,
}) => (
<StyledPillWrapper
paddingSize={SpaceSizes.xs}
paddingType={PaddingTypes.squish}
>
<Inline align="center" gap="sm">
<StatusDot color={color} />
<PillLabel>{label}</PillLabel>
</Inline>
</StyledPillWrapper>
);

StatusPill.propTypes = {
label: PropTypes.string.isRequired,
color: PropTypes.oneOf(Object.keys(StatusDotColors)),
};
export default StatusPill;
6 changes: 6 additions & 0 deletions src/components/StatusPill/StatusPill.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { StatusDotColors } from '../StatusDot/StatusDot';

export interface StatusPillProps {
color?: keyof typeof StatusDotColors;
label: string;
}
1 change: 1 addition & 0 deletions src/components/StatusPill/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as StatusPill } from './StatusPill';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './SingleDatePicker';
export * from './SortableList';
export * from './Spinner';
export * from './StatusDot';
export * from './StatusPill';
export * from './Stepper';
export * from './Table';
export * from './Tabs';
Expand Down

0 comments on commit 3469bc3

Please sign in to comment.