Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): rename Lozenge to Badge (#118)
BREAKING CHANGE: Lozenge has been renamed to Badge. If you were using the Lozenge component, you will need to change all references to 'badge' * docs: add base doc files * docs(story): finish lozenge documentation * feat(component): update lozenge to badge * feat(component): remove primary variant * test(component): add badge tests * fix(component): fix import in Badge spec * feat(component): resolve PR comments * feat(component): add tests for background color and resolve PR comments
- Loading branch information
Showing
12 changed files
with
238 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
import { MarginProps } from '../../mixins'; | ||
|
||
import { StyledBadge } from './styled'; | ||
|
||
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement>, MarginProps { | ||
variant?: 'danger' | 'secondary' | 'success' | 'warning'; | ||
} | ||
|
||
export const Badge: React.FC<BadgeProps> = ({ className, style, ...props }) => <StyledBadge {...props} />; |
102 changes: 102 additions & 0 deletions
102
packages/big-design/src/components/Badge/__snapshots__/spec.tsx.snap
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`render danger Badge 1`] = ` | ||
.c0 { | ||
color: #FFFFFF; | ||
border-radius: 0.25rem; | ||
display: inline-block; | ||
font-size: 0.875rem; | ||
font-weight: 600; | ||
text-align: center; | ||
text-transform: uppercase; | ||
padding: 0.25rem; | ||
background-color: #DB3643; | ||
} | ||
<span | ||
class="c0" | ||
> | ||
Badge | ||
</span> | ||
`; | ||
|
||
exports[`render default Badge 1`] = ` | ||
.c0 { | ||
color: #FFFFFF; | ||
border-radius: 0.25rem; | ||
display: inline-block; | ||
font-size: 0.875rem; | ||
font-weight: 600; | ||
text-align: center; | ||
text-transform: uppercase; | ||
padding: 0.25rem; | ||
background-color: #5E637A; | ||
} | ||
<span | ||
class="c0" | ||
> | ||
Badge | ||
</span> | ||
`; | ||
|
||
exports[`render secondary Badge 1`] = ` | ||
.c0 { | ||
color: #FFFFFF; | ||
border-radius: 0.25rem; | ||
display: inline-block; | ||
font-size: 0.875rem; | ||
font-weight: 600; | ||
text-align: center; | ||
text-transform: uppercase; | ||
padding: 0.25rem; | ||
background-color: #5E637A; | ||
} | ||
<span | ||
class="c0" | ||
> | ||
Badge | ||
</span> | ||
`; | ||
|
||
exports[`render success Badge 1`] = ` | ||
.c0 { | ||
color: #FFFFFF; | ||
border-radius: 0.25rem; | ||
display: inline-block; | ||
font-size: 0.875rem; | ||
font-weight: 600; | ||
text-align: center; | ||
text-transform: uppercase; | ||
padding: 0.25rem; | ||
background-color: #208831; | ||
} | ||
<span | ||
class="c0" | ||
> | ||
Badge | ||
</span> | ||
`; | ||
|
||
exports[`render warning Badge 1`] = ` | ||
.c0 { | ||
color: #FFFFFF; | ||
border-radius: 0.25rem; | ||
display: inline-block; | ||
font-size: 0.875rem; | ||
font-weight: 600; | ||
text-align: center; | ||
text-transform: uppercase; | ||
padding: 0.25rem; | ||
color: #313440; | ||
background-color: #FFBF00; | ||
} | ||
<span | ||
class="c0" | ||
> | ||
Badge | ||
</span> | ||
`; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Badge, BadgeProps } from './Badge'; |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { theme } from '@bigcommerce/big-design-theme'; | ||
import { render } from '@testing-library/react'; | ||
import 'jest-styled-components'; | ||
import React from 'react'; | ||
|
||
import { Badge } from './index'; | ||
|
||
test('has margin props', () => { | ||
const { container, rerender } = render(<Badge />); | ||
|
||
expect(container.firstChild).not.toHaveStyle('margin: 1rem'); | ||
|
||
rerender(<Badge margin="medium" />); | ||
|
||
expect(container.firstChild).toHaveStyle('margin: 1rem'); | ||
}); | ||
|
||
test('render default Badge', () => { | ||
const { container } = render(<Badge>Badge</Badge>); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.secondary60}`); | ||
}); | ||
|
||
test('render success Badge', () => { | ||
const { container } = render(<Badge variant="success">Badge</Badge>); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.success50}`); | ||
}); | ||
|
||
test('render danger Badge', () => { | ||
const { container } = render(<Badge variant="danger">Badge</Badge>); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.danger40}`); | ||
}); | ||
|
||
test('render warning Badge', () => { | ||
const { container } = render(<Badge variant="warning">Badge</Badge>); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.warning40}`); | ||
}); | ||
|
||
test('render secondary Badge', () => { | ||
const { container } = render(<Badge variant="secondary">Badge</Badge>); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(container.firstChild).toHaveStyle(`background-color: ${theme.colors.secondary60}`); | ||
}); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Badge, Grid, H0, H1, H2, Link, Text } from '@bigcommerce/big-design'; | ||
import { storiesOf } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { Code, CodePreview, Collapsible } from '../../components'; | ||
import { MarginPropTable } from '../Utilities/index'; | ||
|
||
import { BadgePropTable } from './BadgePropTable'; | ||
|
||
storiesOf('Badge', module).add('Overview', () => ( | ||
<> | ||
<H0>Badges</H0> | ||
|
||
<Text> | ||
Badges are used to quickly indicate status or information to a user visually. Each variant correlates to a | ||
specific status or value.{' '} | ||
<Link href="https://bigcommerce.design/badges" target="_blank"> | ||
Badges Design Guidelines | ||
</Link> | ||
</Text> | ||
|
||
<CodePreview> | ||
{/* jsx-to-string:start */} | ||
<Badge variant="success">active</Badge> | ||
{/* jsx-to-string:end */} | ||
</CodePreview> | ||
|
||
<H1>API</H1> | ||
|
||
<BadgePropTable /> | ||
|
||
<H2>Inherited Props</H2> | ||
|
||
<Collapsible title="Margin Props"> | ||
<MarginPropTable /> | ||
</Collapsible> | ||
|
||
<H1>Variants</H1> | ||
|
||
<Text> | ||
There are four types of variants to choose from: <Code>success</Code>, <Code>secondary</Code>,{' '} | ||
<Code>warning</Code>, and <Code>danger</Code>. You can determine what type by using the{' '} | ||
<Code primary>variant</Code> prop. | ||
</Text> | ||
|
||
<CodePreview> | ||
{/* jsx-to-string:start */} | ||
<Grid columns="repeat(4, min-content)"> | ||
<Badge variant="secondary">secondary</Badge> | ||
<Badge variant="success">success</Badge> | ||
<Badge variant="warning">warning</Badge> | ||
<Badge variant="danger">danger</Badge> | ||
</Grid> | ||
{/* jsx-to-string:end */} | ||
</CodePreview> | ||
</> | ||
)); |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
import { PropTable } from '../../components'; | ||
|
||
export const BadgePropTable: React.FC = () => ( | ||
<PropTable> | ||
<PropTable.Prop name="variant" defaults="secondary" types={['danger', 'secondary', 'success', 'warning']}> | ||
Determines which badge to display. | ||
</PropTable.Prop> | ||
</PropTable> | ||
); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BadgePropTable } from './BadgePropTable'; |
This file was deleted.
Oops, something went wrong.