@42-central/ui-react 0.22.0 → 0.24.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.
- package/dist/{chunk-DJAXXLN6.js → chunk-F2FSHVO5.js} +3 -3
- package/dist/{chunk-DJAXXLN6.js.map → chunk-F2FSHVO5.js.map} +1 -1
- package/dist/components/ambient-background/ambient-background.d.ts +14 -3
- package/dist/components/ambient-background/ambient-background.d.ts.map +1 -1
- package/dist/components/ambient-background/index.js +222 -1
- package/dist/components/ambient-background/index.js.map +1 -1
- package/dist/components/ambient-background/starfield.d.ts +13 -0
- package/dist/components/ambient-background/starfield.d.ts.map +1 -0
- package/dist/components/camera/index.js +2 -2
- package/dist/components/data-table/index.js +1 -1
- package/dist/components/geodesic/a11y.d.ts +15 -0
- package/dist/components/geodesic/a11y.d.ts.map +1 -0
- package/dist/components/geodesic/activity-badge.d.ts +5 -0
- package/dist/components/geodesic/activity-badge.d.ts.map +1 -0
- package/dist/components/geodesic/badge-frame.d.ts +60 -0
- package/dist/components/geodesic/badge-frame.d.ts.map +1 -0
- package/dist/components/geodesic/exam-badge.d.ts +5 -0
- package/dist/components/geodesic/exam-badge.d.ts.map +1 -0
- package/dist/components/geodesic/geometry.d.ts +1089 -0
- package/dist/components/geodesic/geometry.d.ts.map +1 -0
- package/dist/components/geodesic/gift-box-badge.d.ts +5 -0
- package/dist/components/geodesic/gift-box-badge.d.ts.map +1 -0
- package/dist/components/geodesic/gift-token.d.ts +23 -0
- package/dist/components/geodesic/gift-token.d.ts.map +1 -0
- package/dist/components/geodesic/glyph-slot.d.ts +8 -0
- package/dist/components/geodesic/glyph-slot.d.ts.map +1 -0
- package/dist/components/geodesic/index.d.ts +12 -0
- package/dist/components/geodesic/index.d.ts.map +1 -0
- package/dist/components/geodesic/index.js +917 -0
- package/dist/components/geodesic/index.js.map +1 -0
- package/dist/components/geodesic/module-badge.d.ts +5 -0
- package/dist/components/geodesic/module-badge.d.ts.map +1 -0
- package/dist/components/geodesic/planet.d.ts +30 -0
- package/dist/components/geodesic/planet.d.ts.map +1 -0
- package/dist/components/geodesic/project-badge.d.ts +5 -0
- package/dist/components/geodesic/project-badge.d.ts.map +1 -0
- package/dist/components/geodesic/skill-badge.d.ts +5 -0
- package/dist/components/geodesic/skill-badge.d.ts.map +1 -0
- package/dist/components/geodesic/social-badge.d.ts +8 -0
- package/dist/components/geodesic/social-badge.d.ts.map +1 -0
- package/dist/components/geodesic/status.d.ts +80 -0
- package/dist/components/geodesic/status.d.ts.map +1 -0
- package/dist/components/geodesic/styles.css +146 -0
- package/dist/components/photo-capture/index.js +2 -2
- package/dist/theme.css +75 -0
- package/package.json +2 -1
- package/src/as-child.contract.test.tsx +2 -0
- package/src/components/ambient-background/ambient-background.test.tsx +59 -0
- package/src/components/ambient-background/ambient-background.tsx +15 -2
- package/src/components/ambient-background/starfield.tsx +331 -0
- package/src/components/geodesic/a11y.ts +10 -0
- package/src/components/geodesic/activity-badge.tsx +17 -0
- package/src/components/geodesic/badge-frame.tsx +324 -0
- package/src/components/geodesic/exam-badge.tsx +17 -0
- package/src/components/geodesic/geometry.test.ts +60 -0
- package/src/components/geodesic/geometry.ts +367 -0
- package/src/components/geodesic/gift-box-badge.tsx +17 -0
- package/src/components/geodesic/gift-token.tsx +104 -0
- package/src/components/geodesic/glyph-slot.tsx +28 -0
- package/src/components/geodesic/index.ts +13 -0
- package/src/components/geodesic/module-badge.tsx +17 -0
- package/src/components/geodesic/planet.tsx +131 -0
- package/src/components/geodesic/project-badge.tsx +17 -0
- package/src/components/geodesic/skill-badge.tsx +17 -0
- package/src/components/geodesic/social-badge.tsx +21 -0
- package/src/components/geodesic/status.test.ts +66 -0
- package/src/components/geodesic/status.ts +176 -0
- package/src/components/geodesic/styles.css +146 -0
- package/src/icon-stroke.test.tsx +7 -0
- package/src/theme.css +75 -0
- package/src/theme.test.ts +10 -2
|
@@ -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
|
+
}
|
package/src/icon-stroke.test.tsx
CHANGED
|
@@ -28,7 +28,14 @@ const sources = readdirSync(componentsDir, { recursive: true, encoding: "utf8" }
|
|
|
28
28
|
*/
|
|
29
29
|
const NOT_ICONS: Record<string, string> = {
|
|
30
30
|
"avatar/avatar.tsx": "the group's notch mask, never painted",
|
|
31
|
+
"ambient-background/starfield.tsx":
|
|
32
|
+
"a background illustration: filled dots and glints, no stroke",
|
|
31
33
|
"circular-progress/circular-progress.tsx": "a progress ring, its width is the `thickness` prop",
|
|
34
|
+
"geodesic/badge-frame.tsx":
|
|
35
|
+
"an illustration: wires drawn in viewBox units, scaling with the badge",
|
|
36
|
+
"geodesic/gift-token.tsx":
|
|
37
|
+
"an illustration: the orbit is drawn in viewBox units, scaling with the token",
|
|
38
|
+
"geodesic/planet.tsx": "an illustration: its own wire weights, fixed with non-scaling-stroke",
|
|
32
39
|
"spinner/spinner.tsx": "a loading ring, weighted to read while it spins",
|
|
33
40
|
}
|
|
34
41
|
|
package/src/theme.css
CHANGED
|
@@ -1420,6 +1420,81 @@ body {
|
|
|
1420
1420
|
--ambient-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.4' numOctaves='2' stitchTiles='stitch' result='t'/%3E%3CfeColorMatrix in='t' type='matrix' values='0 0 0 0 0.573 0 0 0 0 0.69 0 0 0 0 0.98 0 0 0 1 0' result='c'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='gamma' amplitude='0.09' exponent='2' offset='0'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
|
|
1421
1421
|
}
|
|
1422
1422
|
|
|
1423
|
+
/* The starfield's motion (`withStarfield`, see ambient-background/starfield.tsx).
|
|
1424
|
+
Every animated piece sets its own delay and duration inline, so these are
|
|
1425
|
+
just the shapes; the utilities are applied behind `motion-safe:`. */
|
|
1426
|
+
@theme static {
|
|
1427
|
+
/* The brighter stars breathe, slowly and out of step. Dimming, never
|
|
1428
|
+
vanishing: a star that blinks out reads as a glitch, not a twinkle. */
|
|
1429
|
+
--animate-ambient-star-twinkle: ambient-star-twinkle 8s ease-in-out infinite;
|
|
1430
|
+
/* The dust dims the same way, deeper and slower, one group per layer. */
|
|
1431
|
+
--animate-ambient-star-dim: ambient-star-dim 17s ease-in-out infinite;
|
|
1432
|
+
/* The nebula's clouds swing slowly away and back, each by its own drift
|
|
1433
|
+
(`--drift-*`, set per cloud): moved, swollen a little and thinned out at
|
|
1434
|
+
the far end, eased at both. */
|
|
1435
|
+
--animate-ambient-nebula-drift: ambient-nebula-drift 90s ease-in-out infinite alternate;
|
|
1436
|
+
/* A meteor's whole cycle is mostly waiting: it streaks across in the first
|
|
1437
|
+
2% (about a second of its long cycle), its tail growing behind the head
|
|
1438
|
+
as it fades in and burning out before it stops, then nothing until the
|
|
1439
|
+
next pass. Linear, because a meteor doesn't ease. */
|
|
1440
|
+
--animate-ambient-meteor: ambient-meteor 40s linear infinite;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
@keyframes ambient-star-twinkle {
|
|
1444
|
+
0%,
|
|
1445
|
+
100% {
|
|
1446
|
+
opacity: 1;
|
|
1447
|
+
}
|
|
1448
|
+
50% {
|
|
1449
|
+
opacity: 0.5;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
@keyframes ambient-star-dim {
|
|
1454
|
+
0%,
|
|
1455
|
+
100% {
|
|
1456
|
+
opacity: 1;
|
|
1457
|
+
}
|
|
1458
|
+
50% {
|
|
1459
|
+
opacity: 0.35;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
@keyframes ambient-nebula-drift {
|
|
1464
|
+
to {
|
|
1465
|
+
transform: translate3d(var(--drift-x), var(--drift-y), 0) scale(var(--drift-scale));
|
|
1466
|
+
opacity: var(--drift-fade);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
@keyframes ambient-meteor {
|
|
1471
|
+
0% {
|
|
1472
|
+
opacity: 0;
|
|
1473
|
+
transform: translateX(0) scaleX(0.2);
|
|
1474
|
+
}
|
|
1475
|
+
0.5% {
|
|
1476
|
+
opacity: 1;
|
|
1477
|
+
}
|
|
1478
|
+
2%,
|
|
1479
|
+
100% {
|
|
1480
|
+
opacity: 0;
|
|
1481
|
+
transform: translateX(18rem) scaleX(1);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
/* `motion-safe:` reads only the OS setting; apps that let people choose
|
|
1486
|
+
in-app set `data-motion="reduced"` on `<html>`, and the sky stills for that
|
|
1487
|
+
too: no drift, no dimming, no meteors. */
|
|
1488
|
+
:where(:root[data-motion="reduced"]) {
|
|
1489
|
+
.ambient-starfield,
|
|
1490
|
+
.ambient-starfield * {
|
|
1491
|
+
animation: none;
|
|
1492
|
+
}
|
|
1493
|
+
.ambient-starfield-meteors {
|
|
1494
|
+
display: none;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1423
1498
|
/* `Tabs`: a trigger whose list's indicator is still `hidden` — the server
|
|
1424
1499
|
render, and the client until Ark has measured the selected trigger (Ark
|
|
1425
1500
|
clears `hidden` and sets the rect in the same render). The selected trigger
|