|
1
|
import * as React from "react" |
|
2
|
|
|
3
|
import { clx } from "@/utils/clx" |
|
4
|
import { VariantProps, cva } from "cva" |
|
5
|
|
|
6
|
const statusBadgeVariants = cva({ |
|
7
|
base: "flex items-center justify-center w-5 h-[18px] [&_div]:w-2 [&_div]:h-2 [&_div]:rounded-sm", |
|
8
|
variants: { |
|
9
|
color: { |
|
10
|
green: "[&_div]:bg-ui-tag-green-icon", |
|
11
|
red: "[&_div]:bg-ui-tag-red-icon", |
|
12
|
orange: "[&_div]:bg-ui-tag-orange-icon", |
|
13
|
blue: "[&_div]:bg-ui-tag-blue-icon", |
|
14
|
purple: "[&_div]:bg-ui-tag-purple-icon", |
|
15
|
grey: "[&_div]:bg-ui-tag-neutral-icon", |
|
16
|
}, |
|
17
|
}, |
|
18
|
defaultVariants: { |
|
19
|
color: "grey", |
|
20
|
}, |
|
21
|
}) |
|
22
|
|
|
23
|
interface StatusBadgeProps |
|
24
|
extends Omit<React.ComponentPropsWithoutRef<"span">, "color">, |
|
25
|
VariantProps<typeof statusBadgeVariants> {} |
|
26
|
|
|
27
|
/** |
|
28
|
* This component is based on the span element and supports all of its props |
|
29
|
*/ |
|
30
|
const StatusBadge = React.forwardRef<HTMLSpanElement, StatusBadgeProps>( |
|
31
|
( |
|
32
|
{ |
|
33
|
children, |
|
34
|
className, |
|
35
|
/** |
|
36
|
* The status's color. |
|
37
|
*/ |
|
38
|
color = "grey", |
|
39
|
...props |
|
40
|
}: StatusBadgeProps, |
|
41
|
ref |
|
42
|
) => { |
|
43
|
return ( |
|
44
|
<span |
|
45
|
ref={ref} |
|
46
|
className={clx( |
|
47
|
"txt-compact-xsmall-plus bg-ui-bg-subtle text-ui-fg-subtle border-ui-border-base box-border flex w-fit select-none items-center overflow-hidden rounded-md border pl-0 pr-1 leading-none", |
|
48
|
className |
|
49
|
)} |
|
50
|
{...props} |
|
51
|
> |
|
52
|
<div role="presentation" className={statusBadgeVariants({ color })}> |
|
53
|
<div /> |
|
54
|
</div> |
|
55
|
{children} |
|
56
|
</span> |
|
57
|
) |
|
58
|
} |
|
59
|
) |
|
60
|
StatusBadge.displayName = "StatusBadge" |
|
61
|
|
|
62
|
export { StatusBadge } |