Skip to content

Commit b789f2d

Browse files
(Badge): add new types that haven't been available until now
1 parent bb994c2 commit b789f2d

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
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?: '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-badge_${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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,63 @@ export const Inverse: ComponentStoryObj<typeof Badge> = {
4141
},
4242
},
4343
};
44+
45+
/**
46+
*
47+
*/
48+
export const Lightest: ComponentStoryObj<typeof Badge> = {
49+
args: {
50+
type: 'lightest',
51+
children: 'Badge Label',
52+
},
53+
parameters: {
54+
docs: {
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',
101+
},
102+
},
103+
};

0 commit comments

Comments
 (0)