@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,72 @@
|
|
|
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 a file at three public exports, so a
|
|
5
|
+
* consumer names this shape as `SelectProps["options"][number]` rather than
|
|
6
|
+
* importing a fourth symbol.
|
|
7
|
+
*/
|
|
8
|
+
interface SelectOption {
|
|
9
|
+
/** The value this option sets. Unique within the list, and what `value` matches. */
|
|
10
|
+
value: string;
|
|
11
|
+
/** The visible words, and what a screen reader reads for the option and in the trigger. */
|
|
12
|
+
label: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether this option cannot be chosen. A disabled option drops to the muted
|
|
15
|
+
* ink and is skipped by the Arrow keys rather than removed, so a reader can
|
|
16
|
+
* still see it is an option that is not available to them right now.
|
|
17
|
+
*/
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SelectProps {
|
|
21
|
+
/**
|
|
22
|
+
* The options, in the order they appear in the list. Each option is a value, a
|
|
23
|
+
* visible label and an optional `disabled` flag. A select with no options has
|
|
24
|
+
* nothing to open, and a select with a single option is not a choice, so both
|
|
25
|
+
* raise a development warning.
|
|
26
|
+
*/
|
|
27
|
+
options: SelectOption[];
|
|
28
|
+
/**
|
|
29
|
+
* The currently chosen value, matching one option's `value`. This is a
|
|
30
|
+
* controlled component with no internal selection state, so the caller stores
|
|
31
|
+
* the value and passes it back. Left empty or set to a value that matches no
|
|
32
|
+
* option, the trigger shows the placeholder, and a non-empty value that matches
|
|
33
|
+
* nothing raises a development warning.
|
|
34
|
+
*/
|
|
35
|
+
value?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Called with the new value when the reader chooses a different option. The
|
|
38
|
+
* caller stores it and passes it back as `value`; the control keeps no state of
|
|
39
|
+
* its own.
|
|
40
|
+
*/
|
|
41
|
+
onValueChange: (value: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Required. The accessible name for the trigger, applied as its `aria-label`, so
|
|
44
|
+
* a screen-reader user hears what the control chooses before its value. Name the
|
|
45
|
+
* thing the select sets, "Timezone" rather than the current value. There is no
|
|
46
|
+
* default, because a guessed name would describe the wrong thing on most screens.
|
|
47
|
+
*/
|
|
48
|
+
label: string;
|
|
49
|
+
/**
|
|
50
|
+
* The text shown in the trigger when nothing is chosen. It is a prompt, not an
|
|
51
|
+
* option, so it never appears in the list and cannot be chosen. Keep it a short
|
|
52
|
+
* instruction such as "Choose a timezone". Omitted, the trigger is blank until a
|
|
53
|
+
* value is set.
|
|
54
|
+
*/
|
|
55
|
+
placeholder?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the whole control is unavailable. A disabled select drops to the muted
|
|
58
|
+
* ink, does not open, and is skipped by the Tab key. Defaults to `false`.
|
|
59
|
+
*/
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Merged onto the trigger. Width, margin and place in a layout belong here. A
|
|
63
|
+
* class you pass wins over the trigger's own where the two conflict, because it
|
|
64
|
+
* is merged last. It is the one route by which colour can reach the control, and
|
|
65
|
+
* the two-colour-axes rule applies to it in full: a select takes neither a status
|
|
66
|
+
* nor a category tint.
|
|
67
|
+
*/
|
|
68
|
+
className?: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function Select({ options, value, onValueChange, label, placeholder, disabled, className, }: SelectProps): import("react").JSX.Element | null;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/components/select.tsx"],"names":[],"mappings":"AAyDA;;;;;;GAMG;AACH,UAAU,YAAY;IACpB,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAA;IACb,2FAA2F;IAC3F,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAmID,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,MAAM,CAAC,EACrB,OAAO,EACP,KAAK,EACL,aAAa,EACb,KAAK,EACL,WAAW,EACX,QAAgB,EAChB,SAAS,GACV,EAAE,WAAW,sCAgGb"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Select is a trigger that opens a list to choose one option from. Its home is a
|
|
5
|
+
* single choice out of a list too long to lay out flat, a timezone or a unit
|
|
6
|
+
* system being the case it was built for, where the options are worth having but
|
|
7
|
+
* not worth the vertical space of showing them all at once.
|
|
8
|
+
*
|
|
9
|
+
* WHY A SELECT RATHER THAN A ROW OF OPTIONS. The system already ships two
|
|
10
|
+
* controls that show every option at once, SegmentedControl and a radio group,
|
|
11
|
+
* and both are the better answer while the options are few. A select earns its
|
|
12
|
+
* place only once the list grows past what a row can hold: it trades the glance
|
|
13
|
+
* of a flat set for the compactness of a closed trigger, so the cost is a reader
|
|
14
|
+
* has to open it to see the options, and the gain is a long list does not push
|
|
15
|
+
* the rest of the form down the page. Under roughly seven options the flat form
|
|
16
|
+
* is easier to scan and this control is the wrong reach.
|
|
17
|
+
*
|
|
18
|
+
* IT IS BUILT ON BASE UI's Select, AND THAT IS WHERE THE KEYBOARD COMES FROM.
|
|
19
|
+
* The trigger is the one tab stop; Enter, Space or Arrow Down opens the list;
|
|
20
|
+
* the Arrow keys move a highlight through the options with the popup holding
|
|
21
|
+
* focus; Enter chooses the highlighted option and closes; Escape closes without
|
|
22
|
+
* choosing. That is the WAI-ARIA listbox pattern rather than a bespoke one
|
|
23
|
+
* nobody has tested, and the primitive renders `role="combobox"` on the trigger,
|
|
24
|
+
* `role="listbox"` on the popup and `role="option"` with `aria-selected` on each
|
|
25
|
+
* item, so a screen reader reads the control in the register a reader expects.
|
|
26
|
+
*
|
|
27
|
+
* THE LIST FLOATS IN A PORTAL, ON PURPOSE. The options are rendered through
|
|
28
|
+
* `Select.Portal` into a `Select.Positioner`, so the popup escapes the overflow
|
|
29
|
+
* clipping and stacking context of whatever card or scroll area the trigger sits
|
|
30
|
+
* in. The positioner publishes the trigger's width as `--anchor-width` and the
|
|
31
|
+
* room below as `--available-height`, so the popup matches the trigger and scrolls
|
|
32
|
+
* inside the viewport rather than growing past it.
|
|
33
|
+
*
|
|
34
|
+
* NEITHER COLOUR AXIS. A select sets a value; it states no clinical level and
|
|
35
|
+
* names no category, so it carries neither `data-status` nor `data-category` and
|
|
36
|
+
* draws only neutral chrome. The chosen option is marked in the list by a tick
|
|
37
|
+
* from `Select.ItemIndicator`, a lucide Check, rather than by a hue, so the
|
|
38
|
+
* selection survives greyscale and reads without colour, and the semantic carrier
|
|
39
|
+
* underneath it is `aria-selected` rather than any pixel at all. When the choice
|
|
40
|
+
* is a clinical value with a range and a verdict, the control is a reading input,
|
|
41
|
+
* not a bare select, because a select formats nothing and asserts nothing.
|
|
42
|
+
*
|
|
43
|
+
* THE TRIGGER FLOORS ITS TARGET AND CARRIES ITS OWN RING. The trigger floors its
|
|
44
|
+
* hit area at `--opsin-target-minimum` in rem so a 44pt pressable region survives
|
|
45
|
+
* and grows with the reader's text size, and it carries the focus ring in its own
|
|
46
|
+
* class list so a project installed without the product stylesheet does not lose
|
|
47
|
+
* it. The placeholder ink is the measured `--muted-foreground` chrome role read
|
|
48
|
+
* from the value part's `data-placeholder` state rather than an opacity wash, so
|
|
49
|
+
* an empty trigger stays legible while reading as unfilled.
|
|
50
|
+
*/
|
|
51
|
+
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
|
52
|
+
import { Check, ChevronsUpDown } from "lucide-react";
|
|
53
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
54
|
+
import { cn } from "../utils.js";
|
|
55
|
+
/**
|
|
56
|
+
* The trigger, spelled once. A button that looks like a field: a hairline box on
|
|
57
|
+
* the background surface with the value on the left and the open indicator on the
|
|
58
|
+
* right. The ink is written as the arbitrary property `[color:var(--foreground)]`
|
|
59
|
+
* and not `text-foreground`, for the reason `segmented-control.tsx` sets out at
|
|
60
|
+
* length: tailwind-merge files a `text-*` colour in the same conflict group as the
|
|
61
|
+
* `text-opsin-*` type step and drops one of them, so the arbitrary property lands
|
|
62
|
+
* in the `color` group instead and both the ink and the size survive. The disabled
|
|
63
|
+
* ink is the measured `--muted-foreground` chrome role rather than an opacity wash,
|
|
64
|
+
* because an opacity on the trigger would composite the label and the box together
|
|
65
|
+
* and drift both towards the ground. The target floor is `--opsin-target-minimum`
|
|
66
|
+
* in rem with a literal fallback, so the declaration stays valid where the token
|
|
67
|
+
* sheet was not installed and grows with the reader's text size.
|
|
68
|
+
*/
|
|
69
|
+
const TRIGGER = "inline-flex w-full items-center justify-between gap-opsin-2 " +
|
|
70
|
+
"rounded-opsin-md border border-border bg-background " +
|
|
71
|
+
"px-opsin-3 py-opsin-2 min-h-(--opsin-target-minimum,2.75rem) " +
|
|
72
|
+
"text-opsin-body [color:var(--foreground)] text-left align-middle cursor-pointer " +
|
|
73
|
+
"transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
|
|
74
|
+
"hover:bg-state-hover " +
|
|
75
|
+
"data-[disabled]:cursor-not-allowed data-[disabled]:[color:var(--muted-foreground)] data-[disabled]:hover:bg-background " +
|
|
76
|
+
"focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
|
|
77
|
+
/**
|
|
78
|
+
* The selected value text, or the placeholder when nothing is chosen. The
|
|
79
|
+
* placeholder ink is the muted chrome role, switched on by the value part's own
|
|
80
|
+
* `data-placeholder` state, so an unfilled trigger reads as unfilled without a
|
|
81
|
+
* colour on either axis. It truncates rather than wrapping, so a long label keeps
|
|
82
|
+
* the trigger one line high.
|
|
83
|
+
*/
|
|
84
|
+
const VALUE = "truncate [color:var(--foreground)] data-[placeholder]:[color:var(--muted-foreground)]";
|
|
85
|
+
/**
|
|
86
|
+
* The open indicator, a lucide ChevronsUpDown at the trigger's trailing edge. It
|
|
87
|
+
* is the muted chrome role and `aria-hidden`, because it is decoration on a
|
|
88
|
+
* control whose role and state assistive technology already reads.
|
|
89
|
+
*/
|
|
90
|
+
const ICON = "flex shrink-0 items-center [color:var(--muted-foreground)]";
|
|
91
|
+
/**
|
|
92
|
+
* UNFOLD, the fourth of the five interaction motions (ADR 0031), shared by every
|
|
93
|
+
* popup in the system so a list opens the way a menu, a select, a combobox, a
|
|
94
|
+
* popover and a tooltip all do.
|
|
95
|
+
*
|
|
96
|
+
* The list grows out of the trigger that opened it rather than appearing out
|
|
97
|
+
* of nowhere. `origin-(--transform-origin)` reads the point Base UI's
|
|
98
|
+
* positioner computes on the trigger's side of the popup, so it scales up from
|
|
99
|
+
* there and collapses back into it. It arrives from 0.96 and slightly soft, a
|
|
100
|
+
* 4px blur that clears as it settles, so it comes into focus the way an object
|
|
101
|
+
* does when it is brought close, on `spring-settle`, the spring
|
|
102
|
+
* tokens/motion.json names for popovers, tooltips and menus. It leaves faster
|
|
103
|
+
* than it came, to 0.98 and transparent on `ease-exit` over `duration-fast`,
|
|
104
|
+
* because a reader does not need to watch a dismissal finish. When Escape, or
|
|
105
|
+
* a second press on the control that opened it, closes it, Base UI marks the
|
|
106
|
+
* popup `data-instant="dismiss"`, and that cancels the transition, so a reader
|
|
107
|
+
* who asked for it gone has it gone at once. Base UI also marks a popup opened from the keyboard
|
|
108
|
+
* `data-instant="click"`, and that one is ignored on purpose: a reader who
|
|
109
|
+
* opens it with Enter sees the same unfold as a reader with a pointer.
|
|
110
|
+
*
|
|
111
|
+
* Under `prefers-reduced-motion: reduce` the scale and the blur are pinned to
|
|
112
|
+
* rest, and `spring-settle` collapses in the generated sheet to a 100ms linear
|
|
113
|
+
* fade, so the list still visibly appears and does not travel. The exit's
|
|
114
|
+
* `duration-fast` collapses to 1ms. The list holds the options of a choice and never a reading, so nothing here animates a value.
|
|
115
|
+
*/
|
|
116
|
+
const UNFOLD = "origin-(--transform-origin) " +
|
|
117
|
+
"transition-[opacity,scale,filter] duration-(--opsin-duration-spring-settle) ease-opsin-spring-settle " +
|
|
118
|
+
"data-[starting-style]:opacity-0 data-[starting-style]:scale-96 data-[starting-style]:blur-xs " +
|
|
119
|
+
"data-[ending-style]:opacity-0 data-[ending-style]:scale-98 " +
|
|
120
|
+
"data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit " +
|
|
121
|
+
"data-[instant=dismiss]:transition-none " +
|
|
122
|
+
"motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[starting-style]:blur-none " +
|
|
123
|
+
"motion-reduce:data-[ending-style]:scale-100";
|
|
124
|
+
/**
|
|
125
|
+
* The popup surface, spelled once. A raised card with a hairline: `bg-card`
|
|
126
|
+
* lifts it off whatever it floats over, `border-border` draws its edge for
|
|
127
|
+
* greyscale, and the `overlay` material rung casts the one black-alpha shadow the
|
|
128
|
+
* material ladder publishes for a floating surface, so the list reads as a raised
|
|
129
|
+
* object rather than a flat block. It matches the trigger's width through the
|
|
130
|
+
* positioner's `--anchor-width` and caps its height at `--available-height` with
|
|
131
|
+
* an internal scroll, so a long list stays inside the viewport rather than
|
|
132
|
+
* growing past it. Consuming the material token rather than a raw shadow literal
|
|
133
|
+
* keeps this file inside the colour contract.
|
|
134
|
+
* Its entrance and exit are `UNFOLD`, set out above.
|
|
135
|
+
*
|
|
136
|
+
* The `z-50` layer sits on the positioner, not here, because the positioner is
|
|
137
|
+
* the element Base UI places on the page. On the popup it was a child's
|
|
138
|
+
* z-index under an unlayered parent, so a Sheet's own `z-50` layers painted
|
|
139
|
+
* over the list and took the press meant for an option (issue #17).
|
|
140
|
+
*/
|
|
141
|
+
const POPUP = "max-h-[var(--available-height)] min-w-[var(--anchor-width)] overflow-y-auto " +
|
|
142
|
+
"rounded-opsin-md border border-edge bg-card p-opsin-1 " +
|
|
143
|
+
"shadow-(--opsin-material-raised-shadow) [color:var(--foreground)] " +
|
|
144
|
+
UNFOLD;
|
|
145
|
+
/**
|
|
146
|
+
* One option row, spelled once. A full-width row with the label on the left and
|
|
147
|
+
* room for the tick on the right. The highlight is the neutral `state-hover`
|
|
148
|
+
* surface switched on by `data-highlighted`, which is the active option under the
|
|
149
|
+
* Arrow keys and under the pointer, so the roving highlight is visible without a
|
|
150
|
+
* colour on either axis. A disabled option drops to the muted ink and is skipped
|
|
151
|
+
* by the keys. Each row floors its target at `--opsin-target-minimum` so a touch
|
|
152
|
+
* reader gets a 44pt row.
|
|
153
|
+
*/
|
|
154
|
+
const ITEM = "relative flex w-full cursor-pointer select-none items-center gap-opsin-2 " +
|
|
155
|
+
"rounded-opsin-sm px-opsin-3 py-opsin-2 min-h-(--opsin-target-minimum,2.75rem) " +
|
|
156
|
+
"text-opsin-body [color:var(--foreground)] outline-none " +
|
|
157
|
+
"data-[highlighted]:bg-state-hover " +
|
|
158
|
+
"data-[disabled]:cursor-not-allowed data-[disabled]:[color:var(--muted-foreground)] data-[disabled]:bg-transparent";
|
|
159
|
+
/**
|
|
160
|
+
* Development warnings, said once per distinct offender. Nothing here has an
|
|
161
|
+
* `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a consumer
|
|
162
|
+
* makes with the clinical API, and a select asserts nothing clinical.
|
|
163
|
+
* `segmented-control.tsx` keeps the same small set for the same reason.
|
|
164
|
+
*/
|
|
165
|
+
const warned = new Set();
|
|
166
|
+
function warnDev(key, message) {
|
|
167
|
+
if (!isDevelopment() || warned.has(key))
|
|
168
|
+
return;
|
|
169
|
+
warned.add(key);
|
|
170
|
+
console.warn(message);
|
|
171
|
+
}
|
|
172
|
+
export function Select({ options, value, onValueChange, label, placeholder, disabled = false, className, }) {
|
|
173
|
+
if (isDevelopment()) {
|
|
174
|
+
if (!Array.isArray(options) || options.length === 0) {
|
|
175
|
+
warnDev("no-options", "[opsinjs] <Select> was rendered with no options, so it has nothing to " +
|
|
176
|
+
"open. A select is a choice between options; supply them through the " +
|
|
177
|
+
"`options` prop.");
|
|
178
|
+
}
|
|
179
|
+
else if (options.length === 1) {
|
|
180
|
+
warnDev("one-option", "[opsinjs] <Select> was given a single option, which is not a choice. " +
|
|
181
|
+
"Either add the other options, or render the one thing as a label rather " +
|
|
182
|
+
"than a control the reader cannot change.");
|
|
183
|
+
}
|
|
184
|
+
if (typeof label !== "string" || label.trim() === "") {
|
|
185
|
+
warnDev("no-label", "[opsinjs] <Select> was rendered with no `label`. The trigger is a combobox " +
|
|
186
|
+
"and needs an accessible name: without one a screen-reader user hears a " +
|
|
187
|
+
"control with no idea what it chooses. Pass `label` with the name of the " +
|
|
188
|
+
'thing the select sets, such as "Timezone".');
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(options) &&
|
|
191
|
+
options.length > 0 &&
|
|
192
|
+
typeof value === "string" &&
|
|
193
|
+
value !== "" &&
|
|
194
|
+
!options.some((option) => option.value === value)) {
|
|
195
|
+
warnDev(`value-not-in-options:${value}`, `[opsinjs] <Select value="${value}"> does not match any option's value, so ` +
|
|
196
|
+
"the trigger shows the placeholder. This is a controlled component: pass a " +
|
|
197
|
+
"`value` equal to one option's `value`.");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (!Array.isArray(options) || options.length === 0) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
return (_jsxs(SelectPrimitive.Root, { items: options, value: value ? value : null, onValueChange: (next) => onValueChange(String(next)), disabled: disabled, children: [_jsxs(SelectPrimitive.Trigger, { "data-slot": "select", "aria-label": label, className: cn(TRIGGER, className), children: [_jsx(SelectPrimitive.Value, { "data-slot": "select-value", className: VALUE, placeholder: placeholder }), _jsx(SelectPrimitive.Icon, { "data-slot": "select-icon", className: ICON, children: _jsx(ChevronsUpDown, { "aria-hidden": "true", className: "size-[1em]" }) })] }), _jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Positioner, { className: "z-50", sideOffset: 6, alignItemWithTrigger: false, children: _jsx(SelectPrimitive.Popup, { "data-slot": "select-popup", className: POPUP, children: options.map((option) => (_jsxs(SelectPrimitive.Item, { value: option.value, disabled: option.disabled, "data-slot": "select-item", className: ITEM, children: [_jsx(SelectPrimitive.ItemText, { "data-slot": "select-item-text", children: option.label }), _jsx(SelectPrimitive.ItemIndicator, { "data-slot": "select-item-indicator", className: "ml-auto flex shrink-0 items-center [color:var(--foreground)]", children: _jsx(Check, { "aria-hidden": "true", className: "size-[1em]" }) })] }, option.value))) }) }) })] }));
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/components/select.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAsBhC;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,GACX,8DAA8D;IAC9D,sDAAsD;IACtD,+DAA+D;IAC/D,kFAAkF;IAClF,yEAAyE;IACzE,uBAAuB;IACvB,yHAAyH;IACzH,6JAA6J,CAAA;AAE/J;;;;;;GAMG;AACH,MAAM,KAAK,GACT,uFAAuF,CAAA;AAEzF;;;;GAIG;AACH,MAAM,IAAI,GAAG,4DAA4D,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,GACV,8BAA8B;IAC9B,uGAAuG;IACvG,+FAA+F;IAC/F,6DAA6D;IAC7D,2FAA2F;IAC3F,yCAAyC;IACzC,8FAA8F;IAC9F,6CAA6C,CAAA;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,KAAK,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KAAK,iBAAW,cAAc,EAAC,SAAS,EAAE,KAAK,YAC7D,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,MAAC,eAAe,CAAC,IAAI,IAEnB,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ,eACf,aAAa,EACvB,SAAS,EAAE,IAAI,aAEf,KAAC,eAAe,CAAC,QAAQ,iBAAW,kBAAkB,YACnD,MAAM,CAAC,KAAK,GACY,EAC3B,KAAC,eAAe,CAAC,aAAa,iBAClB,uBAAuB,EACjC,SAAS,EAAC,8DAA8D,YAExE,KAAC,KAAK,mBAAa,MAAM,EAAC,SAAS,EAAC,YAAY,GAAG,GACrB,KAd3B,MAAM,CAAC,KAAK,CAeI,CACxB,CAAC,GACoB,GACG,GACN,IACJ,CACxB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Detent } from "../opsinjs.ts";
|
|
3
|
+
/**
|
|
4
|
+
* How a close was asked for.
|
|
5
|
+
*
|
|
6
|
+
* Five routes rather than Base UI's nine, because the distinctions this
|
|
7
|
+
* component's accessibility contract turns on are coarser than the ones the
|
|
8
|
+
* primitive reports. What matters to a product is whether the reader made a
|
|
9
|
+
* deliberate exit (`close-control`) or brushed against one of the ambient ones
|
|
10
|
+
* (`scrim`, `escape`, `drag`). The first needs no confirmation and the other
|
|
11
|
+
* three, over unsaved input, need the same one.
|
|
12
|
+
*
|
|
13
|
+
* Module-local, not exported: a component file's public surface is its props
|
|
14
|
+
* and its component, and callers name this as `SheetProps["onOpenChange"]`'s
|
|
15
|
+
* second parameter.
|
|
16
|
+
*/
|
|
17
|
+
type SheetDismissRoute = "close-control" | "scrim" | "escape" | "drag" | "other";
|
|
18
|
+
export interface SheetProps {
|
|
19
|
+
/**
|
|
20
|
+
* Whether the sheet is on screen. Required and controlled: a modal surface
|
|
21
|
+
* that owned its own visibility would be a surface a product could not close
|
|
22
|
+
* when the data underneath it changed.
|
|
23
|
+
*/
|
|
24
|
+
open: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Called when the sheet asks to open or close. The second argument says which
|
|
27
|
+
* route was taken: `close-control` for the header's close button,
|
|
28
|
+
* `scrim` for a tap on the background, `escape` for the escape key or the
|
|
29
|
+
* platform's back gesture, `drag` for a swipe down, and `other` for anything
|
|
30
|
+
* else, including a close the product asked for itself.
|
|
31
|
+
*
|
|
32
|
+
* The sheet does not close itself: `open` is the only thing that closes it.
|
|
33
|
+
* That is what makes "ask before discarding unsaved input" possible. Leave
|
|
34
|
+
* `open` alone, show the confirmation, and close when the reader answers.
|
|
35
|
+
*/
|
|
36
|
+
onOpenChange: (open: boolean, route: SheetDismissRoute) => void;
|
|
37
|
+
/**
|
|
38
|
+
* The sheet's accessible name, and a visible heading. Required: an unnamed
|
|
39
|
+
* modal surface is announced as "dialog" and nothing else, which tells a
|
|
40
|
+
* screen-reader user that something has taken the screen and not what.
|
|
41
|
+
*/
|
|
42
|
+
title: string;
|
|
43
|
+
/**
|
|
44
|
+
* Rest positions, in order; the first is where the sheet opens. A single
|
|
45
|
+
* entry disables drag-between-detents, which is the common case and the
|
|
46
|
+
* default.
|
|
47
|
+
*
|
|
48
|
+
* `"content"` is supported only on its own. It is not a snap point but the
|
|
49
|
+
* absence of one: the sheet takes its own height, up to the full viewport,
|
|
50
|
+
* and the browser lays it out. `"half"` and `"full"` are fractions of the
|
|
51
|
+
* viewport and can be combined; passing `"content"` alongside either drops it
|
|
52
|
+
* with a development warning, because a sheet that can reach the full screen
|
|
53
|
+
* is already as tall as the screen and has no content height to return to.
|
|
54
|
+
*
|
|
55
|
+
* @default ["content"]
|
|
56
|
+
*/
|
|
57
|
+
detents?: Detent[];
|
|
58
|
+
/**
|
|
59
|
+
* Traps focus, marks the page behind `aria-hidden`, and lets the scrim stop
|
|
60
|
+
* a pointer. Be exact about the mechanism: the primitive marks everything
|
|
61
|
+
* outside the portal `aria-hidden="true"` rather than setting the HTML
|
|
62
|
+
* `inert` attribute, so the page behind is hidden and unreachable but it is
|
|
63
|
+
* NOT inert. The difference is observable, because focus moved
|
|
64
|
+
* programmatically from behind the sheet takes and keeps focus on a control
|
|
65
|
+
* the accessibility tree has just been told is not there. A modal sheet is
|
|
66
|
+
* also the only state in which the sheet takes focus on appearance:
|
|
67
|
+
* `modal={false}` does none of this, so it opens where the reader can see it
|
|
68
|
+
* and leaves the caret exactly where they left it.
|
|
69
|
+
*
|
|
70
|
+
* A non-modal sheet has no accessibility story on this page beyond that
|
|
71
|
+
* sentence. It is pinned to the bottom edge while the page behind stays
|
|
72
|
+
* focusable, which is the obscured-focus shape WCAG 2.4.11 is about, and
|
|
73
|
+
* nothing here has been checked against it.
|
|
74
|
+
*
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
77
|
+
modal?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the scrim, the escape key and a downward drag close the sheet. Set
|
|
80
|
+
* it `false` for a form, where each of those three is an accident waiting to
|
|
81
|
+
* throw away what somebody typed. It never removes the close control in the
|
|
82
|
+
* header: a modal surface with no way out is a trap, and the one surface that
|
|
83
|
+
* legitimately has no "went away" outcome is a `Dialog`.
|
|
84
|
+
*
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
dismissible?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The pinned action area. A prop rather than a compound part because a prop
|
|
90
|
+
* can carry it, and because the pinning is the point: the footer sits outside
|
|
91
|
+
* the scrolling region, above the software keyboard and above the safe-area
|
|
92
|
+
* inset, so the primary action cannot be scrolled away from or covered.
|
|
93
|
+
*/
|
|
94
|
+
footer?: ReactNode;
|
|
95
|
+
/**
|
|
96
|
+
* Merged onto the sheet's container, and last in the list, so it wins. The
|
|
97
|
+
* sheet is full width on a phone and no wider than the comfortable body
|
|
98
|
+
* measure above the `sm` breakpoint, because the system's own doctrine caps
|
|
99
|
+
* the reading measure on every surface. Left uncapped, a 1024px sheet puts
|
|
100
|
+
* roughly 120 characters on a line and turns a footer action into a 984px
|
|
101
|
+
* bar. The cap is a default rather than a lock: a product that wants the
|
|
102
|
+
* sheet wider or narrower on a large display sets a `max-w` here and this
|
|
103
|
+
* class overrides the default.
|
|
104
|
+
*/
|
|
105
|
+
className?: string;
|
|
106
|
+
/**
|
|
107
|
+
* What the sheet holds. Usually a single `Sheet.Content`, which is the
|
|
108
|
+
* scrolling region; anything placed beside it does not scroll.
|
|
109
|
+
*/
|
|
110
|
+
children: ReactNode;
|
|
111
|
+
}
|
|
112
|
+
export declare function Sheet({ open, onOpenChange, title, detents, modal, dismissible, footer, className, children, }: SheetProps): import("react").JSX.Element;
|
|
113
|
+
export declare namespace Sheet {
|
|
114
|
+
var Content: typeof SheetContent;
|
|
115
|
+
var Description: typeof SheetDescription;
|
|
116
|
+
}
|
|
117
|
+
export interface SheetContentProps {
|
|
118
|
+
/** Everything that scrolls. */
|
|
119
|
+
children: ReactNode;
|
|
120
|
+
/**
|
|
121
|
+
* Merged onto the scrolling region. The region's own classes win where they
|
|
122
|
+
* conflict, and the two that must not be overridden are the ones that make it
|
|
123
|
+
* a scroll boundary at all.
|
|
124
|
+
*/
|
|
125
|
+
className?: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The scrolling region, and the one part of a Sheet that is a real export.
|
|
129
|
+
*
|
|
130
|
+
* It is an export because the consumer supplies its content and no prop could
|
|
131
|
+
* carry it: a sheet may hold something above or below the scrolling area, and
|
|
132
|
+
* only the caller knows which of the things they are putting in should move
|
|
133
|
+
* when the rest does.
|
|
134
|
+
*
|
|
135
|
+
* It is also the element Base UI looks for. `Drawer.Content` stamps
|
|
136
|
+
* `data-drawer-content`, and the drawer's own pointer handling treats a touch
|
|
137
|
+
* that begins inside it as a scroll rather than a swipe. That is what stops a
|
|
138
|
+
* flick at the top of a scrolled list from dismissing the sheet, and it is why
|
|
139
|
+
* `overscroll-contain` sits beside it: one stops the sheet from being dragged,
|
|
140
|
+
* the other stops the page behind from being scrolled.
|
|
141
|
+
*
|
|
142
|
+
* IT IS A FOCUS STOP, DELIBERATELY AND UNCONDITIONALLY. A scroll container that
|
|
143
|
+
* holds nothing focusable can only be reached and scrolled from the keyboard
|
|
144
|
+
* where the browser decides to make scrollers focusable on its own. That is
|
|
145
|
+
* Chrome and Edge from 127, and not Safari or Firefox. This system's readers
|
|
146
|
+
* are on Safari, and a sheet holding a long list of things nobody can reach
|
|
147
|
+
* with the keyboard is a WCAG 2.1.1 failure whatever the page says about arrow
|
|
148
|
+
* keys. `tabIndex={0}` makes it the same stop in every engine.
|
|
149
|
+
*
|
|
150
|
+
* Unconditional, and the alternative was worse. Measuring whether the content
|
|
151
|
+
* actually overflows would mean measuring layout in JavaScript on every render
|
|
152
|
+
* and every resize, and a tab stop that appears and disappears as the content
|
|
153
|
+
* changes is harder to learn than one that is always there. The cost is one
|
|
154
|
+
* extra stop in a sheet whose content fits.
|
|
155
|
+
*
|
|
156
|
+
* `role="group"` with the sheet's own name, because a nameless stop is a stop a
|
|
157
|
+
* screen-reader user arrives at without being told what it is or why focus
|
|
158
|
+
* paused there. The name is the title the product already wrote, which
|
|
159
|
+
* `SheetTitleId` carries, so nothing here needs translating. The role is
|
|
160
|
+
* dropped entirely rather than pointed at a missing id when there is no Sheet
|
|
161
|
+
* above it.
|
|
162
|
+
*/
|
|
163
|
+
export declare function SheetContent({ children, className }: SheetContentProps): import("react").JSX.Element;
|
|
164
|
+
export interface SheetDescriptionProps {
|
|
165
|
+
/** The sentence the reader weighs before they answer. */
|
|
166
|
+
children: ReactNode;
|
|
167
|
+
/** Merged onto the paragraph. */
|
|
168
|
+
className?: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The sheet's description, and the sentence a reader must weigh before they
|
|
172
|
+
* answer.
|
|
173
|
+
*
|
|
174
|
+
* It is a compound part rather than a prop, because only the caller knows which
|
|
175
|
+
* of the paragraphs they are putting in is the description. `Drawer.Description`
|
|
176
|
+
* renders a `<p>` and registers its id with the drawer store, so the popup
|
|
177
|
+
* gains `aria-describedby` pointing here with no id plumbing in this file, the
|
|
178
|
+
* way the title already gains `aria-labelledby` through `Drawer.Title`. That is
|
|
179
|
+
* the gap this part closes: before it, the sheet named itself and described
|
|
180
|
+
* nothing, so the scope or purpose a reader must weigh was on screen but not
|
|
181
|
+
* tied to the dialog by aria.
|
|
182
|
+
*
|
|
183
|
+
* It is rendered visibly and is never a hidden string. The consequence of an
|
|
184
|
+
* answer is not something to hide from a reader who is not on a screen reader,
|
|
185
|
+
* and a description held only in an attribute is one the sighted reader never
|
|
186
|
+
* sees. There is at most one. A form sheet that has no such sentence renders
|
|
187
|
+
* none rather than being handed an empty one, because a description that points
|
|
188
|
+
* at no text is worse than the absence it papers over.
|
|
189
|
+
*/
|
|
190
|
+
export declare function SheetDescription({ children, className }: SheetDescriptionProps): import("react").JSX.Element;
|
|
191
|
+
export {};
|
|
192
|
+
//# sourceMappingURL=sheet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sheet.d.ts","sourceRoot":"","sources":["../../src/components/sheet.tsx"],"names":[],"mappings":"AAuDA,OAAO,EASL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AA0C1D;;;;;;;;;;;;;GAaG;AACH,KAAK,iBAAiB,GAAG,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AA+ahF,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAA;IACb;;;;;;;;;;OAUG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAA;IAC/D;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAA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