@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,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Questionnaire is the styled shell around a set of questions a product owns. It
|
|
3
|
+
* groups them, gives the group one accessible name, shows the reader where they
|
|
4
|
+
* are in it, and tells the product when the reader has reached the end. It scores
|
|
5
|
+
* nothing, interprets nothing, and ships no question of its own.
|
|
6
|
+
*
|
|
7
|
+
* WHY THE ROSTER DECLINED IT, AND WHY THAT SHAPES EVERY LINE. The name was kept
|
|
8
|
+
* off the roster because a validated instrument is licensed, worded, scored and
|
|
9
|
+
* interpreted by its publisher, and a component that rendered one would invite a
|
|
10
|
+
* product to edit its wording or its scoring, which is a clinical-safety problem
|
|
11
|
+
* rather than an API one. This build answers that by owning none of it. The
|
|
12
|
+
* component holds no instrument, no question text, no options, no score, no band
|
|
13
|
+
* and no interpretation. Every question, every control and every word of a result
|
|
14
|
+
* arrives from the product through props, and the product does its own scoring off
|
|
15
|
+
* this component, where opsinjs cannot reach it. What is left is a container: a
|
|
16
|
+
* form, a title, a progress readout, and a list of question slots the product
|
|
17
|
+
* fills. That is the whole component, and the smallness is the point.
|
|
18
|
+
*
|
|
19
|
+
* IT RENDERS THE CONTROLS IT IS HANDED AND BUILDS NONE. Each question carries a
|
|
20
|
+
* `control`, which is a React node the product composes from whatever single
|
|
21
|
+
* input the question needs: a Field, a RadioGroup, a ScaleInput, a Textarea. The
|
|
22
|
+
* shell never reaches inside that node, never reads its value and never knows what
|
|
23
|
+
* the answer was. So it cannot total the answers and it cannot grade them, which
|
|
24
|
+
* is exactly the guarantee the roster asked for: there is no code path here that
|
|
25
|
+
* could turn a set of answers into a verdict.
|
|
26
|
+
*
|
|
27
|
+
* IT IS A CLIENT COMPONENT FOR ONE REASON. The progress readout says which
|
|
28
|
+
* question the reader is on, "Question 2 of 3", and to know that the shell tracks
|
|
29
|
+
* a current index as focus moves through the list. That single piece of state is
|
|
30
|
+
* why the file carries the client directive. The index is a plain ordinal count of
|
|
31
|
+
* position in the list. It is not a health value, it is not a score, and it is
|
|
32
|
+
* never coloured or dressed as one. A questionnaire with `showProgress` off tracks
|
|
33
|
+
* the index still, so a product can turn the readout on without a remount, and the
|
|
34
|
+
* cost is one integer.
|
|
35
|
+
*
|
|
36
|
+
* IT OWNS THE SUBMIT EVENT SO A STRAY RETURN KEY CANNOT NAVIGATE. The root is a
|
|
37
|
+
* real `<form>`, and a form with no action that receives a submit reloads the page,
|
|
38
|
+
* which on a half-answered questionnaire loses the reader's work. So the shell
|
|
39
|
+
* always intercepts submit, cancels the default, and calls `onComplete` when the
|
|
40
|
+
* product passed one. The product places its own submit control among the question
|
|
41
|
+
* controls, and pressing it, or pressing Return in a text field, is what completes
|
|
42
|
+
* the set. `onComplete` is told that the reader finished and nothing more: no
|
|
43
|
+
* answers, no total, no reading. What happens next belongs to the product.
|
|
44
|
+
*
|
|
45
|
+
* NEITHER COLOUR AXIS. A questionnaire states no clinical level and names no
|
|
46
|
+
* category of measurement, so it carries neither `data-status` nor `data-category`
|
|
47
|
+
* and draws only neutral chrome. Colour that arrives through `className`, or inside
|
|
48
|
+
* a product's own control, is the product's to keep off both axes; the shell adds
|
|
49
|
+
* none. A result the product computes from the answers is the product's surface to
|
|
50
|
+
* build with the status components, well away from this container.
|
|
51
|
+
*/
|
|
52
|
+
import { type ReactNode } from "react";
|
|
53
|
+
/**
|
|
54
|
+
* One question in the set. Kept as a local type rather than a fourth public
|
|
55
|
+
* export, for the reason `badge.tsx` gives about its own variant union: the
|
|
56
|
+
* registry contract fixes this file at three public exports, so a consumer names
|
|
57
|
+
* this shape as `QuestionnaireProps["questions"][number]` rather than importing a
|
|
58
|
+
* fourth symbol.
|
|
59
|
+
*/
|
|
60
|
+
interface QuestionnaireQuestion {
|
|
61
|
+
/**
|
|
62
|
+
* A stable identifier for the question, unique within the set. It keys the list
|
|
63
|
+
* and is the product's handle on the question. It is never shown to the reader
|
|
64
|
+
* and never scored.
|
|
65
|
+
*/
|
|
66
|
+
id: string;
|
|
67
|
+
/**
|
|
68
|
+
* The question as the reader reads it, in the product's own words. A string, or
|
|
69
|
+
* a richer node when the product needs a link or emphasis inside it. The shell
|
|
70
|
+
* shows it and reads it to assistive technology; it never edits it.
|
|
71
|
+
*/
|
|
72
|
+
prompt: ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* The answer control, composed by the product. This is where a Field, a
|
|
75
|
+
* RadioGroup, a ScaleInput or a Textarea goes. The shell renders it untouched,
|
|
76
|
+
* reads no value from it, and reaches no verdict about the answer.
|
|
77
|
+
*/
|
|
78
|
+
control: ReactNode;
|
|
79
|
+
}
|
|
80
|
+
export interface QuestionnaireProps {
|
|
81
|
+
/**
|
|
82
|
+
* The questionnaire's name, in the product's own words. Supplied as the group's
|
|
83
|
+
* accessible name and shown as the title, so a screen-reader user hears what the
|
|
84
|
+
* set is before its first question. Optional, because a product may name the set
|
|
85
|
+
* in the surrounding page instead; when it is omitted the form carries no name of
|
|
86
|
+
* its own, and a development warning suggests supplying one.
|
|
87
|
+
*/
|
|
88
|
+
title?: string;
|
|
89
|
+
/**
|
|
90
|
+
* The questions, in the order they are asked. Each is an id, a prompt and a
|
|
91
|
+
* control the product composes. The shell renders them as a list and never reads
|
|
92
|
+
* an answer from a control, so it can neither total nor grade them. An empty
|
|
93
|
+
* array renders nothing and warns in development, because a questionnaire with no
|
|
94
|
+
* questions is a shell around nothing.
|
|
95
|
+
*/
|
|
96
|
+
questions: QuestionnaireQuestion[];
|
|
97
|
+
/**
|
|
98
|
+
* Called when the reader completes the set, which is when the form is submitted.
|
|
99
|
+
* It is told that the reader finished and nothing else: no answers, no total and
|
|
100
|
+
* no reading, because the shell scores nothing. The product reads its own
|
|
101
|
+
* controls and does its own scoring off this component. Omitted, submit is still
|
|
102
|
+
* cancelled so a stray Return key cannot reload the page.
|
|
103
|
+
*/
|
|
104
|
+
onComplete?: () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Shows a "Question N of M" readout above the list that names where the reader is
|
|
107
|
+
* as focus moves through the questions. It is a plain ordinal count of position,
|
|
108
|
+
* not a health value, so it is drawn as quiet text and never coloured. Defaults
|
|
109
|
+
* to `false`.
|
|
110
|
+
*/
|
|
111
|
+
showProgress?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Merged onto the root form. Width, margin and place in a layout belong here. It
|
|
114
|
+
* is the one route by which colour can reach the shell, and the two colour axes
|
|
115
|
+
* rule applies to it in full: a questionnaire takes neither a status nor a
|
|
116
|
+
* category tint. A class you pass wins where it conflicts, because it is merged
|
|
117
|
+
* last.
|
|
118
|
+
*/
|
|
119
|
+
className?: string;
|
|
120
|
+
}
|
|
121
|
+
export declare function Questionnaire({ title, questions, onComplete, showProgress, className, }: QuestionnaireProps): import("react").JSX.Element | null;
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=questionnaire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"questionnaire.d.ts","sourceRoot":"","sources":["../../src/components/questionnaire.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAKvD;;;;;;GAMG;AACH,UAAU,qBAAqB;IAC7B;;;;OAIG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;;;OAIG;IACH,MAAM,EAAE,SAAS,CAAA;IACjB;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAA;CACnB;AA6DD,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;OAMG;IACH,SAAS,EAAE,qBAAqB,EAAE,CAAA;IAClC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;IACvB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAoB,EACpB,SAAS,GACV,EAAE,kBAAkB,sCAwGpB"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Questionnaire is the styled shell around a set of questions a product owns. It
|
|
5
|
+
* groups them, gives the group one accessible name, shows the reader where they
|
|
6
|
+
* are in it, and tells the product when the reader has reached the end. It scores
|
|
7
|
+
* nothing, interprets nothing, and ships no question of its own.
|
|
8
|
+
*
|
|
9
|
+
* WHY THE ROSTER DECLINED IT, AND WHY THAT SHAPES EVERY LINE. The name was kept
|
|
10
|
+
* off the roster because a validated instrument is licensed, worded, scored and
|
|
11
|
+
* interpreted by its publisher, and a component that rendered one would invite a
|
|
12
|
+
* product to edit its wording or its scoring, which is a clinical-safety problem
|
|
13
|
+
* rather than an API one. This build answers that by owning none of it. The
|
|
14
|
+
* component holds no instrument, no question text, no options, no score, no band
|
|
15
|
+
* and no interpretation. Every question, every control and every word of a result
|
|
16
|
+
* arrives from the product through props, and the product does its own scoring off
|
|
17
|
+
* this component, where opsinjs cannot reach it. What is left is a container: a
|
|
18
|
+
* form, a title, a progress readout, and a list of question slots the product
|
|
19
|
+
* fills. That is the whole component, and the smallness is the point.
|
|
20
|
+
*
|
|
21
|
+
* IT RENDERS THE CONTROLS IT IS HANDED AND BUILDS NONE. Each question carries a
|
|
22
|
+
* `control`, which is a React node the product composes from whatever single
|
|
23
|
+
* input the question needs: a Field, a RadioGroup, a ScaleInput, a Textarea. The
|
|
24
|
+
* shell never reaches inside that node, never reads its value and never knows what
|
|
25
|
+
* the answer was. So it cannot total the answers and it cannot grade them, which
|
|
26
|
+
* is exactly the guarantee the roster asked for: there is no code path here that
|
|
27
|
+
* could turn a set of answers into a verdict.
|
|
28
|
+
*
|
|
29
|
+
* IT IS A CLIENT COMPONENT FOR ONE REASON. The progress readout says which
|
|
30
|
+
* question the reader is on, "Question 2 of 3", and to know that the shell tracks
|
|
31
|
+
* a current index as focus moves through the list. That single piece of state is
|
|
32
|
+
* why the file carries the client directive. The index is a plain ordinal count of
|
|
33
|
+
* position in the list. It is not a health value, it is not a score, and it is
|
|
34
|
+
* never coloured or dressed as one. A questionnaire with `showProgress` off tracks
|
|
35
|
+
* the index still, so a product can turn the readout on without a remount, and the
|
|
36
|
+
* cost is one integer.
|
|
37
|
+
*
|
|
38
|
+
* IT OWNS THE SUBMIT EVENT SO A STRAY RETURN KEY CANNOT NAVIGATE. The root is a
|
|
39
|
+
* real `<form>`, and a form with no action that receives a submit reloads the page,
|
|
40
|
+
* which on a half-answered questionnaire loses the reader's work. So the shell
|
|
41
|
+
* always intercepts submit, cancels the default, and calls `onComplete` when the
|
|
42
|
+
* product passed one. The product places its own submit control among the question
|
|
43
|
+
* controls, and pressing it, or pressing Return in a text field, is what completes
|
|
44
|
+
* the set. `onComplete` is told that the reader finished and nothing more: no
|
|
45
|
+
* answers, no total, no reading. What happens next belongs to the product.
|
|
46
|
+
*
|
|
47
|
+
* NEITHER COLOUR AXIS. A questionnaire states no clinical level and names no
|
|
48
|
+
* category of measurement, so it carries neither `data-status` nor `data-category`
|
|
49
|
+
* and draws only neutral chrome. Colour that arrives through `className`, or inside
|
|
50
|
+
* a product's own control, is the product's to keep off both axes; the shell adds
|
|
51
|
+
* none. A result the product computes from the answers is the product's surface to
|
|
52
|
+
* build with the status components, well away from this container.
|
|
53
|
+
*/
|
|
54
|
+
import { useId, useState } from "react";
|
|
55
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
56
|
+
import { cn } from "../utils.js";
|
|
57
|
+
/**
|
|
58
|
+
* The root form, spelled once. A column of the title, the progress readout and the
|
|
59
|
+
* question list, with the space between them from the space scale so the whole
|
|
60
|
+
* group grows with the reader's text size. It sets no surface and no colour beyond
|
|
61
|
+
* the neutral ink, so it drops into a card or a page without claiming either axis.
|
|
62
|
+
*/
|
|
63
|
+
const ROOT = "flex flex-col gap-opsin-5 [color:var(--foreground)]";
|
|
64
|
+
/** The questionnaire's name, at the title step, in the neutral ink. */
|
|
65
|
+
const TITLE = "m-0 text-opsin-title3 font-semibold [color:var(--foreground)]";
|
|
66
|
+
/**
|
|
67
|
+
* The progress readout. A quiet footnote in the muted ink, so it orients the
|
|
68
|
+
* reader without competing with the questions. It is a plain ordinal count of
|
|
69
|
+
* position, never a health value, so it takes no status colour and no emphasis a
|
|
70
|
+
* reading would earn.
|
|
71
|
+
*/
|
|
72
|
+
const PROGRESS = "m-0 text-opsin-footnote [color:var(--muted-foreground)]";
|
|
73
|
+
/** The list of questions, an ordered list with its own bullets stripped. */
|
|
74
|
+
const LIST = "m-0 flex list-none flex-col gap-opsin-5 p-0";
|
|
75
|
+
/**
|
|
76
|
+
* One question, spelled once. A list item that stacks its prompt over its control
|
|
77
|
+
* with a hairline above it, so the set reads as a sequence of separated steps
|
|
78
|
+
* rather than one dense block. The first item drops the rule and the padding it
|
|
79
|
+
* pays for, so the list does not open on a stray line.
|
|
80
|
+
*/
|
|
81
|
+
const QUESTION = "flex flex-col gap-opsin-2 border-t border-edge pt-opsin-5 " +
|
|
82
|
+
"first:border-t-0 first:pt-0";
|
|
83
|
+
/** The prompt, at the body step in the neutral ink. */
|
|
84
|
+
const PROMPT = "text-opsin-body font-medium [color:var(--foreground)]";
|
|
85
|
+
/**
|
|
86
|
+
* The control wrapper, which is also the per-question group. It sets spacing only
|
|
87
|
+
* and no colour, so the product's own control keeps its look. It carries
|
|
88
|
+
* `role="group"` and is named by the prompt through `aria-labelledby`, so a
|
|
89
|
+
* screen-reader user hears which question a control belongs to even when the
|
|
90
|
+
* control the product passed carries no accessible name of its own.
|
|
91
|
+
*/
|
|
92
|
+
const CONTROL = "flex flex-col gap-opsin-2";
|
|
93
|
+
/**
|
|
94
|
+
* Development warnings, said once per distinct offender. Nothing here has an
|
|
95
|
+
* `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a consumer
|
|
96
|
+
* makes with the clinical API, and a questionnaire shell asserts nothing clinical.
|
|
97
|
+
* `badge.tsx` and `segmented-control.tsx` keep the same small set for the same
|
|
98
|
+
* reason.
|
|
99
|
+
*/
|
|
100
|
+
const warned = new Set();
|
|
101
|
+
function warnDev(key, message) {
|
|
102
|
+
if (!isDevelopment() || warned.has(key))
|
|
103
|
+
return;
|
|
104
|
+
warned.add(key);
|
|
105
|
+
console.warn(message);
|
|
106
|
+
}
|
|
107
|
+
export function Questionnaire({ title, questions, onComplete, showProgress = false, className, }) {
|
|
108
|
+
const titleId = useId();
|
|
109
|
+
const promptBaseId = useId();
|
|
110
|
+
const [current, setCurrent] = useState(0);
|
|
111
|
+
if (isDevelopment()) {
|
|
112
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
113
|
+
warnDev("no-questions", "[opsinjs] <Questionnaire> was rendered with no questions, so it has " +
|
|
114
|
+
"nothing to draw. Supply the set through the `questions` prop, where each " +
|
|
115
|
+
"question is an id, a prompt and a control your product composes.");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const seen = new Set();
|
|
119
|
+
for (const question of questions) {
|
|
120
|
+
if (seen.has(question.id)) {
|
|
121
|
+
warnDev(`duplicate-id:${question.id}`, `[opsinjs] <Questionnaire> was given two questions with id="${question.id}". ` +
|
|
122
|
+
"The id keys the list and is your handle on the question, so it has to be " +
|
|
123
|
+
"unique within the set.");
|
|
124
|
+
}
|
|
125
|
+
seen.add(question.id);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (typeof title !== "string" || title.trim() === "") {
|
|
129
|
+
warnDev("no-title", "[opsinjs] <Questionnaire> was rendered with no `title`. The form then " +
|
|
130
|
+
"carries no accessible name of its own. Either pass `title` with the name " +
|
|
131
|
+
"of the set, or name the set in the surrounding page so a screen-reader " +
|
|
132
|
+
"user still learns what the questions are for.");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const named = typeof title === "string" && title.trim() !== "";
|
|
139
|
+
const position = Math.min(current, questions.length - 1) + 1;
|
|
140
|
+
return (_jsxs("form", { "data-slot": "questionnaire", "aria-labelledby": named ? titleId : undefined, onSubmit: (event) => {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
onComplete?.();
|
|
143
|
+
}, className: cn(ROOT, className), children: [named ? (_jsx("div", { id: titleId, "data-slot": "questionnaire-title", className: TITLE, children: title })) : null, showProgress ? (_jsxs("p", { "data-slot": "questionnaire-progress", "aria-live": "polite", className: PROGRESS, children: ["Question ", position, " of ", questions.length] })) : null, _jsx("ol", { className: LIST, children: questions.map((question, index) => {
|
|
144
|
+
const promptId = `${promptBaseId}-${index}`;
|
|
145
|
+
return (_jsxs("li", { "data-slot": "questionnaire-question", "data-question-index": index, onFocus: () => setCurrent(index), className: QUESTION, children: [_jsx("div", { id: promptId, "data-slot": "questionnaire-prompt", className: PROMPT, children: question.prompt }), _jsx("div", { role: "group", "aria-labelledby": promptId, "data-slot": "questionnaire-control", className: CONTROL, children: question.control })] }, question.id));
|
|
146
|
+
}) })] }));
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=questionnaire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"questionnaire.js","sourceRoot":"","sources":["../../src/components/questionnaire.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AA8BhC;;;;;GAKG;AACH,MAAM,IAAI,GAAG,qDAAqD,CAAA;AAElE,uEAAuE;AACvE,MAAM,KAAK,GAAG,+DAA+D,CAAA;AAE7E;;;;;GAKG;AACH,MAAM,QAAQ,GAAG,yDAAyD,CAAA;AAE1E,4EAA4E;AAC5E,MAAM,IAAI,GAAG,6CAA6C,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,QAAQ,GACZ,4DAA4D;IAC5D,6BAA6B,CAAA;AAE/B,uDAAuD;AACvD,MAAM,MAAM,GAAG,uDAAuD,CAAA;AAEtE;;;;;;GAMG;AACH,MAAM,OAAO,GAAG,2BAA2B,CAAA;AAE3C;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;AAEhC,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Y,wBAAwB,yBACb,KAAK,EAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAChC,SAAS,EAAE,QAAQ,aAEnB,cACE,EAAE,EAAE,QAAQ,eACF,sBAAsB,EAChC,SAAS,EAAE,MAAM,YAEhB,QAAQ,CAAC,MAAM,GACZ,EACN,cACE,IAAI,EAAC,OAAO,qBACK,QAAQ,eACf,uBAAuB,EACjC,SAAS,EAAE,OAAO,YAEjB,QAAQ,CAAC,OAAO,GACb,KApBD,QAAQ,CAAC,EAAE,CAqBb,CACN,CAAA;gBACH,CAAC,CAAC,GACC,IACA,CACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One option in the list. Kept as a local type rather than a fourth public
|
|
3
|
+
* export, for the reason `segmented-control.tsx` gives about its own option
|
|
4
|
+
* shape: the registry contract fixes this file at three public exports, so a
|
|
5
|
+
* consumer names this as `RadioGroupProps["options"][number]` rather than
|
|
6
|
+
* importing a fourth symbol.
|
|
7
|
+
*/
|
|
8
|
+
interface RadioGroupOption {
|
|
9
|
+
/** The value this option sets. Unique within the list, and what `value` matches. */
|
|
10
|
+
value: string;
|
|
11
|
+
/** The visible words, and the primary part of what a screen reader reads for the option. */
|
|
12
|
+
label: string;
|
|
13
|
+
/**
|
|
14
|
+
* An optional helper line under the label, for a short clarification of what
|
|
15
|
+
* the option means. It sits in the muted ink and is read as part of the
|
|
16
|
+
* option, so keep it to a phrase rather than a paragraph.
|
|
17
|
+
*/
|
|
18
|
+
description?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether this option cannot be chosen. A disabled option drops to the muted
|
|
21
|
+
* ink and is skipped by the Arrow keys rather than removed, so the reader can
|
|
22
|
+
* still see it is an option that is not available to them right now.
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RadioGroupProps {
|
|
27
|
+
/**
|
|
28
|
+
* The options, in the order they appear. Two or more: a group offering one
|
|
29
|
+
* option is not a choice, and a group offering none has nothing to render.
|
|
30
|
+
* Each option is a value, a visible label, an optional `description` line and
|
|
31
|
+
* an optional `disabled` flag.
|
|
32
|
+
*/
|
|
33
|
+
options: RadioGroupOption[];
|
|
34
|
+
/**
|
|
35
|
+
* The currently chosen value, matching one option's `value`. This is a
|
|
36
|
+
* controlled component with no internal selection state, so a `value` that
|
|
37
|
+
* matches no option renders the list with nothing chosen, and a development
|
|
38
|
+
* warning names it.
|
|
39
|
+
*/
|
|
40
|
+
value: string;
|
|
41
|
+
/**
|
|
42
|
+
* Called with the new value when the reader chooses a different option. The
|
|
43
|
+
* caller stores it and passes it back as `value`; the group keeps no state of
|
|
44
|
+
* its own.
|
|
45
|
+
*/
|
|
46
|
+
onValueChange: (value: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Required. The name of the choice, rendered as a visible legend above the
|
|
49
|
+
* list and wired to the radiogroup with `aria-labelledby`, so a sighted reader
|
|
50
|
+
* and a screen-reader user meet the same name. Name the thing being chosen,
|
|
51
|
+
* "Reminder style" rather than "Standard, Quiet, None". There is no default,
|
|
52
|
+
* because a guessed name would describe the wrong thing on most screens.
|
|
53
|
+
*/
|
|
54
|
+
label: string;
|
|
55
|
+
/**
|
|
56
|
+
* Merged onto the root group. Width, margin and place in a layout belong here.
|
|
57
|
+
* A class you pass wins over the group's own where the two conflict, because it
|
|
58
|
+
* is merged last. It is the one route by which colour can reach the group, and
|
|
59
|
+
* the two-colour-axes rule applies to it in full: a radio group takes neither a
|
|
60
|
+
* status nor a category tint.
|
|
61
|
+
*/
|
|
62
|
+
className?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare function RadioGroup({ options, value, onValueChange, label, className, }: RadioGroupProps): import("react").JSX.Element | null;
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=radio-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../../src/components/radio-group.tsx"],"names":[],"mappings":"AAkEA;;;;;;GAMG;AACH,UAAU,gBAAgB;IACxB,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAA;IACb,4FAA4F;IAC5F,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAyGD,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,OAAO,EAAE,gBAAgB,EAAE,CAAA;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,UAAU,CAAC,EACzB,OAAO,EACP,KAAK,EACL,aAAa,EACb,KAAK,EACL,SAAS,GACV,EAAE,eAAe,sCAuFjB"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* RadioGroup is a vertical list of labelled options where exactly one is chosen.
|
|
5
|
+
* It is the tall, readable form of a single choice: each option sits on its own
|
|
6
|
+
* row with a circle, a label and an optional line of helper text, and the reader
|
|
7
|
+
* runs their eye down the list rather than across it.
|
|
8
|
+
*
|
|
9
|
+
* IT IS ONE TAB STOP, AND THAT IS THE POINT IT SHARES WITH SegmentedControl.
|
|
10
|
+
* A reader arrowing down a list of options expects Tab to pass the whole list
|
|
11
|
+
* rather than to stop on every option in it, and a keyboard user who meets six
|
|
12
|
+
* tab stops where the design promised one has been handed a control that reads
|
|
13
|
+
* as six. So this is a radio group in the WAI-ARIA sense: the group takes the
|
|
14
|
+
* single tab stop, and the Arrow keys move a roving focus between the options
|
|
15
|
+
* inside it. Base UI's RadioGroup is built on its Composite primitive, which
|
|
16
|
+
* keeps that one roving stop and moves it with the Arrow keys, renders
|
|
17
|
+
* `role="radiogroup"` on the container, renders `role="radio"` with
|
|
18
|
+
* `aria-checked` on each option, and makes selection follow focus. That is the
|
|
19
|
+
* tested radio group pattern rather than a bespoke one nobody has listened to.
|
|
20
|
+
*
|
|
21
|
+
* WHY THIS AND NOT SegmentedControl, WHICH IS THE SAME PRIMITIVE. Both wrap Base
|
|
22
|
+
* UI's RadioGroup, and both are one single choice. They differ in shape and in
|
|
23
|
+
* what that shape is for. SegmentedControl is a compact single row that switches
|
|
24
|
+
* one parameter of a view, a chart's day, week or month window being the case it
|
|
25
|
+
* was built for, where every option is a word or two and all of them are worth
|
|
26
|
+
* showing at once. RadioGroup is the vertical list for a settled choice of two
|
|
27
|
+
* to about seven options, where an option may carry a description and the reader
|
|
28
|
+
* is choosing rather than toggling. Reach for this when the options need room to
|
|
29
|
+
* be read; reach for SegmentedControl when they are a tight set of siblings that
|
|
30
|
+
* belong on one line. Past about seven options a list is a scroll rather than a
|
|
31
|
+
* glance, and the honest control is a select inside a field.
|
|
32
|
+
*
|
|
33
|
+
* NEITHER COLOUR AXIS. A radio group asks the reader to pick one of a set of
|
|
34
|
+
* choices; it states no clinical level and names no category, so it carries
|
|
35
|
+
* neither `data-status` nor `data-category` and draws no status or category hue.
|
|
36
|
+
* The chosen option is marked three ways so none of them is load-bearing alone:
|
|
37
|
+
* `aria-checked` for assistive technology, the circle filling with the accent
|
|
38
|
+
* (ADR 0029) for a sighted reader, and the dot inside it for greyscale and for a
|
|
39
|
+
* reader stylesheet that strips fills. The accent is the selected-state role, not
|
|
40
|
+
* a status, so the selection reads without a level's colour doing the work.
|
|
41
|
+
*
|
|
42
|
+
* THE LABEL IS A VISIBLE LEGEND, NOT ONLY AN ACCESSIBLE NAME. `label` is
|
|
43
|
+
* required, and it is rendered as a heading above the list and wired to the
|
|
44
|
+
* radiogroup with `aria-labelledby`, so a sighted reader and a screen-reader
|
|
45
|
+
* user meet the same name for the choice. Name the thing being chosen, "Reminder
|
|
46
|
+
* style" rather than "Standard, Quiet, None", because a guessed name would
|
|
47
|
+
* describe the wrong thing on most screens, and a radiogroup with no accessible
|
|
48
|
+
* name is a defect a screen-reader user meets as a set of radios with no idea
|
|
49
|
+
* what they set.
|
|
50
|
+
*
|
|
51
|
+
* EACH OPTION IS A ROW THAT FLOORS ITS TARGET. Every option is a pressable Radio
|
|
52
|
+
* whose hit area floors at `--opsin-target-minimum` in rem, so a 44pt target
|
|
53
|
+
* survives and grows with the reader's text size rather than pinning at a device
|
|
54
|
+
* pixel. The circle and the dot are sized in `em`, so they grow with the option
|
|
55
|
+
* they belong to. A disabled option drops to the muted ink and is skipped by the
|
|
56
|
+
* Arrow keys rather than removed, so the reader can still see it is an option
|
|
57
|
+
* that is not available to them right now.
|
|
58
|
+
*/
|
|
59
|
+
import { Radio } from "@base-ui/react/radio";
|
|
60
|
+
import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
|
|
61
|
+
import { useId } from "react";
|
|
62
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
63
|
+
import { cn } from "../utils.js";
|
|
64
|
+
/**
|
|
65
|
+
* The list container, spelled once. A plain vertical stack, because the options
|
|
66
|
+
* carry their own boundaries through the row hover and the selected ring rather
|
|
67
|
+
* than through a track around the whole group.
|
|
68
|
+
*/
|
|
69
|
+
const GROUP = "flex w-full flex-col gap-opsin-0-5";
|
|
70
|
+
/**
|
|
71
|
+
* The visible legend above the list. It is a heading in weight rather than in
|
|
72
|
+
* element, wired to the radiogroup by `aria-labelledby`, so the name a
|
|
73
|
+
* screen-reader user hears is the name a sighted reader sees.
|
|
74
|
+
*/
|
|
75
|
+
const LABEL = "px-opsin-3 pb-opsin-1 text-opsin-subheadline font-medium [color:var(--foreground)]";
|
|
76
|
+
/**
|
|
77
|
+
* One option row, spelled once.
|
|
78
|
+
*
|
|
79
|
+
* It is the pressable Radio, so it carries the target floor, the focus ring and
|
|
80
|
+
* the hover. `items-start` aligns the circle with the first line of the label so
|
|
81
|
+
* a two-line option keeps the circle beside its label rather than centred on the
|
|
82
|
+
* block. The row draws a transparent border in its rest state so the hover and
|
|
83
|
+
* the layout do not shift, and the ink is written as the arbitrary property
|
|
84
|
+
* `[color:var(--foreground)]` rather than `text-foreground` so tailwind-merge
|
|
85
|
+
* files it in the `color` group and does not drop it against the `text-opsin-*`
|
|
86
|
+
* step, which is the trap `button.tsx` records at length. A disabled row drops to
|
|
87
|
+
* the measured muted ink rather than an opacity wash, so its label stays legible
|
|
88
|
+
* while it reads as unavailable, and the Arrow keys skip it. The `group` class is
|
|
89
|
+
* here so the circle and the dot can read this row's `data-checked` and
|
|
90
|
+
* `data-disabled` state.
|
|
91
|
+
*/
|
|
92
|
+
const ITEM = "group flex w-full cursor-pointer select-none items-start gap-opsin-3 " +
|
|
93
|
+
"rounded-opsin-md border border-transparent px-opsin-3 py-opsin-2 text-left align-top " +
|
|
94
|
+
"min-h-(--opsin-target-minimum,2.75rem) text-opsin-body [color:var(--foreground)] " +
|
|
95
|
+
"transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
|
|
96
|
+
"data-[unchecked]:hover:bg-state-hover " +
|
|
97
|
+
"data-[disabled]:cursor-not-allowed data-[disabled]:[color:var(--muted-foreground)] data-[disabled]:hover:bg-transparent " +
|
|
98
|
+
"focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
|
|
99
|
+
/**
|
|
100
|
+
* The circle, spelled once. A neutral ring on the background so the dot has
|
|
101
|
+
* something to sit against. When the row is checked the circle fills with the
|
|
102
|
+
* accent, `--brand`, inside its `--brand-edge` rim (ADR 0029), the way a ticked
|
|
103
|
+
* checkbox does, so the two selection controls read as one family. The dot
|
|
104
|
+
* inside it keeps the selected circle readable in greyscale. Sized in `em` so it
|
|
105
|
+
* grows with the option's text. It is `aria-hidden` because the selected state is carried by the row's
|
|
106
|
+
* `aria-checked` and the label text, so the circle is decoration for the eye.
|
|
107
|
+
*/
|
|
108
|
+
const CONTROL = "relative mt-[0.15em] flex size-[1.15em] shrink-0 items-center justify-center " +
|
|
109
|
+
"rounded-full border border-border bg-background " +
|
|
110
|
+
"transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
|
|
111
|
+
"group-data-[checked]:border-brand-edge group-data-[checked]:bg-brand";
|
|
112
|
+
/**
|
|
113
|
+
* The dot, spelled once. Base UI's Radio.Indicator renders this span only when
|
|
114
|
+
* the option is checked, so an unchecked circle is genuinely empty rather than
|
|
115
|
+
* holding a hidden dot. It is `--brand-foreground`, the ink measured on the
|
|
116
|
+
* accent fill at the body floor, sized in `em` so it grows with the option.
|
|
117
|
+
*
|
|
118
|
+
* TOGGLE, the second of the five interaction motions (ADR 0031), as a radio
|
|
119
|
+
* draws it. The dot grows out of the centre of the circle on `spring-snap`,
|
|
120
|
+
* the spring tokens/motion.json names for a control the reader just chose,
|
|
121
|
+
* from nothing on the indicator's `data-starting-style` frame. The dot of the
|
|
122
|
+
* option being left shrinks back into its centre at the same moment, on
|
|
123
|
+
* `ease-exit` over `duration-fast`, because Base UI keeps a leaving indicator
|
|
124
|
+
* mounted until its `data-ending-style` transition ends. So the choice is seen
|
|
125
|
+
* to move from one circle to the other, while the circle's fill changes on its
|
|
126
|
+
* own colour transition underneath. A dot shows a choice and never a reading,
|
|
127
|
+
* so the overshoot is allowed. Under `prefers-reduced-motion: reduce` both
|
|
128
|
+
* durations collapse, so the dot is whole, or gone, the frame after the choice.
|
|
129
|
+
*/
|
|
130
|
+
const INDICATOR = "size-[0.45em] rounded-full bg-brand-foreground " +
|
|
131
|
+
"transition-[scale] duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
|
|
132
|
+
"data-[starting-style]:scale-0 data-[ending-style]:scale-0 " +
|
|
133
|
+
"data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit";
|
|
134
|
+
/** The label and description column, kept narrow so a long label wraps rather than pushes the circle. */
|
|
135
|
+
const ITEM_TEXT = "flex min-w-0 flex-col gap-opsin-0-5";
|
|
136
|
+
/** The option's words. */
|
|
137
|
+
const ITEM_LABEL = "text-opsin-body leading-snug";
|
|
138
|
+
/** The optional helper line, in the muted ink and a step quieter than the label. */
|
|
139
|
+
const ITEM_DESCRIPTION = "text-opsin-footnote leading-snug [color:var(--muted-foreground)]";
|
|
140
|
+
/**
|
|
141
|
+
* Development warnings, said once per distinct offender. Nothing here has an
|
|
142
|
+
* `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
|
|
143
|
+
* consumer makes with the clinical API, and a radio group asserts nothing
|
|
144
|
+
* clinical. `segmented-control.tsx` and `divider.tsx` keep the same small set
|
|
145
|
+
* for the same reason.
|
|
146
|
+
*/
|
|
147
|
+
const warned = new Set();
|
|
148
|
+
function warnDev(key, message) {
|
|
149
|
+
if (!isDevelopment() || warned.has(key))
|
|
150
|
+
return;
|
|
151
|
+
warned.add(key);
|
|
152
|
+
console.warn(message);
|
|
153
|
+
}
|
|
154
|
+
export function RadioGroup({ options, value, onValueChange, label, className, }) {
|
|
155
|
+
const labelId = useId();
|
|
156
|
+
if (isDevelopment()) {
|
|
157
|
+
if (!Array.isArray(options) || options.length === 0) {
|
|
158
|
+
warnDev("no-options", "[opsinjs] <RadioGroup> was rendered with no options, so it has nothing to " +
|
|
159
|
+
"draw. A radio group is a choice between two or more options; supply them " +
|
|
160
|
+
"through the `options` prop.");
|
|
161
|
+
}
|
|
162
|
+
else if (options.length === 1) {
|
|
163
|
+
warnDev("one-option", "[opsinjs] <RadioGroup> was given a single option, which is not a choice. " +
|
|
164
|
+
"Either add the other options, or render the one thing as a label rather " +
|
|
165
|
+
"than a control the reader cannot change.");
|
|
166
|
+
}
|
|
167
|
+
if (typeof label !== "string" || label.trim() === "") {
|
|
168
|
+
warnDev("no-label", "[opsinjs] <RadioGroup> was rendered with no `label`. The group is a " +
|
|
169
|
+
"radiogroup and needs an accessible name: without one a screen-reader user " +
|
|
170
|
+
"hears a set of radios with no idea what they choose between. Pass `label` " +
|
|
171
|
+
'with the name of the choice, such as "Reminder style".');
|
|
172
|
+
}
|
|
173
|
+
if (Array.isArray(options) &&
|
|
174
|
+
options.length > 0 &&
|
|
175
|
+
!options.some((option) => option.value === value)) {
|
|
176
|
+
warnDev(`value-not-in-options:${String(value)}`, `[opsinjs] <RadioGroup value="${String(value)}"> does not match any option's ` +
|
|
177
|
+
"value, so the list renders with nothing chosen. This is a controlled " +
|
|
178
|
+
"component: pass a `value` equal to one option's `value`.");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!Array.isArray(options) || options.length === 0) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return (_jsxs(BaseRadioGroup, { "data-slot": "radio-group", "aria-labelledby": labelId, value: value, onValueChange: (next) => onValueChange(String(next)), className: cn(GROUP, className), children: [_jsx("div", { id: labelId, "data-slot": "radio-group-label", className: LABEL, children: label }), options.map((option) => (_jsxs(Radio.Root, { value: option.value, disabled: option.disabled, "data-slot": "radio-group-item", className: ITEM, children: [_jsx("span", { "aria-hidden": "true", "data-slot": "radio-group-control", className: CONTROL, children: _jsx(Radio.Indicator, { "data-slot": "radio-group-indicator", className: INDICATOR }) }), _jsxs("span", { "data-slot": "radio-group-item-text", className: ITEM_TEXT, children: [_jsx("span", { "data-slot": "radio-group-item-label", className: ITEM_LABEL, children: option.label }), option.description ? (_jsx("span", { "data-slot": "radio-group-item-description", className: ITEM_DESCRIPTION, children: option.description })) : null] })] }, option.value)))] }));
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=radio-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group.js","sourceRoot":"","sources":["../../src/components/radio-group.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;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