@42-central/ui-react 0.20.2 → 0.23.0

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.
Files changed (137) hide show
  1. package/dist/{chunk-45QRQKRC.js → chunk-3L5GLI67.js} +12 -8
  2. package/dist/chunk-3L5GLI67.js.map +1 -0
  3. package/dist/{chunk-C74TV64U.js → chunk-4FEOMQYR.js} +4 -4
  4. package/dist/{chunk-C74TV64U.js.map → chunk-4FEOMQYR.js.map} +1 -1
  5. package/dist/{chunk-LFQDB5OD.js → chunk-D3JYDAUZ.js} +3 -3
  6. package/dist/{chunk-LFQDB5OD.js.map → chunk-D3JYDAUZ.js.map} +1 -1
  7. package/dist/{chunk-UVQXRDRO.js → chunk-DHJB4UJD.js} +3 -3
  8. package/dist/{chunk-UVQXRDRO.js.map → chunk-DHJB4UJD.js.map} +1 -1
  9. package/dist/{chunk-UCCJUFOG.js → chunk-F2FSHVO5.js} +3 -3
  10. package/dist/{chunk-UCCJUFOG.js.map → chunk-F2FSHVO5.js.map} +1 -1
  11. package/dist/{chunk-Z4MBCKG5.js → chunk-FB2G4LNH.js} +4 -4
  12. package/dist/{chunk-Z4MBCKG5.js.map → chunk-FB2G4LNH.js.map} +1 -1
  13. package/dist/{chunk-FDCPMUJK.js → chunk-IRNF274I.js} +3 -3
  14. package/dist/chunk-IRNF274I.js.map +1 -0
  15. package/dist/{chunk-O5W3QWJ6.js → chunk-J44FJ7PH.js} +3 -3
  16. package/dist/{chunk-O5W3QWJ6.js.map → chunk-J44FJ7PH.js.map} +1 -1
  17. package/dist/{chunk-WXL5RP6P.js → chunk-MRAJ45IM.js} +3 -3
  18. package/dist/{chunk-WXL5RP6P.js.map → chunk-MRAJ45IM.js.map} +1 -1
  19. package/dist/{chunk-45TG7H5Q.js → chunk-OZMSXYBX.js} +3 -3
  20. package/dist/{chunk-45TG7H5Q.js.map → chunk-OZMSXYBX.js.map} +1 -1
  21. package/dist/{chunk-37VQGKD6.js → chunk-SZEOTXRZ.js} +4 -4
  22. package/dist/{chunk-37VQGKD6.js.map → chunk-SZEOTXRZ.js.map} +1 -1
  23. package/dist/{chunk-2BNIHOMT.js → chunk-YPFSRZ3T.js} +3 -3
  24. package/dist/{chunk-2BNIHOMT.js.map → chunk-YPFSRZ3T.js.map} +1 -1
  25. package/dist/{chunk-5CNVVA7I.js → chunk-YWTOW7PZ.js} +4 -4
  26. package/dist/{chunk-5CNVVA7I.js.map → chunk-YWTOW7PZ.js.map} +1 -1
  27. package/dist/components/autocomplete/index.js +2 -2
  28. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts +94 -0
  29. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts.map +1 -0
  30. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts +76 -0
  31. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts.map +1 -0
  32. package/dist/components/calendar-heatmap/index.d.ts +2 -0
  33. package/dist/components/calendar-heatmap/index.d.ts.map +1 -0
  34. package/dist/components/calendar-heatmap/index.js +311 -0
  35. package/dist/components/calendar-heatmap/index.js.map +1 -0
  36. package/dist/components/camera/index.js +4 -4
  37. package/dist/components/clipboard/index.js +1 -1
  38. package/dist/components/combobox/index.js +2 -2
  39. package/dist/components/combobox-list/index.js +4 -4
  40. package/dist/components/data-table/index.js +13 -13
  41. package/dist/components/date-picker/index.js +5 -5
  42. package/dist/components/geodesic/a11y.d.ts +15 -0
  43. package/dist/components/geodesic/a11y.d.ts.map +1 -0
  44. package/dist/components/geodesic/activity-badge.d.ts +5 -0
  45. package/dist/components/geodesic/activity-badge.d.ts.map +1 -0
  46. package/dist/components/geodesic/badge-frame.d.ts +60 -0
  47. package/dist/components/geodesic/badge-frame.d.ts.map +1 -0
  48. package/dist/components/geodesic/exam-badge.d.ts +5 -0
  49. package/dist/components/geodesic/exam-badge.d.ts.map +1 -0
  50. package/dist/components/geodesic/geometry.d.ts +1089 -0
  51. package/dist/components/geodesic/geometry.d.ts.map +1 -0
  52. package/dist/components/geodesic/gift-box-badge.d.ts +5 -0
  53. package/dist/components/geodesic/gift-box-badge.d.ts.map +1 -0
  54. package/dist/components/geodesic/gift-token.d.ts +23 -0
  55. package/dist/components/geodesic/gift-token.d.ts.map +1 -0
  56. package/dist/components/geodesic/glyph-slot.d.ts +8 -0
  57. package/dist/components/geodesic/glyph-slot.d.ts.map +1 -0
  58. package/dist/components/geodesic/index.d.ts +12 -0
  59. package/dist/components/geodesic/index.d.ts.map +1 -0
  60. package/dist/components/geodesic/index.js +917 -0
  61. package/dist/components/geodesic/index.js.map +1 -0
  62. package/dist/components/geodesic/module-badge.d.ts +5 -0
  63. package/dist/components/geodesic/module-badge.d.ts.map +1 -0
  64. package/dist/components/geodesic/planet.d.ts +30 -0
  65. package/dist/components/geodesic/planet.d.ts.map +1 -0
  66. package/dist/components/geodesic/project-badge.d.ts +5 -0
  67. package/dist/components/geodesic/project-badge.d.ts.map +1 -0
  68. package/dist/components/geodesic/skill-badge.d.ts +5 -0
  69. package/dist/components/geodesic/skill-badge.d.ts.map +1 -0
  70. package/dist/components/geodesic/social-badge.d.ts +8 -0
  71. package/dist/components/geodesic/social-badge.d.ts.map +1 -0
  72. package/dist/components/geodesic/status.d.ts +80 -0
  73. package/dist/components/geodesic/status.d.ts.map +1 -0
  74. package/dist/components/geodesic/styles.css +146 -0
  75. package/dist/components/input/index.js +1 -1
  76. package/dist/components/input/input.d.ts.map +1 -1
  77. package/dist/components/menu/index.js +1 -1
  78. package/dist/components/menu/menu.d.ts +7 -5
  79. package/dist/components/menu/menu.d.ts.map +1 -1
  80. package/dist/components/multi-combobox-list/index.js +4 -4
  81. package/dist/components/multi-select/index.js +3 -3
  82. package/dist/components/navigation-progress/index.d.ts +2 -0
  83. package/dist/components/navigation-progress/index.d.ts.map +1 -0
  84. package/dist/components/navigation-progress/index.js +133 -0
  85. package/dist/components/navigation-progress/index.js.map +1 -0
  86. package/dist/components/navigation-progress/navigation-progress.d.ts +46 -0
  87. package/dist/components/navigation-progress/navigation-progress.d.ts.map +1 -0
  88. package/dist/components/number-input/index.js +2 -2
  89. package/dist/components/number-input/number-input.d.ts.map +1 -1
  90. package/dist/components/password-input/index.js +1 -1
  91. package/dist/components/photo-capture/index.js +4 -4
  92. package/dist/components/pills-input/index.js +2 -2
  93. package/dist/components/pin-input/index.js +1 -1
  94. package/dist/components/select/index.js +3 -3
  95. package/dist/components/spotlight/index.js +3 -3
  96. package/dist/components/tags-input/index.js +2 -2
  97. package/dist/components/text-input/index.js +1 -1
  98. package/dist/components/textarea/index.js +1 -1
  99. package/dist/components/time-input/index.js +3 -3
  100. package/dist/components/tree-multi-select/index.js +3 -3
  101. package/dist/components/tree-select/index.js +2 -2
  102. package/dist/index.js +2 -2
  103. package/package.json +2 -1
  104. package/src/as-child.contract.test.tsx +6 -0
  105. package/src/components/calendar-heatmap/calendar-heatmap-grid.test.ts +186 -0
  106. package/src/components/calendar-heatmap/calendar-heatmap-grid.ts +192 -0
  107. package/src/components/calendar-heatmap/calendar-heatmap.test.tsx +180 -0
  108. package/src/components/calendar-heatmap/calendar-heatmap.tsx +385 -0
  109. package/src/components/calendar-heatmap/index.ts +11 -0
  110. package/src/components/geodesic/a11y.ts +10 -0
  111. package/src/components/geodesic/activity-badge.tsx +17 -0
  112. package/src/components/geodesic/badge-frame.tsx +324 -0
  113. package/src/components/geodesic/exam-badge.tsx +17 -0
  114. package/src/components/geodesic/geometry.test.ts +60 -0
  115. package/src/components/geodesic/geometry.ts +367 -0
  116. package/src/components/geodesic/gift-box-badge.tsx +17 -0
  117. package/src/components/geodesic/gift-token.tsx +104 -0
  118. package/src/components/geodesic/glyph-slot.tsx +28 -0
  119. package/src/components/geodesic/index.ts +13 -0
  120. package/src/components/geodesic/module-badge.tsx +17 -0
  121. package/src/components/geodesic/planet.tsx +131 -0
  122. package/src/components/geodesic/project-badge.tsx +17 -0
  123. package/src/components/geodesic/skill-badge.tsx +17 -0
  124. package/src/components/geodesic/social-badge.tsx +21 -0
  125. package/src/components/geodesic/status.test.ts +66 -0
  126. package/src/components/geodesic/status.ts +176 -0
  127. package/src/components/geodesic/styles.css +146 -0
  128. package/src/components/input/input.test.tsx +23 -0
  129. package/src/components/input/input.tsx +10 -6
  130. package/src/components/menu/menu.tsx +16 -9
  131. package/src/components/navigation-progress/index.ts +14 -0
  132. package/src/components/navigation-progress/navigation-progress.test.tsx +184 -0
  133. package/src/components/navigation-progress/navigation-progress.tsx +228 -0
  134. package/src/components/number-input/number-input.tsx +3 -4
  135. package/src/icon-stroke.test.tsx +5 -0
  136. package/dist/chunk-45QRQKRC.js.map +0 -1
  137. package/dist/chunk-FDCPMUJK.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ "use client"
2
+
3
+ import { type CSSProperties, useId } from "react"
4
+ import { cn } from "../../lib/cn"
5
+ import { props as attrs } from "../../lib/props"
6
+ import type { WithTestId } from "../../lib/test-id"
7
+ import { imageProps } from "./a11y"
8
+ import { useSettled } from "./badge-frame"
9
+ import { GEOMETRY } from "./geometry"
10
+ import { color, faceFill, fadeWidth, fillLevel, paint } from "./status"
11
+
12
+ export type PlanetProps = WithTestId & {
13
+ /**
14
+ * How far along, 0–100: lights the planet from the bottom up exactly as an
15
+ * in-progress badge does (same face order, floor and tones), animating
16
+ * between values.
17
+ */
18
+ progress: number
19
+ /** Rendered width and height: px, or any CSS length (`100%`, `clamp(…)`). */
20
+ size?: number | string
21
+ /** Accessible name. Without one the planet is decorative and hidden from assistive tech. */
22
+ label?: string
23
+ className?: string
24
+ style?: CSSProperties
25
+ }
26
+
27
+ const solid = GEOMETRY.planet
28
+ const FACES = solid.facets.length
29
+
30
+ /** Each face's centre height in the 64×64 viewBox, by bottom-up rank. */
31
+ const CENTRE_Y_BY_RANK = solid.facets
32
+ .map((facet) => {
33
+ const ys = facet.points.split(" ").map((point) => Number(point.split(",")[1]))
34
+ return { rank: facet.rank, y: ys.reduce((a, b) => a + b, 0) / ys.length }
35
+ })
36
+ .sort((a, b) => a.rank - b.rank)
37
+ .map((face) => face.y)
38
+
39
+ /**
40
+ * Where the lit edge sits on the planet at `progress`, as a fraction of its
41
+ * rendered size from the top: the centre of the face half-way through the
42
+ * fade. What a readout beside it lines a leader up with.
43
+ */
44
+ export function planetLevelOffset(progress: number) {
45
+ const edge = fillLevel("in-progress", progress, FACES) - fadeWidth(FACES) / 2
46
+ const rank = Math.min(FACES - 1, Math.max(0, Math.round(edge)))
47
+ return (CENTRE_Y_BY_RANK[rank] ?? 32) / 64
48
+ }
49
+
50
+ /**
51
+ * The level planet from the homepage hero: a finer geodesic sphere lit like an
52
+ * in-progress badge. Faces light bottom-up through `fillLevel` and
53
+ * `faceLight`, in the in-progress pink tones, cascading up when progress
54
+ * rises and draining when it falls; it fills up when it appears.
55
+ */
56
+ export function Planet({ progress, size = 240, label, className, style, testId }: PlanetProps) {
57
+ const id = useId().replace(/[^\w-]/g, "")
58
+ const pink = color("pink", 300)
59
+ const target = fillLevel("in-progress", progress, FACES)
60
+ return (
61
+ <span
62
+ className={cn("geodesic-badge", className)}
63
+ {...imageProps(label)}
64
+ {...attrs({ "data-testid": testId })}
65
+ style={{ display: "inline-grid", width: size, height: size, flex: "none", ...style }}
66
+ >
67
+ <svg
68
+ aria-hidden="true"
69
+ viewBox="0 0 64 64"
70
+ width="100%"
71
+ height="100%"
72
+ overflow="visible"
73
+ style={{ gridArea: "1 / 1", display: "block" }}
74
+ >
75
+ <defs>
76
+ <radialGradient id={`${id}-halo`}>
77
+ <stop offset="0.6" stopColor={pink} stopOpacity={0.1} />
78
+ <stop offset="1" stopColor={pink} stopOpacity={0} />
79
+ </radialGradient>
80
+ </defs>
81
+ <circle cx={32} cy={32} r={44} fill={`url(#${id}-halo)`} />
82
+ {/* Softer than a badge's faces: the planet is large, and its
83
+ wireframe has to read through the lit half. */}
84
+ <g opacity={0.6}>
85
+ <SmoothFill target={target} />
86
+ </g>
87
+ <g fill="none" stroke={paint("pink", [200, 400])} strokeLinejoin="round">
88
+ <path
89
+ d={solid.hidden}
90
+ strokeOpacity={0.2}
91
+ strokeWidth={0.5}
92
+ vectorEffect="non-scaling-stroke"
93
+ />
94
+ <path
95
+ d={solid.edges}
96
+ strokeOpacity={0.85}
97
+ strokeWidth={0.6}
98
+ vectorEffect="non-scaling-stroke"
99
+ />
100
+ </g>
101
+ </svg>
102
+ </span>
103
+ )
104
+ }
105
+
106
+ /**
107
+ * The lit level is a CSS-transitioned custom property every face reads (see
108
+ * `.geodesic-facet-smooth` in styles.css): the edge sweeps through the faces
109
+ * continuously, with no per-face delays and no per-frame React work. The
110
+ * badges fill each face through a gradient instead; on a sphere this large
111
+ * and fine, a sweep of whole faces reads better.
112
+ */
113
+ function SmoothFill({ target }: { target: number }) {
114
+ const level = useSettled(0, target)
115
+ return (
116
+ <g
117
+ className="geodesic-solid-smooth"
118
+ style={{ "--geodesic-level": level, "--geodesic-fade": fadeWidth(FACES) } as CSSProperties}
119
+ >
120
+ {solid.facets.map((facet) => (
121
+ <polygon
122
+ key={facet.points}
123
+ className="geodesic-facet-smooth"
124
+ points={facet.points}
125
+ fill={faceFill("pink", "in-progress", facet.tone)}
126
+ style={{ "--geodesic-rank": facet.rank } as CSSProperties}
127
+ />
128
+ ))}
129
+ </g>
130
+ )
131
+ }
@@ -0,0 +1,17 @@
1
+ import { type BadgeBaseProps, BadgeFrame } from "./badge-frame"
2
+ import { GEOMETRY } from "./geometry"
3
+
4
+ export type ProjectBadgeProps = BadgeBaseProps
5
+
6
+ /** A project: the cube in a hexagon. Validated, purple. */
7
+ export function ProjectBadge(props: ProjectBadgeProps) {
8
+ return (
9
+ <BadgeFrame
10
+ {...props}
11
+ tile={{ kind: "polygon", points: GEOMETRY.tiles.hexagon }}
12
+ solids={[GEOMETRY.project]}
13
+ doneHue="purple"
14
+ locked="silhouette"
15
+ />
16
+ )
17
+ }
@@ -0,0 +1,17 @@
1
+ import { type BadgeBaseProps, BadgeFrame } from "./badge-frame"
2
+ import { GEOMETRY } from "./geometry"
3
+
4
+ export type SkillBadgeProps = BadgeBaseProps
5
+
6
+ /** A skill: the crystal in a 7-sided tile. Acquired, it takes indigo — the kit's `brand` ramp, the closest it has. */
7
+ export function SkillBadge(props: SkillBadgeProps) {
8
+ return (
9
+ <BadgeFrame
10
+ {...props}
11
+ tile={{ kind: "polygon", points: GEOMETRY.tiles.heptagon }}
12
+ solids={[GEOMETRY.skill]}
13
+ doneHue="brand"
14
+ locked="silhouette"
15
+ />
16
+ )
17
+ }
@@ -0,0 +1,21 @@
1
+ import { type BadgeBaseProps, BadgeFrame } from "./badge-frame"
2
+ import { GEOMETRY } from "./geometry"
3
+
4
+ export type SocialBadgeProps = BadgeBaseProps
5
+
6
+ /**
7
+ * Social: three small icosahedra linked in an 8-sided tile. The frame gives it
8
+ * no done colour; it takes cyan until the design says otherwise.
9
+ */
10
+ export function SocialBadge(props: SocialBadgeProps) {
11
+ return (
12
+ <BadgeFrame
13
+ {...props}
14
+ tile={{ kind: "polygon", points: GEOMETRY.tiles.octagon }}
15
+ solids={GEOMETRY.social}
16
+ links={GEOMETRY.socialLinks}
17
+ doneHue="cyan"
18
+ locked="silhouette"
19
+ />
20
+ )
21
+ }
@@ -0,0 +1,66 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { faceLight, fillLevel, inProgressShare, MIN_IN_PROGRESS } from "./status"
3
+
4
+ describe("inProgressShare", () => {
5
+ it("maps 0–100 onto the floor–100", () => {
6
+ expect(inProgressShare(0)).toBe(MIN_IN_PROGRESS)
7
+ expect(inProgressShare(100)).toBe(100)
8
+ expect(inProgressShare(50)).toBe(MIN_IN_PROGRESS + (100 - MIN_IN_PROGRESS) / 2)
9
+ })
10
+
11
+ it("clamps out-of-range and non-finite progress", () => {
12
+ expect(inProgressShare(-5)).toBe(MIN_IN_PROGRESS)
13
+ expect(inProgressShare(Number.NaN)).toBe(MIN_IN_PROGRESS)
14
+ expect(inProgressShare(250)).toBe(100)
15
+ })
16
+ })
17
+
18
+ describe("fillLevel and faceLight", () => {
19
+ const lights = (status: Parameters<typeof fillLevel>[0], progress: number, faces: number) =>
20
+ Array.from({ length: faces }, (_, rank) =>
21
+ faceLight(rank, fillLevel(status, progress, faces), faces),
22
+ )
23
+ const total = (values: number[]) => values.reduce((a, b) => a + b, 0)
24
+
25
+ it("lights every face when done and none when locked or available", () => {
26
+ expect(lights("done", 0, 40)).toEqual(Array(40).fill(1))
27
+ expect(lights("locked", 100, 40)).toEqual(Array(40).fill(0))
28
+ expect(lights("available", 100, 40)).toEqual(Array(40).fill(0))
29
+ })
30
+
31
+ it("lights every face at 100% in progress", () => {
32
+ expect(lights("in-progress", 100, 3)).toEqual([1, 1, 1])
33
+ expect(lights("in-progress", 100, 40)).toEqual(Array(40).fill(1))
34
+ })
35
+
36
+ it("shows some light at 0% in progress, even on a 3-face exam", () => {
37
+ expect(lights("in-progress", 0, 3)[0]).toBeGreaterThan(0)
38
+ expect(lights("in-progress", 0, 40)[0]).toBeGreaterThan(0)
39
+ })
40
+
41
+ it("moves the fill at every percent on a small solid", () => {
42
+ for (let p = 1; p <= 100; p++)
43
+ expect(total(lights("in-progress", p, 3))).toBeGreaterThan(
44
+ total(lights("in-progress", p - 1, 3)),
45
+ )
46
+ })
47
+
48
+ it("never dims a face as progress grows", () => {
49
+ for (const faces of [3, 4, 40]) {
50
+ let last = lights("in-progress", 0, faces)
51
+ for (let p = 1; p <= 100; p++) {
52
+ const next = lights("in-progress", p, faces)
53
+ for (const [rank, light] of next.entries())
54
+ expect(light).toBeGreaterThanOrEqual(last[rank] ?? 0)
55
+ last = next
56
+ }
57
+ }
58
+ })
59
+
60
+ it("spreads the module's edge over a few faces, bottom first", () => {
61
+ const module = lights("in-progress", 50, 40)
62
+ expect(module.filter((light) => light > 0 && light < 1).length).toBeGreaterThan(1)
63
+ for (let rank = 1; rank < module.length; rank++)
64
+ expect(module[rank]).toBeLessThanOrEqual(module[rank - 1] ?? 1)
65
+ })
66
+ })
@@ -0,0 +1,176 @@
1
+ /**
2
+ * The badges' colour grammar, from the Figma frame "Badges — 4 statuses, 4
3
+ * levels": one colour per status, and the same progression on every shape —
4
+ * wireframe, then half lit, then full with a closed orbit.
5
+ *
6
+ * Only "done" varies by shape (a module is green, a validated exam gold…), so
7
+ * each badge passes its own done hue and everything else comes from here.
8
+ */
9
+
10
+ export type BadgeStatus = "locked" | "available" | "in-progress" | "done"
11
+
12
+ /**
13
+ * A kit colour ramp, read as `--color-<hue>-<step>`, or `neutral`: the
14
+ * page's own ink, built from the Figma neutral pairs (see `neutral` below).
15
+ */
16
+ export type Hue =
17
+ | "neutral"
18
+ | "brand"
19
+ | "blue"
20
+ | "cyan"
21
+ | "teal"
22
+ | "green"
23
+ | "yellow"
24
+ | "orange"
25
+ | "red"
26
+ | "pink"
27
+ | "purple"
28
+
29
+ /**
30
+ * One colour per theme. `--geodesic-light` is 0 under a dark theme and 1
31
+ * under a light one (styles.css sets it from `data-theme`), so this resolves
32
+ * to `dark` or `light`; with no theme set it stays dark.
33
+ */
34
+ export function themed(dark: string, light: string) {
35
+ return `color-mix(in srgb, ${dark}, ${light} calc(var(--geodesic-light, 0) * 100%))`
36
+ }
37
+
38
+ /** A colour at an opacity, for tints and glows. */
39
+ function alpha(value: string, percent: number) {
40
+ return percent === 100 ? value : `color-mix(in srgb, ${value} ${percent}%, transparent)`
41
+ }
42
+
43
+ /**
44
+ * The neutral ramp, painted the way the Figma file paints neutral text and
45
+ * lines, never with the gray scales: a step is how far from the page toward
46
+ * its ink. On a dark page that is white at an opacity, down to `brand-950`
47
+ * (the page itself) at 900 and past; on a light page `brand-900` at an
48
+ * opacity, from white at 50 and below. So 400 is `Text/text-tertiary` in
49
+ * light, and 700 `Text/text-secondary`.
50
+ */
51
+ function neutral(theme: "dark" | "light", step: number) {
52
+ if (theme === "dark")
53
+ return step >= 900
54
+ ? "var(--color-brand-950, currentColor)"
55
+ : alpha("var(--color-white, currentColor)", 100 - step / 10)
56
+ return step <= 50
57
+ ? "var(--color-white, currentColor)"
58
+ : alpha("var(--color-brand-900, currentColor)", step / 10)
59
+ }
60
+
61
+ /**
62
+ * Kit ramps as CSS custom properties, falling back to `currentColor` so a page
63
+ * without the kit theme gets monochrome badges instead of invisible ones.
64
+ */
65
+ export function color(hue: Hue, step: number) {
66
+ if (hue === "neutral") return themed(neutral("dark", step), neutral("light", step))
67
+ return `var(--color-${hue}-${step}, currentColor)`
68
+ }
69
+
70
+ /** A kit ramp at an opacity, for tints and glows. */
71
+ export function tint(hue: Hue, step: number, percent: number) {
72
+ return alpha(color(hue, step), percent)
73
+ }
74
+
75
+ const STATUS_HUE: Record<Exclude<BadgeStatus, "done">, Hue> = {
76
+ locked: "neutral",
77
+ available: "purple",
78
+ "in-progress": "pink",
79
+ }
80
+
81
+ export function hueOf(status: BadgeStatus, doneHue: Hue): Hue {
82
+ return status === "done" ? doneHue : STATUS_HUE[status]
83
+ }
84
+
85
+ /**
86
+ * A ramp step per theme, optionally at an opacity. Light mode keeps dark's
87
+ * steps wherever they still read, so both themes carry the same softness;
88
+ * only what would vanish on a light page (a near-white 200 wire) moves, and
89
+ * by as little as it takes: `paint("purple", [200, 400])`.
90
+ */
91
+ export function paint(hue: Hue, [dark, light]: readonly [number, number], percent = 100) {
92
+ if (hue === "neutral")
93
+ return themed(alpha(neutral("dark", dark), percent), alpha(neutral("light", light), percent))
94
+ return themed(tint(hue, dark, percent), tint(hue, light, percent))
95
+ }
96
+
97
+ /** A facet's light bucket, 0 (darkest) to 3 (brightest). */
98
+ export type Tone = 0 | 1 | 2 | 3
99
+
100
+ /** Facet light buckets to ramp steps, dark then light. */
101
+ const TONE_STEPS = { dark: [600, 500, 400, 300], light: [600, 500, 400, 300] } as const
102
+
103
+ /** In progress is "half lit": a lighter, flatter pink, so no facet reads as a hole. */
104
+ const IN_PROGRESS_TONE_STEPS = { dark: [400, 300, 300, 200], light: [400, 300, 300, 200] } as const
105
+
106
+ /**
107
+ * A facet's fill for its light bucket, per status and theme.
108
+ *
109
+ * Locked and available light no facet, so theirs only shows while lit faces
110
+ * drain out after a status change back down; a deep, see-through step close
111
+ * to the page keeps that drain from flashing coloured faces.
112
+ */
113
+ export function faceFill(hue: Hue, status: BadgeStatus, tone: Tone) {
114
+ if (status === "locked" || status === "available") return paint(hue, [800, 100], 40)
115
+ const steps = status === "in-progress" ? IN_PROGRESS_TONE_STEPS : TONE_STEPS
116
+ return paint(hue, [steps.dark[tone], steps.light[tone]])
117
+ }
118
+
119
+ /**
120
+ * The floor of an in-progress badge: started work always shows some light, so
121
+ * "in progress at 0%" never reads as "available".
122
+ */
123
+ export const MIN_IN_PROGRESS = 15
124
+
125
+ /**
126
+ * Progress as an in-progress badge draws it: 0–100 mapped linearly onto
127
+ * MIN_IN_PROGRESS–100, so the floor costs no resolution — every step of
128
+ * progress still moves the fill.
129
+ */
130
+ export function inProgressShare(progress: number) {
131
+ const clamped = Math.min(100, Math.max(0, Number.isFinite(progress) ? progress : 0))
132
+ return MIN_IN_PROGRESS + (clamped / 100) * (100 - MIN_IN_PROGRESS)
133
+ }
134
+
135
+ /**
136
+ * How many faces the lit edge spreads over: one on a small solid, so its
137
+ * single boundary face fades with every percent, and about three on the
138
+ * module's forty, so the frontier reads soft instead of jagged.
139
+ */
140
+ export function fadeWidth(facetCount: number) {
141
+ return Math.max(1, Math.round(facetCount / 12))
142
+ }
143
+
144
+ /**
145
+ * Where the fill stands, measured in faces along the bottom-up order: a face
146
+ * of rank `r` is lit by how far the level has passed it (see faceLight).
147
+ * Done is full, locked and available are empty, and in progress maps
148
+ * `progress` through inProgressShare, so 0% still shows light.
149
+ */
150
+ export function fillLevel(
151
+ status: BadgeStatus,
152
+ progress: number,
153
+ facetCount: number,
154
+ fade = fadeWidth(facetCount),
155
+ ) {
156
+ const full = facetCount - 1 + fade
157
+ if (status === "done") return full
158
+ if (status !== "in-progress") return 0
159
+ return (inProgressShare(progress) / 100) * full
160
+ }
161
+
162
+ /**
163
+ * The badges' liquid fill: a much wider edge, about a quarter of the faces, so
164
+ * the frontier is a slope of faces at different fill heights.
165
+ */
166
+ export function liquidFadeWidth(facetCount: number) {
167
+ return Math.max(1, Math.round(facetCount / 4))
168
+ }
169
+
170
+ /**
171
+ * How lit the face of rank `rank` is at a fill level, 0 to 1, continuous:
172
+ * the CSS ramp `.geodesic-facet-smooth` computes, in JS, for the tests.
173
+ */
174
+ export function faceLight(rank: number, level: number, facetCount: number) {
175
+ return Math.min(1, Math.max(0, (level - rank) / fadeWidth(facetCount)))
176
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Geodesic badges — theme switch, status transitions and the progress fill.
3
+ * See `badge-frame.tsx` and `planet.tsx`. Imported separately from
4
+ * `styles.css`/`theme.css` — only consumers who render a geodesic badge need
5
+ * this file:
6
+ *
7
+ * import "@42/ui-react/geodesic/styles.css";
8
+ *
9
+ * Reduced motion is honoured two ways: the OS setting
10
+ * (`prefers-reduced-motion`), and `data-motion="reduced"` on `<html>` for
11
+ * apps that let people choose in-app.
12
+ */
13
+
14
+ /*
15
+ * Which theme the badges are drawn for: 1 under a light theme, 0 under a
16
+ * dark one, inherited, so the nearest themed ancestor wins. Every badge
17
+ * colour picks its dark or light step from it (see `themed` in status.ts).
18
+ */
19
+ [data-theme="light"] {
20
+ --geodesic-light: 1;
21
+ }
22
+ [data-theme="dark"] {
23
+ --geodesic-light: 0;
24
+ }
25
+
26
+ /*
27
+ * A slotted glyph (a lucide icon, usually) fills its slot and draws a 1.5px
28
+ * stroke whatever size the badge renders at — lucide's stroke width lives in
29
+ * its 24-unit viewBox, so without this a small badge gets a hairline glyph and
30
+ * a large one a heavy one.
31
+ */
32
+ .geodesic-glyph-slot > svg {
33
+ width: 100%;
34
+ height: 100%;
35
+ stroke-width: 1.5;
36
+ }
37
+ .geodesic-glyph-slot > svg * {
38
+ vector-effect: non-scaling-stroke;
39
+ }
40
+
41
+ /*
42
+ * A status change recolours a badge in place (neutral to purple to pink to its
43
+ * done hue), so every shape eases its paint and the wrapper its glow. Rules
44
+ * below that set their own transition repeat these properties, since a
45
+ * transition list replaces, not adds.
46
+ */
47
+ .geodesic-badge {
48
+ transition: filter 300ms ease;
49
+ }
50
+ .geodesic-badge :where(circle, polygon, path, rect) {
51
+ transition:
52
+ fill 300ms ease,
53
+ stroke 300ms ease,
54
+ fill-opacity 300ms ease,
55
+ stroke-opacity 300ms ease;
56
+ }
57
+ /* Layers that come and go with a status (silhouette, lock) fade, not pop. */
58
+ .geodesic-crossfade {
59
+ transform-box: fill-box;
60
+ transform-origin: center;
61
+ transition:
62
+ opacity 300ms ease,
63
+ transform 300ms ease;
64
+ }
65
+ .geodesic-crossfade[data-shown="false"] {
66
+ opacity: 0;
67
+ }
68
+ .geodesic-lock[data-shown="false"] {
69
+ transform: scale(0.8);
70
+ }
71
+
72
+ :where(:root[data-motion="reduced"]) {
73
+ .geodesic-badge,
74
+ .geodesic-badge :where(circle, polygon, path, rect),
75
+ .geodesic-crossfade {
76
+ transition: none;
77
+ }
78
+ }
79
+ @media (prefers-reduced-motion: reduce) {
80
+ .geodesic-badge,
81
+ .geodesic-badge :where(circle, polygon, path, rect),
82
+ .geodesic-crossfade {
83
+ transition: none;
84
+ }
85
+ }
86
+
87
+ /*
88
+ * The fill level is a registered number, so CSS can transition it. The
89
+ * planet turns it into each face's opacity (smooth); the badges into where
90
+ * each face's own gradient stands (liquid).
91
+ */
92
+ @property --geodesic-level {
93
+ syntax: "<number>";
94
+ inherits: true;
95
+ initial-value: 0;
96
+ }
97
+ .geodesic-solid-smooth {
98
+ transition: --geodesic-level 900ms cubic-bezier(0.4, 0, 0.2, 1);
99
+ }
100
+ .geodesic-facet-smooth {
101
+ fill-opacity: clamp(
102
+ 0,
103
+ calc((var(--geodesic-level) - var(--geodesic-rank)) / var(--geodesic-fade)),
104
+ 1
105
+ );
106
+ transition: fill 300ms ease;
107
+ }
108
+
109
+ /*
110
+ * The badges' liquid fill: how far the level has passed this face, 0 to 1,
111
+ * as for the planet's smooth one; but instead of an opacity it sets where the face's own
112
+ * gradient stands. The mask is laid out on the face's bounding box, so the
113
+ * ramp (2.5 times the face's height, smoothstep-eased, so no edge shows)
114
+ * rises from the face's base at 0 to past its top at 1.
115
+ */
116
+ .geodesic-facet-liquid {
117
+ --geodesic-fill: clamp(
118
+ 0,
119
+ (var(--geodesic-level) - var(--geodesic-rank)) /
120
+ var(--geodesic-fade),
121
+ 1
122
+ );
123
+ --geodesic-ramp: 250;
124
+ /* The ramp's top edge, in % of the face's height from its base. */
125
+ --geodesic-edge: calc(var(--geodesic-fill) * (100 + var(--geodesic-ramp)));
126
+ mask-image: linear-gradient(
127
+ to top,
128
+ #000 calc((var(--geodesic-edge) - var(--geodesic-ramp)) * 1%),
129
+ rgb(0 0 0 / 0.84) calc((var(--geodesic-edge) - var(--geodesic-ramp) * 0.75) * 1%),
130
+ rgb(0 0 0 / 0.5) calc((var(--geodesic-edge) - var(--geodesic-ramp) * 0.5) * 1%),
131
+ rgb(0 0 0 / 0.16) calc((var(--geodesic-edge) - var(--geodesic-ramp) * 0.25) * 1%),
132
+ transparent calc(var(--geodesic-edge) * 1%)
133
+ );
134
+ transition: fill 300ms ease;
135
+ }
136
+
137
+ :where(:root[data-motion="reduced"]) {
138
+ .geodesic-solid-smooth {
139
+ transition: none;
140
+ }
141
+ }
142
+ @media (prefers-reduced-motion: reduce) {
143
+ .geodesic-solid-smooth {
144
+ transition: none;
145
+ }
146
+ }
@@ -2,6 +2,7 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react"
2
2
  import { createRef } from "react"
3
3
  import { describe, expect, it, vi } from "vitest"
4
4
  import { Field } from "../field/field"
5
+ import { Kbd } from "../kbd/kbd"
5
6
  import { Input, InputBase } from "./input"
6
7
 
7
8
  describe("Input", () => {
@@ -109,3 +110,25 @@ describe("InputBase", () => {
109
110
  expect(screen.getByTestId("shell").tagName).toBe("DIV")
110
111
  })
111
112
  })
113
+
114
+ /**
115
+ * Shell icon sizing (#422) — the shell sizes svgs through `:where()`, at zero
116
+ * class specificity, so a component in a slot that sizes its own icons keeps
117
+ * them. The classes are asserted, not the computed size: jsdom runs no Tailwind.
118
+ */
119
+ describe("InputBase (icon sizing)", () => {
120
+ it("sizes svgs at zero specificity, never with a bare descendant rule", () => {
121
+ render(<InputBase testId="shell" startSlot={<svg aria-hidden="true" />} />)
122
+ const cls = screen.getByTestId("shell").className
123
+ expect(cls).toContain("[:where(&)_svg]:size-4")
124
+ expect(cls).toContain("[:where(&)_svg]:shrink-0")
125
+ expect(cls).not.toMatch(/\[&_svg\]/)
126
+ })
127
+
128
+ it("keeps a slotted Kbd's own icon sizing", () => {
129
+ render(<Input placeholder="Search" endSlot={<Kbd hotkey="mod+k" size="sm" />} />)
130
+ const caps = document.querySelectorAll("kbd kbd")
131
+ expect(caps.length).toBe(2)
132
+ for (const cap of caps) expect(cap.className).toContain("[&_svg]:size-3")
133
+ })
134
+ })
@@ -77,7 +77,11 @@ export const shellChrome = [
77
77
  "data-disabled:cursor-not-allowed data-disabled:opacity-60",
78
78
  "data-disabled:bg-white/8",
79
79
  "data-pointer:cursor-pointer",
80
- "[&_svg]:pointer-events-none [&_svg]:shrink-0",
80
+ // `:where()` drops every shell svg rule to zero class specificity, so it
81
+ // sizes bare icons (the slot's own, the family's chevron / clear) while a
82
+ // component in a slot that styles its own icons (Kbd, Badge, Spinner…), or
83
+ // a size class on the icon itself, wins whatever the CSS order (#422).
84
+ "[:where(&)_svg]:pointer-events-none [:where(&)_svg]:shrink-0",
81
85
  ]
82
86
 
83
87
  /** Surface treatment per `variant`, shared across the input shells. */
@@ -126,27 +130,27 @@ export const inputShell = cva([...shellChrome, "flex w-full items-center gap-y-0
126
130
  xs: [
127
131
  "ps-1.5 pe-1.5",
128
132
  "data-with-start-slot:ps-2 data-with-end-slot:pe-2",
129
- `min-h-7 ${shellGap.xs} text-xs [&_svg]:size-3`,
133
+ `min-h-7 ${shellGap.xs} text-xs [:where(&)_svg]:size-3`,
130
134
  ],
131
135
  sm: [
132
136
  "ps-2 pe-2",
133
137
  "data-with-start-slot:ps-2.5 data-with-end-slot:pe-2.5",
134
- `min-h-8 ${shellGap.sm} text-sm [&_svg]:size-3.5`,
138
+ `min-h-8 ${shellGap.sm} text-sm [:where(&)_svg]:size-3.5`,
135
139
  ],
136
140
  md: [
137
141
  "ps-2 pe-2",
138
142
  "data-with-start-slot:ps-2.5 data-with-end-slot:pe-2.5",
139
- `min-h-9 ${shellGap.md} text-md [&_svg]:size-4`,
143
+ `min-h-9 ${shellGap.md} text-md [:where(&)_svg]:size-4`,
140
144
  ],
141
145
  lg: [
142
146
  "ps-3 pe-3",
143
147
  "data-with-start-slot:ps-3.5 data-with-end-slot:pe-3.5",
144
- `min-h-10 ${shellGap.lg} text-lg [&_svg]:size-5`,
148
+ `min-h-10 ${shellGap.lg} text-lg [:where(&)_svg]:size-5`,
145
149
  ],
146
150
  xl: [
147
151
  "ps-3.5 pe-3.5",
148
152
  "data-with-start-slot:ps-4 data-with-end-slot:pe-4",
149
- `min-h-12 ${shellGap.xl} text-xl [&_svg]:size-6`,
153
+ `min-h-12 ${shellGap.xl} text-xl [:where(&)_svg]:size-6`,
150
154
  ],
151
155
  },
152
156
  },