forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterPill.tsx
More file actions
67 lines (60 loc) · 1.66 KB
/
Copy pathFilterPill.tsx
File metadata and controls
67 lines (60 loc) · 1.66 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
60
61
62
63
64
65
66
67
// src/components/ui/FilterPill.tsx
import { cva } from "class-variance-authority"
import clsx from "clsx"
import type { ButtonHTMLAttributes, ReactNode } from "react"
type FilterPillSize = "sm" | "md"
type FilterPillInactive = "transparent" | "inset" | "strikethrough"
interface FilterPillProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
active: boolean
text?: string
children?: ReactNode
size?: FilterPillSize
activeColor?: string
inactive?: FilterPillInactive
}
const pill = cva(
"font-mono transition-colors duration-150 cursor-pointer border-none disabled:opacity-40 disabled:cursor-not-allowed",
{
variants: {
size: {
sm: "px-2 py-0.5 text-2xs rounded-nm-sm",
md: "px-2.5 py-1 text-xs rounded-nm-sm",
},
},
defaultVariants: {
size: "md",
},
}
)
const INACTIVE_STYLES: Record<FilterPillInactive, string> = {
transparent: "bg-transparent text-muted hover:text-secondary",
inset: "nm-inset-sm text-tertiary hover:text-secondary",
strikethrough: "bg-transparent text-muted hover:text-secondary line-through opacity-50",
}
function FilterPill({
active,
text,
children,
size = "md",
activeColor = "text-primary",
inactive = "transparent",
className,
...props
}: FilterPillProps) {
return (
<button
type="button"
aria-pressed={active}
className={clsx(
pill({ size }),
active ? clsx("nm-raised-sm font-semibold", activeColor) : INACTIVE_STYLES[inactive],
className
)}
{...props}
>
{children ?? text}
</button>
)
}
export type { FilterPillInactive, FilterPillProps, FilterPillSize }
export { FilterPill }