From e1bacf3e05e08675f09a42220ce69bc49bdf12e9 Mon Sep 17 00:00:00 2001 From: Amanda Chang Date: Wed, 14 Apr 2021 09:35:58 -0500 Subject: [PATCH] feat(component): add primary variant to badge (#518) --- .../big-design/src/components/Badge/Badge.tsx | 2 +- .../Badge/__snapshots__/spec.tsx.snap | 21 +++++++++++++++++++ .../big-design/src/components/Badge/spec.tsx | 7 +++++++ .../src/components/Badge/styled.tsx | 6 ++++++ packages/docs/PropTables/BadgePropTable.tsx | 2 +- packages/docs/pages/Badge/BadgePage.tsx | 7 ++++--- 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/big-design/src/components/Badge/Badge.tsx b/packages/big-design/src/components/Badge/Badge.tsx index 16933745d..3b2c4a333 100644 --- a/packages/big-design/src/components/Badge/Badge.tsx +++ b/packages/big-design/src/components/Badge/Badge.tsx @@ -6,7 +6,7 @@ import { StyledBadge } from './styled'; export interface BadgeProps extends HTMLAttributes, MarginProps { label: string; - variant?: 'danger' | 'secondary' | 'success' | 'warning'; + variant?: 'danger' | 'secondary' | 'success' | 'warning' | 'primary'; } export const Badge: React.FC = memo(({ className, style, label, ...props }) => diff --git a/packages/big-design/src/components/Badge/__snapshots__/spec.tsx.snap b/packages/big-design/src/components/Badge/__snapshots__/spec.tsx.snap index b3b37c8c7..07369d522 100644 --- a/packages/big-design/src/components/Badge/__snapshots__/spec.tsx.snap +++ b/packages/big-design/src/components/Badge/__snapshots__/spec.tsx.snap @@ -42,6 +42,27 @@ exports[`render default Badge 1`] = ` `; +exports[`render primary Badge 1`] = ` +.c0 { + color: #FFFFFF; + border-radius: 0.25rem; + display: inline-block; + font-size: 0.75rem; + font-weight: 600; + line-height: 1.25rem; + text-align: center; + text-transform: uppercase; + padding: 0 0.5rem; + background-color: #3C64F4; +} + + + Badge + +`; + exports[`render secondary Badge 1`] = ` .c0 { color: #FFFFFF; diff --git a/packages/big-design/src/components/Badge/spec.tsx b/packages/big-design/src/components/Badge/spec.tsx index aaa702b08..5ee736144 100644 --- a/packages/big-design/src/components/Badge/spec.tsx +++ b/packages/big-design/src/components/Badge/spec.tsx @@ -51,6 +51,13 @@ test('render secondary Badge', () => { expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.secondary60}`); }); +test('render primary Badge', () => { + const { container } = render(); + + expect(container.firstChild).toMatchSnapshot(); + expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.primary40}`); +}); + test("doesn't render if label prop is invalid", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore diff --git a/packages/big-design/src/components/Badge/styled.tsx b/packages/big-design/src/components/Badge/styled.tsx index 339e6eb2b..f8695bbfd 100644 --- a/packages/big-design/src/components/Badge/styled.tsx +++ b/packages/big-design/src/components/Badge/styled.tsx @@ -42,6 +42,12 @@ export const StyledBadge = styled.span>` css` background-color: ${theme.colors.danger40}; `} + + ${({ theme, variant }) => + variant === 'primary' && + css` + background-color: ${theme.colors.primary40}; + `} `; StyledBadge.defaultProps = { diff --git a/packages/docs/PropTables/BadgePropTable.tsx b/packages/docs/PropTables/BadgePropTable.tsx index 77e9aa81e..9e3dc3324 100644 --- a/packages/docs/PropTables/BadgePropTable.tsx +++ b/packages/docs/PropTables/BadgePropTable.tsx @@ -11,7 +11,7 @@ const badgeProps: Prop[] = [ }, { name: 'variant', - types: ['danger', 'secondary', 'success', 'warning'], + types: ['danger', 'secondary', 'success', 'warning', 'primary'], description: 'Determines which badge to display.', defaultValue: 'secondary', }, diff --git a/packages/docs/pages/Badge/BadgePage.tsx b/packages/docs/pages/Badge/BadgePage.tsx index 16f4318f5..84b07870a 100644 --- a/packages/docs/pages/Badge/BadgePage.tsx +++ b/packages/docs/pages/Badge/BadgePage.tsx @@ -32,18 +32,19 @@ const BadgePage = () => (

Variants

- There are four types of variants to choose from: success, secondary,{' '} - warning, and danger. You can determine what type by using the{' '} + There are five types of variants to choose from: success, secondary,{' '} + warning, danger, and primary. You can determine what type by using the{' '} variant prop. {/* jsx-to-string:start */} - + + {/* jsx-to-string:end */}