@42-central/ui-react 0.23.0 → 0.25.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-FUNTJZX7.js → chunk-2CL3FKEY.js} +3 -3
- package/dist/{chunk-FUNTJZX7.js.map → chunk-2CL3FKEY.js.map} +1 -1
- package/dist/{chunk-OZMSXYBX.js → chunk-36NWC4GV.js} +3 -3
- package/dist/{chunk-OZMSXYBX.js.map → chunk-36NWC4GV.js.map} +1 -1
- package/dist/{chunk-4FEOMQYR.js → chunk-54W6VAI3.js} +5 -5
- package/dist/{chunk-4FEOMQYR.js.map → chunk-54W6VAI3.js.map} +1 -1
- package/dist/{chunk-SZEOTXRZ.js → chunk-6II2DVYR.js} +5 -5
- package/dist/{chunk-SZEOTXRZ.js.map → chunk-6II2DVYR.js.map} +1 -1
- package/dist/{chunk-DJLNGWMM.js → chunk-6IRMKF5T.js} +3 -3
- package/dist/{chunk-DJLNGWMM.js.map → chunk-6IRMKF5T.js.map} +1 -1
- package/dist/{chunk-YPFSRZ3T.js → chunk-6UIQJJNJ.js} +3 -3
- package/dist/{chunk-YPFSRZ3T.js.map → chunk-6UIQJJNJ.js.map} +1 -1
- package/dist/{chunk-DT6LKNZF.js → chunk-7247WBTV.js} +5 -4
- package/dist/chunk-7247WBTV.js.map +1 -0
- package/dist/{chunk-6VYGK3Q3.js → chunk-7E7JNWOC.js} +16 -21
- package/dist/chunk-7E7JNWOC.js.map +1 -0
- package/dist/{chunk-C4NFRSOR.js → chunk-7HZBD4YZ.js} +4 -4
- package/dist/{chunk-C4NFRSOR.js.map → chunk-7HZBD4YZ.js.map} +1 -1
- package/dist/{chunk-JVG5ISPT.js → chunk-AHKMN3YQ.js} +3 -3
- package/dist/{chunk-JVG5ISPT.js.map → chunk-AHKMN3YQ.js.map} +1 -1
- package/dist/{chunk-UAYENYS2.js → chunk-AKXALCUN.js} +3 -3
- package/dist/{chunk-UAYENYS2.js.map → chunk-AKXALCUN.js.map} +1 -1
- package/dist/{chunk-BE2LWUHY.js → chunk-BMEJBY6H.js} +5 -3
- package/dist/chunk-BMEJBY6H.js.map +1 -0
- package/dist/{chunk-MXAACRWE.js → chunk-E52Z2FKU.js} +5 -5
- package/dist/{chunk-MXAACRWE.js.map → chunk-E52Z2FKU.js.map} +1 -1
- package/dist/chunk-F374BNL4.js +129 -0
- package/dist/chunk-F374BNL4.js.map +1 -0
- package/dist/{chunk-MRAJ45IM.js → chunk-FZSLSUSX.js} +4 -4
- package/dist/{chunk-MRAJ45IM.js.map → chunk-FZSLSUSX.js.map} +1 -1
- package/dist/{chunk-3L5GLI67.js → chunk-I4B3N3UX.js} +3 -3
- package/dist/{chunk-3L5GLI67.js.map → chunk-I4B3N3UX.js.map} +1 -1
- package/dist/{chunk-IPYHTCFL.js → chunk-IUK7OJXZ.js} +3 -3
- package/dist/{chunk-IPYHTCFL.js.map → chunk-IUK7OJXZ.js.map} +1 -1
- package/dist/{chunk-2MXWEIMD.js → chunk-KKLCHLCZ.js} +12 -11
- package/dist/chunk-KKLCHLCZ.js.map +1 -0
- package/dist/{chunk-YWTOW7PZ.js → chunk-LHUWOA2U.js} +8 -8
- package/dist/{chunk-YWTOW7PZ.js.map → chunk-LHUWOA2U.js.map} +1 -1
- package/dist/{chunk-6N6J2DOE.js → chunk-LIZWCWED.js} +3 -3
- package/dist/{chunk-6N6J2DOE.js.map → chunk-LIZWCWED.js.map} +1 -1
- package/dist/{chunk-O7LS6OZR.js → chunk-LMCUGYHT.js} +3 -3
- package/dist/{chunk-O7LS6OZR.js.map → chunk-LMCUGYHT.js.map} +1 -1
- package/dist/{chunk-DHJB4UJD.js → chunk-N5M4PDBK.js} +4 -4
- package/dist/{chunk-DHJB4UJD.js.map → chunk-N5M4PDBK.js.map} +1 -1
- package/dist/{chunk-DA4QII2N.js → chunk-NLSJ6T7V.js} +4 -4
- package/dist/{chunk-DA4QII2N.js.map → chunk-NLSJ6T7V.js.map} +1 -1
- package/dist/{chunk-UT3TOV2Q.js → chunk-OVT2KZHY.js} +3 -3
- package/dist/{chunk-UT3TOV2Q.js.map → chunk-OVT2KZHY.js.map} +1 -1
- package/dist/{chunk-SVKN5ZHX.js → chunk-PEHFWGTT.js} +16 -13
- package/dist/chunk-PEHFWGTT.js.map +1 -0
- package/dist/{chunk-J44FJ7PH.js → chunk-PFZMB3US.js} +4 -4
- package/dist/{chunk-J44FJ7PH.js.map → chunk-PFZMB3US.js.map} +1 -1
- package/dist/{chunk-IRNF274I.js → chunk-PI7X5YFJ.js} +3 -3
- package/dist/{chunk-IRNF274I.js.map → chunk-PI7X5YFJ.js.map} +1 -1
- package/dist/{chunk-F2FSHVO5.js → chunk-QZ4N5LYG.js} +7 -7
- package/dist/{chunk-F2FSHVO5.js.map → chunk-QZ4N5LYG.js.map} +1 -1
- package/dist/{chunk-E5H3YWZV.js → chunk-SAXWCGWR.js} +3 -3
- package/dist/{chunk-E5H3YWZV.js.map → chunk-SAXWCGWR.js.map} +1 -1
- package/dist/{chunk-SWVUXEBT.js → chunk-SCXXJDKQ.js} +3 -3
- package/dist/{chunk-SWVUXEBT.js.map → chunk-SCXXJDKQ.js.map} +1 -1
- package/dist/{chunk-D3JYDAUZ.js → chunk-T44RW5DW.js} +4 -4
- package/dist/{chunk-D3JYDAUZ.js.map → chunk-T44RW5DW.js.map} +1 -1
- package/dist/{chunk-FB2G4LNH.js → chunk-UDCCOUWR.js} +5 -5
- package/dist/{chunk-FB2G4LNH.js.map → chunk-UDCCOUWR.js.map} +1 -1
- package/dist/{chunk-TCFB23JT.js → chunk-WERJ44ZN.js} +3 -3
- package/dist/{chunk-TCFB23JT.js.map → chunk-WERJ44ZN.js.map} +1 -1
- package/dist/{chunk-QNKD2SQM.js → chunk-X3YIHN2U.js} +5 -5
- package/dist/{chunk-QNKD2SQM.js.map → chunk-X3YIHN2U.js.map} +1 -1
- package/dist/{chunk-VD6PB3VA.js → chunk-X6DESK37.js} +12 -3
- package/dist/chunk-X6DESK37.js.map +1 -0
- package/dist/{chunk-7AQ4MN4M.js → chunk-XUFCI262.js} +4 -4
- package/dist/{chunk-7AQ4MN4M.js.map → chunk-XUFCI262.js.map} +1 -1
- package/dist/{chunk-47LEAR6G.js → chunk-Y2G47ARQ.js} +6 -6
- package/dist/{chunk-47LEAR6G.js.map → chunk-Y2G47ARQ.js.map} +1 -1
- package/dist/{chunk-F342ZT7O.js → chunk-ZVECQBGG.js} +13 -7
- package/dist/chunk-ZVECQBGG.js.map +1 -0
- package/dist/components/action-icon/action-icon.d.ts.map +1 -1
- package/dist/components/action-icon/index.js +1 -1
- package/dist/components/alert/index.js +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 +225 -2
- 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/app-shell/index.js +4 -4
- package/dist/components/autocomplete/index.js +3 -3
- package/dist/components/avatar/index.js +2 -2
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/index.js +1 -1
- package/dist/components/button/index.js +1 -1
- package/dist/components/button-multi-select/index.js +3 -3
- package/dist/components/button-select/index.js +3 -3
- package/dist/components/calendar/index.js +4 -4
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +10 -10
- package/dist/components/card/card.d.ts.map +1 -1
- package/dist/components/card/index.js +1 -1
- package/dist/components/carousel/index.js +2 -2
- package/dist/components/checkbox/checkbox.d.ts +3 -2
- package/dist/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/index.js +2 -2
- package/dist/components/choice-card-group/index.js +2 -2
- package/dist/components/choice-card-group/index.js.map +1 -1
- package/dist/components/clipboard/index.js +3 -3
- package/dist/components/code-block/code-block.d.ts +6 -3
- package/dist/components/code-block/code-block.d.ts.map +1 -1
- package/dist/components/code-block/highlighter.d.ts +16 -15
- package/dist/components/code-block/highlighter.d.ts.map +1 -1
- package/dist/components/code-block/index.d.ts +2 -1
- package/dist/components/code-block/index.d.ts.map +1 -1
- package/dist/components/code-block/index.js +81 -10
- package/dist/components/code-block/index.js.map +1 -1
- package/dist/components/code-block/languages.d.ts +61 -0
- package/dist/components/code-block/languages.d.ts.map +1 -0
- package/dist/components/code-block/static.d.ts +2 -1
- package/dist/components/code-block/static.d.ts.map +1 -1
- package/dist/components/code-block/static.js +99 -10
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/combobox/index.js +3 -3
- package/dist/components/combobox-list/index.js +5 -5
- package/dist/components/compare/index.js +2 -2
- package/dist/components/data-table/index.js +30 -30
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/date-picker/index.js +12 -12
- package/dist/components/download-button/index.js +2 -2
- package/dist/components/drawer/index.js +4 -4
- package/dist/components/field/field.d.ts +3 -0
- package/dist/components/field/field.d.ts.map +1 -1
- package/dist/components/field/index.js +1 -1
- package/dist/components/file-item/index.js +5 -5
- package/dist/components/file-preview/index.js +5 -5
- package/dist/components/file-trigger/index.js +2 -2
- package/dist/components/file-upload/index.js +6 -6
- package/dist/components/gallery/index.js +2 -2
- package/dist/components/geodesic/a11y.d.ts +3 -3
- package/dist/components/geodesic/a11y.d.ts.map +1 -1
- package/dist/components/image-cropper/index.js +7 -7
- package/dist/components/indicator/index.js +1 -1
- package/dist/components/input/index.js +2 -2
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/lightbox/index.js +7 -7
- package/dist/components/menu/index.js +2 -2
- package/dist/components/modal/index.js +4 -4
- package/dist/components/multi-combobox-list/index.js +5 -5
- package/dist/components/multi-select/index.js +6 -6
- package/dist/components/number-input/index.js +3 -3
- package/dist/components/overlays/index.js +6 -6
- package/dist/components/password-input/index.js +3 -3
- package/dist/components/photo-capture/index.js +14 -14
- package/dist/components/pills-input/index.js +5 -5
- package/dist/components/pin-input/index.js +2 -2
- package/dist/components/radio-group/index.js +1 -1
- package/dist/components/rating/index.js +1 -1
- package/dist/components/schedule/index.js +5 -5
- package/dist/components/segment-group/index.js +4 -4
- package/dist/components/select/index.js +4 -4
- package/dist/components/slider/index.js +2 -2
- package/dist/components/spotlight/index.js +9 -9
- package/dist/components/switch/index.js +14 -19
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/switch.d.ts +1 -0
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/components/tabs/index.js +3 -3
- package/dist/components/tags-input/index.js +5 -5
- package/dist/components/text-input/index.js +2 -2
- package/dist/components/textarea/index.js +2 -2
- package/dist/components/theme-icon/index.js +1 -1
- package/dist/components/theme-icon/theme-icon.d.ts.map +1 -1
- package/dist/components/time-input/index.js +7 -7
- package/dist/components/tree-multi-select/index.js +6 -6
- package/dist/components/tree-select/index.js +3 -3
- package/dist/index.js +4 -4
- package/dist/theme.css +103 -23
- package/package.json +1 -1
- package/src/components/action-icon/action-icon.tsx +3 -1
- 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 +333 -0
- package/src/components/badge/badge.tsx +11 -6
- package/src/components/button/button.tsx +1 -1
- package/src/components/card/card.tsx +10 -9
- package/src/components/checkbox/checkbox.test.tsx +17 -9
- package/src/components/checkbox/checkbox.tsx +26 -27
- package/src/components/choice-card-group/choice-card-group.tsx +3 -3
- package/src/components/code-block/code-block.tsx +7 -4
- package/src/components/code-block/highlighter.test.ts +79 -1
- package/src/components/code-block/highlighter.ts +76 -30
- package/src/components/code-block/index.ts +2 -0
- package/src/components/code-block/languages.ts +63 -0
- package/src/components/code-block/static.tsx +2 -1
- package/src/components/data-table/data-table-pagination.tsx +5 -5
- package/src/components/data-table/data-table-stack.tsx +2 -2
- package/src/components/field/field.tsx +14 -0
- package/src/components/kbd/kbd.tsx +2 -1
- package/src/components/switch/switch.test.tsx +15 -0
- package/src/components/switch/switch.tsx +27 -27
- package/src/components/table/table.test.tsx +1 -1
- package/src/components/table/table.tsx +14 -11
- package/src/components/theme-icon/theme-icon.tsx +46 -12
- package/src/icon-stroke.test.tsx +2 -0
- package/src/theme.css +103 -23
- package/src/theme.test.ts +10 -2
- package/dist/chunk-2MXWEIMD.js.map +0 -1
- package/dist/chunk-6VYGK3Q3.js.map +0 -1
- package/dist/chunk-7CNDZZZ6.js +0 -95
- package/dist/chunk-7CNDZZZ6.js.map +0 -1
- package/dist/chunk-BE2LWUHY.js.map +0 -1
- package/dist/chunk-DT6LKNZF.js.map +0 -1
- package/dist/chunk-F342ZT7O.js.map +0 -1
- package/dist/chunk-SVKN5ZHX.js.map +0 -1
- package/dist/chunk-VD6PB3VA.js.map +0 -1
|
@@ -2,6 +2,7 @@ import { cn } from "../../lib/cn"
|
|
|
2
2
|
import { warnRenamedProp } from "../../lib/dev-warn"
|
|
3
3
|
import { props } from "../../lib/props"
|
|
4
4
|
import type { WithTestId } from "../../lib/test-id"
|
|
5
|
+
import { Starfield, type StarfieldClassNames } from "./starfield"
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* AmbientBackground — a decorative, brand-tinted page background: a soft
|
|
@@ -22,6 +23,12 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
22
23
|
* regardless of z-index — nesting a blended layer inside another `fixed`
|
|
23
24
|
* wrapper would cut off what it can blend against).
|
|
24
25
|
*
|
|
26
|
+
* `withStarfield` adds a third, opt-in layer set: a slowly moving starry sky
|
|
27
|
+
* over soft violet nebulae (dimming dust, breathing bright stars, a rare
|
|
28
|
+
* meteor), seeded so it is identical on every render. It follows the same
|
|
29
|
+
* recipe — separate fixed layers, no shared wrapper — and stills under reduced
|
|
30
|
+
* motion, either the OS setting or `data-motion="reduced"` on `<html>`.
|
|
31
|
+
*
|
|
25
32
|
* The actual glow/noise values are CSS custom properties (`--ambient-glow` /
|
|
26
33
|
* `--ambient-noise`, defined in `theme.css`, brand-tinted and theme-aware via
|
|
27
34
|
* `data-theme`) rather than hardcoded here — override either on `:root` to
|
|
@@ -40,19 +47,23 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
40
47
|
*/
|
|
41
48
|
/**
|
|
42
49
|
* There is no root element, so `testId` lands on each layer with its part as a
|
|
43
|
-
* suffix: `` `${testId}-glow` `` and `` `${testId}-noise`
|
|
50
|
+
* suffix: `` `${testId}-glow` `` and `` `${testId}-noise` ``, and with the
|
|
51
|
+
* starfield `` `${testId}-nebula-<n>` ``, `` `${testId}-stars` `` and
|
|
52
|
+
* `` `${testId}-meteors` ``.
|
|
44
53
|
*/
|
|
45
54
|
export type AmbientBackgroundProps = WithTestId & {
|
|
46
55
|
/** Render the radial glow layer. Default `true`. */
|
|
47
56
|
withGlow?: boolean
|
|
48
57
|
/** Render the film-grain noise layer. Default `true`. */
|
|
49
58
|
withNoise?: boolean
|
|
59
|
+
/** Render the starfield over the glow and noise: nebulae, stars and meteors. Default `false`. */
|
|
60
|
+
withStarfield?: boolean
|
|
50
61
|
/** @deprecated Renamed `withGlow`. Removed in the next minor. `withGlow` wins when both are set. */
|
|
51
62
|
glow?: boolean
|
|
52
63
|
/** @deprecated Renamed `withNoise`. Removed in the next minor. `withNoise` wins when both are set. */
|
|
53
64
|
noise?: boolean
|
|
54
65
|
/** Extra classes for each layer. */
|
|
55
|
-
classNames?: {
|
|
66
|
+
classNames?: StarfieldClassNames & {
|
|
56
67
|
glow?: string
|
|
57
68
|
noise?: string
|
|
58
69
|
}
|
|
@@ -63,6 +74,7 @@ export const AmbientBackground = ({
|
|
|
63
74
|
noise,
|
|
64
75
|
withGlow = glow ?? true,
|
|
65
76
|
withNoise = noise ?? true,
|
|
77
|
+
withStarfield = false,
|
|
66
78
|
classNames,
|
|
67
79
|
testId,
|
|
68
80
|
}: AmbientBackgroundProps) => {
|
|
@@ -92,6 +104,7 @@ export const AmbientBackground = ({
|
|
|
92
104
|
{...props({ "data-testid": testId && `${testId}-noise` })}
|
|
93
105
|
/>
|
|
94
106
|
)}
|
|
107
|
+
{withStarfield && <Starfield classNames={classNames} testId={testId} />}
|
|
95
108
|
</>
|
|
96
109
|
)
|
|
97
110
|
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import type { CSSProperties } from "react"
|
|
2
|
+
import { cn } from "../../lib/cn"
|
|
3
|
+
import { props } from "../../lib/props"
|
|
4
|
+
|
|
5
|
+
// The starfield AmbientBackground draws with `withStarfield`: a starry sky over
|
|
6
|
+
// soft violet nebulae, stacked on the glow and noise (the noise is what
|
|
7
|
+
// dithers these gradients so they never band). Every layer takes the same
|
|
8
|
+
// recipe as glow and noise (fixed, -z-10, no shared wrapper) and paints over
|
|
9
|
+
// them, still under every piece of the app.
|
|
10
|
+
//
|
|
11
|
+
// Everything is computed once at module load from a seeded PRNG, so the sky
|
|
12
|
+
// is identical on every render, on the server and the client, and on every
|
|
13
|
+
// visit. It moves, slowly: the clouds drift and swell, the dust dims and comes
|
|
14
|
+
// back, the brighter stars breathe, and now and then a meteor crosses. All of
|
|
15
|
+
// it is CSS animation of transform and opacity (keyframes in theme.css), so
|
|
16
|
+
// the compositor runs it and no script does per frame; and all of it sits
|
|
17
|
+
// behind `motion-safe:` and the `data-motion="reduced"` rule in theme.css, so
|
|
18
|
+
// with reduced motion the sky is a still picture, without the meteors.
|
|
19
|
+
|
|
20
|
+
// mulberry32: tiny, fast, and good enough to scatter dots.
|
|
21
|
+
const prng = (seed: number) => () => {
|
|
22
|
+
seed = (seed + 0x6d2b79f5) | 0
|
|
23
|
+
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
|
|
24
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
|
|
25
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const round = (n: number) => Math.round(n * 100) / 100
|
|
29
|
+
|
|
30
|
+
type Star = { x: number; y: number; r: number; opacity: number }
|
|
31
|
+
|
|
32
|
+
// Most stars are a cool white; a few lean violet or pink, as in the design.
|
|
33
|
+
// On a light sky the same hues go dark, so the dots read as ink, not glare.
|
|
34
|
+
const TONES = [
|
|
35
|
+
"fill-brand-500 dark:fill-brand-100",
|
|
36
|
+
"fill-purple-500 dark:fill-purple-200",
|
|
37
|
+
"fill-pink-500 dark:fill-pink-200",
|
|
38
|
+
] as const
|
|
39
|
+
|
|
40
|
+
type Tone = (typeof TONES)[number]
|
|
41
|
+
|
|
42
|
+
const pickTone = (n: number): Tone => (n < 0.78 ? TONES[0] : n < 0.95 ? TONES[1] : TONES[2])
|
|
43
|
+
|
|
44
|
+
// The dust dims in a few groups, each on its own slow beat, so at any moment
|
|
45
|
+
// some stars are fading and others coming back. A group is a whole layer
|
|
46
|
+
// fading (cheap: the compositor does it), and its stars are scattered all
|
|
47
|
+
// over, so it reads as single stars dimming, not as a region pulsing. The
|
|
48
|
+
// beats share no common factor, so the groups never line up into one blink.
|
|
49
|
+
const DIM_BEATS = [
|
|
50
|
+
{ duration: "11s", delay: "-3s" },
|
|
51
|
+
{ duration: "17s", delay: "-11s" },
|
|
52
|
+
{ duration: "23s", delay: "-7s" },
|
|
53
|
+
] as const
|
|
54
|
+
|
|
55
|
+
// Dots for one repeating tile, by dimming group, then by tone so each tone
|
|
56
|
+
// is one <g>.
|
|
57
|
+
const scatter = (seed: number, size: number, count: number) => {
|
|
58
|
+
const random = prng(seed)
|
|
59
|
+
// Its own sequence, so sorting the dots into groups doesn't move them.
|
|
60
|
+
const group = prng(seed + 1)
|
|
61
|
+
const phases = DIM_BEATS.map(() => new Map<Tone, Star[]>(TONES.map((tone) => [tone, []])))
|
|
62
|
+
for (let i = 0; i < count; i++) {
|
|
63
|
+
// Skewed towards the faintest, smallest dots: a real sky is mostly dust.
|
|
64
|
+
const weight = random() ** 2.4
|
|
65
|
+
const star = {
|
|
66
|
+
// Kept off the tile's edge so no dot is cut in half where tiles meet.
|
|
67
|
+
x: round(2 + random() * (size - 4)),
|
|
68
|
+
y: round(2 + random() * (size - 4)),
|
|
69
|
+
r: round(0.4 + weight * 0.75),
|
|
70
|
+
opacity: round(0.22 + weight * 0.4 + random() * 0.1),
|
|
71
|
+
}
|
|
72
|
+
phases[Math.floor(group() * phases.length)]?.get(pickTone(random()))?.push(star)
|
|
73
|
+
}
|
|
74
|
+
return { size, phases: phases.map((phase) => [...phase]) }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Two tiles of coprime-ish sizes overlap into a pattern that only repeats
|
|
78
|
+
// every few thousand pixels, so the eye never catches the tiling. Fixed pixel
|
|
79
|
+
// tiles (not a scaled viewBox) keep the same density on a phone and a wide
|
|
80
|
+
// screen. Together about one dot per 6000px², the design's own density.
|
|
81
|
+
const TILES = [scatter(42, 509, 26), scatter(1337, 733, 38)]
|
|
82
|
+
|
|
83
|
+
// The few brighter stars, placed by viewport percentage so they spread over
|
|
84
|
+
// any screen. A soft halo rather than a hard disc; the three with `sparkle`
|
|
85
|
+
// carry the design's diffraction spikes, kept thin and short.
|
|
86
|
+
const BRIGHT_STARS = [
|
|
87
|
+
{ x: "8%", y: "14%", sparkle: true, delay: "0s", duration: "7s" },
|
|
88
|
+
{ x: "31%", y: "6%", sparkle: false, delay: "-2s", duration: "9s" },
|
|
89
|
+
{ x: "62%", y: "11%", sparkle: false, delay: "-5s", duration: "8s" },
|
|
90
|
+
{ x: "88%", y: "22%", sparkle: true, delay: "-3s", duration: "10s" },
|
|
91
|
+
{ x: "18%", y: "58%", sparkle: false, delay: "-6s", duration: "8s" },
|
|
92
|
+
{ x: "47%", y: "41%", sparkle: false, delay: "-1s", duration: "11s" },
|
|
93
|
+
{ x: "76%", y: "63%", sparkle: true, delay: "-4s", duration: "9s" },
|
|
94
|
+
{ x: "36%", y: "86%", sparkle: false, delay: "-7s", duration: "10s" },
|
|
95
|
+
{ x: "93%", y: "90%", sparkle: false, delay: "-2.5s", duration: "7s" },
|
|
96
|
+
] as const
|
|
97
|
+
|
|
98
|
+
// A four-point sparkle with concave sides: reads as a lens glint, not a shape.
|
|
99
|
+
const SPARKLE = "M0 -6Q0 0 6 0Q0 0 0 6Q0 0 -6 0Q0 0 0 -6Z"
|
|
100
|
+
|
|
101
|
+
// Each cloud's layer overhangs the viewport by this much on every side, so a
|
|
102
|
+
// cloud cut by the screen's edge (several are) can drift without the cut
|
|
103
|
+
// ever coming into view.
|
|
104
|
+
const BLEED = 15
|
|
105
|
+
const SPAN = 100 + 2 * BLEED
|
|
106
|
+
|
|
107
|
+
// A length or a position given in viewport %, as % of the overhanging layer.
|
|
108
|
+
const inLayer = (viewport: number, offset = 0) => `${round(((viewport + offset) / SPAN) * 100)}%`
|
|
109
|
+
|
|
110
|
+
type Ellipse = { rx: number; ry: number; x: number; y: number }
|
|
111
|
+
type Hue = { color: string; strength: number }
|
|
112
|
+
|
|
113
|
+
// Violet and indigo clouds after the design's "Nébuleuse", softened: wide
|
|
114
|
+
// ellipses that fade out over their whole radius so no edge ever shows. The
|
|
115
|
+
// design's blue core is already the kit's ambient glow; this adds the purple.
|
|
116
|
+
const cloud = ({ rx, ry, x, y }: Ellipse, { color, strength }: Hue) =>
|
|
117
|
+
`radial-gradient(ellipse ${inLayer(rx)} ${inLayer(ry)} at ${inLayer(x, BLEED)} ${inLayer(y, BLEED)}, color-mix(in oklab, var(${color}) ${strength}%, transparent), color-mix(in oklab, var(${color}) ${strength * 0.45}%, transparent) 45%, transparent 100%)`
|
|
118
|
+
|
|
119
|
+
// Each cloud drifts on its own long, slow swing (there and back, eased at
|
|
120
|
+
// both ends), swelling a little and thinning as it goes: a few px a second,
|
|
121
|
+
// so the sky is never seen moving, only found changed. On a light sky the
|
|
122
|
+
// same clouds are pale tints, so the light theme keeps the violet without
|
|
123
|
+
// muddying the page.
|
|
124
|
+
const CLOUDS: {
|
|
125
|
+
at: Ellipse
|
|
126
|
+
dark: Hue
|
|
127
|
+
light: Hue
|
|
128
|
+
drift: { x: string; y: string; scale: number; fade: number; duration: string; delay: string }
|
|
129
|
+
}[] = [
|
|
130
|
+
{
|
|
131
|
+
// Moved down-left, narrowed and brightened (9 → 17) against Figma's « Background / Cosmos »,
|
|
132
|
+
// whose lower-left glows violet behind the first column (2026-10-29).
|
|
133
|
+
at: { rx: 35, ry: 34, x: 23, y: 72 },
|
|
134
|
+
dark: { color: "--color-purple-400", strength: 17 },
|
|
135
|
+
light: { color: "--color-purple-200", strength: 14 },
|
|
136
|
+
drift: { x: "6vw", y: "-4vh", scale: 1.12, fade: 0.7, duration: "70s", delay: "-20s" },
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
at: { rx: 60, ry: 38, x: 42, y: 104 },
|
|
140
|
+
dark: { color: "--color-purple-800", strength: 20 },
|
|
141
|
+
light: { color: "--color-purple-200", strength: 26 },
|
|
142
|
+
drift: { x: "-8vw", y: "-3vh", scale: 1.08, fade: 0.85, duration: "95s", delay: "-50s" },
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
at: { rx: 40, ry: 34, x: 92, y: 4 },
|
|
146
|
+
dark: { color: "--color-purple-800", strength: 22 },
|
|
147
|
+
light: { color: "--color-purple-200", strength: 28 },
|
|
148
|
+
drift: { x: "-5vw", y: "5vh", scale: 1.15, fade: 0.8, duration: "85s", delay: "-10s" },
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
at: { rx: 46, ry: 40, x: 24, y: 20 },
|
|
152
|
+
dark: { color: "--color-brand-700", strength: 18 },
|
|
153
|
+
light: { color: "--color-brand-200", strength: 24 },
|
|
154
|
+
drift: { x: "7vw", y: "4vh", scale: 1.1, fade: 0.85, duration: "110s", delay: "-70s" },
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
at: { rx: 36, ry: 30, x: 4, y: 92 },
|
|
158
|
+
dark: { color: "--color-pink-800", strength: 10 },
|
|
159
|
+
light: { color: "--color-pink-200", strength: 16 },
|
|
160
|
+
drift: { x: "5vw", y: "-6vh", scale: 1.2, fade: 0.6, duration: "75s", delay: "-35s" },
|
|
161
|
+
},
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
// The cloud's picture per theme and its drift, as variables the classes and
|
|
165
|
+
// the ambient-nebula-drift keyframes (theme.css) read.
|
|
166
|
+
const cloudStyle = ({ at, dark, light, drift }: (typeof CLOUDS)[number]) =>
|
|
167
|
+
({
|
|
168
|
+
"--nebula-light": cloud(at, light),
|
|
169
|
+
"--nebula-dark": cloud(at, dark),
|
|
170
|
+
"--drift-x": drift.x,
|
|
171
|
+
"--drift-y": drift.y,
|
|
172
|
+
"--drift-scale": drift.scale,
|
|
173
|
+
"--drift-fade": drift.fade,
|
|
174
|
+
inset: `-${BLEED}%`,
|
|
175
|
+
animationDuration: drift.duration,
|
|
176
|
+
animationDelay: drift.delay,
|
|
177
|
+
}) as CSSProperties
|
|
178
|
+
|
|
179
|
+
// The meteors: three, each on its own long cycle and visible for about a
|
|
180
|
+
// second of it, so one crosses every twenty seconds or so, never on arrival
|
|
181
|
+
// and almost never two at once. Thin, short and faint, high in the sky,
|
|
182
|
+
// falling down and to the left. Seen from the corner of the eye, not watched.
|
|
183
|
+
const METEORS = [
|
|
184
|
+
{ x: "72%", y: "8%", angle: "152deg", duration: "37s", delay: "9s" },
|
|
185
|
+
{ x: "50%", y: "20%", angle: "160deg", duration: "53s", delay: "24s" },
|
|
186
|
+
{ x: "92%", y: "30%", angle: "148deg", duration: "71s", delay: "41s" },
|
|
187
|
+
] as const
|
|
188
|
+
|
|
189
|
+
// The halo's stops, per theme: a gradient stop takes no `dark:` class.
|
|
190
|
+
const HALO_THEME =
|
|
191
|
+
"[--star-halo-core:var(--color-brand-400)] [--star-halo-rim:var(--color-purple-400)] dark:[--star-halo-core:var(--color-brand-100)] dark:[--star-halo-rim:var(--color-purple-300)]"
|
|
192
|
+
|
|
193
|
+
// Every layer's recipe: decorative, out of the pointer's way and out of a
|
|
194
|
+
// forced palette's. `ambient-starfield` is the hook theme.css's
|
|
195
|
+
// `data-motion="reduced"` rule stills it by.
|
|
196
|
+
const LAYER = "ambient-starfield pointer-events-none fixed -z-10 forced-colors:hidden"
|
|
197
|
+
|
|
198
|
+
export type StarfieldClassNames = {
|
|
199
|
+
/** Each nebula cloud's layer. */
|
|
200
|
+
nebula?: string
|
|
201
|
+
/** The layer holding the dust and the brighter stars. */
|
|
202
|
+
stars?: string
|
|
203
|
+
/** The meteors' layer. */
|
|
204
|
+
meteors?: string
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export const Starfield = ({
|
|
208
|
+
classNames,
|
|
209
|
+
testId,
|
|
210
|
+
}: {
|
|
211
|
+
classNames?: StarfieldClassNames
|
|
212
|
+
testId?: string
|
|
213
|
+
}) => (
|
|
214
|
+
<>
|
|
215
|
+
{CLOUDS.map((c, i) => (
|
|
216
|
+
<div
|
|
217
|
+
key={`${c.at.x}-${c.at.y}`}
|
|
218
|
+
aria-hidden="true"
|
|
219
|
+
className={cn(
|
|
220
|
+
LAYER,
|
|
221
|
+
"[background-image:var(--nebula-light)] motion-safe:animate-ambient-nebula-drift dark:[background-image:var(--nebula-dark)]",
|
|
222
|
+
classNames?.nebula,
|
|
223
|
+
)}
|
|
224
|
+
style={cloudStyle(c)}
|
|
225
|
+
{...props({ "data-testid": testId && `${testId}-nebula-${i}` })}
|
|
226
|
+
/>
|
|
227
|
+
))}
|
|
228
|
+
|
|
229
|
+
{/* Fainter on a light sky: dark dots at the dark sky's strength read
|
|
230
|
+
as specks rather than dust. Set on the wrapper, because the layers
|
|
231
|
+
inside animate their own opacity. */}
|
|
232
|
+
<div
|
|
233
|
+
aria-hidden="true"
|
|
234
|
+
className={cn(LAYER, "inset-0 opacity-70 dark:opacity-100", HALO_THEME, classNames?.stars)}
|
|
235
|
+
{...props({ "data-testid": testId && `${testId}-stars` })}
|
|
236
|
+
>
|
|
237
|
+
<svg aria-hidden="true" className="absolute size-0">
|
|
238
|
+
<defs>
|
|
239
|
+
{TILES.flatMap(({ size, phases }, i) =>
|
|
240
|
+
phases.map((groups, phase) => (
|
|
241
|
+
<pattern
|
|
242
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a static, never-reordered list
|
|
243
|
+
key={`${i}-${phase}`}
|
|
244
|
+
id={`ambient-starfield-tile-${i}-${phase}`}
|
|
245
|
+
width={size}
|
|
246
|
+
height={size}
|
|
247
|
+
patternUnits="userSpaceOnUse"
|
|
248
|
+
>
|
|
249
|
+
{groups.map(([tone, stars]) => (
|
|
250
|
+
<g key={tone} className={tone}>
|
|
251
|
+
{stars.map(({ x, y, r, opacity }) => (
|
|
252
|
+
<circle key={`${x}-${y}`} cx={x} cy={y} r={r} fillOpacity={opacity} />
|
|
253
|
+
))}
|
|
254
|
+
</g>
|
|
255
|
+
))}
|
|
256
|
+
</pattern>
|
|
257
|
+
)),
|
|
258
|
+
)}
|
|
259
|
+
<radialGradient id="ambient-starfield-halo">
|
|
260
|
+
<stop offset="0%" style={{ stopColor: "var(--star-halo-core)" }} stopOpacity={0.32} />
|
|
261
|
+
<stop offset="35%" style={{ stopColor: "var(--star-halo-rim)" }} stopOpacity={0.1} />
|
|
262
|
+
<stop offset="100%" style={{ stopColor: "var(--star-halo-rim)" }} stopOpacity={0} />
|
|
263
|
+
</radialGradient>
|
|
264
|
+
</defs>
|
|
265
|
+
</svg>
|
|
266
|
+
|
|
267
|
+
{DIM_BEATS.map(({ duration, delay }, phase) => (
|
|
268
|
+
<svg
|
|
269
|
+
key={duration}
|
|
270
|
+
aria-hidden="true"
|
|
271
|
+
className="absolute inset-0 size-full motion-safe:animate-ambient-star-dim"
|
|
272
|
+
style={{ animationDuration: duration, animationDelay: delay }}
|
|
273
|
+
>
|
|
274
|
+
{TILES.map(({ size }, i) => (
|
|
275
|
+
<rect
|
|
276
|
+
key={size}
|
|
277
|
+
width="100%"
|
|
278
|
+
height="100%"
|
|
279
|
+
fill={`url(#ambient-starfield-tile-${i}-${phase})`}
|
|
280
|
+
/>
|
|
281
|
+
))}
|
|
282
|
+
</svg>
|
|
283
|
+
))}
|
|
284
|
+
|
|
285
|
+
<svg aria-hidden="true" className="absolute inset-0 size-full">
|
|
286
|
+
{BRIGHT_STARS.map(({ x, y, sparkle, delay, duration }) => (
|
|
287
|
+
<svg key={`${x}-${y}`} aria-hidden="true" x={x} y={y} overflow="visible">
|
|
288
|
+
<g
|
|
289
|
+
className="motion-safe:animate-ambient-star-twinkle"
|
|
290
|
+
style={{ animationDelay: delay, animationDuration: duration }}
|
|
291
|
+
>
|
|
292
|
+
<circle r={7} fill="url(#ambient-starfield-halo)" />
|
|
293
|
+
{sparkle ? (
|
|
294
|
+
<path
|
|
295
|
+
d={SPARKLE}
|
|
296
|
+
className="fill-purple-400 dark:fill-purple-100"
|
|
297
|
+
fillOpacity={0.4}
|
|
298
|
+
/>
|
|
299
|
+
) : null}
|
|
300
|
+
<circle r={1.1} className="fill-brand-500 dark:fill-brand-50" fillOpacity={0.85} />
|
|
301
|
+
</g>
|
|
302
|
+
</svg>
|
|
303
|
+
))}
|
|
304
|
+
</svg>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
{/* Only where motion is welcome: a meteor standing still is a scratch. */}
|
|
308
|
+
<div
|
|
309
|
+
aria-hidden="true"
|
|
310
|
+
className={cn(
|
|
311
|
+
LAYER,
|
|
312
|
+
"ambient-starfield-meteors inset-0 hidden overflow-hidden motion-safe:block",
|
|
313
|
+
classNames?.meteors,
|
|
314
|
+
)}
|
|
315
|
+
{...props({ "data-testid": testId && `${testId}-meteors` })}
|
|
316
|
+
>
|
|
317
|
+
{METEORS.map(({ x, y, angle, duration, delay }) => (
|
|
318
|
+
// A zero-size anchor turned to the meteor's heading; the streak
|
|
319
|
+
// ends at it, head first, and flies along that heading.
|
|
320
|
+
<span
|
|
321
|
+
key={`${x}-${y}`}
|
|
322
|
+
className="absolute size-0"
|
|
323
|
+
style={{ left: x, top: y, rotate: angle }}
|
|
324
|
+
>
|
|
325
|
+
<span
|
|
326
|
+
className="absolute top-0 right-0 h-px w-28 origin-right rounded-full bg-linear-to-r from-transparent to-brand-500/50 opacity-0 motion-safe:animate-ambient-meteor dark:to-white/60"
|
|
327
|
+
style={{ animationDuration: duration, animationDelay: delay }}
|
|
328
|
+
/>
|
|
329
|
+
</span>
|
|
330
|
+
))}
|
|
331
|
+
</div>
|
|
332
|
+
</>
|
|
333
|
+
)
|
|
@@ -41,7 +41,13 @@ const badgeVariants = cva(
|
|
|
41
41
|
"inline-flex items-center",
|
|
42
42
|
"whitespace-nowrap select-none",
|
|
43
43
|
"font-sans font-medium",
|
|
44
|
-
|
|
44
|
+
// Figma strokes every badge at 0.5px, inside the box. A CSS border cannot
|
|
45
|
+
// draw that: Chrome rounds any border-width under 1px up to 1px. An inset
|
|
46
|
+
// ring (box-shadow) is not rounded — one device pixel on a 2x screen, a
|
|
47
|
+
// half-strength pixel at 1x, as Figma antialiases it — and takes no layout.
|
|
48
|
+
// Forced colours drop every box-shadow, so there a real 1px border in the
|
|
49
|
+
// system text colour keeps the chip's edge.
|
|
50
|
+
"inset-ring-[0.5px] inset-ring-transparent forced-colors:border forced-colors:border-[CanvasText]",
|
|
45
51
|
"[&_svg]:shrink-0 [&_svg]:pointer-events-none",
|
|
46
52
|
// Inert on the default non-focusable <span> — `:focus-visible` never
|
|
47
53
|
// matches it — and lights up as soon as `asChild` renders Badge onto a
|
|
@@ -67,17 +73,16 @@ const badgeVariants = cva(
|
|
|
67
73
|
light: [
|
|
68
74
|
"bg-black/8 dark:bg-white/16",
|
|
69
75
|
TEXT_COLOR_CLASSES.primary,
|
|
70
|
-
"
|
|
71
|
-
"data-color:bg-(--c-solid)/30 data-color:text-(--c-text) data-color:
|
|
76
|
+
"inset-ring-black/8 dark:inset-ring-white/15",
|
|
77
|
+
"data-color:bg-(--c-solid)/30 data-color:text-(--c-text) data-color:inset-ring-(--c-solid)",
|
|
72
78
|
"data-[color=neutral]:bg-(--c-soft)",
|
|
73
79
|
],
|
|
74
|
-
outline: "bg-transparent text-(--c-text)
|
|
80
|
+
outline: "bg-transparent text-(--c-text) inset-ring-(--c-solid)",
|
|
75
81
|
subtle: "bg-transparent text-(--c-text)",
|
|
76
82
|
// from-*/to-* are the CSS defaults for --tw-gradient-from/to and the
|
|
77
83
|
// --tw-gradient-stops composition chain. Props only override the individual
|
|
78
84
|
// vars they provide — the chain resolves them lazily without JS defaults.
|
|
79
|
-
gradient:
|
|
80
|
-
"bg-origin-border bg-linear-to-r from-purple-300 to-pink-400 text-black border-white/20",
|
|
85
|
+
gradient: "bg-linear-to-r from-purple-300 to-pink-400 text-black inset-ring-white/20",
|
|
81
86
|
},
|
|
82
87
|
// Figma (node 14950-143827) defines sm/md/lg; xs/xl extrapolate one
|
|
83
88
|
// step past either end. Radius follows Figma on every step
|
|
@@ -95,7 +95,7 @@ const buttonVariants = cva(
|
|
|
95
95
|
"not-data-loading:hover:bg-(--c-soft-hover) not-data-loading:hover:border-(--c-solid)",
|
|
96
96
|
],
|
|
97
97
|
outline: [
|
|
98
|
-
"bg-transparent text-(--c-text) border-(--c-solid)",
|
|
98
|
+
"bg-transparent text-(--c-text) border-(--c-solid)/35",
|
|
99
99
|
"not-data-loading:hover:bg-(--c-soft)",
|
|
100
100
|
],
|
|
101
101
|
subtle: ["bg-transparent text-(--c-text)", "not-data-loading:hover:bg-(--c-soft)"],
|
|
@@ -23,14 +23,15 @@ const cardVariants = cva("flex flex-col rounded-card border", {
|
|
|
23
23
|
// behind it rather than imposing a flat hue — used here in both
|
|
24
24
|
// themes for a consistently subtle surface.
|
|
25
25
|
//
|
|
26
|
-
// The border is
|
|
27
|
-
// dark:border-white/
|
|
28
|
-
// `
|
|
29
|
-
//
|
|
30
|
-
//
|
|
26
|
+
// The border is Figma's card hairline, `border-primary` — white at 8 %
|
|
27
|
+
// in the dark theme (`dark:border-white/8`), shared with
|
|
28
|
+
// `ChoiceCardGroup` and with the dividers of `Card.Header` /
|
|
29
|
+
// `Card.Description` / `Card.Footer`. It sat at /15, the kit's form
|
|
30
|
+
// hairline (`Input`'s shell, `SegmentGroup`), which drew every card
|
|
31
|
+
// twice as marked as the mockups.
|
|
31
32
|
default: [
|
|
32
33
|
"bg-white/4 text-brand-950 border-brand-900/20",
|
|
33
|
-
"dark:text-white dark:border-white/
|
|
34
|
+
"dark:text-white dark:border-white/8",
|
|
34
35
|
],
|
|
35
36
|
filled: "bg-(--c-solid) text-(--c-on-solid) border-(--c-solid)",
|
|
36
37
|
light: "bg-(--c-soft) text-(--c-text) border-(--c-soft)",
|
|
@@ -151,7 +152,7 @@ const CardHeader = ({ className, withBorder, testId, ...rest }: CardHeaderProps)
|
|
|
151
152
|
<ark.div
|
|
152
153
|
className={cn(
|
|
153
154
|
"flex flex-col gap-1 px-4 py-3",
|
|
154
|
-
{ "border-b border-brand-900/20 dark:border-white/
|
|
155
|
+
{ "border-b border-brand-900/20 dark:border-white/8": withBorder },
|
|
155
156
|
className,
|
|
156
157
|
)}
|
|
157
158
|
{...props({ "data-testid": testId })}
|
|
@@ -176,7 +177,7 @@ const CardDescription = ({ className, withBorder, testId, ...rest }: CardDescrip
|
|
|
176
177
|
className={cn(
|
|
177
178
|
"text-sm",
|
|
178
179
|
TEXT_COLOR_CLASSES.muted,
|
|
179
|
-
{ "border-t border-brand-900/20 dark:border-white/
|
|
180
|
+
{ "border-t border-brand-900/20 dark:border-white/8": withBorder },
|
|
180
181
|
className,
|
|
181
182
|
)}
|
|
182
183
|
{...props({ "data-testid": testId })}
|
|
@@ -200,7 +201,7 @@ const CardFooter = ({ className, withBorder, testId, ...rest }: CardFooterProps)
|
|
|
200
201
|
<ark.div
|
|
201
202
|
className={cn(
|
|
202
203
|
"flex items-center justify-end gap-2 px-4 py-3",
|
|
203
|
-
{ "border-t border-brand-900/20 dark:border-white/
|
|
204
|
+
{ "border-t border-brand-900/20 dark:border-white/8": withBorder },
|
|
204
205
|
className,
|
|
205
206
|
)}
|
|
206
207
|
{...props({ "data-testid": testId })}
|
|
@@ -51,6 +51,23 @@ describe("Checkbox", () => {
|
|
|
51
51
|
expect(screen.getByText("Select row").className).toContain("sr-only")
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
+
it("aligns the control to the label line when a description sits below", () => {
|
|
55
|
+
const { container } = render(
|
|
56
|
+
<Checkbox label="Airplane mode" description="Disables all radios" />,
|
|
57
|
+
)
|
|
58
|
+
const root = container.querySelector("label") as HTMLElement
|
|
59
|
+
// A grid root with control, label and field as direct cells: the control
|
|
60
|
+
// centers on the label row, and the field hangs under the label.
|
|
61
|
+
expect(root.className).toContain("inline-grid")
|
|
62
|
+
expect(Array.from(root.children).map((el) => el.tagName)).toEqual(["DIV", "SPAN", "DIV"])
|
|
63
|
+
expect(root.lastElementChild?.className).toContain("col-start-2")
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it("keeps a label-only root as an inline row", () => {
|
|
67
|
+
const { container } = render(<Checkbox label="Airplane mode" />)
|
|
68
|
+
expect((container.querySelector("label") as HTMLElement).className).toContain("inline-flex")
|
|
69
|
+
})
|
|
70
|
+
|
|
54
71
|
it("renders a sr-only label with no extra wrapper around it", () => {
|
|
55
72
|
const { container } = render(<Checkbox label="Select row" classNames={{ label: "sr-only" }} />)
|
|
56
73
|
const root = container.querySelector("label") as HTMLElement
|
|
@@ -65,15 +82,6 @@ describe("Checkbox", () => {
|
|
|
65
82
|
expect(Array.from(root.children).map((el) => el.tagName)).toEqual(["DIV", "SPAN", "INPUT"])
|
|
66
83
|
})
|
|
67
84
|
|
|
68
|
-
it("stacks a visible label above its description in one wrapper", () => {
|
|
69
|
-
const { container } = render(<Checkbox label="Notify" description="Weekly digest" />)
|
|
70
|
-
const label = screen.getByText("Notify")
|
|
71
|
-
const description = screen.getByText("Weekly digest")
|
|
72
|
-
const stack = label.parentElement as HTMLElement
|
|
73
|
-
expect(stack).toBe((container.querySelector("label") as HTMLElement).children[1])
|
|
74
|
-
expect(stack.contains(description)).toBe(true)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
85
|
it("renders testId as data-testid on the root label, not the hidden input", () => {
|
|
78
86
|
render(<Checkbox label="Accept terms" testId="accept-terms" />)
|
|
79
87
|
const el = screen.getByTestId("accept-terms")
|
|
@@ -10,7 +10,13 @@ import { type IconMap, iconStroke, mergeIcons } from "../../lib/icons"
|
|
|
10
10
|
import { props } from "../../lib/props"
|
|
11
11
|
import type { Size } from "../../lib/sizes"
|
|
12
12
|
import type { WithTestId } from "../../lib/test-id"
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
FieldShell,
|
|
15
|
+
fieldA11yProps,
|
|
16
|
+
fieldInlineStack,
|
|
17
|
+
fieldLabel,
|
|
18
|
+
requiredMark,
|
|
19
|
+
} from "../field/field"
|
|
14
20
|
import { CheckIcon } from "../popover/icons"
|
|
15
21
|
import { type ControlIndicatorVariant, controlIndicator } from "./control"
|
|
16
22
|
|
|
@@ -22,8 +28,8 @@ import { type ControlIndicatorVariant, controlIndicator } from "./control"
|
|
|
22
28
|
* layout footprint when it's visually hidden (e.g. `classNames.label:
|
|
23
29
|
* "sr-only"`): an absolutely-positioned flex child isn't a flex item at all,
|
|
24
30
|
* so it can't pick up the root's `gap-2`. `description` / `error` live below
|
|
25
|
-
*
|
|
26
|
-
* complete on its own. Implements the kit's `FormControlProps` contract: the
|
|
31
|
+
* the label via the shared `Field` scaffold, with the box centered on the
|
|
32
|
+
* label line, so a `Checkbox` is accessible and complete on its own. Implements the kit's `FormControlProps` contract: the
|
|
27
33
|
* `ref` and `onBlur` land on the submittable hidden `<input>`, and `name`
|
|
28
34
|
* wires it into native form submission.
|
|
29
35
|
*
|
|
@@ -90,6 +96,7 @@ export type CheckboxProps = WithTestId & {
|
|
|
90
96
|
root?: string
|
|
91
97
|
control?: string
|
|
92
98
|
label?: string
|
|
99
|
+
/** The description / error field, under the label. */
|
|
93
100
|
field?: string
|
|
94
101
|
}
|
|
95
102
|
}
|
|
@@ -136,9 +143,10 @@ export const Checkbox = ({
|
|
|
136
143
|
// library can flip it from `fieldState.invalid` (see FormControlProps).
|
|
137
144
|
const isInvalid = invalid || error != null
|
|
138
145
|
|
|
139
|
-
// A visible label above description/error
|
|
140
|
-
//
|
|
141
|
-
//
|
|
146
|
+
// A visible label above description/error switches the root to a grid: the
|
|
147
|
+
// control centers on the label's row alone (not on the whole text stack),
|
|
148
|
+
// and the field hangs under the label in the second column. Label-only
|
|
149
|
+
// (incl. sr-only) stays a plain inline row.
|
|
142
150
|
const hasStack = label != null && (description != null || error != null)
|
|
143
151
|
|
|
144
152
|
const labelNode = label != null && (
|
|
@@ -171,7 +179,9 @@ export const Checkbox = ({
|
|
|
171
179
|
// `relative` contains the absolutely positioned hidden input, which would
|
|
172
180
|
// otherwise escape any scroller this control sits in.
|
|
173
181
|
className={cn(
|
|
174
|
-
|
|
182
|
+
hasStack
|
|
183
|
+
? fieldInlineStack({ size })
|
|
184
|
+
: "relative inline-flex items-center gap-2 select-none",
|
|
175
185
|
className,
|
|
176
186
|
classNames?.root,
|
|
177
187
|
)}
|
|
@@ -181,26 +191,15 @@ export const Checkbox = ({
|
|
|
181
191
|
<Ark.Indicator indeterminate>{icons.indeterminate}</Ark.Indicator>
|
|
182
192
|
</Ark.Control>
|
|
183
193
|
|
|
184
|
-
{
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
{labelNode}
|
|
194
|
-
<FieldShell
|
|
195
|
-
description={description}
|
|
196
|
-
error={error}
|
|
197
|
-
size={size}
|
|
198
|
-
className={classNames?.field}
|
|
199
|
-
>
|
|
200
|
-
<CheckboxHiddenInput ref={ref} onBlur={onBlur} />
|
|
201
|
-
</FieldShell>
|
|
202
|
-
</>
|
|
203
|
-
)}
|
|
194
|
+
{labelNode}
|
|
195
|
+
<FieldShell
|
|
196
|
+
description={description}
|
|
197
|
+
error={error}
|
|
198
|
+
size={size}
|
|
199
|
+
className={cn(hasStack && "col-start-2", classNames?.field)}
|
|
200
|
+
>
|
|
201
|
+
<CheckboxHiddenInput ref={ref} onBlur={onBlur} />
|
|
202
|
+
</FieldShell>
|
|
204
203
|
</Ark.Root>
|
|
205
204
|
)
|
|
206
205
|
}
|
|
@@ -177,8 +177,8 @@ export type ChoiceCardGroupProps<Data extends ChoiceCardGroupData = ChoiceCardIt
|
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* The card surface. Neutral at rest on the kit's translucent surface — the same
|
|
180
|
-
* `bg-white/4` + `border-brand-900/20 dark:border-white/
|
|
181
|
-
*
|
|
180
|
+
* `bg-white/4` + `border-brand-900/20 dark:border-white/8` recipe as `Card`
|
|
181
|
+
* (Figma's `border-primary`, the card hairline): a fixed opaque
|
|
182
182
|
* gray fill can vanish or over-assert depending on the host background, so the
|
|
183
183
|
* fill carries no ground of its own. The selected treatment follows the
|
|
184
184
|
* `variant`, mirroring `Checkbox` / `RadioGroup`:
|
|
@@ -198,7 +198,7 @@ const choiceCard = cva(
|
|
|
198
198
|
"relative flex w-full cursor-pointer rounded-card border text-start select-none transition-[background-color,border-color,box-shadow]",
|
|
199
199
|
"bg-white/4",
|
|
200
200
|
TEXT_COLOR_CLASSES.primary,
|
|
201
|
-
"border-brand-900/20 dark:border-white/
|
|
201
|
+
"border-brand-900/20 dark:border-white/8",
|
|
202
202
|
"hover:border-brand-900/30 dark:hover:border-white/25",
|
|
203
203
|
// Keyboard focus ring on the whole card — the kit's standard brand ring,
|
|
204
204
|
// matching Checkbox / Radio regardless of palette.
|