Skip to content

Commit 4e70e41

Browse files
committed
feat: implement badge component
Implement badge component and it's variations Closes DCOS-21610
1 parent b794c31 commit 4e70e41

7 files changed

Lines changed: 236 additions & 170 deletions

File tree

components/badge/__snapshots__/badge.test.tsx.snap

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,47 @@
22

33
exports[`Badge danger 1`] = `
44
<span
5-
className="css-f00b3g"
5+
className="css-1x7fm58"
66
>
77
danger
88
</span>
99
`;
1010

1111
exports[`Badge default 1`] = `
1212
<span
13-
className="css-b4fwwt"
13+
className="css-mx4jeh"
1414
>
1515
default
1616
</span>
1717
`;
1818

19-
exports[`Badge information 1`] = `
19+
exports[`Badge outline 1`] = `
2020
<span
21-
className="css-19f16re"
21+
className="css-12s43p8"
2222
>
23-
information
23+
outline
24+
</span>
25+
`;
26+
27+
exports[`Badge primary 1`] = `
28+
<span
29+
className="css-25ardn"
30+
>
31+
primary
2432
</span>
2533
`;
2634

2735
exports[`Badge success 1`] = `
2836
<span
29-
className="css-1j3h1kw"
37+
className="css-1xv1zbc"
3038
>
3139
success
3240
</span>
3341
`;
3442

3543
exports[`Badge warning 1`] = `
3644
<span
37-
className="css-wz5vwa"
45+
className="css-r5izn1"
3846
>
3947
warning
4048
</span>

components/badge/badge.test.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,31 @@ describe("Badge", () => {
1111

1212
it("success", () => {
1313
expect(renderer
14-
.create(<Badge appearance="success">success</Badge>)
14+
.create(<Badge theme="success">success</Badge>)
1515
.toJSON()).toMatchSnapshot()
1616
});
1717

18-
it("information", () => {
18+
it("primary", () => {
1919
expect(renderer
20-
.create(<Badge appearance="information">information</Badge>)
20+
.create(<Badge theme="primary">primary</Badge>)
21+
.toJSON()).toMatchSnapshot()
22+
});
23+
24+
it("danger", () => {
25+
expect(renderer
26+
.create(<Badge theme="danger">danger</Badge>)
2127
.toJSON()).toMatchSnapshot()
2228
});
2329

2430
it("warning", () => {
2531
expect(renderer
26-
.create(<Badge appearance="warning">warning</Badge>)
32+
.create(<Badge theme="warning">warning</Badge>)
2733
.toJSON()).toMatchSnapshot()
2834
});
2935

30-
it("danger", () => {
36+
it("outline", () => {
3137
expect(renderer
32-
.create(<Badge appearance="danger">danger</Badge>)
38+
.create(<Badge theme="outline">outline</Badge>)
3339
.toJSON()).toMatchSnapshot()
3440
});
3541
});

components/badge/badge.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import * as React from "react";
22
import { badge } from "./style";
33

44
export interface IBadgeProps {
5-
appearance?: string;
6-
children?: React.ReactNode | string;
5+
theme?: string;
6+
children?: JSX.Element | string;
77
}
88

99
export class Badge extends React.PureComponent<IBadgeProps, {}> {
1010
public static defaultProps: Partial<IBadgeProps> = {
11-
appearance: "default"
11+
theme: "default"
1212
};
1313

1414
public render() {
15-
const { appearance, children } = this.props;
15+
const { theme, children } = this.props;
1616

17-
return <span className={badge(appearance)}>{children}</span>;
17+
return <span className={badge(theme)}>{children}</span>;
1818
}
1919
}
2020

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
import * as React from "react";
22
import { storiesOf } from "@storybook/react";
33
import { withReadme } from "storybook-readme";
4-
import Badge from "../badge";
4+
import { Badge } from "../../index";
55

66
const BadgeReadme = require("../README.md");
77

88
storiesOf("Badge", module)
99
.addDecorator(withReadme([BadgeReadme]))
10-
.addWithInfo("default", () => <Badge>default</Badge>)
11-
.addWithInfo("success", () => <Badge appearance="success">success</Badge>)
12-
.addWithInfo("information", () => <Badge appearance="information">information</Badge>)
13-
.addWithInfo("warning", () => <Badge appearance="warning">warning</Badge>)
14-
.addWithInfo("danger", () => <Badge appearance="danger">danger</Badge>)
10+
.addWithInfo(
11+
"Default",
12+
() => <Badge>Default</Badge>
13+
)
14+
.addWithInfo(
15+
"Success",
16+
"Represents something positive.",
17+
() => <Badge theme="success">Success</Badge>
18+
)
19+
.addWithInfo(
20+
"Primary",
21+
"Represents something more significant than a default.",
22+
() => <Badge theme="primary">Primary</Badge>
23+
)
24+
.addWithInfo(
25+
"Danger",
26+
"Represents something in a danger or error state.",
27+
() => <Badge theme="danger">Danger</Badge>
28+
)
29+
.addWithInfo(
30+
"Warning",
31+
"Represents something that we want to warn the user about but not quite extreme as a danger state.",
32+
() => <Badge theme="warning">Warning</Badge>
33+
)
34+
.addWithInfo(
35+
"Outline",
36+
"Outline badges for when we want the density of the badge to be lighter e.g. when next to data in a table cell",
37+
() => <Badge theme="outline">Outline</Badge>
38+
)

components/badge/style.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from "emotion";
2-
import { getColors, getFonts } from "../../shared/style";
2+
import { getColors, getFonts } from "../../shared/styles/core";
33

4-
const badgeAppearances = {
4+
const badgeTheme = {
55
"default": css`
66
background-color: ${getColors().greyLight};
77
border-color: ${getColors().greyLight};
@@ -31,12 +31,18 @@ const badgeAppearances = {
3131
background-color: ${getColors().white};
3232
border-color: ${getColors().greyLight};
3333
color: ${getColors().greyDark};
34+
`,
35+
"outline-primary": css`
36+
background-color: ${getColors().white};
37+
border-color: ${getColors().purple};
38+
color: ${getColors().greyDark};
3439
`
3540
};
3641

37-
export const badge = (appearance) => {
42+
export const badge = (theme) => {
3843
return css`
39-
${badgeAppearances[appearance]};
44+
${badgeTheme[theme]};
45+
box-sizing: border-box;
4046
border-width: 1px;
4147
border-style: solid;
4248
padding-left: 8px;

0 commit comments

Comments
 (0)