-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathBadge.tsx
More file actions
59 lines (52 loc) · 1.45 KB
/
Badge.tsx
File metadata and controls
59 lines (52 loc) · 1.45 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Slot } from '@radix-ui/react-slot'
import React from 'react'
import type { Shape, Size } from '@sqlmesh-common/types'
import { cn } from '@sqlmesh-common/utils'
import { cva } from 'class-variance-authority'
import './Badge.css'
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
asChild?: boolean
size?: Size
shape?: Shape
}
export const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
({ className, size, shape, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'span'
return (
<Comp
data-component="Badge"
className={cn(badgeVariants({ size, shape, className }))}
ref={ref}
{...props}
/>
)
},
)
Badge.displayName = 'Badge'
const size: Record<Size, string> = {
'2xs': 'h-5 px-2 text-2xs leading-none rounded-2xs',
xs: 'h-6 px-2 text-2xs rounded-xs',
s: 'h-7 px-3 text-xs rounded-sm',
m: 'h-8 px-4 rounded-md',
l: 'h-9 px-4 rounded-lg',
xl: 'h-10 px-4 rounded-xl',
'2xl': 'h-11 px-6 rounded-2xl',
}
const shape: Record<Shape, string> = {
square: 'rounded-none',
round: 'rounded-inherit',
pill: 'rounded-full',
}
const badgeVariants = cva(
'bg-badge-background text-badge-foreground font-mono inline-flex align-middle items-center justify-center gap-2 leading-none whitespace-nowrap font-semibold',
{
variants: {
size,
shape,
},
defaultVariants: {
size: 's',
shape: 'round',
},
},
)