forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.tsx
More file actions
83 lines (75 loc) · 1.87 KB
/
Copy pathCard.tsx
File metadata and controls
83 lines (75 loc) · 1.87 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// src/components/ui/Card.tsx
import { H2 } from "@typography"
import { cva } from "class-variance-authority"
import clsx from "clsx"
import type { CSSProperties, HTMLAttributes } from "react"
import { hexToRgba } from "@/lib/color-utils"
type CardElevation = "raised" | "elevated"
interface CardProps extends HTMLAttributes<HTMLDivElement> {
elevation?: CardElevation
glow?: boolean
glowColor?: string
trackerColor?: string
title?: string
subtitle?: string
lazy?: boolean
}
const card = cva("p-5", {
variants: {
elevation: {
raised: "bg-raised nm-raised",
elevated: "bg-elevated nm-raised-lg",
},
},
defaultVariants: {
elevation: "raised",
},
})
function Card({
elevation = "raised",
glow = false,
glowColor,
trackerColor,
title,
subtitle,
lazy,
className,
style,
children,
...props
}: CardProps) {
const composedStyle: CSSProperties = {}
// Outer haze
if (trackerColor) {
composedStyle.filter = `drop-shadow(0 0 16px ${hexToRgba(trackerColor, 0.11)})`
} else if (glow && glowColor) {
composedStyle.filter = `drop-shadow(0 0 16px ${glowColor})`
}
// Inset accent — pseudo-element for the "face"
if (trackerColor) {
;(composedStyle as Record<string, string>)["--card-accent"] = hexToRgba(trackerColor, 0.08)
}
return (
<div
className={clsx(
card({ elevation }),
"rounded-nm-lg",
lazy && "lazy-card",
trackerColor && "card-accent",
className
)}
style={{ ...composedStyle, ...style }}
{...props}
>
{(title || subtitle) && (
<div className="flex flex-col gap-1">
{title && <H2 className="card-heading">{title}</H2>}
{subtitle && <p className="text-xs font-mono text-tertiary">{subtitle}</p>}
</div>
)}
{children}
</div>
)
}
export type { CardElevation, CardProps }
export { Card }