Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(StatusPill): add component #821

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)};
ajkl2533 marked this conversation as resolved.
Show resolved Hide resolved
`;

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 @@ -16,7 +16,7 @@
export * from './ErrorBoundary';
export * from './FileSelector';
export * from './Filters';
export * from './FlexContainer';

Check warning on line 19 in src/components/index.ts

View workflow job for this annotation

GitHub Actions / 🧹 Run lint

'./FlexContainer' import is restricted from being used by a pattern. FlexContainer is deprecated. Please use Layout primitives instead
export * from './FullscreenModal';
export * from './HexGrade';
export * from './HintTooltip';
Expand All @@ -33,6 +33,7 @@
export * from './SortableList';
export * from './Spinner';
export * from './StatusDot';
export * from './StatusPill';
export * from './Stepper';
export * from './Table';
export * from './Tabs';
Expand Down
Loading