Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

Commit 20ccfcb

Browse files
committed
Refactor to use variants instead of hardcoded colors
1 parent a09f880 commit 20ccfcb

3 files changed

Lines changed: 50 additions & 39 deletions

File tree

packages/visual-stack-docs/src/containers/Components/Docs/badge.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,14 @@ export default () => (
1616
<Snippet tag="s1" src={snippets} />
1717
</Body>
1818
</Panel>
19-
<Panel>
20-
<Body>
21-
{/* s4:start */}
22-
<Box direction="row" gap="default">
23-
<Badge>CJ Performer</Badge>
24-
<Badge>CJ Spotlight</Badge>
25-
<Badge>Content Certified</Badge>
26-
<Badge>New to Network</Badge>
27-
<Badge>SubAffiliate</Badge>
28-
</Box>
29-
{/* s4:end */}
30-
<Snippet tag="s4" src={snippets} />
31-
</Body>
32-
</Panel>
33-
3419
<Panel>
3520
<Body>
3621
{/* s2:start */}
3722
<Box direction="row" gap="default">
38-
<Badge backgroundColor="#9C52F7">CJ Performer</Badge>
39-
<Badge backgroundColor="#EA4B93">CJ Spotlight</Badge>
40-
<Badge backgroundColor="#4574E2">Content Certified</Badge>
41-
<Badge backgroundColor="#0CAAAC">New to Network</Badge>
42-
<Badge backgroundColor="#072477">SubAffiliate</Badge>
23+
<Badge>1</Badge>
24+
<Badge>2</Badge>
25+
<Badge>3</Badge>
26+
<Badge>4819</Badge>
4327
</Box>
4428
{/* s2:end */}
4529
<Snippet tag="s2" src={snippets} />
@@ -50,10 +34,13 @@ export default () => (
5034
<Body>
5135
{/* s3:start */}
5236
<Box direction="row" gap="default">
53-
<Badge backgroundColor="var(--cj-green)">1</Badge>
54-
<Badge backgroundColor="var(--cj-green)">2</Badge>
55-
<Badge backgroundColor="var(--cj-green)">3</Badge>
56-
<Badge backgroundColor="var(--cj-green)">4819</Badge>
37+
<Badge variant="default">0</Badge>
38+
<Badge variant="cj-green">CJ Green</Badge>
39+
<Badge variant="1">CJ Performer</Badge>
40+
<Badge variant="2">CJ Spotlight</Badge>
41+
<Badge variant="3">Content Certified</Badge>
42+
<Badge variant="4">New to Network</Badge>
43+
<Badge variant="5">SubAffiliate</Badge>
5744
</Box>
5845
{/* s3:end */}
5946
<Snippet tag="s3" src={snippets} />

packages/visual-stack/src/components/Badge/Badge.css

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,38 @@
44
line-height: 1rem;
55
border-radius: 0.2rem;
66
display: inline-block;
7-
background-color: #6d7684;
87
color: #ffffff;
98
padding: 0.2rem 0.4rem;
109
text-align: center;
1110
text-transform: uppercase;
1211
width: fit-content;
1312
height: fit-content;
1413
}
14+
15+
.vs-badge-variant-default {
16+
background-color: #6d7684;
17+
}
18+
19+
.vs-badge-variant-cj-green {
20+
background-color: var(--cj-green);
21+
}
22+
23+
.vs-badge-variant-1 {
24+
background-color: #9c52f7;
25+
}
26+
27+
.vs-badge-variant-2 {
28+
background-color: #ea4b93;
29+
}
30+
31+
.vs-badge-variant-3 {
32+
background-color: #4574e2;
33+
}
34+
35+
.vs-badge-variant-4 {
36+
background-color: #0caaac;
37+
}
38+
39+
.vs-badge-variant-5 {
40+
background-color: #072477;
41+
}

packages/visual-stack/src/components/Badge/index.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@ import React from 'react';
44
import './Badge.css';
55
import Box from '../../experimental/Box';
66

7-
export const Badge = ({
8-
children,
9-
className,
10-
backgroundColor,
11-
color,
12-
...restProps
13-
}) => {
7+
export const Badge = ({ children, className, variant, ...restProps }) => {
148
return (
159
<Box
1610
{...restProps}
17-
className={classNames('vs-badge', className)}
18-
style={{
19-
backgroundColor,
20-
color,
21-
}}
11+
className={classNames(
12+
'vs-badge',
13+
`vs-badge-variant-${variant}`,
14+
className
15+
)}
2216
>
2317
{children}
2418
</Box>
2519
);
2620
};
2721

22+
Badge.defaultProps = {
23+
variant: 'default',
24+
};
25+
2826
Badge.propTypes = {
29-
backgroundColor: PropTypes.string,
3027
children: PropTypes.node,
3128
className: PropTypes.string,
32-
color: PropTypes.string,
29+
variant: PropTypes.oneOf('default', 'cj-green', '1', '2', '3', '4', '5'),
3330
};

0 commit comments

Comments
 (0)