-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathBadge.tsx
More file actions
32 lines (30 loc) · 755 Bytes
/
Badge.tsx
File metadata and controls
32 lines (30 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, { FC, HTMLAttributes } from 'react';
import classnames from 'classnames';
/**
*
*/
export type BadgeProps = {
type?: 'inverse' | 'lightest' | 'success' | 'warning' | 'error';
label?: string;
} & HTMLAttributes<HTMLSpanElement>;
/**
*
*/
export const Badge: FC<BadgeProps> = ({ type, label, ...props }) => {
const typeClassName = /^(inverse|lightest)$/.test(type ?? '')
? `slds-badge_${type}`
: null;
const themeClassName = /^(success|warning|error)$/.test(type ?? '')
? `slds-theme_${type}`
: null;
const badgeClassNames = classnames(
'slds-badge',
typeClassName,
themeClassName
);
return (
<span className={badgeClassNames} {...props}>
{label || props.children}
</span>
);
};