@opsinjs/react 0.0.0-stage → 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/components/accordion.d.ts +82 -0
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +154 -0
- package/dist/components/accordion.js.map +1 -0
- package/dist/components/alert-banner.d.ts +291 -0
- package/dist/components/alert-banner.d.ts.map +1 -0
- package/dist/components/alert-banner.js +529 -0
- package/dist/components/alert-banner.js.map +1 -0
- package/dist/components/avatar.d.ts +45 -0
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +159 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +78 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +32 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/body-map.d.ts +51 -0
- package/dist/components/body-map.d.ts.map +1 -0
- package/dist/components/body-map.js +190 -0
- package/dist/components/body-map.js.map +1 -0
- package/dist/components/button.d.ts +260 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +609 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/callout.d.ts +99 -0
- package/dist/components/callout.d.ts.map +1 -0
- package/dist/components/callout.js +285 -0
- package/dist/components/callout.js.map +1 -0
- package/dist/components/card.d.ts +156 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +396 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/care-card.d.ts +182 -0
- package/dist/components/care-card.d.ts.map +1 -0
- package/dist/components/care-card.js +544 -0
- package/dist/components/care-card.js.map +1 -0
- package/dist/components/checkbox.d.ts +58 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +167 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/combobox.d.ts +71 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +204 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/consent-sheet.d.ts +186 -0
- package/dist/components/consent-sheet.d.ts.map +1 -0
- package/dist/components/consent-sheet.js +452 -0
- package/dist/components/consent-sheet.js.map +1 -0
- package/dist/components/dialog.d.ts +108 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +573 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/disclaimer-note.d.ts +144 -0
- package/dist/components/disclaimer-note.d.ts.map +1 -0
- package/dist/components/disclaimer-note.js +486 -0
- package/dist/components/disclaimer-note.js.map +1 -0
- package/dist/components/divider.d.ts +76 -0
- package/dist/components/divider.d.ts.map +1 -0
- package/dist/components/divider.js +101 -0
- package/dist/components/divider.js.map +1 -0
- package/dist/components/dose-tracker.d.ts +137 -0
- package/dist/components/dose-tracker.d.ts.map +1 -0
- package/dist/components/dose-tracker.js +154 -0
- package/dist/components/dose-tracker.js.map +1 -0
- package/dist/components/empty-state.d.ts +171 -0
- package/dist/components/empty-state.d.ts.map +1 -0
- package/dist/components/empty-state.js +387 -0
- package/dist/components/empty-state.js.map +1 -0
- package/dist/components/field.d.ts +195 -0
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +282 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/goal-ring.d.ts +114 -0
- package/dist/components/goal-ring.d.ts.map +1 -0
- package/dist/components/goal-ring.js +254 -0
- package/dist/components/goal-ring.js.map +1 -0
- package/dist/components/icon-button.d.ts +124 -0
- package/dist/components/icon-button.d.ts.map +1 -0
- package/dist/components/icon-button.js +113 -0
- package/dist/components/icon-button.js.map +1 -0
- package/dist/components/link.d.ts +122 -0
- package/dist/components/link.d.ts.map +1 -0
- package/dist/components/link.js +164 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/log-sheet.d.ts +259 -0
- package/dist/components/log-sheet.d.ts.map +1 -0
- package/dist/components/log-sheet.js +437 -0
- package/dist/components/log-sheet.js.map +1 -0
- package/dist/components/menu.d.ts +69 -0
- package/dist/components/menu.d.ts.map +1 -0
- package/dist/components/menu.js +190 -0
- package/dist/components/menu.js.map +1 -0
- package/dist/components/metric-tile.d.ts +301 -0
- package/dist/components/metric-tile.d.ts.map +1 -0
- package/dist/components/metric-tile.js +533 -0
- package/dist/components/metric-tile.js.map +1 -0
- package/dist/components/number-field.d.ts +62 -0
- package/dist/components/number-field.d.ts.map +1 -0
- package/dist/components/number-field.js +134 -0
- package/dist/components/number-field.js.map +1 -0
- package/dist/components/popover.d.ts +70 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +174 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/progress.d.ts +83 -0
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +140 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/questionnaire.d.ts +123 -0
- package/dist/components/questionnaire.d.ts.map +1 -0
- package/dist/components/questionnaire.js +148 -0
- package/dist/components/questionnaire.js.map +1 -0
- package/dist/components/radio-group.d.ts +66 -0
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +186 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/range-bar.d.ts +172 -0
- package/dist/components/range-bar.d.ts.map +1 -0
- package/dist/components/range-bar.js +578 -0
- package/dist/components/range-bar.js.map +1 -0
- package/dist/components/range-legend.d.ts +97 -0
- package/dist/components/range-legend.d.ts.map +1 -0
- package/dist/components/range-legend.js +166 -0
- package/dist/components/range-legend.js.map +1 -0
- package/dist/components/reading-input.d.ts +225 -0
- package/dist/components/reading-input.d.ts.map +1 -0
- package/dist/components/reading-input.js +651 -0
- package/dist/components/reading-input.js.map +1 -0
- package/dist/components/relative-time.d.ts +177 -0
- package/dist/components/relative-time.d.ts.map +1 -0
- package/dist/components/relative-time.js +603 -0
- package/dist/components/relative-time.js.map +1 -0
- package/dist/components/result-card.d.ts +319 -0
- package/dist/components/result-card.d.ts.map +1 -0
- package/dist/components/result-card.js +614 -0
- package/dist/components/result-card.js.map +1 -0
- package/dist/components/scale-input.d.ts +58 -0
- package/dist/components/scale-input.d.ts.map +1 -0
- package/dist/components/scale-input.js +170 -0
- package/dist/components/scale-input.js.map +1 -0
- package/dist/components/score-dial.d.ts +205 -0
- package/dist/components/score-dial.d.ts.map +1 -0
- package/dist/components/score-dial.js +728 -0
- package/dist/components/score-dial.js.map +1 -0
- package/dist/components/scroll-area.d.ts +38 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +138 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/segmented-control.d.ts +69 -0
- package/dist/components/segmented-control.d.ts.map +1 -0
- package/dist/components/segmented-control.js +259 -0
- package/dist/components/segmented-control.js.map +1 -0
- package/dist/components/select.d.ts +72 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +205 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/sheet.d.ts +192 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +952 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/skeleton.d.ts +104 -0
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +266 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/slider.d.ts +55 -0
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +170 -0
- package/dist/components/slider.js.map +1 -0
- package/dist/components/source-citation.d.ts +127 -0
- package/dist/components/source-citation.d.ts.map +1 -0
- package/dist/components/source-citation.js +391 -0
- package/dist/components/source-citation.js.map +1 -0
- package/dist/components/spinner.d.ts +86 -0
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +97 -0
- package/dist/components/spinner.js.map +1 -0
- package/dist/components/status-pill.d.ts +90 -0
- package/dist/components/status-pill.d.ts.map +1 -0
- package/dist/components/status-pill.js +259 -0
- package/dist/components/status-pill.js.map +1 -0
- package/dist/components/stepper.d.ts +99 -0
- package/dist/components/stepper.d.ts.map +1 -0
- package/dist/components/stepper.js +152 -0
- package/dist/components/stepper.js.map +1 -0
- package/dist/components/surface.d.ts +92 -0
- package/dist/components/surface.d.ts.map +1 -0
- package/dist/components/surface.js +261 -0
- package/dist/components/surface.js.map +1 -0
- package/dist/components/switch.d.ts +48 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +152 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/symptom-picker.d.ts +69 -0
- package/dist/components/symptom-picker.d.ts.map +1 -0
- package/dist/components/symptom-picker.js +170 -0
- package/dist/components/symptom-picker.js.map +1 -0
- package/dist/components/tab-bar.d.ts +110 -0
- package/dist/components/tab-bar.d.ts.map +1 -0
- package/dist/components/tab-bar.js +118 -0
- package/dist/components/tab-bar.js.map +1 -0
- package/dist/components/table.d.ts +117 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +65 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +106 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +136 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/term.d.ts +243 -0
- package/dist/components/term.d.ts.map +1 -0
- package/dist/components/term.js +562 -0
- package/dist/components/term.js.map +1 -0
- package/dist/components/textarea.d.ts +157 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +66 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/timeline-entry.d.ts +99 -0
- package/dist/components/timeline-entry.d.ts.map +1 -0
- package/dist/components/timeline-entry.js +47 -0
- package/dist/components/timeline-entry.js.map +1 -0
- package/dist/components/toast.d.ts +80 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/toast.js +266 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/tooltip.d.ts +48 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +159 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/components/trend-sparkline.d.ts +188 -0
- package/dist/components/trend-sparkline.d.ts.map +1 -0
- package/dist/components/trend-sparkline.js +796 -0
- package/dist/components/trend-sparkline.js.map +1 -0
- package/dist/components/value.d.ts +150 -0
- package/dist/components/value.d.ts.map +1 -0
- package/dist/components/value.js +402 -0
- package/dist/components/value.js.map +1 -0
- package/dist/components/visually-hidden.d.ts +61 -0
- package/dist/components/visually-hidden.d.ts.map +1 -0
- package/dist/components/visually-hidden.js +172 -0
- package/dist/components/visually-hidden.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/opsinjs.d.ts +443 -0
- package/dist/opsinjs.d.ts.map +1 -0
- package/dist/opsinjs.js +906 -0
- package/dist/opsinjs.js.map +1 -0
- package/dist/status.d.ts +111 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +125 -0
- package/dist/status.js.map +1 -0
- package/dist/styles.css +2 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +82 -0
- package/dist/utils.js.map +1 -0
- package/package.json +86 -3
- package/styles/base.css +132 -0
- package/styles/roles.css +412 -0
- package/styles/standalone.css +20 -0
- package/styles/tailwind.css +18 -0
- package/styles/theme.css +309 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Stepper shows where a reader is in a fixed, ordered sequence of steps. It
|
|
4
|
+
* marks each step as complete, current or upcoming, and it does nothing else.
|
|
5
|
+
*
|
|
6
|
+
* IT IS AN INDICATOR, NOT A FLOW ENGINE, AND THAT IS THE WHOLE POINT. There is
|
|
7
|
+
* no onStepClick, no navigation, no next or back, and no way for the reader to
|
|
8
|
+
* change the step from inside it. `current` is a value the product passes in
|
|
9
|
+
* from a flow it already owns, and this component reflects it. The catalogue
|
|
10
|
+
* deferred a stepper for a real reason, which is that a bar of steps across the
|
|
11
|
+
* top of a screen invites a product to cram several questions onto one page,
|
|
12
|
+
* and the pattern a health form wants is one question per page. So this file
|
|
13
|
+
* refuses the part of a stepper that does the harm and keeps only the part that
|
|
14
|
+
* reassures: a read-only picture of how far along the reader is.
|
|
15
|
+
*
|
|
16
|
+
* THREE STATES, CARRIED WITHOUT COLOUR. A completed step draws a solid marker
|
|
17
|
+
* with a Check glyph and an sr-only "Completed"; the current step draws a
|
|
18
|
+
* heavier ring around its number and carries aria-current="step" and an sr-only
|
|
19
|
+
* "Current step"; an upcoming step draws a faint ring around its number in
|
|
20
|
+
* muted ink. The three differ by fill weight, by glyph, by the words a screen
|
|
21
|
+
* reader reads, and by their position in the list, so the state survives
|
|
22
|
+
* greyscale, a colour vision deficiency and a black-and-white printout. No step
|
|
23
|
+
* state is carried by hue.
|
|
24
|
+
*
|
|
25
|
+
* NEITHER COLOUR AXIS. A stepper states no clinical level and names no category,
|
|
26
|
+
* so it carries neither data-status nor data-category and draws only neutral
|
|
27
|
+
* chrome. The complete, current and upcoming markers are separated on a neutral
|
|
28
|
+
* ink-to-muted ramp and by the boundary weight of a hairline, never by a status
|
|
29
|
+
* tint or a category identity. The connector between two markers changes weight
|
|
30
|
+
* rather than colour to show the part of the sequence already passed.
|
|
31
|
+
*
|
|
32
|
+
* IT REFUSES A BAD `current` RATHER THAN THROWING. `current` is a 0-based index
|
|
33
|
+
* into `steps`. A value outside the range, or a non-integer, is truncated and
|
|
34
|
+
* clamped to the nearest real step and a development warning names it, because
|
|
35
|
+
* a progress indicator that renders nothing is useless and a step the product
|
|
36
|
+
* did not choose is a lie. The product owns which step the reader is on; this
|
|
37
|
+
* file owns only how it is drawn.
|
|
38
|
+
*
|
|
39
|
+
* SERVER COMPONENT. It has no state, no effect and no event handler, so it
|
|
40
|
+
* ships without "use client" and renders on the server.
|
|
41
|
+
*/
|
|
42
|
+
import { Check } from "lucide-react";
|
|
43
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
44
|
+
import { cn } from "../utils.js";
|
|
45
|
+
/**
|
|
46
|
+
* The marker circle per state, written out as literal strings because Tailwind
|
|
47
|
+
* reads class names as text and a `bg-${state}` template generates no CSS. All
|
|
48
|
+
* three share a border-2 so the ring weight never shifts the marker's box, and
|
|
49
|
+
* the ink is the arbitrary property `[color:var(--foreground)]` rather than
|
|
50
|
+
* `text-foreground` for the tailwind-merge reason segmented-control.tsx sets
|
|
51
|
+
* out at length. The three states differ by fill and boundary weight on a
|
|
52
|
+
* neutral ramp, never by hue.
|
|
53
|
+
*/
|
|
54
|
+
const MARKER_STATE = {
|
|
55
|
+
complete: "border-foreground bg-foreground [color:var(--background)]",
|
|
56
|
+
current: "border-foreground bg-card [color:var(--foreground)]",
|
|
57
|
+
upcoming: "border-border bg-background [color:var(--muted-foreground)]",
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The marker circle, spelled once. Not pressable, so no 44pt target floor: it
|
|
61
|
+
* is a read-only mark, not a button.
|
|
62
|
+
*/
|
|
63
|
+
const MARKER = "flex size-opsin-8 shrink-0 items-center justify-center rounded-full " +
|
|
64
|
+
"border-2 text-opsin-footnote font-medium tabular-nums";
|
|
65
|
+
/**
|
|
66
|
+
* The label per state. The current step's label gains weight so the current
|
|
67
|
+
* position reads without leaning on the marker alone, and an upcoming label
|
|
68
|
+
* drops to the muted ink. Written as `[color:var(--foreground)]` for the same
|
|
69
|
+
* tailwind-merge reason as the marker.
|
|
70
|
+
*/
|
|
71
|
+
const LABEL_STATE = {
|
|
72
|
+
complete: "[color:var(--foreground)]",
|
|
73
|
+
current: "font-medium [color:var(--foreground)]",
|
|
74
|
+
upcoming: "[color:var(--muted-foreground)]",
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The vertical line between two markers. It runs stronger where the step above
|
|
78
|
+
* it is complete and faint where it is not, so the part of the sequence
|
|
79
|
+
* already passed reads by weight and not by colour. Decorative, so it is
|
|
80
|
+
* aria-hidden.
|
|
81
|
+
*/
|
|
82
|
+
const CONNECTOR_STATE = {
|
|
83
|
+
done: "bg-foreground",
|
|
84
|
+
todo: "bg-border",
|
|
85
|
+
};
|
|
86
|
+
const CONNECTOR = "mt-opsin-1 w-0.5 flex-1 rounded-full";
|
|
87
|
+
/**
|
|
88
|
+
* The word a screen reader reads for each state, so the state is never colour
|
|
89
|
+
* alone.
|
|
90
|
+
*/
|
|
91
|
+
const STATE_SR = {
|
|
92
|
+
complete: "Completed",
|
|
93
|
+
current: "Current step",
|
|
94
|
+
upcoming: "Upcoming",
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Development warnings, said once per distinct offender. Nothing here has an
|
|
98
|
+
* OpsinErrorCode: the codes in tokens/errors.json describe a mistake a
|
|
99
|
+
* consumer makes with the clinical API, and a stepper asserts nothing
|
|
100
|
+
* clinical. segmented-control.tsx keeps the same small uncoded set for the
|
|
101
|
+
* same reason.
|
|
102
|
+
*/
|
|
103
|
+
const warned = new Set();
|
|
104
|
+
function warnDev(key, message) {
|
|
105
|
+
if (!isDevelopment() || warned.has(key))
|
|
106
|
+
return;
|
|
107
|
+
warned.add(key);
|
|
108
|
+
console.warn(message);
|
|
109
|
+
}
|
|
110
|
+
export function Stepper({ steps, current, className, label }) {
|
|
111
|
+
if (isDevelopment()) {
|
|
112
|
+
if (!Array.isArray(steps) || steps.length === 0) {
|
|
113
|
+
warnDev("no-steps", "[opsinjs] Stepper was rendered with no steps, so it has nothing to " +
|
|
114
|
+
"draw. Pass a `steps` array of at least two labelled steps.");
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
if (steps.length === 1) {
|
|
118
|
+
warnDev("one-step", "[opsinjs] Stepper was given a single step, which is not a sequence. " +
|
|
119
|
+
"A step indicator earns its place only once there are two or more " +
|
|
120
|
+
"steps to show progress across; render one thing as a heading " +
|
|
121
|
+
"instead.");
|
|
122
|
+
}
|
|
123
|
+
if (!Number.isInteger(current) || current < 0 || current >= steps.length) {
|
|
124
|
+
warnDev(`current-out-of-range:${String(current)}`, `[opsinjs] Stepper current={${String(current)}} is outside the range ` +
|
|
125
|
+
`of the ${steps.length} steps supplied, so it has been clamped to ` +
|
|
126
|
+
"the nearest step. `current` is a 0-based index into `steps`, and " +
|
|
127
|
+
"the product owns which step the reader is on.");
|
|
128
|
+
}
|
|
129
|
+
steps.forEach((step, index) => {
|
|
130
|
+
if (typeof step?.label !== "string" || step.label.trim() === "") {
|
|
131
|
+
warnDev(`step-missing-label:${index}`, `[opsinjs] Stepper step ${index} has no \`label\`. Every step needs ` +
|
|
132
|
+
"a short label naming what happens at it, otherwise the reader " +
|
|
133
|
+
"meets a numbered marker with nothing to read.");
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!Array.isArray(steps) || steps.length === 0) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const activeIndex = Math.max(0, Math.min(Math.trunc(Number(current) || 0), steps.length - 1));
|
|
142
|
+
return (_jsx("ol", { "data-slot": "stepper", "aria-label": label, className: cn("flex flex-col", className), children: steps.map((step, index) => {
|
|
143
|
+
const state = index < activeIndex
|
|
144
|
+
? "complete"
|
|
145
|
+
: index === activeIndex
|
|
146
|
+
? "current"
|
|
147
|
+
: "upcoming";
|
|
148
|
+
const isLast = index === steps.length - 1;
|
|
149
|
+
return (_jsxs("li", { "data-slot": "stepper-step", "aria-current": state === "current" ? "step" : undefined, className: "flex gap-opsin-3", children: [_jsxs("div", { className: "flex flex-col items-center", children: [_jsx("span", { "data-slot": "stepper-marker", className: cn(MARKER, MARKER_STATE[state]), children: state === "complete" ? (_jsx(Check, { "aria-hidden": "true", className: "size-[1em]" })) : (index + 1) }), !isLast ? (_jsx("span", { "data-slot": "stepper-connector", "aria-hidden": "true", className: cn(CONNECTOR, index < activeIndex ? CONNECTOR_STATE.done : CONNECTOR_STATE.todo) })) : null] }), _jsxs("div", { className: cn("flex flex-col gap-opsin-0-5", !isLast && "pb-opsin-6"), children: [_jsx("span", { "data-slot": "stepper-label", className: cn("text-opsin-subheadline", LABEL_STATE[state]), children: step.label }), step.description ? (_jsx("span", { className: "text-opsin-footnote [color:var(--muted-foreground)]", children: step.description })) : null, _jsx("span", { className: "sr-only", children: STATE_SR[state] })] })] }, index));
|
|
150
|
+
}) }));
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=stepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepper.js","sourceRoot":"","sources":["../../src/components/stepper.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AA8BhC;;;;;;;;GAQG;AACH,MAAM,YAAY,GAA8B;IAC9C,QAAQ,EAAE,2DAA2D;IACrE,OAAO,EAAE,qDAAqD;IAC9D,QAAQ,EAAE,6DAA6D;CACxE,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,GACV,sEAAsE;IACtE,uDAAuD,CAAA;AAEzD;;;;;GAKG;AACH,MAAM,WAAW,GAA8B;IAC7C,QAAQ,EAAE,2BAA2B;IACrC,OAAO,EAAE,uCAAuC;IAChD,QAAQ,EAAE,iCAAiC;CAC5C,CAAA;AAED;;;;;GAKG;AACH,MAAM,eAAe,GAAoC;IACvD,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,WAAW;CAClB,CAAA;AAED,MAAM,SAAS,GAAG,sCAAsC,CAAA;AAExD;;;GAGG;AACH,MAAM,QAAQ,GAA8B;IAC1C,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,UAAU;CACrB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,IAAI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EAAC,SAAS,EAAC,YAAY,GAAG,CACpD,CAAC,CAAC,CAAC,CACF,KAAK,GAAG,CAAC,CACV,GACI,EACN,CAAC,MAAM,CAAC,CAAC,CAAC,CACT,4BACY,mBAAmB,iBACjB,MAAM,EAClB,SAAS,EAAE,EAAE,CACX,SAAS,EACT,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAClE,GACD,CACH,CAAC,CAAC,CAAC,IAAI,IACJ,EACN,eAAK,SAAS,EAAE,EAAE,CAAC,6BAA6B,EAAE,CAAC,MAAM,IAAI,YAAY,CAAC,aACxE,4BACY,eAAe,EACzB,SAAS,EAAE,EAAE,CAAC,wBAAwB,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,YAE1D,IAAI,CAAC,KAAK,GACN,EACN,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAClB,eAAM,SAAS,EAAC,qDAAqD,YAClE,IAAI,CAAC,WAAW,GACZ,CACR,CAAC,CAAC,CAAC,IAAI,EACR,eAAM,SAAS,EAAC,SAAS,YAAE,QAAQ,CAAC,KAAK,CAAC,GAAQ,IAC9C,KAxCD,KAAK,CAyCP,CACN,CAAA;QACH,CAAC,CAAC,GACC,CACN,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface is the material a layer is made of, and the promise that whatever
|
|
3
|
+
* sits on it stays readable.
|
|
4
|
+
*
|
|
5
|
+
* THE RUNG NAMES ARE THE TOKEN NAMES (ADR 0014). `canvas`, `card`, `raised`,
|
|
6
|
+
* `sheet`, `overlay`, `scrim`. Three documents named these six rungs three
|
|
7
|
+
* different ways and the token source won, because it is the only one a
|
|
8
|
+
* stylesheet resolves: every value below is a `--opsin-material-<rung>-*`
|
|
9
|
+
* custom property emitted from `tokens/material.json`. The union this component
|
|
10
|
+
* takes is imported from `../opsinjs.ts` rather than declared here, so there is
|
|
11
|
+
* one list and it is the list the CSS has.
|
|
12
|
+
*
|
|
13
|
+
* The trap in that renaming is worth stating before anybody translates an older
|
|
14
|
+
* design file: `raised`, `sheet` and `overlay` appear in the retired vocabulary
|
|
15
|
+
* AND in this one, and two of them mean a different depth. The retired set's
|
|
16
|
+
* `overlay` covered the page while leaving it recognisable, and that job is
|
|
17
|
+
* this ladder's `sheet`. This ladder's `overlay` is chrome that content scrolls
|
|
18
|
+
* beneath, a pinned toolbar or a tab bar. Mapping by ordinal lands a
|
|
19
|
+
* dismissible sheet on the chrome rung and a tab bar on the sheet rung, and
|
|
20
|
+
* both compile.
|
|
21
|
+
*
|
|
22
|
+
* WHAT THIS COMPONENT ACTUALLY OWNS, given that the token layer already does
|
|
23
|
+
* most of the work. `@opsinjs/tokens/tokens.css` emits a `@media
|
|
24
|
+
* (prefers-reduced-transparency: reduce)` block for all six rungs that swaps
|
|
25
|
+
* `-tint` to `-opaque`, forces `-tint-alpha` to 1 and drops `-blur` to 0,
|
|
26
|
+
* deliberately leaving `-border`, `-shadow` and the geometry alone. So the
|
|
27
|
+
* scrim needs no reduced-transparency handling from this file at all: it reads
|
|
28
|
+
* the same two custom properties in both states and gets the right answer.
|
|
29
|
+
*
|
|
30
|
+
* The one thing a stylesheet cannot do is remove an element. A backdrop whose
|
|
31
|
+
* filter has collapsed to `blur(0px) saturate(1)` is still a backdrop root: the
|
|
32
|
+
* browser still snapshots what is behind it and still promotes the layer, on a
|
|
33
|
+
* rung that has asked not to be composited at all. That is the part this
|
|
34
|
+
* component owns, and it is why `Surface.Backdrop` is not rendered on an opaque
|
|
35
|
+
* rung and is removed from the render under reduced transparency, under
|
|
36
|
+
* increased contrast, under forced colours, and where `backdrop-filter` is
|
|
37
|
+
* unavailable.
|
|
38
|
+
*
|
|
39
|
+
* IT IS A SERVER COMPONENT, and that is a requirement rather than an
|
|
40
|
+
* optimisation. Every state it has is a user preference or an engine
|
|
41
|
+
* capability, and each one is answered by a media or support query in CSS.
|
|
42
|
+
* Those states are reduced transparency, increased contrast, forced colours and
|
|
43
|
+
* the absence of `backdrop-filter`. Reading any of them in JavaScript would mean
|
|
44
|
+
* rendering the
|
|
45
|
+
* wrong material on the server and correcting it after hydration, which is a
|
|
46
|
+
* visible flash of the wrong depth on the surface a health value is sitting on.
|
|
47
|
+
*/
|
|
48
|
+
import type { ReactNode } from "react";
|
|
49
|
+
import { type MaterialRung } from "../opsinjs.ts";
|
|
50
|
+
export interface SurfaceProps {
|
|
51
|
+
/**
|
|
52
|
+
* Which rung of the material ladder. Required: there is no sensible default
|
|
53
|
+
* depth, and a component that guessed would put a surface at the wrong height
|
|
54
|
+
* silently. The names are the token names: `canvas`, `card`, `raised`,
|
|
55
|
+
* `sheet`, `overlay` and `scrim`.
|
|
56
|
+
*/
|
|
57
|
+
rung: MaterialRung;
|
|
58
|
+
/**
|
|
59
|
+
* Renders the rung's opaque fallback regardless of engine or preference. A
|
|
60
|
+
* reviewer needs this to see the degraded path without changing an operating
|
|
61
|
+
* system setting, and print and export need it so that a translucent tint is
|
|
62
|
+
* never composited against paper. The exception to name is its reach: the
|
|
63
|
+
* prop changes the tint and the alpha and nothing else. On paper the boundary
|
|
64
|
+
* reaches paper whatever the settings, because the edge is drawn as an
|
|
65
|
+
* outline rather than a box-shadow and a printer keeps an outline, and the
|
|
66
|
+
* rounded geometry reaches it with the boundary. The fill is a separate
|
|
67
|
+
* question with two owners. The theme layer's print block in
|
|
68
|
+
* `packages/react/styles/roles.css` decides what colour the fill would be on
|
|
69
|
+
* paper, carrying the rung to its opaque tint; whether the fill prints at all
|
|
70
|
+
* is the reader's own background-graphics setting, which a browser leaves off
|
|
71
|
+
* by default. Setting this prop is therefore not by itself the whole print
|
|
72
|
+
* path: this component owns only whether its own boundary is drawn with a
|
|
73
|
+
* property a printer keeps.
|
|
74
|
+
*/
|
|
75
|
+
opaque?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Merged onto the root. Shape belongs here: Surface sets no corner of its
|
|
78
|
+
* own, and every layer inside it inherits whatever radius the caller applies.
|
|
79
|
+
*
|
|
80
|
+
* It is also unrestricted, so it is the one prop through which a caller can
|
|
81
|
+
* put colour on a Surface, and the two-colour-axes rule applies to it in full:
|
|
82
|
+
* a Surface may take a category tint or sit under a status, never both. A
|
|
83
|
+
* category-tinted Surface renders its status as a StatusPill inside it rather
|
|
84
|
+
* than as a tint on the root. Both axes on one element is OPSIN-0001, and this
|
|
85
|
+
* component cannot detect it. `cn` merges whatever it is handed.
|
|
86
|
+
*/
|
|
87
|
+
className?: string;
|
|
88
|
+
/** Everything the surface holds. */
|
|
89
|
+
children: ReactNode;
|
|
90
|
+
}
|
|
91
|
+
export declare function Surface({ rung, opaque, className, children, }: SurfaceProps): import("react").JSX.Element;
|
|
92
|
+
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../../src/components/surface.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAgLhE,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,IAAI,EAAE,YAAY,CAAA;IAClB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oCAAoC;IACpC,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,OAAO,CAAC,EACtB,IAAI,EACJ,MAAc,EACd,SAAS,EACT,QAAQ,GACT,EAAE,YAAY,+BA0Nd"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
3
|
+
import { cn } from "../utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Which rungs composite what is behind them.
|
|
6
|
+
*
|
|
7
|
+
* This is the one structural fact about the ladder that lives in this file
|
|
8
|
+
* rather than in the tokens, and it is here because it decides whether an
|
|
9
|
+
* ELEMENT exists. That is a decision CSS cannot express from a custom
|
|
10
|
+
* property's value. Everything else about a rung (its tint, alpha, blur,
|
|
11
|
+
* saturation, border and shadow) is read through `var()` and is never copied
|
|
12
|
+
* here.
|
|
13
|
+
*
|
|
14
|
+
* `Record<MaterialRung, boolean>` on purpose: adding a rung to the union
|
|
15
|
+
* without answering this question is a compile error rather than a surface that
|
|
16
|
+
* silently renders with no backdrop. The drift this cannot catch is a rung that
|
|
17
|
+
* changes its mind. If `tokens/material.json` flipped `raised` to
|
|
18
|
+
* `translucent: true`, this file would keep it opaque and the rung would render
|
|
19
|
+
* its tint with no blur behind it. That shows up as a flat panel where a
|
|
20
|
+
* frosted one was expected, and the fix is one line here.
|
|
21
|
+
*/
|
|
22
|
+
const TRANSLUCENT = {
|
|
23
|
+
canvas: false,
|
|
24
|
+
card: false,
|
|
25
|
+
raised: false,
|
|
26
|
+
sheet: true,
|
|
27
|
+
overlay: true,
|
|
28
|
+
scrim: true,
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The three rung names that exist only in the retired vocabulary, and the rung
|
|
32
|
+
* each one meant, matched by JOB rather than by position on the ladder.
|
|
33
|
+
*
|
|
34
|
+
* The job each retired name did, spelled out, because this table is the one
|
|
35
|
+
* place a by-position translation can be introduced silently and it has been
|
|
36
|
+
* once already: retired `base` was the page itself, which is `canvas`; retired
|
|
37
|
+
* `panel` was a layer lifted above the page without covering it, which is
|
|
38
|
+
* `raised`; retired `chrome` was a pinned toolbar or tab bar, which is
|
|
39
|
+
* `overlay`. It must stay in step with the translation table on
|
|
40
|
+
* `content/docs/components/surface.mdx`, and the row to check first is `panel`.
|
|
41
|
+
* The retired vocabulary also had a `raised`, meaning a bounded block of
|
|
42
|
+
* content, and taking that row's answer lands a lifted panel one rung too low
|
|
43
|
+
* on the flat `card` material.
|
|
44
|
+
*
|
|
45
|
+
* Only three of the six can be caught here. `raised`, `sheet` and `overlay` are
|
|
46
|
+
* spelled the same in both vocabularies, so a component cannot tell a caller
|
|
47
|
+
* who meant this ladder from one who meant the other. That is exactly why the
|
|
48
|
+
* page says a search-and-replace is not a safe translation.
|
|
49
|
+
*/
|
|
50
|
+
const RENAMED_RUNGS = {
|
|
51
|
+
base: "canvas",
|
|
52
|
+
panel: "raised",
|
|
53
|
+
chrome: "overlay",
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* This file ships as source into JavaScript projects, where the union is
|
|
57
|
+
* advice. A rung outside the six resolves no tokens at all, so there is no
|
|
58
|
+
* material to draw and no honest guess to make.
|
|
59
|
+
*/
|
|
60
|
+
function isMaterialRung(value) {
|
|
61
|
+
return typeof value === "string" && Object.hasOwn(TRANSLUCENT, value);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The complaints this file has already made, so it makes each of them once.
|
|
65
|
+
*
|
|
66
|
+
* Not `warnOnce`, and the reason is the same one the rung warning gives below:
|
|
67
|
+
* `tokens/errors.json` has no code for either of these mistakes, a component
|
|
68
|
+
* may not mint one, and `warnOnce` is keyed on a code. What can be borrowed
|
|
69
|
+
* from it is the policy. `tokens/errors.json` says a warning fires once per
|
|
70
|
+
* offending call site, because a repeated identical complaint teaches nothing
|
|
71
|
+
* and drowns the next one, and an unrecognised rung inside a mapped list
|
|
72
|
+
* otherwise prints once per row per render pass.
|
|
73
|
+
*
|
|
74
|
+
* Module scope in a server component is shared between requests. For anything
|
|
75
|
+
* that touches a reader's screen that is a disqualifying property, and it is
|
|
76
|
+
* the reason this file refuses to count composited surfaces. Here it is
|
|
77
|
+
* harmless. The only thing this set ever holds is a rung string a
|
|
78
|
+
* developer typed into a prop, nothing is written to it outside a development
|
|
79
|
+
* build, and one request silencing a repeat of the same complaint in the next
|
|
80
|
+
* is the behaviour `warnOnce` already has.
|
|
81
|
+
*/
|
|
82
|
+
const warnedKeys = new Set();
|
|
83
|
+
/**
|
|
84
|
+
* Bounded, because a development server can run for days and this set is never
|
|
85
|
+
* cleared. Reaching sixteen distinct malformed values in one session means the
|
|
86
|
+
* report has already been made several times over; going quiet is better than
|
|
87
|
+
* growing without limit.
|
|
88
|
+
*/
|
|
89
|
+
const MAX_WARNED_KEYS = 16;
|
|
90
|
+
function warnOncePerSession(key, message) {
|
|
91
|
+
if (!isDevelopment())
|
|
92
|
+
return;
|
|
93
|
+
if (warnedKeys.has(key) || warnedKeys.size >= MAX_WARNED_KEYS)
|
|
94
|
+
return;
|
|
95
|
+
warnedKeys.add(key);
|
|
96
|
+
try {
|
|
97
|
+
console.warn(`[opsinjs] ${message}`);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
/* A patched console is not a reason to take a health product down. */
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The opacity the scrim has to reach for this rung, as a CSS expression over
|
|
105
|
+
* the rung's own tokens.
|
|
106
|
+
*
|
|
107
|
+
* `max()` rather than either token alone, and the reason is the whole point of
|
|
108
|
+
* the part. `-tint-alpha` is how the rung wants to look; `-scrim` is the
|
|
109
|
+
* minimum opacity `tokens/material.json` publishes for it. That is what "the
|
|
110
|
+
* scrim cannot be removed by any prop" means in code: there is no prop, and
|
|
111
|
+
* there is also no token value, that takes this below the published floor.
|
|
112
|
+
*
|
|
113
|
+
* THE EXPRESSION IS NOT A NO-OP, and an earlier version of this comment said it
|
|
114
|
+
* was. `@opsinjs/tokens/tokens.css` emits `-scrim` in the `:root` block only;
|
|
115
|
+
* the dark block redeclares `-tint`, `-tint-alpha`, `-border` and `-opaque` and
|
|
116
|
+
* never redeclares `-scrim`. So the floor is theme-agnostic while the tint
|
|
117
|
+
* alpha is not, and in dark theme it currently binds on `sheet` and on
|
|
118
|
+
* `overlay`, whose dark `tintAlpha` values sit below the single published floor
|
|
119
|
+
* and are raised to it here. The direction is safe, because more opaque is more
|
|
120
|
+
* readable. A maintainer must nevertheless not read this expression as
|
|
121
|
+
* removable, and whether `minScrimOpacity` should be published per theme the
|
|
122
|
+
* way `tintAlpha` is, is a question for the token owner rather than for this
|
|
123
|
+
* file.
|
|
124
|
+
*
|
|
125
|
+
* There is one floor per rung and no content-weight prop, on purpose.
|
|
126
|
+
* `tokens/material.json` publishes a single `minScrimOpacity` per rung, measured
|
|
127
|
+
* against that rung's opaque fallback, and there is no second, thinner floor for
|
|
128
|
+
* large text anywhere in the token source. A prop that let a caller ask for a
|
|
129
|
+
* thinner large-text floor would record an intention nothing acts on, which is a
|
|
130
|
+
* knob a caller can misunderstand, and it would be a latent behaviour change: a
|
|
131
|
+
* thinner large-text floor published later would silently thin the scrim under
|
|
132
|
+
* every existing large caller in the less readable direction. So the prop
|
|
133
|
+
* returns in the same commit as the token that gives it an effect, never before
|
|
134
|
+
* it.
|
|
135
|
+
*/
|
|
136
|
+
function publishedScrimFloor(rung) {
|
|
137
|
+
return `max(var(--opsin-material-${rung}-tint-alpha), var(--opsin-material-${rung}-scrim))`;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The filter, written once and used twice. Safari carried `backdrop-filter`
|
|
141
|
+
* behind the `-webkit-` prefix until version 18, and the tested floor for this
|
|
142
|
+
* system is Safari 16.4. So the prefixed spelling is not legacy politeness but
|
|
143
|
+
* the difference between a blurred sheet and an opaque one for readers on a
|
|
144
|
+
* phone they have not replaced.
|
|
145
|
+
*/
|
|
146
|
+
const BACKDROP_FILTER = "blur(var(--opsinjs-surface-blur)) saturate(var(--opsinjs-surface-saturation))";
|
|
147
|
+
export function Surface({ rung, opaque = false, className, children, }) {
|
|
148
|
+
if (!isMaterialRung(rung)) {
|
|
149
|
+
/* Not an OPSIN code. `tokens/errors.json` has no entry for a material rung
|
|
150
|
+
outside the six, and a component may not mint one. The table is generated
|
|
151
|
+
from that file and the codes are a versioned contract. A plain
|
|
152
|
+
development warning is the honest channel until OPSIN-0022 exists.
|
|
153
|
+
|
|
154
|
+
The content still renders. StatusPill returns null for a status outside
|
|
155
|
+
its four because a pill with no level asserts nothing; a Surface with no
|
|
156
|
+
material is a different case entirely. It is a presentational wrapper,
|
|
157
|
+
and dropping it would take a reader's own readings off the screen to
|
|
158
|
+
report a styling mistake. So the material is omitted, visibly, and the
|
|
159
|
+
content is left where it was. */
|
|
160
|
+
const offending = String(rung);
|
|
161
|
+
const suggestion = RENAMED_RUNGS[offending];
|
|
162
|
+
warnOncePerSession(`rung:${offending}`, `<Surface> received rung="${offending}", which is not one of ` +
|
|
163
|
+
"canvas, card, raised, sheet, overlay, scrim. " +
|
|
164
|
+
(suggestion === undefined
|
|
165
|
+
? "No material was applied."
|
|
166
|
+
: `That name is from the retired vocabulary; the rung that does that ` +
|
|
167
|
+
`job is now "${suggestion}". Map the old names by job, never by ` +
|
|
168
|
+
`position: the retired "overlay" is this ladder's "sheet". `) +
|
|
169
|
+
"See /docs/project/decisions/0014-material-rung-names.");
|
|
170
|
+
return (_jsx("div", { "data-slot": "surface", className: cn("relative", className), children: _jsx("div", { "data-slot": "surface-content", className: "relative", children: children }) }));
|
|
171
|
+
}
|
|
172
|
+
const style = {
|
|
173
|
+
"--opsinjs-surface-tint": opaque
|
|
174
|
+
? `var(--opsin-material-${rung}-opaque)`
|
|
175
|
+
: `var(--opsin-material-${rung}-tint)`,
|
|
176
|
+
"--opsinjs-surface-opaque": `var(--opsin-material-${rung}-opaque)`,
|
|
177
|
+
"--opsinjs-surface-alpha": opaque ? "1" : publishedScrimFloor(rung),
|
|
178
|
+
"--opsinjs-surface-blur": `var(--opsin-material-${rung}-blur)`,
|
|
179
|
+
"--opsinjs-surface-saturation": `var(--opsin-material-${rung}-saturation)`,
|
|
180
|
+
"--opsinjs-surface-edge": `var(--opsin-material-${rung}-border)`,
|
|
181
|
+
"--opsinjs-surface-edge-width": "var(--opsin-border-hairline)",
|
|
182
|
+
/* The rung's drop shadow, which is a `<shadow>` or the keyword `none` in
|
|
183
|
+
every rung's token, so it can be handed straight to the property. The
|
|
184
|
+
reduced-transparency block deliberately leaves it alone: once the
|
|
185
|
+
translucency is gone, the shadow and the edge are what is left to say
|
|
186
|
+
which layer is on top. */
|
|
187
|
+
boxShadow: `var(--opsin-material-${rung}-shadow)`,
|
|
188
|
+
};
|
|
189
|
+
return (
|
|
190
|
+
/* `relative` and nothing else. NOT `isolate`, and this is the one line in
|
|
191
|
+
the file most likely to be "tidied up" into a bug: `isolation: isolate`
|
|
192
|
+
creates a backdrop root, and a backdrop root is the boundary a
|
|
193
|
+
`backdrop-filter` is allowed to see behind. Isolate the root and the
|
|
194
|
+
backdrop blurs the inside of the surface instead of the page underneath
|
|
195
|
+
it, which looks like nothing happening at all. Painting order does the
|
|
196
|
+
job on its own. All four layers are positioned with `z-index: auto`, so
|
|
197
|
+
they paint in document order and the content is last. */
|
|
198
|
+
_jsxs("div", { "data-slot": "surface", style: style, className: cn("relative", className), children: [opaque || !TRANSLUCENT[rung] ? null : (_jsx("div", { "data-slot": "surface-backdrop", "aria-hidden": "true", className: cn("pointer-events-none absolute inset-0 rounded-[inherit]",
|
|
199
|
+
/* Absent, not neutralised. The token layer has already collapsed
|
|
200
|
+
the blur to 0 under this query; what it cannot do is stop the
|
|
201
|
+
element being a backdrop root, so this is the component's half of
|
|
202
|
+
the same answer. `display: none` leaves the node in the DOM and
|
|
203
|
+
removes it from the render, which is as close to absent as a
|
|
204
|
+
server component gets without shipping a media-query listener and
|
|
205
|
+
a hydration flash to a reader who asked for less. */
|
|
206
|
+
"[@media(prefers-reduced-transparency:reduce)]:hidden",
|
|
207
|
+
/* accessibility/increased-contrast names four things
|
|
208
|
+
`prefers-contrast: more` will do, and the fourth is "disable
|
|
209
|
+
translucency and blur, by reusing the reduced-transparency
|
|
210
|
+
degradation". This is that, for this component. High contrast and
|
|
211
|
+
frosted glass are incompatible requests. */
|
|
212
|
+
"contrast-more:hidden",
|
|
213
|
+
/* A forced-colours palette has already replaced the material with
|
|
214
|
+
system colours, so a composited blur over a system-coloured page
|
|
215
|
+
is cost with no information in it. This is the fourth condition
|
|
216
|
+
that takes the backdrop out of the render, beside reduced
|
|
217
|
+
transparency, increased contrast and the absence of
|
|
218
|
+
`backdrop-filter`. */
|
|
219
|
+
"forced-colors:hidden",
|
|
220
|
+
/* The `@supports` fallback and the reduced-transparency fallback are
|
|
221
|
+
the same fallback on purpose (tokens/material.json), which is what
|
|
222
|
+
makes the degraded path the one that gets exercised by real
|
|
223
|
+
readers rather than only by an old engine nobody has. Both
|
|
224
|
+
spellings are tested because Safari carried only the prefixed one
|
|
225
|
+
until 18 and the tested floor is 16.4. */
|
|
226
|
+
"[@supports_not_((backdrop-filter:blur(1px))_or_(-webkit-backdrop-filter:blur(1px)))]:hidden"), style: {
|
|
227
|
+
backdropFilter: BACKDROP_FILTER,
|
|
228
|
+
WebkitBackdropFilter: BACKDROP_FILTER,
|
|
229
|
+
} })), _jsx("div", { "data-slot": "surface-scrim", "aria-hidden": "true", className: cn("pointer-events-none absolute inset-0 rounded-[inherit]",
|
|
230
|
+
/* Where the backdrop is gone, the tint has to stop being a tint. The
|
|
231
|
+
reduced-transparency case needs no class here because the tokens
|
|
232
|
+
already swap `-tint` for `-opaque` and force the alpha to 1; these
|
|
233
|
+
two cases are the ones no stylesheet in the system covers. */
|
|
234
|
+
"contrast-more:[--opsinjs-surface-tint:var(--opsinjs-surface-opaque)] contrast-more:[--opsinjs-surface-alpha:1]", "[@supports_not_((backdrop-filter:blur(1px))_or_(-webkit-backdrop-filter:blur(1px)))]:[--opsinjs-surface-tint:var(--opsinjs-surface-opaque)]", "[@supports_not_((backdrop-filter:blur(1px))_or_(-webkit-backdrop-filter:blur(1px)))]:[--opsinjs-surface-alpha:1]"), style: {
|
|
235
|
+
backgroundColor: "var(--opsinjs-surface-tint)",
|
|
236
|
+
opacity: "var(--opsinjs-surface-alpha)",
|
|
237
|
+
} }), _jsx("div", { "data-slot": "surface-edge", "aria-hidden": "true", className: cn("pointer-events-none absolute inset-0 rounded-[inherit]",
|
|
238
|
+
/* WIDTH ONLY, AND THAT IS NOT THE SECOND REQUIREMENT. Increased
|
|
239
|
+
contrast asks for hairline dividers at low alpha to "become solid
|
|
240
|
+
at full token colour"; this line takes the outline width from the
|
|
241
|
+
hairline width to the emphasis width and leaves
|
|
242
|
+
`--opsinjs-surface-edge` at `--opsin-material-<rung>-border`, which
|
|
243
|
+
several rungs publish at a low alpha. The negative
|
|
244
|
+
`outline-offset` reads the same width variable, so it widens with
|
|
245
|
+
the edge and the thicker outline still sits inside the box. A wider
|
|
246
|
+
edge at the same alpha is more visible than a thinner one and is not
|
|
247
|
+
the same as an explicit one, and whether the result clears the
|
|
248
|
+
non-text contrast floor has not been measured.
|
|
249
|
+
|
|
250
|
+
It stops at the width on purpose. Substituting a solid colour here
|
|
251
|
+
would be this component choosing a border colour the ladder did not
|
|
252
|
+
publish, and it would give `canvas` and `scrim` an edge they are
|
|
253
|
+
specified not to have, because their border token is the keyword
|
|
254
|
+
`none`. The colour half belongs to `tokens/material.json`, and the
|
|
255
|
+
page says so rather than claiming this line answers it. */
|
|
256
|
+
"contrast-more:[--opsinjs-surface-edge-width:var(--opsin-border-emphasis)]"), style: {
|
|
257
|
+
outline: "var(--opsinjs-surface-edge-width) solid var(--opsinjs-surface-edge)",
|
|
258
|
+
outlineOffset: "calc(-1 * var(--opsinjs-surface-edge-width))",
|
|
259
|
+
} }), _jsx("div", { "data-slot": "surface-content", className: "relative", children: children })] }));
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../../src/components/surface.tsx"],"names":[],"mappings":";AAkDA,OAAO,EAAE,aAAa,EAAqB,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAEhC;;;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AAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,aACxE,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACrC,2BACY,kBAAkB,iBAChB,MAAM,EAClB,SAAS,EAAE,EAAE,CACX,wDAAwD;gBACxD;;;;;;uEAMuD;gBACvD,sDAAsD;gBACtD;;;;8DAI8C;gBAC9C,sBAAsB;gBACtB;;;;;wCAKwB;gBACxB,sBAAsB;gBACtB;;;;;4DAK4C;gBAC5C,6FAA6F,CAC9F,EACD,KAAK,EAAE;oBACL,cAAc,EAAE,eAAe;oBAC/B,oBAAoB,EAAE,eAAe;iBACtC,GACD,CACH,EAID,2BACY,eAAe,iBACb,MAAM,EAClB,SAAS,EAAE,EAAE,CACX,wDAAwD;gBACxD;;;gFAGgE;gBAChE,gHAAgH,EAChH,6IAA6I,EAC7I,kHAAkH,CACnH,EACD,KAAK,EAAE;oBACL,eAAe,EAAE,6BAA6B;oBAC9C,OAAO,EAAE,8BAA8B;iBACxC,GACD,EAsDF,2BACY,cAAc,iBACZ,MAAM,EAClB,SAAS,EAAE,EAAE,CACX,wDAAwD;gBACxD;;;;;;;;;;;;;;;;;6EAiB6D;gBAC7D,2EAA2E,CAC5E,EACD,KAAK,EAAE;oBACL,OAAO,EACL,qEAAqE;oBACvE,aAAa,EAAE,8CAA8C;iBAC9D,GACD,EAKF,2BAAe,iBAAiB,EAAC,SAAS,EAAC,UAAU,YAClD,QAAQ,GACL,IACF,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface SwitchProps {
|
|
2
|
+
/**
|
|
3
|
+
* Required. The accessible name and the visible words for the control, applied
|
|
4
|
+
* as the switch's `aria-labelledby` so a screen-reader user hears what the
|
|
5
|
+
* toggle sets before its state. Name the setting the switch turns on, "Larger
|
|
6
|
+
* text" rather than "On". There is no default, because a guessed name would
|
|
7
|
+
* describe the wrong thing on most screens, and a missing or empty label
|
|
8
|
+
* raises a development warning rather than rendering an unnamed control.
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the switch is on. This is a controlled component with no internal
|
|
13
|
+
* state, so the caller holds the boolean, applies the effect the switch names,
|
|
14
|
+
* and passes the new value straight back through `onCheckedChange`.
|
|
15
|
+
*/
|
|
16
|
+
checked: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Called with the new boolean when the reader flips the switch. The caller
|
|
19
|
+
* commits the change straight away, because a switch takes effect on the flip
|
|
20
|
+
* rather than on a later submit, and passes the result back as `checked`.
|
|
21
|
+
*/
|
|
22
|
+
onCheckedChange: (checked: boolean) => void;
|
|
23
|
+
/**
|
|
24
|
+
* An optional helper line under the label, for a sentence that says what the
|
|
25
|
+
* setting does or what turning it on will change. It is read to assistive
|
|
26
|
+
* technology as the switch's description rather than part of its name, so the
|
|
27
|
+
* name stays the label alone. Keep it to one plain sentence; a paragraph
|
|
28
|
+
* belongs above the control, not inside it.
|
|
29
|
+
*/
|
|
30
|
+
description?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the switch cannot be changed. A disabled switch keeps its current
|
|
33
|
+
* position and its label so the reader can still see the setting and its
|
|
34
|
+
* state, drops the track to a quieter weight, and takes no focus and no key.
|
|
35
|
+
* Defaults to `false`.
|
|
36
|
+
*/
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Merged onto the root row. Width, margin and place in a layout belong here. A
|
|
40
|
+
* class you pass wins over the row's own where the two conflict, because it is
|
|
41
|
+
* merged last. It is the one route by which colour can reach the row, and the
|
|
42
|
+
* two-colour-axes rule applies to it in full: a switch takes neither a status
|
|
43
|
+
* nor a category tint.
|
|
44
|
+
*/
|
|
45
|
+
className?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function Switch({ label, checked, onCheckedChange, description, disabled, className, }: SwitchProps): import("react").JSX.Element;
|
|
48
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/components/switch.tsx"],"names":[],"mappings":"AAkJA,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;;;OAIG;IACH,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,MAAM,CAAC,EACrB,KAAK,EACL,OAAO,EACP,eAAe,EACf,WAAW,EACX,QAAgB,EAChB,SAAS,GACV,EAAE,WAAW,+BAoDb"}
|