Skip to content

Commit 255088c

Browse files
authored
Merge pull request #458 from mashmatrix/support-slds-2-badge
Update `Badge` for SLDS2
2 parents 7b1ef61 + b789f2d commit 255088c

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

src/scripts/Badge.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ import classnames from 'classnames';
55
*
66
*/
77
export type BadgeProps = {
8-
type?: 'default' | 'shade' | 'inverse';
8+
type?: 'inverse' | 'lightest' | 'success' | 'warning' | 'error';
99
label?: string;
1010
} & HTMLAttributes<HTMLSpanElement>;
1111

1212
/**
1313
*
1414
*/
1515
export const Badge: FC<BadgeProps> = ({ type, label, ...props }) => {
16-
const typeClassName = type ? `slds-theme_${type}` : null;
17-
const badgeClassNames = classnames('slds-badge', typeClassName);
16+
const typeClassName = /^(inverse|lightest)$/.test(type ?? '')
17+
? `slds-badge_${type}`
18+
: null;
19+
const themeClassName = /^(success|warning|error)$/.test(type ?? '')
20+
? `slds-theme_${type}`
21+
: null;
22+
const badgeClassNames = classnames(
23+
'slds-badge',
24+
typeClassName,
25+
themeClassName
26+
);
1827
return (
1928
<span className={badgeClassNames} {...props}>
2029
{label || props.children}

stories/Badge.stories.tsx

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,74 @@ export const Default: ComponentStoryObj<typeof Badge> = {
3030
/**
3131
*
3232
*/
33-
export const Shade: ComponentStoryObj<typeof Badge> = {
33+
export const Inverse: ComponentStoryObj<typeof Badge> = {
3434
args: {
35-
type: 'shade',
35+
type: 'inverse',
3636
children: 'Badge Label',
3737
},
3838
parameters: {
3939
docs: {
40-
storyDescription: 'Badge with type: shade',
40+
storyDescription: 'Badge with type: inverse',
4141
},
4242
},
4343
};
4444

4545
/**
4646
*
4747
*/
48-
export const Inverse: ComponentStoryObj<typeof Badge> = {
48+
export const Lightest: ComponentStoryObj<typeof Badge> = {
4949
args: {
50-
type: 'inverse',
50+
type: 'lightest',
5151
children: 'Badge Label',
5252
},
5353
parameters: {
5454
docs: {
55-
storyDescription: 'Badge with type: inverse',
55+
storyDescription: 'Badge with type: lightest',
56+
},
57+
},
58+
};
59+
60+
/**
61+
*
62+
*/
63+
export const Success: ComponentStoryObj<typeof Badge> = {
64+
args: {
65+
type: 'success',
66+
children: 'Badge Label',
67+
},
68+
parameters: {
69+
docs: {
70+
storyDescription: 'Badge with type: success',
71+
},
72+
},
73+
};
74+
75+
/**
76+
*
77+
*/
78+
export const Warning: ComponentStoryObj<typeof Badge> = {
79+
args: {
80+
type: 'warning',
81+
children: 'Badge Label',
82+
},
83+
parameters: {
84+
docs: {
85+
storyDescription: 'Badge with type: warning',
86+
},
87+
},
88+
};
89+
90+
/**
91+
*
92+
*/
93+
export const Error: ComponentStoryObj<typeof Badge> = {
94+
args: {
95+
type: 'error',
96+
children: 'Badge Label',
97+
},
98+
parameters: {
99+
docs: {
100+
storyDescription: 'Badge with type: error',
56101
},
57102
},
58103
};

0 commit comments

Comments
 (0)