@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,186 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type SheetProps } from "./sheet.tsx";
|
|
3
|
+
/**
|
|
4
|
+
* What is collected, who sees it, and how long it is kept.
|
|
5
|
+
*
|
|
6
|
+
* Three sentences the product writes, not three values this component labels.
|
|
7
|
+
* There is no `collectedLabel`, no heading above the list and no visually
|
|
8
|
+
* hidden term in front of each row, because every one of those would be an
|
|
9
|
+
* English word opsinjs had chosen for a sheet whose entire content is somebody
|
|
10
|
+
* else's legal statement. Each field is a whole statement in the
|
|
11
|
+
* reader's own language, and the field name says what belongs in it.
|
|
12
|
+
*/
|
|
13
|
+
export interface ConsentScope {
|
|
14
|
+
/**
|
|
15
|
+
* What is collected, in the reader's words, as a complete sentence. Name the
|
|
16
|
+
* data rather than the mechanism: what a reader wants to know is which of
|
|
17
|
+
* their readings this is about, not that it will be "processed".
|
|
18
|
+
*/
|
|
19
|
+
collected: string;
|
|
20
|
+
/**
|
|
21
|
+
* Who can see it, as a complete sentence. Name them. "our partners" is not
|
|
22
|
+
* an answer, and a reader cannot decide about a recipient they cannot name.
|
|
23
|
+
*/
|
|
24
|
+
sharedWith: string;
|
|
25
|
+
/**
|
|
26
|
+
* How long it is kept and what happens at the end, as a complete sentence.
|
|
27
|
+
* Name a period or a condition the reader could check for themselves; a
|
|
28
|
+
* pointer to a retention policy is a pointer to a document nobody will open.
|
|
29
|
+
*/
|
|
30
|
+
retention: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What the product must store. The component produces it; it never stores it.
|
|
34
|
+
*
|
|
35
|
+
* There is no `withdrawn`, no `expired` and no `notAsked` here, and their
|
|
36
|
+
* absence is deliberate rather than an omission: those are states of a consent
|
|
37
|
+
* over its life, held by whatever the product stores this in, and a record
|
|
38
|
+
* handed back at the moment of a decision cannot describe what happened to it
|
|
39
|
+
* afterwards.
|
|
40
|
+
*/
|
|
41
|
+
export interface ConsentDecision {
|
|
42
|
+
/** True when the reader pressed the accept control, false when they pressed decline. */
|
|
43
|
+
granted: boolean;
|
|
44
|
+
/** ISO timestamp, taken at the moment the control was pressed. */
|
|
45
|
+
at: string;
|
|
46
|
+
/** Stable id of the consent being asked for, exactly as it was passed in. */
|
|
47
|
+
consentId: string;
|
|
48
|
+
/**
|
|
49
|
+
* Version of the text that was actually shown. Without it the product cannot
|
|
50
|
+
* later say what the person agreed to, and a consent record that cannot
|
|
51
|
+
* answer that question is not evidence of anything.
|
|
52
|
+
*/
|
|
53
|
+
textVersion: string;
|
|
54
|
+
/**
|
|
55
|
+
* The scope as it was shown, carried through unchanged. It is here because
|
|
56
|
+
* the specification says the record is "a decision, a timestamp, the
|
|
57
|
+
* identifier and version of the text that was shown, and the scope consented
|
|
58
|
+
* to", and the interface it declares had four of those five. A version id
|
|
59
|
+
* resolves to the scope only for a product that kept every version it ever
|
|
60
|
+
* published; this makes the answer part of the record itself.
|
|
61
|
+
*/
|
|
62
|
+
scope: ConsentScope;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The optional full text, and the label of the control that reveals it.
|
|
66
|
+
*
|
|
67
|
+
* BOTH HALVES TOGETHER, which is the shape `DisclaimerNote.more` uses and for
|
|
68
|
+
* the same reason. A panel with no label needs one invented here, and the label
|
|
69
|
+
* a design system would invent is *terms*, *details* or *learn more*. That is
|
|
70
|
+
* the exact class of name the specification refuses, in the one list a screen
|
|
71
|
+
* reader can read with no sentence around it.
|
|
72
|
+
*/
|
|
73
|
+
export interface ConsentDetails {
|
|
74
|
+
/**
|
|
75
|
+
* What the control that reveals the text is called, in the reader's language.
|
|
76
|
+
* Name what is behind it rather than the act of opening it: a control called
|
|
77
|
+
* only *terms* or *details* names nothing, and a screen reader's list of
|
|
78
|
+
* controls is where that costs somebody the thing they were looking for.
|
|
79
|
+
*/
|
|
80
|
+
label: string;
|
|
81
|
+
/** The full text itself. Rendered in place, never behind a link to elsewhere. */
|
|
82
|
+
content: ReactNode;
|
|
83
|
+
}
|
|
84
|
+
export interface ConsentSheetProps extends Omit<SheetProps, "title" | "children" | "footer"> {
|
|
85
|
+
/**
|
|
86
|
+
* Stable id of the consent being asked for. It is not shown to the reader; it
|
|
87
|
+
* is what a product's own record is keyed on, and it is required because a
|
|
88
|
+
* decision with nothing to attach it to is not a record.
|
|
89
|
+
*/
|
|
90
|
+
consentId: string;
|
|
91
|
+
/**
|
|
92
|
+
* The version of the wording on this sheet. Change it whenever any of the
|
|
93
|
+
* text changes, and never reuse one: a consent record with no version cannot
|
|
94
|
+
* answer the only question anybody will ever ask of it, which is what the
|
|
95
|
+
* person actually read.
|
|
96
|
+
*/
|
|
97
|
+
textVersion: string;
|
|
98
|
+
/**
|
|
99
|
+
* What is being asked, phrased as a question the reader can answer yes or no
|
|
100
|
+
* to. It is the sheet's accessible name and its visible heading. The two are
|
|
101
|
+
* the same element, which is why there is no separate `title`.
|
|
102
|
+
*/
|
|
103
|
+
heading: string;
|
|
104
|
+
/**
|
|
105
|
+
* What the data is for, in one or two sentences, in terms of what the reader
|
|
106
|
+
* gets rather than what the product does internally. One decision per sheet:
|
|
107
|
+
* bundling is a design error rather than a prop, so there is no array here
|
|
108
|
+
* and no way to make this the introduction to a list of switches.
|
|
109
|
+
*/
|
|
110
|
+
purpose: string;
|
|
111
|
+
/** What is collected, who can see it and how long it is kept. Rendered as a list. */
|
|
112
|
+
scope: ConsentScope;
|
|
113
|
+
/**
|
|
114
|
+
* Where the reader can change this decision later, as a sentence in their own
|
|
115
|
+
* language. Required, and the sheet will not ask without it: a consent with no
|
|
116
|
+
* exit is not revocable whatever the copy says.
|
|
117
|
+
*
|
|
118
|
+
* It renders as text and is deliberately not turned into a link. A string is
|
|
119
|
+
* not a destination, and the doctrine's answer is that revocation lives where
|
|
120
|
+
* the data lives rather than inside the sheet that asked for it. So what
|
|
121
|
+
* belongs here is the sentence that tells the reader where to go, and the
|
|
122
|
+
* control belongs on the screen showing the data.
|
|
123
|
+
*/
|
|
124
|
+
withdrawalPath: string;
|
|
125
|
+
/**
|
|
126
|
+
* The full wording, disclosed in place behind a named control, for the reader
|
|
127
|
+
* who wants all of it. Omitted, no control is drawn: an empty disclosure is a
|
|
128
|
+
* promise of more that there is no more of.
|
|
129
|
+
*/
|
|
130
|
+
details?: ConsentDetails;
|
|
131
|
+
/**
|
|
132
|
+
* What the reader loses by declining, stated before they choose. Optional,
|
|
133
|
+
* because opsinjs cannot know whether a product still works after a refusal.
|
|
134
|
+
* It is required by the doctrine whenever it does not. If refusing breaks
|
|
135
|
+
* something the reader came for, this is where they are told, and they are
|
|
136
|
+
* told before the controls rather than in a confirmation afterwards.
|
|
137
|
+
*/
|
|
138
|
+
consequenceOfDeclining?: string;
|
|
139
|
+
/**
|
|
140
|
+
* What stands where the two controls would have been when the sheet cannot
|
|
141
|
+
* ask. Optional, and the default is English, which is the one string in this
|
|
142
|
+
* file a reader can see that opsinjs wrote. It is interface copy rather than
|
|
143
|
+
* consent wording: it names the state of the interface, it agrees to nothing
|
|
144
|
+
* and it describes no purpose, no recipient and no retention period. The
|
|
145
|
+
* scenario that produces it is a translation row nobody filled in, which is
|
|
146
|
+
* exactly the reader who will not read the default, so a product that ships
|
|
147
|
+
* more than one language passes its own sentence here. It never becomes a
|
|
148
|
+
* question and it never draws a control.
|
|
149
|
+
*/
|
|
150
|
+
notAskedMessage?: string;
|
|
151
|
+
/**
|
|
152
|
+
* The word on the accept control. Required, with no default anywhere in this
|
|
153
|
+
* file, and there is no fallback if it is blank.
|
|
154
|
+
*
|
|
155
|
+
* Name the outcome rather than the press: a label that begins with the
|
|
156
|
+
* reader's own word for yes and then says what will happen is an answer, and
|
|
157
|
+
* one that only describes pressing the button is not. A generic label raises
|
|
158
|
+
* a development warning and is rendered exactly as written. Only the product
|
|
159
|
+
* knows what it is agreeing to, and a component that rewrote the word would be
|
|
160
|
+
* writing consent copy.
|
|
161
|
+
*/
|
|
162
|
+
acceptLabel: string;
|
|
163
|
+
/**
|
|
164
|
+
* The word on the decline control. Required, and it carries the same weight as
|
|
165
|
+
* `acceptLabel` in every dimension this component controls: there is no
|
|
166
|
+
* `hideDecline`, no `declineVariant`, and no way to make this one quieter.
|
|
167
|
+
*
|
|
168
|
+
* Name the outcome it refuses, in the same shape and at about the same length
|
|
169
|
+
* as the accept label. A word that postpones rather than answers raises a
|
|
170
|
+
* development warning, because in a screen reader's list of controls a
|
|
171
|
+
* postponement and a refusal are not the same choice.
|
|
172
|
+
*/
|
|
173
|
+
declineLabel: string;
|
|
174
|
+
/**
|
|
175
|
+
* Called when the reader presses one of the two controls, and at no other
|
|
176
|
+
* time. Closing the sheet without pressing either calls nothing: it is not a
|
|
177
|
+
* refusal, and it is certainly not consent.
|
|
178
|
+
*
|
|
179
|
+
* The component does not close itself afterwards. `open` is the caller's, as
|
|
180
|
+
* it is on every Sheet, so a product can show what happens next before the
|
|
181
|
+
* surface goes away.
|
|
182
|
+
*/
|
|
183
|
+
onDecision: (decision: ConsentDecision) => void;
|
|
184
|
+
}
|
|
185
|
+
export declare function ConsentSheet({ consentId, textVersion, heading, purpose, scope, withdrawalPath, details, consequenceOfDeclining, notAskedMessage, acceptLabel, declineLabel, onDecision, ...sheet }: ConsentSheetProps): import("react").JSX.Element;
|
|
186
|
+
//# sourceMappingURL=consent-sheet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-sheet.d.ts","sourceRoot":"","sources":["../../src/components/consent-sheet.tsx"],"names":[],"mappings":"AAyEA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAK1E,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AA0KpD;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAA;IAChB,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAA;IACV,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;;;;;;OAOG;IACH,KAAK,EAAE,YAAY,CAAA;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,OAAO,EAAE,SAAS,CAAA;CACnB;AAED,MAAM,WAAW,iBACf,SAAQ,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;IACzD;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,qFAAqF;IACrF,KAAK,EAAE,YAAY,CAAA;IACnB;;;;;;;;;;OAUG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;;;;;OAUG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;;;;;;;;OASG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;;;;;;;OAQG;IACH,UAAU,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAA;CAChD;AAED,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,WAAW,EACX,OAAO,EACP,OAAO,EACP,KAAK,EACL,cAAc,EACd,OAAO,EACP,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,YAAY,EACZ,UAAU,EACV,GAAG,KAAK,EACT,EAAE,iBAAiB,+BAybnB"}
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* ConsentSheet is one permission, asked once, with refusing exactly as easy as
|
|
5
|
+
* agreeing.
|
|
6
|
+
*
|
|
7
|
+
* THERE IS NO CONSENT WORDING IN THIS FILE AND THERE NEVER WILL BE. Not a
|
|
8
|
+
* default heading, not a purpose sentence, not a data category, not a retention
|
|
9
|
+
* period, not a jurisdiction, not a regulator, not a lawful basis, and not the
|
|
10
|
+
* words on the two controls. Every consent string a reader sees here arrives as
|
|
11
|
+
* a prop. One sentence does not, and it is the one that says nothing was asked:
|
|
12
|
+
* it is interface copy with no legal content, it carries its own prop so a
|
|
13
|
+
* product can translate it, and it is the only string this file will ever put on
|
|
14
|
+
* screen. A consent sentence is a legal statement with somebody's name behind it, and a
|
|
15
|
+
* design system has neither a legal owner nor a reader; a sentence shipped from
|
|
16
|
+
* here would arrive in a product whose author never read it, describing a use
|
|
17
|
+
* that product may not have and omitting one it does. It would arrive
|
|
18
|
+
* looking reviewed, because it came from a library. `disclaimer-note.tsx` makes
|
|
19
|
+
* the same refusal about the same class of text and for the same reason.
|
|
20
|
+
*
|
|
21
|
+
* SO THE MISSING CASE REFUSES TO ASK. Every other component in this system
|
|
22
|
+
* renders an absence and carries on. This one withholds the decision controls
|
|
23
|
+
* entirely when any of the wording a consent record needs is missing, and says
|
|
24
|
+
* on screen that nothing was asked. That is a harder failure than the rest of
|
|
25
|
+
* the system's and it is deliberate: the alternative is a stored record saying
|
|
26
|
+
* somebody agreed to something the interface never told them, which is the one
|
|
27
|
+
* outcome that cannot be undone afterwards. It fails towards no consent, and no
|
|
28
|
+
* consent is a state every product using this component has to support anyway,
|
|
29
|
+
* because refusal is a real option.
|
|
30
|
+
*
|
|
31
|
+
* REFUSING IS EXACTLY AS EASY AS AGREEING, BY CONSTRUCTION RATHER THAN BY
|
|
32
|
+
* CONVENTION. The two controls are the same component, the same variant, the
|
|
33
|
+
* same size, the same width and the same height, adjacent in the tab order,
|
|
34
|
+
* separated by `--opsin-target-separation`, and neither is focused on open.
|
|
35
|
+
* There is no `variant` prop on either, no `acceptClassName`, no `emphasis`, no
|
|
36
|
+
* `primaryAction`, and no way to reach one of them from outside. Every one of
|
|
37
|
+
* those, offered anywhere, has been used to shrink the refusal. The one
|
|
38
|
+
* remaining route is a descendant selector smuggled through `className`, and a
|
|
39
|
+
* development-only measurement below reports it rather than pretending the hole
|
|
40
|
+
* is closed.
|
|
41
|
+
*
|
|
42
|
+
* IT ASKS ONE QUESTION. There is no `purposes` array and no per-item switch,
|
|
43
|
+
* because a sheet that can carry three purposes will carry three purposes under
|
|
44
|
+
* one control the first time a deadline is close. Three permissions are three
|
|
45
|
+
* sheets, each shown when it becomes relevant. That is what
|
|
46
|
+
* `health/consent-and-disclosure` rule 1 asks for and what makes a partial yes
|
|
47
|
+
* expressible at all.
|
|
48
|
+
*
|
|
49
|
+
* IT EXTENDS Sheet AND INHERITS `open`/`onOpenChange` UNCHANGED (ADR 0021).
|
|
50
|
+
* The specification says "extends Sheet" and declares neither prop, so as
|
|
51
|
+
* written this component could not be opened. It is not repaired by declaring a
|
|
52
|
+
* second copy here: `ConsentSheetProps` extends `SheetProps` with the three
|
|
53
|
+
* members this component supplies itself removed, and everything else passes
|
|
54
|
+
* through with the meaning Sheet's own page gives it. That is the open pair,
|
|
55
|
+
* `detents`, `modal`, `dismissible` and `className`.
|
|
56
|
+
*
|
|
57
|
+
* CLOSING IS NOT DECIDING, AND IT IS NOT REFUSING EITHER. `onDecision` fires
|
|
58
|
+
* only when a reader presses one of the two controls. A close by the escape
|
|
59
|
+
* key, the scrim, a drag or the header's close control calls nothing at all,
|
|
60
|
+
* and the product learns about it through `onOpenChange`, which is Sheet's and
|
|
61
|
+
* carries the route. The absence of a call is the absence of a decision; there
|
|
62
|
+
* is no third value on `granted` because a boolean that could also mean "did
|
|
63
|
+
* not answer" is a boolean somebody will store as `false`, and a refusal
|
|
64
|
+
* nobody made is a record about a person that is not true.
|
|
65
|
+
*
|
|
66
|
+
* IT IS A CLIENT COMPONENT, and every one of these is independently sufficient:
|
|
67
|
+
* it holds the disclosure state for the full text, it attaches two click
|
|
68
|
+
* handlers, it reads layout in development to check the two controls match, and
|
|
69
|
+
* it renders Sheet, which is `"use client"` because it portals, traps focus and
|
|
70
|
+
* listens for a drag.
|
|
71
|
+
*/
|
|
72
|
+
import { ChevronDown } from "lucide-react";
|
|
73
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
74
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
75
|
+
import { cn, trimTrailing } from "../utils.js";
|
|
76
|
+
import { Button } from "./button.js";
|
|
77
|
+
import { Sheet } from "./sheet.js";
|
|
78
|
+
/**
|
|
79
|
+
* Development warnings, said once per distinct offender.
|
|
80
|
+
*
|
|
81
|
+
* Nothing this file complains about has an `OpsinErrorCode`. The codes in
|
|
82
|
+
* `tokens/errors.json` are a versioned contract describing mistakes a consumer
|
|
83
|
+
* makes with the CLINICAL API, and the errors page is generated from that file,
|
|
84
|
+
* so a component may not mint one. What is borrowed is the policy rather than
|
|
85
|
+
* the registry: `tokens/errors.json` fires a warning once per offending call
|
|
86
|
+
* site, because a complaint repeated on every render teaches nothing and buries
|
|
87
|
+
* the next one. Four other files in this directory carry the same twelve lines
|
|
88
|
+
* for the same reason; the repair belongs in `../opsinjs.ts`, which is not this
|
|
89
|
+
* component's file to edit, and it is reported here rather than fixed quietly.
|
|
90
|
+
*/
|
|
91
|
+
const warned = new Set();
|
|
92
|
+
/**
|
|
93
|
+
* Bounded, because several of the keys below carry a consent id or a label and
|
|
94
|
+
* a development session runs for days. Sixteen distinct complaints means the
|
|
95
|
+
* report has been made several times over; going quiet beats growing without
|
|
96
|
+
* limit.
|
|
97
|
+
*/
|
|
98
|
+
const MAX_WARNED_KEYS = 16;
|
|
99
|
+
function warnDev(key, message) {
|
|
100
|
+
if (!isDevelopment() || warned.has(key) || warned.size >= MAX_WARNED_KEYS)
|
|
101
|
+
return;
|
|
102
|
+
warned.add(key);
|
|
103
|
+
try {
|
|
104
|
+
console.warn(message);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
/* A patched console is not a reason to take a health product down. */
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The focus ring, declared here rather than inherited.
|
|
112
|
+
*
|
|
113
|
+
* `@opsinjs/react/base.css` gives every `:focus-visible` an outline, and that
|
|
114
|
+
* stylesheet is opt-in, so a consumer's app may never load it. The disclosure
|
|
115
|
+
* control below is the only element in this file that is not a `Button`, so it
|
|
116
|
+
* is the only one that would lose its ring silently. It sits on a surface where
|
|
117
|
+
* a keyboard reader most needs to know where they are.
|
|
118
|
+
*/
|
|
119
|
+
const FOCUS_RING = "focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
|
|
120
|
+
/**
|
|
121
|
+
* The class both decision controls carry, identical, so they cannot drift apart.
|
|
122
|
+
*
|
|
123
|
+
* `wrap-anywhere` is the last-resort guard against a clipped answer. A label is
|
|
124
|
+
* one string the product wrote, it may be one long compound word in German or
|
|
125
|
+
* Finnish, and a cell that is 171px wide at a 390 viewport gives it nowhere to
|
|
126
|
+
* break. The same utility for the same reason is in `disclaimer-note.tsx`, and
|
|
127
|
+
* it is argued against `wrap-break-word` in `result-card.tsx`, so this is the
|
|
128
|
+
* house answer rather than a new one: a word with no break opportunity breaks
|
|
129
|
+
* mid-word rather than being clipped, and a clipped answer on a consent sheet
|
|
130
|
+
* is the one word that tells yes from no.
|
|
131
|
+
*
|
|
132
|
+
* `px-opsin-3!` replaces Button's own `px-opsin-5` on this surface only, because
|
|
133
|
+
* the padding is rem-based and doubles at 200% text. Twenty pixels a side
|
|
134
|
+
* becomes forty, which leaves 91px of a 171px cell for text set at 34px, and no
|
|
135
|
+
* word fits that. Twelve pixels a side leaves 123px. The important suffix earns
|
|
136
|
+
* its place. `cn()` is `twMerge(clsx(...))` with `tailwind-merge` unconfigured,
|
|
137
|
+
* so it does not know the `opsin` spacing scale and keeps both `px-opsin-5` from
|
|
138
|
+
* `SIZE.md` and this override in the class list rather than collapsing them to
|
|
139
|
+
* one. Two single-class rules of equal specificity then fall to source order,
|
|
140
|
+
* and the stylesheet emits `px-opsin-5` after `px-opsin-3`, so a plain
|
|
141
|
+
* `px-opsin-3` would never take effect. `px-opsin-3!` compiles to an
|
|
142
|
+
* `!important` declaration that wins by the cascade whatever the emission order.
|
|
143
|
+
* The two controls carry one constant so a later edit cannot tighten one and not
|
|
144
|
+
* the other, which is the thing this whole component is about.
|
|
145
|
+
*/
|
|
146
|
+
const DECISION_BUTTON = "h-full wrap-anywhere px-opsin-3!";
|
|
147
|
+
/**
|
|
148
|
+
* How far apart the two decision controls may measure before this file says so.
|
|
149
|
+
*
|
|
150
|
+
* One CSS pixel of slack, because `getBoundingClientRect` returns fractions and
|
|
151
|
+
* two boxes laid out by the same grid track can differ in the last decimal
|
|
152
|
+
* place on a fractional device pixel ratio. It is a rounding allowance and not
|
|
153
|
+
* a tolerance for a real difference: anything a reader could see is far larger
|
|
154
|
+
* than this.
|
|
155
|
+
*/
|
|
156
|
+
const SAME_SIZE_SLACK = 1;
|
|
157
|
+
/**
|
|
158
|
+
* What stands where the two controls would have been when the sheet cannot ask.
|
|
159
|
+
*
|
|
160
|
+
* This is interface copy and not consent wording, which is why the file's
|
|
161
|
+
* opening refusal does not reach it. It names the state of the interface, it
|
|
162
|
+
* agrees to nothing, and it describes no purpose, no recipient, no retention
|
|
163
|
+
* period and no jurisdiction. It is therefore not the class of sentence the
|
|
164
|
+
* opening paragraph refuses to ship. It is a last-resort default in English,
|
|
165
|
+
* and a product that ships more than one language replaces it wholesale through
|
|
166
|
+
* the `notAskedMessage` prop.
|
|
167
|
+
*/
|
|
168
|
+
const NOT_ASKED_FALLBACK = "This question cannot be answered right now. Nothing has been recorded. " +
|
|
169
|
+
"You can close this.";
|
|
170
|
+
/**
|
|
171
|
+
* Decline labels that name no outcome.
|
|
172
|
+
*
|
|
173
|
+
* The page is explicit: "never label the decline control *not now* when it
|
|
174
|
+
* means *no*, or *maybe later* when there is no later". The reason is that a
|
|
175
|
+
* screen reader can list every control on a surface with no sentence around
|
|
176
|
+
* them. In that list a postponement and a refusal are not the same choice, and
|
|
177
|
+
* only one of them is an answer to the question that was asked. This is a
|
|
178
|
+
* warning and never a refusal: only the product knows whether there genuinely
|
|
179
|
+
* is a later, and a component that blocked the word would be writing consent
|
|
180
|
+
* copy by veto.
|
|
181
|
+
*/
|
|
182
|
+
const POSTPONING_DECLINE_LABELS = [
|
|
183
|
+
"not now",
|
|
184
|
+
"maybe later",
|
|
185
|
+
"later",
|
|
186
|
+
"ask me later",
|
|
187
|
+
"remind me later",
|
|
188
|
+
"skip",
|
|
189
|
+
"skip for now",
|
|
190
|
+
"cancel",
|
|
191
|
+
"close",
|
|
192
|
+
"no thanks",
|
|
193
|
+
];
|
|
194
|
+
/**
|
|
195
|
+
* Accept labels that name no outcome.
|
|
196
|
+
*
|
|
197
|
+
* *Continue* is the one that matters: an accept control that is also the way
|
|
198
|
+
* forward is the *agree that is also continue* the specification names as a way
|
|
199
|
+
* of collecting a decision nobody made. The others are the family it travels
|
|
200
|
+
* in. They are words that describe pressing the button rather than what
|
|
201
|
+
* pressing it does.
|
|
202
|
+
*/
|
|
203
|
+
const UNNAMED_ACCEPT_LABELS = [
|
|
204
|
+
"ok",
|
|
205
|
+
"okay",
|
|
206
|
+
"continue",
|
|
207
|
+
"next",
|
|
208
|
+
"done",
|
|
209
|
+
"got it",
|
|
210
|
+
"accept",
|
|
211
|
+
"agree",
|
|
212
|
+
"i agree",
|
|
213
|
+
"allow",
|
|
214
|
+
"enable",
|
|
215
|
+
"confirm",
|
|
216
|
+
"yes",
|
|
217
|
+
];
|
|
218
|
+
/**
|
|
219
|
+
* Whether a string actually arrived with words in it.
|
|
220
|
+
*
|
|
221
|
+
* `typeof` first because this file ships as source into JavaScript projects,
|
|
222
|
+
* where a required `string` is advice and `.trim()` on whatever turned up is a
|
|
223
|
+
* crash rather than a warning. A whitespace-only string is how consent copy
|
|
224
|
+
* actually goes missing, and it must count as missing rather than as supplied.
|
|
225
|
+
* That happens with a translation table with a row nobody filled in, or a
|
|
226
|
+
* content service returning an empty field for a locale.
|
|
227
|
+
*/
|
|
228
|
+
function isSupplied(value) {
|
|
229
|
+
return typeof value === "string" && value.trim() !== "";
|
|
230
|
+
}
|
|
231
|
+
/** Case- and punctuation-insensitive, for comparing a label against a list. */
|
|
232
|
+
function plainLabel(value) {
|
|
233
|
+
return trimTrailing(value.toLowerCase(), ".…!?:;,").trim();
|
|
234
|
+
}
|
|
235
|
+
export function ConsentSheet({ consentId, textVersion, heading, purpose, scope, withdrawalPath, details, consequenceOfDeclining, notAskedMessage, acceptLabel, declineLabel, onDecision, ...sheet }) {
|
|
236
|
+
const detailsId = useId();
|
|
237
|
+
const detailsTriggerId = useId();
|
|
238
|
+
const decisionsRef = useRef(null);
|
|
239
|
+
const [detailsOpen, setDetailsOpen] = useState(false);
|
|
240
|
+
const [openLastRender, setOpenLastRender] = useState(sheet.open);
|
|
241
|
+
/* THE DISCLOSURE RESETS ON EVERY OPEN, and it is the same argument Sheet
|
|
242
|
+
makes for returning to its first detent. A consent asked twice must be the
|
|
243
|
+
same consent both times: a sheet that reopened with the full wording
|
|
244
|
+
already expanded because the reader opened it last week is a sheet whose
|
|
245
|
+
shape depends on something they cannot see, and one that reopened collapsed
|
|
246
|
+
after they expanded it would lose their place mid-read. Reset is the
|
|
247
|
+
version that is the same for everybody, every time.
|
|
248
|
+
|
|
249
|
+
Adjusted during the render that notices the change rather than in an
|
|
250
|
+
effect, which is React's own answer for state derived from a prop: an
|
|
251
|
+
effect would commit the sheet with the panel still open, paint it, and then
|
|
252
|
+
correct it. */
|
|
253
|
+
if (openLastRender !== sheet.open) {
|
|
254
|
+
setOpenLastRender(sheet.open);
|
|
255
|
+
if (sheet.open)
|
|
256
|
+
setDetailsOpen(false);
|
|
257
|
+
}
|
|
258
|
+
/* EVERYTHING A CONSENT RECORD NEEDS, CHECKED AS WORDS RATHER THAN AS TYPES.
|
|
259
|
+
Each of these is `string` in the interface and every one of them arrives at
|
|
260
|
+
runtime from a content service, a translation table or a `&&` branch, where
|
|
261
|
+
`string` is advice. The list is not a style rule: without the heading there
|
|
262
|
+
is no question, without the purpose it is not informed, without a scope
|
|
263
|
+
fact the reader has not been told who sees it, without the withdrawal path
|
|
264
|
+
it is not revocable, without both labels the pair cannot be equal, and
|
|
265
|
+
without the id and the version the record cannot say what was agreed. Miss
|
|
266
|
+
one and this sheet does not ask. */
|
|
267
|
+
const missing = [];
|
|
268
|
+
if (!isSupplied(consentId))
|
|
269
|
+
missing.push("consentId");
|
|
270
|
+
if (!isSupplied(textVersion))
|
|
271
|
+
missing.push("textVersion");
|
|
272
|
+
if (!isSupplied(heading))
|
|
273
|
+
missing.push("heading");
|
|
274
|
+
if (!isSupplied(purpose))
|
|
275
|
+
missing.push("purpose");
|
|
276
|
+
if (!isSupplied(scope?.collected))
|
|
277
|
+
missing.push("scope.collected");
|
|
278
|
+
if (!isSupplied(scope?.sharedWith))
|
|
279
|
+
missing.push("scope.sharedWith");
|
|
280
|
+
if (!isSupplied(scope?.retention))
|
|
281
|
+
missing.push("scope.retention");
|
|
282
|
+
if (!isSupplied(withdrawalPath))
|
|
283
|
+
missing.push("withdrawalPath");
|
|
284
|
+
if (!isSupplied(acceptLabel))
|
|
285
|
+
missing.push("acceptLabel");
|
|
286
|
+
if (!isSupplied(declineLabel))
|
|
287
|
+
missing.push("declineLabel");
|
|
288
|
+
const askable = missing.length === 0;
|
|
289
|
+
if (!askable) {
|
|
290
|
+
warnDev(`unaskable:${String(consentId)}:${missing.join(",")}`, `[opsinjs] <ConsentSheet> was rendered without ${missing.join(", ")}, so it ` +
|
|
291
|
+
"did not ask and drew no decision controls. opsinjs ships no consent " +
|
|
292
|
+
"wording. It ships no heading, no purpose, no scope, no retention " +
|
|
293
|
+
"period and no words for the two controls, because every one of them " +
|
|
294
|
+
"is a legal statement with an owner, and a design system is not it. " +
|
|
295
|
+
"Every item on " +
|
|
296
|
+
"that list is something a stored consent record has to be able to name; " +
|
|
297
|
+
"a whitespace-only string counts as missing, which is how a locale " +
|
|
298
|
+
"nobody filled in reaches this check.");
|
|
299
|
+
}
|
|
300
|
+
if (isSupplied(declineLabel) && POSTPONING_DECLINE_LABELS.includes(plainLabel(declineLabel))) {
|
|
301
|
+
warnDev(`decline-postpones:${plainLabel(declineLabel)}`, `[opsinjs] <ConsentSheet> has a decline control labelled "${declineLabel}", ` +
|
|
302
|
+
"which postpones rather than answers. A screen reader can list every " +
|
|
303
|
+
"control on a surface with no sentence around them, and in that list a " +
|
|
304
|
+
"postponement is not a refusal. Name the outcome. Say something like " +
|
|
305
|
+
"\"no, do not share them\", unless there genuinely is a later, in which " +
|
|
306
|
+
"case this word is the right one and this warning is noise. It was " +
|
|
307
|
+
"rendered as written.");
|
|
308
|
+
}
|
|
309
|
+
if (isSupplied(acceptLabel) && UNNAMED_ACCEPT_LABELS.includes(plainLabel(acceptLabel))) {
|
|
310
|
+
warnDev(`accept-unnamed:${plainLabel(acceptLabel)}`, `[opsinjs] <ConsentSheet> has an accept control labelled "${acceptLabel}", ` +
|
|
311
|
+
"which names the press rather than what it agrees to. \"continue\" " +
|
|
312
|
+
"in particular makes agreement the way forward, which is the shape this " +
|
|
313
|
+
"component exists to refuse. Name the outcome, in the reader's own " +
|
|
314
|
+
"language. It was rendered as written.");
|
|
315
|
+
}
|
|
316
|
+
if (isSupplied(acceptLabel) &&
|
|
317
|
+
isSupplied(declineLabel) &&
|
|
318
|
+
plainLabel(acceptLabel) === plainLabel(declineLabel)) {
|
|
319
|
+
warnDev(`labels-identical:${plainLabel(acceptLabel)}`, "[opsinjs] <ConsentSheet> was given the same word for accept and decline. " +
|
|
320
|
+
"The two controls are identical in every dimension this component " +
|
|
321
|
+
"controls, so the words are the only thing telling them apart, and two " +
|
|
322
|
+
"of the same word is a coin toss with a record attached.");
|
|
323
|
+
}
|
|
324
|
+
/* THE EQUAL-WEIGHT PROMISE, MEASURED RATHER THAN ASSERTED.
|
|
325
|
+
The pair is equal by construction: one grid, two tracks, one component, one
|
|
326
|
+
variant, one size. The single route left open is a descendant selector
|
|
327
|
+
passed through `className`.
|
|
328
|
+
`[&_[data-slot=consent-sheet-decline]_button]:…` reaches the refusal and
|
|
329
|
+
nothing in the type system can see it. Rather than
|
|
330
|
+
claim a hole is closed, this reads the two boxes back after layout and says
|
|
331
|
+
so when they differ.
|
|
332
|
+
|
|
333
|
+
Development only, once per open, and after paint: `useEffect` runs when the
|
|
334
|
+
browser has laid the sheet out, which is the only moment either box has a
|
|
335
|
+
size. It reads the controls out of the row by `data-slot` rather than
|
|
336
|
+
holding a ref to each, because `Button` pins its own `data-slot` after the
|
|
337
|
+
spread and cannot carry one of ours. The slot lives on the cell around it,
|
|
338
|
+
which is what the anatomy on the page says. */
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
if (!isDevelopment() || !sheet.open || !askable)
|
|
341
|
+
return;
|
|
342
|
+
const row = decisionsRef.current;
|
|
343
|
+
if (!row)
|
|
344
|
+
return;
|
|
345
|
+
const controls = row.querySelectorAll('[data-slot="button"]');
|
|
346
|
+
if (controls.length !== 2)
|
|
347
|
+
return;
|
|
348
|
+
const first = controls[0]?.getBoundingClientRect();
|
|
349
|
+
const second = controls[1]?.getBoundingClientRect();
|
|
350
|
+
if (!first || !second)
|
|
351
|
+
return;
|
|
352
|
+
const widthGap = Math.abs(first.width - second.width);
|
|
353
|
+
const heightGap = Math.abs(first.height - second.height);
|
|
354
|
+
if (widthGap <= SAME_SIZE_SLACK && heightGap <= SAME_SIZE_SLACK)
|
|
355
|
+
return;
|
|
356
|
+
warnDev(`unequal:${String(consentId)}`, "[opsinjs] <ConsentSheet> measured its two decision controls at different " +
|
|
357
|
+
`sizes: ${Math.round(widthGap)}px apart in width and ` +
|
|
358
|
+
`${Math.round(heightGap)}px in height. This component renders them as one ` +
|
|
359
|
+
"component in one grid with one variant, so a difference means something " +
|
|
360
|
+
"reached them from outside. That is almost always a descendant selector in " +
|
|
361
|
+
"`className`. The visual hierarchy of the two controls is the real " +
|
|
362
|
+
"question being asked, and it is not a neutral one.");
|
|
363
|
+
}, [sheet.open, askable, consentId, acceptLabel, declineLabel]);
|
|
364
|
+
function decide(granted) {
|
|
365
|
+
/* Read at the moment the control is pressed, inside an event handler, so
|
|
366
|
+
there is no clock in the render path and nothing for the server and the
|
|
367
|
+
client to disagree about. */
|
|
368
|
+
onDecision({
|
|
369
|
+
granted,
|
|
370
|
+
at: new Date().toISOString(),
|
|
371
|
+
consentId,
|
|
372
|
+
textVersion,
|
|
373
|
+
scope,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
return (_jsx(Sheet, { ...sheet,
|
|
377
|
+
/* THE HEADING IS THE SHEET'S TITLE, WHICH IS WHY THERE IS NO `title`.
|
|
378
|
+
The specification renames Sheet's `title` to `heading` and keeps both
|
|
379
|
+
in the same tree, which as a TypeScript `extends` would produce a modal
|
|
380
|
+
surface with two names. One would be announced and one read. Sheet's
|
|
381
|
+
title is an `<h2>` that Base UI points the popup's `aria-labelledby`
|
|
382
|
+
at, so handing it the heading makes the visible question and the
|
|
383
|
+
accessible name the same string, once. That is also what satisfies
|
|
384
|
+
"focus moved to the heading on open" without any focus handling here:
|
|
385
|
+
Sheet moves focus to the popup, the popup is named by this element,
|
|
386
|
+
and the heading is what a screen reader reads on arrival. */
|
|
387
|
+
title: heading,
|
|
388
|
+
/* THE DECISION CONTROLS ARE PINNED, AND THAT IS A TRADE, NOT A FREE WIN.
|
|
389
|
+
A decision control that scrolls out of reach on a long sheet is its own
|
|
390
|
+
failure, so the two answers live in Sheet's pinned footer and stay
|
|
391
|
+
reachable whatever the body's height. The cost is that on a short
|
|
392
|
+
viewport the answers are on screen before the last two sentences, the
|
|
393
|
+
withdrawal path and the consequence of declining, have necessarily been
|
|
394
|
+
read. Two things hold the line against a reader deciding blind. The DOM
|
|
395
|
+
order puts the consequence last in the scrolling column, at the
|
|
396
|
+
consequence block below, so a screen reader reaches it before these
|
|
397
|
+
controls. And Sheet draws a scroll edge above this footer while any text
|
|
398
|
+
remains below the fold, so the surface does not read as finished. */
|
|
399
|
+
footer: askable ? (_jsxs("div", { ref: decisionsRef, "data-slot": "consent-sheet-decisions",
|
|
400
|
+
/* A TWO-TRACK GRID, AND IT NEVER COLLAPSES TO ONE.
|
|
401
|
+
Grid tracks are equal by default and grid rows stretch, so the
|
|
402
|
+
two cells are the same width and the same height whatever length
|
|
403
|
+
the two labels are. That is the whole contract, held by the
|
|
404
|
+
layout rather than by a rule somebody has to remember. A wrapping
|
|
405
|
+
flex row would have given them different heights on the line they
|
|
406
|
+
wrapped, and stacking them would have made one of them the one
|
|
407
|
+
under the thumb. The pair still never stacks. At 200% text the
|
|
408
|
+
labels wrap and both controls grow taller together, and the
|
|
409
|
+
horizontal padding is reduced from Button's default on both cells
|
|
410
|
+
identically through `DECISION_BUTTON`, so the text keeps a usable
|
|
411
|
+
width once the padding doubles. A word with no break opportunity
|
|
412
|
+
breaks mid-word rather than being clipped, because a clipped
|
|
413
|
+
answer on a consent sheet is the one word that tells yes from no.
|
|
414
|
+
|
|
415
|
+
The gap is the target-separation token rather than a space step.
|
|
416
|
+
They are the same 0.5rem today; the token is the one that means
|
|
417
|
+
"two adjacent 44pt targets", so it is the one that will follow if
|
|
418
|
+
the separation rule ever changes. The literal fallback is in the
|
|
419
|
+
class because the variable is declared in
|
|
420
|
+
`@opsinjs/tokens/tokens.css`, which reaches a page only when the
|
|
421
|
+
app imports it: without it a bare read resolves to nothing, `gap`
|
|
422
|
+
falls back to 0, and decline and accept end up touching on the
|
|
423
|
+
surface where a mis-tap costs the most. */
|
|
424
|
+
className: "grid w-full grid-cols-2 gap-(--opsin-target-separation,0.5rem)", children: [_jsx("div", { "data-slot": "consent-sheet-decline", className: "min-w-0", children: _jsx(Button, { variant: "secondary", size: "md", fullWidth: true, className: DECISION_BUTTON, onClick: () => decide(false), children: declineLabel }) }), _jsx("div", { "data-slot": "consent-sheet-accept", className: "min-w-0", children: _jsx(Button, { variant: "secondary", size: "md", fullWidth: true, className: DECISION_BUTTON, onClick: () => decide(true), children: acceptLabel }) })] })) : (
|
|
425
|
+
/* Unlovely on purpose, and in the place the controls would have been.
|
|
426
|
+
It is addressed to the reader and not the author: it tells them that
|
|
427
|
+
nothing was asked and nothing recorded, rather than asking a question
|
|
428
|
+
with pieces of it missing. It is replaceable because the case that
|
|
429
|
+
produces it is a missing locale, so a product with more than one
|
|
430
|
+
language passes its own sentence through `notAskedMessage`. */
|
|
431
|
+
_jsx("p", { "data-slot": "consent-sheet-decisions-missing", className: "m-0 text-opsin-body", children: isSupplied(notAskedMessage) ? notAskedMessage : NOT_ASKED_FALLBACK })), children: _jsx(Sheet.Content, { children: _jsxs("div", { "data-slot": "consent-sheet",
|
|
432
|
+
/* ONE TYPE STEP FOR EVERYTHING BELOW THE HEADING, AND NO MUTED INK
|
|
433
|
+
ANYWHERE IN THIS COLUMN. Nothing on a consent sheet is small print:
|
|
434
|
+
the retention period set one step down in pale grey satisfies the
|
|
435
|
+
letter of a requirement and none of its purpose, and it is the most
|
|
436
|
+
common way this surface is got wrong. Sheet's header Close control
|
|
437
|
+
above this column is quieter than everything here and stays that
|
|
438
|
+
way, because a consent surface that offers three loud controls has
|
|
439
|
+
three answers. The colour is inherited
|
|
440
|
+
rather than set, which also sidesteps the tailwind-merge collision
|
|
441
|
+
`disclaimer-note.tsx` documents. `text-opsin-body` and
|
|
442
|
+
`text-foreground` land in one conflict group and one of them is
|
|
443
|
+
silently dropped. */
|
|
444
|
+
className: "flex flex-col gap-opsin-4 py-opsin-2 text-opsin-body", children: [isSupplied(purpose) ? (_jsx(Sheet.Description, { className: "m-0", children: purpose })) : null, askable ? (_jsxs("ul", { "data-slot": "consent-sheet-scope", className: "m-0 list-disc pl-opsin-5 [&>li+li]:mt-opsin-2", children: [_jsx("li", { "data-slot": "consent-sheet-scope-collected", children: scope?.collected }), _jsx("li", { "data-slot": "consent-sheet-scope-shared-with", children: scope?.sharedWith }), _jsx("li", { "data-slot": "consent-sheet-scope-retention", children: scope?.retention })] })) : null, details && isSupplied(details.label) ? (_jsxs("div", { "data-slot": "consent-sheet-details", className: "flex flex-col", children: [_jsxs("button", { type: "button", id: detailsTriggerId, "data-slot": "consent-sheet-details-trigger", "aria-expanded": detailsOpen, "aria-controls": detailsId, onClick: () => setDetailsOpen((current) => !current), className: cn("flex min-h-(--opsin-target-minimum,2.75rem) w-full items-center gap-opsin-2", "rounded-opsin-sm text-left underline underline-offset-2", FOCUS_RING), children: [_jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-[1em] shrink-0",
|
|
445
|
+
/* `--opsin-duration-fast` collapses to 1ms inside the
|
|
446
|
+
product stylesheet's own reduced-motion block, so this
|
|
447
|
+
needs no branch of its own: the glyph turns instantly for
|
|
448
|
+
a reader who asked for that, and the state it carries is
|
|
449
|
+
already on `aria-expanded` for everyone. */
|
|
450
|
+
"transition-transform duration-(--opsin-duration-fast) ease-opsin-standard", detailsOpen ? "rotate-180" : null) }), _jsx("span", { className: "min-w-0", children: details.label })] }), _jsx("div", { id: detailsId, role: "group", "aria-labelledby": detailsTriggerId, "data-slot": "consent-sheet-details-panel", className: cn("flex flex-col gap-opsin-2 pt-opsin-2", detailsOpen ? null : "not-print:hidden"), children: details.content })] })) : null, isSupplied(withdrawalPath) ? (_jsx("p", { "data-slot": "consent-sheet-withdrawal", className: "m-0", children: withdrawalPath })) : null, isSupplied(consequenceOfDeclining) ? (_jsx("p", { "data-slot": "consent-sheet-consequence", className: "m-0", children: consequenceOfDeclining })) : null] }) }) }));
|
|
451
|
+
}
|
|
452
|
+
//# sourceMappingURL=consent-sheet.js.map
|