@hoardodile/ui 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ import { getSpecialTagStyleConfig } from "@hoardodile/ui/components/special-tag-surface"
2
+ import {
3
+ computeTagChipColors,
4
+ isSpecialTagStyle,
5
+ type TagSpecialStyle,
6
+ } from "@hoardodile/ui/lib/colors"
7
+ import { cn } from "@hoardodile/ui/lib/utils"
8
+ import type { CSSProperties } from "react"
9
+
10
+ export type ResolvedTagChipSurface = {
11
+ readonly className: string
12
+ readonly style: CSSProperties | undefined
13
+ /** The special SVG texture to layer under the chip's content, or null. */
14
+ readonly texture: TagSpecialStyle | null
15
+ }
16
+
17
+ /**
18
+ * Resolves a chip's visual surface for a user-assigned color — the single
19
+ * source of chip coloring shared by every tag/category pill in the app.
20
+ *
21
+ * A plain color tints the whole chip (a 6% wash as fill, the color as ink,
22
+ * deepening to the hover tint when `active`); the five special styles
23
+ * (silver, gold, rainbow, oilslick, kintsugi) render their SVG texture;
24
+ * an empty color falls back to the default muted chip, taking the primary
25
+ * fill when `active`.
26
+ */
27
+ export function resolveTagChipSurface(
28
+ color: string,
29
+ active: boolean,
30
+ ): ResolvedTagChipSurface {
31
+ if (isSpecialTagStyle(color)) {
32
+ const config = getSpecialTagStyleConfig(color)
33
+ return {
34
+ className: cn(
35
+ "relative isolate group",
36
+ config.default.className,
37
+ active ? config.active?.className : undefined,
38
+ ),
39
+ style: {
40
+ ...config.default.style,
41
+ ...(active ? config.active?.style : {}),
42
+ },
43
+ texture: color,
44
+ }
45
+ }
46
+
47
+ if (color === "") {
48
+ return active
49
+ ? {
50
+ className: "bg-primary text-primary-foreground hover:bg-primary/90",
51
+ style: undefined,
52
+ texture: null,
53
+ }
54
+ : {
55
+ className: "bg-muted text-foreground hover:bg-accent",
56
+ style: undefined,
57
+ texture: null,
58
+ }
59
+ }
60
+
61
+ const chipColors = computeTagChipColors(color)
62
+ return {
63
+ className: "bg-(--chip-bg) hover:bg-(--chip-hover-bg)",
64
+ style: {
65
+ ["--chip-bg" as string]: active ? chipColors.hoverBg : chipColors.baseBg,
66
+ ["--chip-hover-bg" as string]: chipColors.hoverBg,
67
+ color: chipColors.fg,
68
+ },
69
+ texture: null,
70
+ }
71
+ }