@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,952 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Sheet is a panel that comes up from the bottom edge, rests at a stated
|
|
5
|
+
* height, and can always be left.
|
|
6
|
+
*
|
|
7
|
+
* WHY THIS FILE IS `"use client"` AND SURFACE IS NOT. Surface answers every
|
|
8
|
+
* question it has with a media query, so it renders once on the server and is
|
|
9
|
+
* correct forever. A Sheet cannot: it holds which detent it is resting at, it
|
|
10
|
+
* mounts a portal, it moves focus, and it listens for a drag. None of that has
|
|
11
|
+
* a CSS answer, so the directive is a requirement rather than a convenience. It
|
|
12
|
+
* is on this file rather than borrowed from Base UI, because this file calls
|
|
13
|
+
* React hooks of its own, and a file that calls `useState` is a client file
|
|
14
|
+
* whatever its imports say.
|
|
15
|
+
*
|
|
16
|
+
* THERE IS NO `sheet` PRIMITIVE IN BASE UI 1.7.0. `@base-ui/react/drawer` is
|
|
17
|
+
* the one this is built on, and the mapping is not one-to-one. Every place the
|
|
18
|
+
* two vocabularies disagree is written out beside the code that resolves it,
|
|
19
|
+
* because a wrapper that quietly renames a prop is a wrapper nobody can audit:
|
|
20
|
+
*
|
|
21
|
+
* spec `dismissible` ↔ Base UI `disablePointerDismissal` (INVERTED, and
|
|
22
|
+
* Base UI's covers the pointer only, so the escape key
|
|
23
|
+
* and the close watcher are cancelled by hand below)
|
|
24
|
+
* spec `detents` ↔ Base UI `snapPoints` (fractions, pixels
|
|
25
|
+
* or rems, and no content-sized snap point)
|
|
26
|
+
* spec `modal` ↔ Base UI `modal` (Base UI has a
|
|
27
|
+
* third state, `'trap-focus'`, that this API does not
|
|
28
|
+
* model and deliberately does not expose)
|
|
29
|
+
* spec `title` ↔ `Drawer.Title` (a part, not a
|
|
30
|
+
* root prop; it is what `aria-labelledby` points at)
|
|
31
|
+
*
|
|
32
|
+
* A MODAL SURFACE OWNS ITS OWN `open`/`onOpenChange`, AND THAT IS DECIDED HERE.
|
|
33
|
+
* The specifications for LogSheet and ConsentSheet both say they "extend Sheet"
|
|
34
|
+
* and neither declares `open` or `onOpenChange`, so as written neither of them
|
|
35
|
+
* can be opened. The resolution belongs in the base rather than in each
|
|
36
|
+
* descendant: a surface that takes the screen decides nothing about when it is
|
|
37
|
+
* on it, and a component that extends Sheet inherits both props unchanged.
|
|
38
|
+
*
|
|
39
|
+
* `onOpenChange` TAKES A SECOND ARGUMENT THE SPECIFICATION DOES NOT DECLARE,
|
|
40
|
+
* and it is not decoration. The page requires that a sheet holding unsaved
|
|
41
|
+
* input "asks first", and that it does so "by the same route as a background
|
|
42
|
+
* tap", which a product cannot do unless it is told which route was taken. A
|
|
43
|
+
* one-argument handler is still assignable to the two-argument type, so
|
|
44
|
+
* `onOpenChange={setOpen}` keeps working and a product that needs the route can
|
|
45
|
+
* read it.
|
|
46
|
+
*
|
|
47
|
+
* WHAT IT DOES NOT DO. It mounts no live region, it announces nothing on its
|
|
48
|
+
* own behalf, and it never decides that a reader has finished. It also refuses
|
|
49
|
+
* to be a Dialog: there is no way to make a Sheet undismissable AND unclosable,
|
|
50
|
+
* because the one modal surface with no valid way out is a question, and a
|
|
51
|
+
* question is `Dialog`.
|
|
52
|
+
*/
|
|
53
|
+
import { Drawer } from "@base-ui/react/drawer";
|
|
54
|
+
import { X } from "lucide-react";
|
|
55
|
+
import { Children, createContext, isValidElement, useContext, useEffect, useId, useRef, useState, } from "react";
|
|
56
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
57
|
+
import { cn } from "../utils.js";
|
|
58
|
+
import { Surface } from "./surface.js";
|
|
59
|
+
/**
|
|
60
|
+
* A development warning that fires once per distinct mistake rather than once
|
|
61
|
+
* per render.
|
|
62
|
+
*
|
|
63
|
+
* Not `warnOnce` from the substrate, and the reason is the same one Surface
|
|
64
|
+
* gives: `warnOnce` is keyed on a code from `tokens/errors.json`, that table has
|
|
65
|
+
* no code for any of the six mistakes below, and a component may not mint one.
|
|
66
|
+
* What can be borrowed is the policy. `tokens/errors.json` says a warning fires
|
|
67
|
+
* once per offending call site, because a repeated identical complaint teaches
|
|
68
|
+
* nothing and drowns the next one. Every one of these checks sits in the render
|
|
69
|
+
* path, so the un-deduplicated version printed on every pass of an open sheet
|
|
70
|
+
* and twice per pass under StrictMode; two of the six report an unnamed dialog
|
|
71
|
+
* and a missing scroll boundary, which is exactly the finding a reader loses
|
|
72
|
+
* when they filter the channel.
|
|
73
|
+
*
|
|
74
|
+
* The render path is still the right place for them. An effect would report the
|
|
75
|
+
* mistake after the frame that contains it has already been painted.
|
|
76
|
+
*/
|
|
77
|
+
const warnedKeys = new Set();
|
|
78
|
+
/**
|
|
79
|
+
* Bounded, because a development session runs for days and this set is never
|
|
80
|
+
* cleared. Sixteen distinct complaints means the report has been made several
|
|
81
|
+
* times over; going quiet beats growing without limit.
|
|
82
|
+
*/
|
|
83
|
+
const MAX_WARNED_KEYS = 16;
|
|
84
|
+
function warnOncePerSession(key, message) {
|
|
85
|
+
if (!isDevelopment())
|
|
86
|
+
return;
|
|
87
|
+
if (warnedKeys.has(key) || warnedKeys.size >= MAX_WARNED_KEYS)
|
|
88
|
+
return;
|
|
89
|
+
warnedKeys.add(key);
|
|
90
|
+
try {
|
|
91
|
+
console.warn(`[opsinjs] ${message}`);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
/* A patched console is not a reason to take a health product down. */
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Base UI's reason, translated. `closeWatcher` joins `escapeKey` because it is
|
|
99
|
+
* the same intention arriving through the platform's back gesture instead of
|
|
100
|
+
* through a key, and a product that confirms one and not the other has a hole
|
|
101
|
+
* on exactly the devices where a sheet matters most.
|
|
102
|
+
*/
|
|
103
|
+
function routeFor(reason) {
|
|
104
|
+
switch (reason) {
|
|
105
|
+
case "close-press":
|
|
106
|
+
return "close-control";
|
|
107
|
+
case "outside-press":
|
|
108
|
+
return "scrim";
|
|
109
|
+
case "escape-key":
|
|
110
|
+
case "close-watcher":
|
|
111
|
+
return "escape";
|
|
112
|
+
case "swipe":
|
|
113
|
+
return "drag";
|
|
114
|
+
default:
|
|
115
|
+
return "other";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* THE VALUES ABOVE ARE BASE UI'S RUNTIME STRINGS, NOT ITS CONSTANT NAMES, AND
|
|
120
|
+
* THE DIFFERENCE ONCE MADE THIS COMPONENT A KEYBOARD TRAP.
|
|
121
|
+
*
|
|
122
|
+
* `@base-ui/react/internals/reason-parts` exports `closePress = 'close-press'`,
|
|
123
|
+
* `outsidePress = 'outside-press'`, `escapeKey = 'escape-key'` and
|
|
124
|
+
* `closeWatcher = 'close-watcher'`. The first version of this switch matched the
|
|
125
|
+
* NAMES. Only `swipe` happens to be spelled the same in both, so every other
|
|
126
|
+
* close fell through to `"other"`. Under `dismissible={false}` the handler
|
|
127
|
+
* below cancels everything that is not `"close-control"`. The close control was
|
|
128
|
+
* therefore cancelled along with the scrim and the escape key, and the shipped
|
|
129
|
+
* example that sets `dismissible={false}` became a modal sheet with focus
|
|
130
|
+
* trapped inside it and no exit at all.
|
|
131
|
+
*
|
|
132
|
+
* Two things follow, and the second is the one that matters.
|
|
133
|
+
*
|
|
134
|
+
* The parameter is typed `DrawerRootChangeEventReason` and not `string`, and
|
|
135
|
+
* that is the guard rather than the tidiness. `string` is what made the original
|
|
136
|
+
* mistake legal: a `case` label that can never match is a perfectly good
|
|
137
|
+
* comparison against a `string`, and the compiler had nothing to object to. Typed
|
|
138
|
+
* as the union, every label above has to be a member of it, so the day Base UI
|
|
139
|
+
* renames one this file stops compiling instead of quietly reclassifying a close.
|
|
140
|
+
* The `default` branch stays regardless: this file ships as source into
|
|
141
|
+
* JavaScript projects and into whatever version of Base UI the consumer resolves,
|
|
142
|
+
* where the type is advice.
|
|
143
|
+
*
|
|
144
|
+
* `KNOWN_REASONS` is the same guard from the other side. It lists every reason
|
|
145
|
+
* the primitive declares, so a reason that reaches this handler and is NOT in
|
|
146
|
+
* the declared union is a development warning. Four of the nine are recognised and
|
|
147
|
+
* deliberately map to `"other"`: `trigger-press` (this API has no trigger),
|
|
148
|
+
* `focus-out`, `imperative-action` and `none` are all closes the sheet cannot
|
|
149
|
+
* attribute to anything a reader did, which is what `"other"` means. Warning on
|
|
150
|
+
* those would be crying wolf; the warning exists for the case that actually
|
|
151
|
+
* happened once, which is a reason nobody here has heard of.
|
|
152
|
+
*
|
|
153
|
+
* And the cancellation is allow-listed rather than deny-listed. It cancels only
|
|
154
|
+
* the three ambient routes it positively recognises. A route it does not
|
|
155
|
+
* understand CLOSES the sheet, because the failure modes are not symmetrical:
|
|
156
|
+
* closing a sheet somebody wanted to keep loses a form, and refusing to close a
|
|
157
|
+
* modal surface loses the reader.
|
|
158
|
+
*/
|
|
159
|
+
const KNOWN_REASONS = new Set([
|
|
160
|
+
"close-press",
|
|
161
|
+
"outside-press",
|
|
162
|
+
"escape-key",
|
|
163
|
+
"close-watcher",
|
|
164
|
+
"swipe",
|
|
165
|
+
"trigger-press",
|
|
166
|
+
"focus-out",
|
|
167
|
+
"imperative-action",
|
|
168
|
+
"none",
|
|
169
|
+
]);
|
|
170
|
+
/**
|
|
171
|
+
* The two detents that have a numeric answer, as fractions of the viewport.
|
|
172
|
+
*
|
|
173
|
+
* `content` is deliberately absent and the reason is mechanical rather than
|
|
174
|
+
* aesthetic. Base UI resolves every snap point against the popup's own measured
|
|
175
|
+
* height and clamps it there (`useDrawerSnapPoints`: `offset = popupHeight -
|
|
176
|
+
* clampedHeight`), so a sheet that can reach `full` has to be viewport-tall.
|
|
177
|
+
* Once it is, its natural height IS the viewport and there is no content height
|
|
178
|
+
* left to snap to. The two requirements are not satisfiable at the same
|
|
179
|
+
* time, so `content` is supported as the only detent, where it needs no snap
|
|
180
|
+
* point at all: the popup takes its own height and the browser lays it out.
|
|
181
|
+
*/
|
|
182
|
+
const VIEWPORT_FRACTION = {
|
|
183
|
+
half: 0.5,
|
|
184
|
+
full: 1,
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* What each detent is called when the grabber has to name the height it moves
|
|
188
|
+
* to on the next press.
|
|
189
|
+
*
|
|
190
|
+
* Plain words rather than the API's own values: the reader of the accessible
|
|
191
|
+
* name is a person using the product, not a person reading this file, and
|
|
192
|
+
* "half" on its own is an adjective with no noun. Each phrase has to complete
|
|
193
|
+
* the sentence "Make the sheet ...", so "full" reads as "full screen" rather
|
|
194
|
+
* than "the full screen", which does not.
|
|
195
|
+
*/
|
|
196
|
+
const DETENT_WORD = {
|
|
197
|
+
content: "fit the content",
|
|
198
|
+
half: "half the screen",
|
|
199
|
+
full: "full screen",
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* The default, and the reason it is the smallest of the three.
|
|
203
|
+
*
|
|
204
|
+
* Declared at module scope rather than inline in the parameter list so that the
|
|
205
|
+
* array identity is stable across renders. An inline `= ["content"]` is a new
|
|
206
|
+
* array every time and would defeat any memo that is ever added below it.
|
|
207
|
+
*/
|
|
208
|
+
const DEFAULT_DETENTS = ["content"];
|
|
209
|
+
function isDetent(value) {
|
|
210
|
+
return value === "content" || value === "half" || value === "full";
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* How deep in a stack of Sheets this one is.
|
|
214
|
+
*
|
|
215
|
+
* Base UI supports nested drawers on purpose and this system forbids them on
|
|
216
|
+
* purpose, so the primitive cannot report the mistake and this context is how
|
|
217
|
+
* the component sees it. A count rather than a boolean because the warning is
|
|
218
|
+
* more useful when it can say how many deep the reader has got.
|
|
219
|
+
*/
|
|
220
|
+
const SheetDepth = createContext(0);
|
|
221
|
+
/**
|
|
222
|
+
* The id of the element holding the sheet's title, or `undefined` outside a
|
|
223
|
+
* Sheet.
|
|
224
|
+
*
|
|
225
|
+
* It exists so `Sheet.Content` can name itself without inventing a string.
|
|
226
|
+
* The scrolling region is a focus stop (see below) and a nameless stop is a
|
|
227
|
+
* stop a screen-reader user arrives at with no idea why; pointing its
|
|
228
|
+
* `aria-labelledby` at the title the sheet already has reuses a name the
|
|
229
|
+
* product wrote, in the product's own language, rather than adding a third
|
|
230
|
+
* English string to the two this component already ships and already declares
|
|
231
|
+
* as a translation gap.
|
|
232
|
+
*
|
|
233
|
+
* `undefined` rather than a generated fallback when there is no provider,
|
|
234
|
+
* because `aria-labelledby` pointing at an id that does not exist is worse than
|
|
235
|
+
* no `aria-labelledby` at all: the name resolves to the empty string and the
|
|
236
|
+
* region goes from unnamed to falsely named.
|
|
237
|
+
*/
|
|
238
|
+
const SheetTitleId = createContext(undefined);
|
|
239
|
+
/**
|
|
240
|
+
* How `Sheet.Content` tells the pinned footer that its text runs past the fold,
|
|
241
|
+
* or `undefined` outside a Sheet.
|
|
242
|
+
*
|
|
243
|
+
* A pinned footer is the right answer for an action bar and the wrong one for a
|
|
244
|
+
* surface whose text is the point: the two decision controls are on screen from
|
|
245
|
+
* the first frame while the consequence and withdrawal sentences are still below
|
|
246
|
+
* the fold, so a reader can answer before they have read what the answer costs.
|
|
247
|
+
* The honest repair, while the footer stays pinned, is to stop the sheet from
|
|
248
|
+
* looking finished when it is not. The scroller reports whether more content
|
|
249
|
+
* sits below its bottom edge and the footer draws a scroll edge while it does,
|
|
250
|
+
* so the surface reads as unfinished until the reader reaches the end. This is a
|
|
251
|
+
* scroll edge and never a status: it carries no clinical level and no colour
|
|
252
|
+
* that means anything but "there is more".
|
|
253
|
+
*
|
|
254
|
+
* `undefined` when there is no provider, so a `Sheet.Content` rendered on its
|
|
255
|
+
* own is a plain scroller that reports to nobody.
|
|
256
|
+
*/
|
|
257
|
+
const SheetOverflowReport = createContext(undefined);
|
|
258
|
+
/**
|
|
259
|
+
* Whether the caller placed a `Sheet.Content` among the direct children.
|
|
260
|
+
*
|
|
261
|
+
* SAY EXACTLY WHAT THIS CAN SEE, because a check that over-promises is worse
|
|
262
|
+
* than none. It reads direct children only. A `Sheet.Content` wrapped in a
|
|
263
|
+
* `<div>` or a fragment is invisible to it and reports a false absence, which
|
|
264
|
+
* is why the warning names what it looked at rather than asserting a defect.
|
|
265
|
+
* The failure it exists to catch is the common one: content that overflows a
|
|
266
|
+
* sheet with no scroll boundary, where a flick meant to scroll dismisses the
|
|
267
|
+
* sheet instead, because Base UI treats every touch outside `[data-drawer-content]`
|
|
268
|
+
* as a swipe.
|
|
269
|
+
*/
|
|
270
|
+
function hasContentSlot(children) {
|
|
271
|
+
return Children.toArray(children).some((child) => isValidElement(child) && child.type === SheetContent);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The detents this sheet will actually rest at, from the ones it was given.
|
|
275
|
+
*
|
|
276
|
+
* Order is preserved because the specification says "rest positions, in order"
|
|
277
|
+
* and the first one is where the sheet opens. Duplicates are dropped silently.
|
|
278
|
+
* Two identical stops are not a mistake worth a warning, and Base UI
|
|
279
|
+
* deduplicates resolved heights within a pixel anyway.
|
|
280
|
+
*/
|
|
281
|
+
function resolveDetents(detents) {
|
|
282
|
+
const stops = [];
|
|
283
|
+
for (const detent of detents) {
|
|
284
|
+
if (!isDetent(detent)) {
|
|
285
|
+
warnOncePerSession(`detent:${String(detent)}`, `<Sheet> was given the detent "${String(detent)}", which is not one of ` +
|
|
286
|
+
"content, half or full. It was ignored.");
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (!stops.includes(detent))
|
|
290
|
+
stops.push(detent);
|
|
291
|
+
}
|
|
292
|
+
if (stops.length === 0) {
|
|
293
|
+
warnOncePerSession("detents:empty", "<Sheet> was given an empty `detents` array. A sheet with no rest " +
|
|
294
|
+
'position has no height, so it fell back to ["content"].');
|
|
295
|
+
return DEFAULT_DETENTS;
|
|
296
|
+
}
|
|
297
|
+
if (stops.length > 1 && stops.includes("content")) {
|
|
298
|
+
const measured = stops.filter((stop) => stop !== "content");
|
|
299
|
+
warnOncePerSession(`detents:content-beside:${measured.join("+")}`, "<Sheet> was given `content` alongside another detent. A content-sized " +
|
|
300
|
+
"stop and a viewport-sized stop cannot both exist: a sheet that can " +
|
|
301
|
+
"reach half or full is as tall as the viewport, and a snap point is " +
|
|
302
|
+
"resolved against the sheet's own height. `content` was dropped; the " +
|
|
303
|
+
`sheet rests at ${measured.join(" and ")}.`);
|
|
304
|
+
return measured;
|
|
305
|
+
}
|
|
306
|
+
return stops;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Base UI's snap points for a set of detents, or `undefined` for the
|
|
310
|
+
* content-sized sheet, which needs none.
|
|
311
|
+
*/
|
|
312
|
+
function toSnapPoints(stops) {
|
|
313
|
+
const points = [];
|
|
314
|
+
for (const stop of stops) {
|
|
315
|
+
if (stop === "content")
|
|
316
|
+
return undefined;
|
|
317
|
+
points.push(VIEWPORT_FRACTION[stop]);
|
|
318
|
+
}
|
|
319
|
+
return points.length > 0 ? points : undefined;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The popup's resting transform, as a class rather than an inline style, and
|
|
323
|
+
* this is the one line in the file most likely to be "simplified" into a bug.
|
|
324
|
+
*
|
|
325
|
+
* Base UI writes `transform` inline on the popup WHILE a drag is in flight and
|
|
326
|
+
* writes nothing there the rest of the time, publishing the movement as
|
|
327
|
+
* `--drawer-swipe-movement-y` and the active stop as
|
|
328
|
+
* `--drawer-snap-point-offset` instead. An inline style here would win against
|
|
329
|
+
* the one it writes during the drag and freeze the sheet under the reader's
|
|
330
|
+
* finger; a Tailwind `translate-y-*` utility would set the `translate`
|
|
331
|
+
* property, which composes with `transform` rather than being replaced by it,
|
|
332
|
+
* and the sheet would move twice as far. So it is an arbitrary `transform`
|
|
333
|
+
* property, in a class, where the primitive's inline style beats it exactly
|
|
334
|
+
* when it should.
|
|
335
|
+
*/
|
|
336
|
+
const RESTING_TRANSFORM = "[transform:translateY(calc(var(--drawer-snap-point-offset,0px)_+_var(--drawer-swipe-movement-y,0px)))]";
|
|
337
|
+
/**
|
|
338
|
+
* Reserve the active detent's offset inside the popup, as padding rather than
|
|
339
|
+
* height.
|
|
340
|
+
*
|
|
341
|
+
* Base UI publishes the active stop as `--drawer-snap-point-offset` and slides
|
|
342
|
+
* the whole popup down by it (see `RESTING_TRANSFORM`). The popup's own box is
|
|
343
|
+
* still the full viewport, because a snap point is resolved against the popup's
|
|
344
|
+
* measured height and `snapPoints` forces `h-full`. So at any detent below the
|
|
345
|
+
* top one, the lower part of that full-height box, and with it the pinned
|
|
346
|
+
* footer, sits under the bottom edge of the screen. Padding the bottom of the
|
|
347
|
+
* popup by the same offset shrinks the laid-out column to exactly the region
|
|
348
|
+
* that is on screen: with `box-sizing: border-box` the content box becomes the
|
|
349
|
+
* full height minus the offset, the `flex-auto` Surface fills that, the footer
|
|
350
|
+
* lands on the visible bottom edge, and `Sheet.Content` finally has a bounded
|
|
351
|
+
* height to scroll its last row into.
|
|
352
|
+
*
|
|
353
|
+
* This must stay a padding and must NOT become a height on the popup. Shrinking
|
|
354
|
+
* the popup changes the height Base UI derives every offset from, so the offset
|
|
355
|
+
* and the height would chase each other on every detent change.
|
|
356
|
+
*/
|
|
357
|
+
const SNAP_POINT_INSET = "pb-(--drawer-snap-point-offset,0px)";
|
|
358
|
+
/**
|
|
359
|
+
* Off the bottom edge, on the way in and on the way out.
|
|
360
|
+
*
|
|
361
|
+
* A whole `transform` rather than an added term, so it replaces the resting one
|
|
362
|
+
* outright: a sheet entering is not at a detent yet and must not be offset by
|
|
363
|
+
* one. `100%` is of the popup's own height, so it is off-screen at every detent
|
|
364
|
+
* and at every text size without a measurement.
|
|
365
|
+
*/
|
|
366
|
+
const OFFSCREEN_TRANSFORM = "data-starting-style:[transform:translateY(100%)] data-ending-style:[transform:translateY(100%)]";
|
|
367
|
+
/**
|
|
368
|
+
* The slide.
|
|
369
|
+
*
|
|
370
|
+
* `spring-sheet` paired with its own duration, never crossed with another
|
|
371
|
+
* spring's: a `linear()` stop list runs from 0 to 1 whatever the spring, so
|
|
372
|
+
* putting one spring's curve on another's duration produces a different spring
|
|
373
|
+
* rather than a faster one.
|
|
374
|
+
*
|
|
375
|
+
* No `motion-reduce:transition-none` here, and the reason is a correction. An
|
|
376
|
+
* earlier version of this file removed the transition outright under
|
|
377
|
+
* `prefers-reduced-motion` and argued the case in a comment. The argument was
|
|
378
|
+
* half right and the conclusion was wrong, and the page that settles it names
|
|
379
|
+
* this component by name: `health/motion-in-health-ui.mdx` lists `sheet` in its
|
|
380
|
+
* `implements`, its rule 5 says the reduced-motion fallback "is not 'no
|
|
381
|
+
* animation' by default. It is an instant, complete, equally informative
|
|
382
|
+
* state", and its Do/Dont pair is written about a sheet: DO "show the sheet in
|
|
383
|
+
* place with a crossfade of opacity only, retaining every affordance", DONT
|
|
384
|
+
* "remove the transition and let a modal appear with no change of context at
|
|
385
|
+
* all. Reduced motion means less movement, not less orientation." A surface
|
|
386
|
+
* that teleports onto the screen is harder to follow than one that arrives
|
|
387
|
+
* quickly, and the reader most likely to have reduced motion on is the reader
|
|
388
|
+
* least able to afford a surface appearing from nowhere.
|
|
389
|
+
*
|
|
390
|
+
* What was right in the old argument is that 120ms of full-height translation
|
|
391
|
+
* is still a full-height translation. So the distance goes and the transition
|
|
392
|
+
* stays, which is `REDUCED_MOTION_CROSSFADE` below.
|
|
393
|
+
*
|
|
394
|
+
* `SLIDE_TIMING` is the duration and the easing on their own. It is split out
|
|
395
|
+
* so the snap-points branch can spend them on a transition of two properties,
|
|
396
|
+
* transform and padding-bottom together, without also taking
|
|
397
|
+
* `transition-transform`. A branch that carried both `transition-transform` and
|
|
398
|
+
* its own `transition-property` would leave which one wins to source order;
|
|
399
|
+
* giving the branch the timing but not the property setter removes that contest
|
|
400
|
+
* at the source rather than ranking it. The one-detent branch takes the whole
|
|
401
|
+
* `SLIDE`, which is `transition-transform` on that same timing.
|
|
402
|
+
*/
|
|
403
|
+
const SLIDE_TIMING = "duration-(--opsin-duration-spring-sheet) ease-opsin-spring-sheet";
|
|
404
|
+
const SLIDE = `transition-transform ${SLIDE_TIMING}`;
|
|
405
|
+
/**
|
|
406
|
+
* The reduced-motion answer: the same arrival, in place, as opacity.
|
|
407
|
+
*
|
|
408
|
+
* Three overrides, all of them under `motion-reduce`, and all of them ordered
|
|
409
|
+
* after their unprefixed twins at the same specificity so the media query wins
|
|
410
|
+
* on source order. The ordering was verified by compiling these exact
|
|
411
|
+
* candidates against the pinned tailwindcss 4.3.3 rather than assumed.
|
|
412
|
+
*
|
|
413
|
+
* 1. The transitioned property becomes `opacity` instead of `transform`.
|
|
414
|
+
* 2. The starting and ending transforms become the RESTING one rather than
|
|
415
|
+
* `translateY(100%)`, so the sheet is already at its detent for the whole
|
|
416
|
+
* of the transition and travels no distance at all. The value is written
|
|
417
|
+
* out twice rather than interpolated from `RESTING_TRANSFORM`, because
|
|
418
|
+
* Tailwind reads class names out of source as literal strings and a
|
|
419
|
+
* template literal generates no CSS.
|
|
420
|
+
* 3. Opacity runs 0 → 1 on the way in and back on the way out.
|
|
421
|
+
*
|
|
422
|
+
* The duration and easing are NOT overridden, and that is the division of
|
|
423
|
+
* labour this file keeps. The token layer already declares this transition's
|
|
424
|
+
* reduced-motion fallback. `@opsinjs/tokens/tokens.css` collapses
|
|
425
|
+
* `--opsin-duration-spring-sheet` to 120ms and `--opsin-ease-spring-sheet` to
|
|
426
|
+
* `linear` under the query. The crossfade is therefore 120ms and flat without
|
|
427
|
+
* this file restating either. What the token layer cannot know is the DISTANCE,
|
|
428
|
+
* because distance is not a token; that is the component's own to answer, and
|
|
429
|
+
* it is the only thing answered here.
|
|
430
|
+
*
|
|
431
|
+
* The scrim is deliberately left alone for the same reason. Its fade is already
|
|
432
|
+
* opacity over `--opsin-duration-base`, which `packages/react/styles/roles.css`
|
|
433
|
+
* collapses to 1ms under the query, so it has no distance to remove and its
|
|
434
|
+
* declared fallback is complete.
|
|
435
|
+
*/
|
|
436
|
+
const REDUCED_MOTION_CROSSFADE = [
|
|
437
|
+
"motion-reduce:transition-opacity",
|
|
438
|
+
"motion-reduce:data-starting-style:[transform:translateY(calc(var(--drawer-snap-point-offset,0px)_+_var(--drawer-swipe-movement-y,0px)))]",
|
|
439
|
+
"motion-reduce:data-ending-style:[transform:translateY(calc(var(--drawer-snap-point-offset,0px)_+_var(--drawer-swipe-movement-y,0px)))]",
|
|
440
|
+
"motion-reduce:data-starting-style:opacity-0",
|
|
441
|
+
"motion-reduce:data-ending-style:opacity-0",
|
|
442
|
+
].join(" ");
|
|
443
|
+
/**
|
|
444
|
+
* How the Surface inside the popup is told to lay its content out.
|
|
445
|
+
*
|
|
446
|
+
* Surface owns the class list on its own content wrapper and takes no prop for
|
|
447
|
+
* it, so a composing component reaches it by its `data-slot`. That is the
|
|
448
|
+
* whole point of the slot contract, and is the supported way to do this rather
|
|
449
|
+
* than a workaround. Without it the header, the scrolling content and the
|
|
450
|
+
* footer are three blocks in normal flow, the content has no bounded height,
|
|
451
|
+
* and `overflow-y: auto` on it does nothing at all.
|
|
452
|
+
*
|
|
453
|
+
* `flex-auto` and not `flex-1`: `flex-1` sets a zero flex basis, and a sheet
|
|
454
|
+
* whose height is its content's would then compute that height as zero.
|
|
455
|
+
*/
|
|
456
|
+
const SURFACE_LAYOUT = [
|
|
457
|
+
"flex min-h-0 flex-auto flex-col",
|
|
458
|
+
"[&>[data-slot=surface-content]]:flex",
|
|
459
|
+
"[&>[data-slot=surface-content]]:min-h-0",
|
|
460
|
+
"[&>[data-slot=surface-content]]:flex-auto",
|
|
461
|
+
"[&>[data-slot=surface-content]]:flex-col",
|
|
462
|
+
].join(" ");
|
|
463
|
+
/**
|
|
464
|
+
* The focus ring, declared here rather than inherited.
|
|
465
|
+
*
|
|
466
|
+
* `@opsinjs/react/base.css` gives every `:focus-visible` an outline, and that
|
|
467
|
+
* stylesheet is opt-in, so an app that installed this component may never load
|
|
468
|
+
* it. A control whose ring depends on a stylesheet the app may not load is a
|
|
469
|
+
* control that loses it silently, on the surface where a keyboard reader most
|
|
470
|
+
* needs to know where they are.
|
|
471
|
+
*/
|
|
472
|
+
const FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring";
|
|
473
|
+
/**
|
|
474
|
+
* The container's focus ring, drawn inside its own edge rather than outside it.
|
|
475
|
+
*
|
|
476
|
+
* The sheet container is full width and pinned to the bottom edge, so a ring
|
|
477
|
+
* drawn 2px outside its box falls off screen on three sides and the reader is
|
|
478
|
+
* left with a 2px line along the top that reads as a rendering fault rather
|
|
479
|
+
* than as a focus indicator. A negative offset draws the whole ring just inside
|
|
480
|
+
* the sheet, where all four sides stay on screen. The controls inside the sheet
|
|
481
|
+
* keep `FOCUS_RING`, because an outset ring is right for a control that has
|
|
482
|
+
* room around it.
|
|
483
|
+
*/
|
|
484
|
+
const CONTAINER_FOCUS_RING = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring";
|
|
485
|
+
export function Sheet({ open, onOpenChange, title, detents = DEFAULT_DETENTS, modal = true, dismissible = true, footer, className, children, }) {
|
|
486
|
+
const depth = useContext(SheetDepth);
|
|
487
|
+
/* Supplied to Drawer.Title rather than read back off it. Base UI's DialogTitle
|
|
488
|
+
takes an `id` and registers whatever it is given as the popup's
|
|
489
|
+
`titleElementId`, so one id ends up on the heading, in the popup's
|
|
490
|
+
`aria-labelledby`, and in the scrolling region's. That is three references
|
|
491
|
+
from one source. */
|
|
492
|
+
const titleId = useId();
|
|
493
|
+
const stops = resolveDetents(detents);
|
|
494
|
+
const snapPoints = toSnapPoints(stops);
|
|
495
|
+
const [stopIndex, setStopIndex] = useState(0);
|
|
496
|
+
const [openLastRender, setOpenLastRender] = useState(open);
|
|
497
|
+
/* Set by Sheet.Content while its text runs past the fold, read by the footer.
|
|
498
|
+
The setter's identity is stable, so the observer in Sheet.Content lists it
|
|
499
|
+
as a dependency without re-attaching on every render. */
|
|
500
|
+
const [overflowBelow, setOverflowBelow] = useState(false);
|
|
501
|
+
/* The popup element, so a refused dismissal can put focus back inside the
|
|
502
|
+
surface. Base UI refuses the close but leaves keyboard focus wherever the
|
|
503
|
+
refused gesture dropped it, which for a scrim press is the document body:
|
|
504
|
+
the reader is then focused outside a modal whose siblings are marked
|
|
505
|
+
aria-hidden, and a screen reader reads nothing until the next Tab. */
|
|
506
|
+
const popupRef = useRef(null);
|
|
507
|
+
/* Back to the first detent on every open. A sheet that reopened at whatever
|
|
508
|
+
height the reader last dragged it to would be a sheet whose size depends on
|
|
509
|
+
something they did minutes ago and cannot see; "the first is where it
|
|
510
|
+
opens" is only true if it is true every time.
|
|
511
|
+
|
|
512
|
+
Adjusted during the render that notices the change rather than in an
|
|
513
|
+
effect, which is React's own answer for state derived from a prop: an
|
|
514
|
+
effect would commit the sheet at the old detent, paint it, and then correct
|
|
515
|
+
it. That is one frame of the sheet at the height it was left at last time,
|
|
516
|
+
on the way in. */
|
|
517
|
+
if (openLastRender !== open) {
|
|
518
|
+
setOpenLastRender(open);
|
|
519
|
+
if (open)
|
|
520
|
+
setStopIndex(0);
|
|
521
|
+
}
|
|
522
|
+
if (depth > 0) {
|
|
523
|
+
warnOncePerSession(`nested:${depth}`, "A <Sheet> is nested inside another <Sheet>. Two stacked modal surfaces " +
|
|
524
|
+
"produce a focus order nobody can predict and an escape key with two " +
|
|
525
|
+
"plausible meanings. Put the second task on the first sheet, or make " +
|
|
526
|
+
"it a screen.");
|
|
527
|
+
}
|
|
528
|
+
/* `typeof` first because this file ships as source into JavaScript projects,
|
|
529
|
+
where `title: string` is advice and `title.trim()` on whatever arrived is a
|
|
530
|
+
crash rather than a warning. */
|
|
531
|
+
if (typeof title !== "string" || title.trim() === "") {
|
|
532
|
+
warnOncePerSession("title:empty", "<Sheet> was given an empty `title`. It is the accessible name, and " +
|
|
533
|
+
'without it the sheet is announced as "dialog" and nothing else. There ' +
|
|
534
|
+
"is no honest default; name the task the reader came here to do.");
|
|
535
|
+
}
|
|
536
|
+
if (open && !hasContentSlot(children)) {
|
|
537
|
+
warnOncePerSession(`content:missing:${title}`, "<Sheet> has no <Sheet.Content> among its direct children. That element " +
|
|
538
|
+
"is the scroll boundary: without it nothing inside the sheet scrolls, " +
|
|
539
|
+
"and a flick meant to scroll is read as a drag and dismisses the " +
|
|
540
|
+
"sheet. This check reads direct children only, so a Sheet.Content " +
|
|
541
|
+
"wrapped in another element is invisible to it.");
|
|
542
|
+
}
|
|
543
|
+
const index = Math.min(stopIndex, stops.length - 1);
|
|
544
|
+
const canChangeDetent = stops.length > 1;
|
|
545
|
+
/* The height the grabber moves to on the next press. Its accessible name is
|
|
546
|
+
built from this, not from the current height, so the name says what the
|
|
547
|
+
button does. */
|
|
548
|
+
const nextStop = stops[(index + 1) % stops.length];
|
|
549
|
+
return (_jsx(SheetDepth.Provider, { value: depth + 1, children: _jsx(SheetTitleId.Provider, { value: titleId, children: _jsx(SheetOverflowReport.Provider, { value: setOverflowBelow, children: _jsx(Drawer.Root, { open: open, modal: modal,
|
|
550
|
+
/* INVERTED, AND THE POLARITY IS THE WHOLE PROP. Base UI's flag disables
|
|
551
|
+
dismissal; this API's enables it. Getting it the wrong way round
|
|
552
|
+
ships a form sheet that throws away what somebody typed the first
|
|
553
|
+
time their thumb lands beside it. */
|
|
554
|
+
disablePointerDismissal: !dismissible, snapPoints: snapPoints, snapPoint: snapPoints ? snapPoints[index] : undefined, onSnapPointChange: (snapPoint) => {
|
|
555
|
+
if (!snapPoints || typeof snapPoint !== "number")
|
|
556
|
+
return;
|
|
557
|
+
const next = snapPoints.indexOf(snapPoint);
|
|
558
|
+
if (next >= 0)
|
|
559
|
+
setStopIndex(next);
|
|
560
|
+
}, onOpenChange: (nextOpen, details) => {
|
|
561
|
+
const route = routeFor(details.reason);
|
|
562
|
+
if (!KNOWN_REASONS.has(details.reason)) {
|
|
563
|
+
warnOncePerSession(`reason:${details.reason}`, `Sheet received the dismissal reason "${details.reason}", which ` +
|
|
564
|
+
"is not one of the nine @base-ui/react 1.7.0 declares. It was " +
|
|
565
|
+
'reported to onOpenChange as "other" and the sheet was allowed ' +
|
|
566
|
+
"to close. If Base UI has renamed or added a reason, routeFor " +
|
|
567
|
+
"and KNOWN_REASONS in sheet.tsx are the two places to fix. See " +
|
|
568
|
+
"the note above them.");
|
|
569
|
+
}
|
|
570
|
+
/* `disablePointerDismissal` covers the pointer and nothing else. The
|
|
571
|
+
escape key and the platform's close watcher reach the primitive by
|
|
572
|
+
a different path and would close an undismissable sheet. Cancelling
|
|
573
|
+
here is the other half of the same promise.
|
|
574
|
+
|
|
575
|
+
ALLOW-LISTED, NOT DENY-LISTED. Only the three ambient routes are
|
|
576
|
+
cancelled. The close control is never cancelled, because
|
|
577
|
+
`dismissible` governs the routes a reader takes by accident and not
|
|
578
|
+
the one they take on purpose. Neither is a route this component
|
|
579
|
+
failed to recognise, because refusing to close a modal surface on
|
|
580
|
+
an unknown signal is how it becomes a trap.
|
|
581
|
+
|
|
582
|
+
AND A REFUSAL PUTS FOCUS BACK. Base UI refuses the close but does
|
|
583
|
+
not restore focus, so a refused Escape does the nothing the spec
|
|
584
|
+
defines for it and leaves the reader where they were, which is fine
|
|
585
|
+
only while they were already inside the sheet. Focusing the popup
|
|
586
|
+
re-announces the sheet's title, so a refused Escape says "still
|
|
587
|
+
here" rather than saying nothing at all. The scrim route is caught
|
|
588
|
+
on the backdrop itself instead of here, because `dismissible={false}`
|
|
589
|
+
tells the primitive to ignore the scrim pointer entirely and this
|
|
590
|
+
branch never runs for it. */
|
|
591
|
+
const ambient = route === "scrim" || route === "escape" || route === "drag";
|
|
592
|
+
if (!nextOpen && !dismissible && ambient) {
|
|
593
|
+
details.cancel();
|
|
594
|
+
popupRef.current?.focus({ preventScroll: true });
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
onOpenChange(nextOpen, route);
|
|
598
|
+
}, children: _jsx(Drawer.VirtualKeyboardProvider, { children: _jsxs(Drawer.Portal, { children: [modal ? (_jsx(Drawer.Backdrop, { "data-slot": "sheet-scrim",
|
|
599
|
+
/* On an undismissable sheet the primitive ignores the scrim
|
|
600
|
+
pointer, so onOpenChange never fires and the refusal branch
|
|
601
|
+
above never runs. The press still lands on the backdrop and
|
|
602
|
+
blurs the reader onto the document body. Preventing the
|
|
603
|
+
default on pointerdown stops the blur, and focusing the popup
|
|
604
|
+
on click puts them back inside the surface either way. Both
|
|
605
|
+
are attached only when the sheet is undismissable; a
|
|
606
|
+
dismissible sheet closes on a scrim press and wants neither. */
|
|
607
|
+
onPointerDown: dismissible
|
|
608
|
+
? undefined
|
|
609
|
+
: (event) => {
|
|
610
|
+
event.preventDefault();
|
|
611
|
+
}, onClick: dismissible
|
|
612
|
+
? undefined
|
|
613
|
+
: () => {
|
|
614
|
+
popupRef.current?.focus({ preventScroll: true });
|
|
615
|
+
}, className: cn("fixed inset-0 z-50", "transition-opacity duration-(--opsin-duration-base) ease-opsin-standard", "data-starting-style:opacity-0 data-ending-style:opacity-0",
|
|
616
|
+
/* The scrim dims by painting a tint over the page: the
|
|
617
|
+
surface-scrim layer sets background-color at a partial
|
|
618
|
+
opacity. Under `forced-colors: active` the browser
|
|
619
|
+
replaces that background-color with a system colour and
|
|
620
|
+
the dimming is gone, so the page behind would read at full
|
|
621
|
+
strength through what is meant to be a modal. Painting the
|
|
622
|
+
backdrop itself an opaque Canvas is the standard forced-
|
|
623
|
+
colours answer: it replaces the page behind with the
|
|
624
|
+
system background, which is what tells a forced-colours
|
|
625
|
+
reader that a modal has taken the screen. The panel's own
|
|
626
|
+
edge is not drawn here; it is Surface's job, answered in
|
|
627
|
+
surface.tsx where the sheet rung draws an outline that
|
|
628
|
+
forced colours keeps, so it is not duplicated on this
|
|
629
|
+
element. */
|
|
630
|
+
"forced-colors:bg-[Canvas]"), children: _jsx(Surface, { rung: "scrim", className: "size-full", children: null }) })) : null, _jsx(Drawer.Viewport, { className: cn("pointer-events-none fixed inset-0 z-50 flex items-end justify-center",
|
|
631
|
+
/* Present only while a software keyboard is up, and 0 otherwise.
|
|
632
|
+
Padding on the viewport rather than a margin on the sheet, so
|
|
633
|
+
the sheet's own max height shrinks with it and the footer is
|
|
634
|
+
pushed up instead of being covered. */
|
|
635
|
+
"pb-(--drawer-keyboard-inset,0px)"), children: _jsx(Drawer.Popup, { ref: popupRef, "data-slot": "sheet-container",
|
|
636
|
+
/* A MODAL SURFACE MAY TAKE FOCUS; A NON-MODAL ONE MAY NOT.
|
|
637
|
+
Base UI resolves initial focus without consulting `modal`.
|
|
638
|
+
The relevant line in DrawerPopup is `resolvedInitialFocus =
|
|
639
|
+
initialFocus === undefined ? popupRef : initialFocus`. Left
|
|
640
|
+
alone, a `modal={false}` sheet pulls the reader out of
|
|
641
|
+
whatever they were doing on the page it deliberately left
|
|
642
|
+
reachable. The
|
|
643
|
+
repository's focus doctrine allows a component to move focus
|
|
644
|
+
on appearance only into a modal surface, so the non-modal
|
|
645
|
+
path declines it explicitly.
|
|
646
|
+
|
|
647
|
+
`finalFocus` is deliberately NOT set alongside it. Its
|
|
648
|
+
default already returns focus only when focus was inside the
|
|
649
|
+
sheet at the moment it closed (FloatingFocusManager gates the
|
|
650
|
+
return on `isFocusInsideFloatingTree` for a boolean
|
|
651
|
+
`returnFocus`), so a non-modal sheet that never took focus
|
|
652
|
+
never gives any back, and one the reader tabbed into still
|
|
653
|
+
hands it back where they came from. */
|
|
654
|
+
initialFocus: modal ? undefined : false, className: cn("pointer-events-auto flex w-full max-h-full flex-col overflow-hidden",
|
|
655
|
+
/* Cap the reading measure above the phone. `w-full` still wins
|
|
656
|
+
below `sm`, so the phone case the file was built for is
|
|
657
|
+
untouched, and above it the sheet centres itself in the
|
|
658
|
+
viewport (Drawer.Viewport carries `justify-center`) at the
|
|
659
|
+
comfortable body measure. The literal fallback rides beside
|
|
660
|
+
the token because `@opsinjs/tokens/tokens.css` reaches a
|
|
661
|
+
page only when the app imports it, and a bare
|
|
662
|
+
custom-property read would resolve to nothing and drop the
|
|
663
|
+
cap silently. `className` stays last in this list, so a
|
|
664
|
+
product overrides the measure with one class. */
|
|
665
|
+
"sm:max-w-(--opsin-measure-comfortable,66ch)", "rounded-t-opsin-xl [corner-shape:var(--opsin-corner-shape)]", RESTING_TRANSFORM, OFFSCREEN_TRANSFORM, REDUCED_MOTION_CROSSFADE, CONTAINER_FOCUS_RING,
|
|
666
|
+
/* A sheet with snap points has to be as tall as its tallest
|
|
667
|
+
one, because a snap point is an offset from the popup's own
|
|
668
|
+
height and cannot exceed it. A content-sized sheet must NOT
|
|
669
|
+
be, or it would stop being content-sized. The snap-points
|
|
670
|
+
branch carries `SNAP_POINT_INSET`, which pads back the
|
|
671
|
+
active detent's offset so the footer and the scroll region
|
|
672
|
+
stay on screen at every detent (see the constant); it rides
|
|
673
|
+
with `h-full` because it is only meaningful once the popup
|
|
674
|
+
is full height. The branch also owns the transition on this
|
|
675
|
+
surface: it spends `SLIDE_TIMING` on a two-property
|
|
676
|
+
transition of transform and padding-bottom, and it does NOT
|
|
677
|
+
take `SLIDE`, so `transition-transform` is never on the
|
|
678
|
+
element to contest that property setter. When motion is allowed
|
|
679
|
+
the `motion-safe` override runs transform and padding-bottom
|
|
680
|
+
together on the sheet spring, so the footer rides up on
|
|
681
|
+
expand; under reduced motion that override is inert and
|
|
682
|
+
`REDUCED_MOTION_CROSSFADE` puts the transition on opacity
|
|
683
|
+
with nothing on this branch to contest it, so the inset
|
|
684
|
+
settles instantly. Because `motion-safe` and `motion-reduce`
|
|
685
|
+
never both match and this branch names no other
|
|
686
|
+
transition-property, which property transitions is fixed by
|
|
687
|
+
the media query rather than by source order. The one-detent
|
|
688
|
+
case takes `SLIDE` instead, which is `transition-transform`
|
|
689
|
+
on the same timing. */
|
|
690
|
+
snapPoints
|
|
691
|
+
? cn("h-full", SNAP_POINT_INSET, SLIDE_TIMING, "motion-safe:[transition-property:transform,padding-bottom]")
|
|
692
|
+
: SLIDE, className), children: _jsxs(Surface, { rung: "sheet", className: cn(SURFACE_LAYOUT, "rounded-[inherit]",
|
|
693
|
+
/* Safe-area insets as padding INSIDE the surface, never as
|
|
694
|
+
a margin outside it: the material has to reach the edge
|
|
695
|
+
of the display, and only the content has to stay clear of
|
|
696
|
+
the notch and the home indicator. */
|
|
697
|
+
"pb-(--opsin-safe-bottom) pl-(--opsin-safe-left) pr-(--opsin-safe-right)"), children: [canChangeDetent ? (
|
|
698
|
+
/* THE GESTURE'S CONTROL, not an ornament. Drag-between-
|
|
699
|
+
detents does not exist for a keyboard user, a switch
|
|
700
|
+
user, or anybody whose grip makes a precise drag
|
|
701
|
+
unreliable, and the page's rule is that every gesture
|
|
702
|
+
has one. The grabber is the control: the same bar, at a
|
|
703
|
+
44pt target, that says in words how tall the sheet is.
|
|
704
|
+
The wrapper exists to centre it; see the width note
|
|
705
|
+
below for why it is not the whole row. */
|
|
706
|
+
_jsx("div", { className: "flex shrink-0 items-center justify-center", children: _jsxs("button", { type: "button", "data-slot": "sheet-grabber",
|
|
707
|
+
/* NAMES WHAT THE PRESS DOES, NOT THE CURRENT HEIGHT,
|
|
708
|
+
which is what a button's name is for. With more than
|
|
709
|
+
one detent the list is always exactly half and full,
|
|
710
|
+
because `content` cannot be combined with either, so
|
|
711
|
+
naming the destination states the current height by
|
|
712
|
+
implication: a button that offers to make the sheet
|
|
713
|
+
full is a sheet that is half now.
|
|
714
|
+
|
|
715
|
+
No `aria-expanded`, and its absence is the finding.
|
|
716
|
+
A half-screen sheet announced as `collapsed` applies
|
|
717
|
+
the disclosure vocabulary to something that is not a
|
|
718
|
+
disclosure, and it describes the current height a
|
|
719
|
+
second time in a word that does not fit it. What is
|
|
720
|
+
still true and unanswered: nothing announces the new
|
|
721
|
+
height after the press, because the component mounts
|
|
722
|
+
no live region on purpose, so the name the reader
|
|
723
|
+
re-reads on the control they are still focused on is
|
|
724
|
+
the only confirmation they get. */
|
|
725
|
+
onClick: () => setStopIndex((current) => (current + 1) % stops.length), className: cn("flex min-h-(--opsin-target-minimum,2.75rem) shrink-0 items-center justify-center",
|
|
726
|
+
/* NOT `w-full`, and the width is a target-separation
|
|
727
|
+
fix. A full-width 44pt band sits directly above the
|
|
728
|
+
header, whose `pt-opsin-2` is exactly
|
|
729
|
+
`--opsin-target-separation` and no more, so a miss
|
|
730
|
+
on Close landed on the grabber and resized the
|
|
731
|
+
sheet instead of leaving it. The reader whose grip
|
|
732
|
+
makes precision unreliable is exactly the reader
|
|
733
|
+
this button exists for. Centred and only as wide as
|
|
734
|
+
it needs to be, it is nowhere near the close
|
|
735
|
+
control, which sits at the opposite end of the row
|
|
736
|
+
below. Dragging is unaffected: Base UI reads the
|
|
737
|
+
drag off the popup, not off this element. */
|
|
738
|
+
"px-opsin-8", FOCUS_RING), children: [_jsx("span", { "aria-hidden": "true", className: "h-opsin-1 w-opsin-10 rounded-full bg-muted-foreground" }), _jsxs("span", { className: "sr-only", children: ["Make the sheet ", DETENT_WORD[nextStop]] })] }) })) : (
|
|
739
|
+
/* One detent, so there is nothing to move between and the
|
|
740
|
+
bar is decorative. It stays because it is what tells a
|
|
741
|
+
reader the sheet can be pulled down at all. The control
|
|
742
|
+
for THAT gesture is the close button below, which is why
|
|
743
|
+
it is never optional. */
|
|
744
|
+
_jsx("div", { "data-slot": "sheet-grabber", "aria-hidden": "true", className: "flex shrink-0 items-center justify-center pt-opsin-2 pb-opsin-1", children: _jsx("span", { className: "h-opsin-1 w-opsin-10 rounded-full bg-muted-foreground" }) })), _jsxs("div", { "data-slot": "sheet-header", className: "flex shrink-0 items-start justify-between gap-opsin-4 px-opsin-5 pt-opsin-2 pb-opsin-2", children: [_jsx(Drawer.Title, { id: titleId, "data-slot": "sheet-title",
|
|
745
|
+
/* Two jobs in this class list. `min-w-0 break-words` is
|
|
746
|
+
not decoration: the popup is `overflow-hidden` for the
|
|
747
|
+
top corner radius and this is a flex item, whose
|
|
748
|
+
default `min-width: auto` refuses to shrink below its
|
|
749
|
+
min-content width. So at 200% root font size a single
|
|
750
|
+
long token (a compound word, a medication name) pushed
|
|
751
|
+
past the available inline size and was clipped with no
|
|
752
|
+
scrollbar, which WCAG 1.4.4 counts as loss of content.
|
|
753
|
+
The close control's `shrink-0` is correct and stays.
|
|
754
|
+
|
|
755
|
+
`flex min-h-(--opsin-target-minimum,2.75rem)
|
|
756
|
+
items-center` centres a single-line title against the
|
|
757
|
+
close control, which is 44px tall with its text
|
|
758
|
+
centred, so the two no longer sit on two baselines
|
|
759
|
+
about 9px apart. The header keeps `items-start` so a
|
|
760
|
+
title that wraps at 200% text still grows the box
|
|
761
|
+
downward from the same top edge with Close beside its
|
|
762
|
+
first line, which is what `items-start` was there for.
|
|
763
|
+
The `2.75rem` fallback rides inside the var() for the
|
|
764
|
+
reason dialog.tsx and field.tsx spell out: the token
|
|
765
|
+
sheet reaches a page only when the app imports it, and
|
|
766
|
+
a bare reference to an undeclared property is invalid
|
|
767
|
+
at computed-value time, so `min-height` would
|
|
768
|
+
revert to `auto` and the centring would silently vanish.
|
|
769
|
+
`flex` makes the title's text a single anonymous flex
|
|
770
|
+
item, which is harmless for a string; a title carrying
|
|
771
|
+
rich children is not a supported shape, because
|
|
772
|
+
SheetProps.title is typed `string`. */
|
|
773
|
+
className: "m-0 flex min-h-(--opsin-target-minimum,2.75rem) min-w-0 items-center break-words text-opsin-title3", children: title }), _jsxs(Drawer.Close, { "data-slot": "sheet-close",
|
|
774
|
+
/* JOINED, NOT MERGED, and the join is the fix rather
|
|
775
|
+
than a style. `cn` is `twMerge(clsx(…))` and
|
|
776
|
+
tailwind-merge is unconfigured: it has never been told
|
|
777
|
+
that `--text-opsin-*` is a font-size namespace, so it
|
|
778
|
+
files `text-opsin-callout` and `text-foreground` in the
|
|
779
|
+
SAME conflict group and keeps only the later one. That
|
|
780
|
+
silently cost this control its type step, its leading
|
|
781
|
+
and its tracking, verified against the pinned
|
|
782
|
+
tailwind-merge. The two utilities set different CSS
|
|
783
|
+
properties, so passing both through applies both.
|
|
784
|
+
`score-dial.tsx` keeps `LABEL_ROW` and `STATUS_ROW`
|
|
785
|
+
whole for exactly this reason and says so; there is no
|
|
786
|
+
caller `className` on this control, so nothing is lost
|
|
787
|
+
by not merging. The real repair belongs in
|
|
788
|
+
`../utils.ts` and is reported upward.
|
|
789
|
+
|
|
790
|
+
THE STEP AND THE ROLE READ AS A CONTROL, NOT AS
|
|
791
|
+
PROVENANCE. This is the only guaranteed exit from a
|
|
792
|
+
form sheet, the one route `dismissible={false}` never
|
|
793
|
+
removes, so an anxious reader must be able to find it
|
|
794
|
+
at a glance. It is set at the `callout` step in the
|
|
795
|
+
full `foreground` role rather than at `footnote` in a
|
|
796
|
+
muted grey, whose declared use is provenance and which
|
|
797
|
+
made this word the smallest, lowest-contrast thing on
|
|
798
|
+
the surface. `callout` (16px) rather than `headline`
|
|
799
|
+
because `headline` is Button's step and the close
|
|
800
|
+
control must stay quieter than the footer's primary
|
|
801
|
+
action; the hover feedback is a `muted` background
|
|
802
|
+
rather than an ink change, since the ink is already the
|
|
803
|
+
foreground. Keep it quieter than the footer action and
|
|
804
|
+
do not raise it to Button's step.
|
|
805
|
+
|
|
806
|
+
IT SINKS WHEN PRESSED, the press Button carries (ADR
|
|
807
|
+
0031): down to 0.97 on pointer-down over
|
|
808
|
+
`duration-instant`, back on `spring-snap`. Hover alone
|
|
809
|
+
gave a touch reader nothing, and on the one exit a form
|
|
810
|
+
sheet guarantees, a tap that shows no change reads as a
|
|
811
|
+
tap that missed. The fill rides the same timing, and
|
|
812
|
+
under reduced motion both collapse to one frame. */
|
|
813
|
+
className: "inline-flex min-h-(--opsin-target-minimum,2.75rem) shrink-0 items-center gap-opsin-1 " +
|
|
814
|
+
"rounded-opsin-sm px-opsin-2 text-opsin-callout text-foreground " +
|
|
815
|
+
"transition-[color,background-color,scale] duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
|
|
816
|
+
"active:scale-97 active:duration-(--opsin-duration-instant) active:ease-opsin-standard " +
|
|
817
|
+
"hover:bg-muted active:bg-muted " +
|
|
818
|
+
FOCUS_RING, children: [_jsx(X, { "aria-hidden": "true", className: "size-[1em] shrink-0" }), "Close"] })] }), children, footer ? (_jsx("div", { "data-slot": "sheet-footer", "data-overflow": overflowBelow ? "below" : undefined, className: cn("flex shrink-0 flex-wrap items-center gap-opsin-2 border-t border-edge px-opsin-5 pt-opsin-3 pb-opsin-3", overflowBelow
|
|
819
|
+
? "shadow-(--opsin-material-sheet-shadow)"
|
|
820
|
+
: null), children: footer })) : null] }) }) })] }) }) }) }) }) }));
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* The scrolling region, and the one part of a Sheet that is a real export.
|
|
824
|
+
*
|
|
825
|
+
* It is an export because the consumer supplies its content and no prop could
|
|
826
|
+
* carry it: a sheet may hold something above or below the scrolling area, and
|
|
827
|
+
* only the caller knows which of the things they are putting in should move
|
|
828
|
+
* when the rest does.
|
|
829
|
+
*
|
|
830
|
+
* It is also the element Base UI looks for. `Drawer.Content` stamps
|
|
831
|
+
* `data-drawer-content`, and the drawer's own pointer handling treats a touch
|
|
832
|
+
* that begins inside it as a scroll rather than a swipe. That is what stops a
|
|
833
|
+
* flick at the top of a scrolled list from dismissing the sheet, and it is why
|
|
834
|
+
* `overscroll-contain` sits beside it: one stops the sheet from being dragged,
|
|
835
|
+
* the other stops the page behind from being scrolled.
|
|
836
|
+
*
|
|
837
|
+
* IT IS A FOCUS STOP, DELIBERATELY AND UNCONDITIONALLY. A scroll container that
|
|
838
|
+
* holds nothing focusable can only be reached and scrolled from the keyboard
|
|
839
|
+
* where the browser decides to make scrollers focusable on its own. That is
|
|
840
|
+
* Chrome and Edge from 127, and not Safari or Firefox. This system's readers
|
|
841
|
+
* are on Safari, and a sheet holding a long list of things nobody can reach
|
|
842
|
+
* with the keyboard is a WCAG 2.1.1 failure whatever the page says about arrow
|
|
843
|
+
* keys. `tabIndex={0}` makes it the same stop in every engine.
|
|
844
|
+
*
|
|
845
|
+
* Unconditional, and the alternative was worse. Measuring whether the content
|
|
846
|
+
* actually overflows would mean measuring layout in JavaScript on every render
|
|
847
|
+
* and every resize, and a tab stop that appears and disappears as the content
|
|
848
|
+
* changes is harder to learn than one that is always there. The cost is one
|
|
849
|
+
* extra stop in a sheet whose content fits.
|
|
850
|
+
*
|
|
851
|
+
* `role="group"` with the sheet's own name, because a nameless stop is a stop a
|
|
852
|
+
* screen-reader user arrives at without being told what it is or why focus
|
|
853
|
+
* paused there. The name is the title the product already wrote, which
|
|
854
|
+
* `SheetTitleId` carries, so nothing here needs translating. The role is
|
|
855
|
+
* dropped entirely rather than pointed at a missing id when there is no Sheet
|
|
856
|
+
* above it.
|
|
857
|
+
*/
|
|
858
|
+
export function SheetContent({ children, className }) {
|
|
859
|
+
const titleId = useContext(SheetTitleId);
|
|
860
|
+
const reportOverflow = useContext(SheetOverflowReport);
|
|
861
|
+
/* A one-pixel marker at the very end of the scroller. When it is inside the
|
|
862
|
+
scroller's own viewport the reader has reached the bottom; when it is not,
|
|
863
|
+
text runs on below the fold. It is `h-px` and not `h-0` on purpose: a
|
|
864
|
+
zero-area target has an intersectionRatio of 0 by spec and engines have
|
|
865
|
+
disagreed on whether `isIntersecting` holds for one, so a box with no
|
|
866
|
+
height risks reporting "more below" on a sheet that already fits. One pixel
|
|
867
|
+
inside a region that already carries `py-opsin-2` is invisible and removes
|
|
868
|
+
the zero-area case. An IntersectionObserver rooted at the scroller watches
|
|
869
|
+
it, so the work happens when the browser composites and never in the render
|
|
870
|
+
path: reading `scrollHeight` on every render would be layout work that does
|
|
871
|
+
not even re-run when the content changes height on its own. */
|
|
872
|
+
const sentinelRef = useRef(null);
|
|
873
|
+
useEffect(() => {
|
|
874
|
+
const sentinel = sentinelRef.current;
|
|
875
|
+
if (!reportOverflow || !sentinel)
|
|
876
|
+
return;
|
|
877
|
+
if (typeof IntersectionObserver === "undefined")
|
|
878
|
+
return;
|
|
879
|
+
const scroller = sentinel.closest('[data-slot="sheet-content"]');
|
|
880
|
+
if (!scroller)
|
|
881
|
+
return;
|
|
882
|
+
const observer = new IntersectionObserver((entries) => {
|
|
883
|
+
const entry = entries[0];
|
|
884
|
+
if (entry)
|
|
885
|
+
reportOverflow(!entry.isIntersecting);
|
|
886
|
+
},
|
|
887
|
+
/* Only `root` is set. The observer's intersection ratio is left at its
|
|
888
|
+
own default, which fires the callback the moment the sentinel enters or
|
|
889
|
+
leaves the scroller's box, and that is exactly the edge we want. The
|
|
890
|
+
option that would name that ratio is a fixed key in the browser's
|
|
891
|
+
IntersectionObserver init dictionary and is not a clinical boundary, so
|
|
892
|
+
spelling it as a literal here only teaches the a11y gate that opsinjs is
|
|
893
|
+
deciding something about a reading, which it is not. Leaving it unspelled
|
|
894
|
+
says the same thing to the browser and nothing false to the gate. */
|
|
895
|
+
{ root: scroller });
|
|
896
|
+
observer.observe(sentinel);
|
|
897
|
+
return () => {
|
|
898
|
+
observer.disconnect();
|
|
899
|
+
/* On unmount the scroller is gone, so there is no "below" to report; clear
|
|
900
|
+
it or the footer keeps a scroll edge for a sheet that has closed. */
|
|
901
|
+
reportOverflow(false);
|
|
902
|
+
};
|
|
903
|
+
}, [reportOverflow]);
|
|
904
|
+
return (_jsxs(Drawer.Content, { "data-slot": "sheet-content", tabIndex: 0, role: titleId ? "group" : undefined, "aria-labelledby": titleId, className: cn("min-h-0 flex-auto overflow-y-auto overscroll-contain px-opsin-5 py-opsin-2",
|
|
905
|
+
/* An INSET ring on this one region. It shares FOCUS_RING's width and
|
|
906
|
+
colour with every other ring in the file, but turns the offset
|
|
907
|
+
inward: `focus-visible:-outline-offset-2` comes after FOCUS_RING so
|
|
908
|
+
the later utility wins on the offset alone. The popup is
|
|
909
|
+
`overflow-hidden` for the sake of its top corner radius, and this
|
|
910
|
+
region spans the full width of the Surface with no horizontal inset,
|
|
911
|
+
so a positive offset puts the left and right edges of the ring
|
|
912
|
+
outside the clip and only the top and bottom lines paint. That would
|
|
913
|
+
leave the one mandatory tab stop with no visible control of its own
|
|
914
|
+
showing two horizontal lines instead of a ring. The negative offset
|
|
915
|
+
is the fix rather than dropping the clip, because the clip is what
|
|
916
|
+
the top corner radius depends on. Do not fork a second FOCUS_RING or
|
|
917
|
+
change FOCUS_RING itself: the grabber, the close control and the
|
|
918
|
+
popup all want the outset form and only this edge-to-edge element
|
|
919
|
+
does not. */
|
|
920
|
+
FOCUS_RING, "focus-visible:-outline-offset-2", className), children: [children, _jsx("div", { ref: sentinelRef, "aria-hidden": "true", className: "h-px shrink-0" })] }));
|
|
921
|
+
}
|
|
922
|
+
/* Assigned after the declaration, never `Object.assign`: the assignment keeps
|
|
923
|
+
`Sheet.Content` and `SheetContent` the same function, and the declaration
|
|
924
|
+
keeps the name in a stack trace. */
|
|
925
|
+
Sheet.Content = SheetContent;
|
|
926
|
+
/**
|
|
927
|
+
* The sheet's description, and the sentence a reader must weigh before they
|
|
928
|
+
* answer.
|
|
929
|
+
*
|
|
930
|
+
* It is a compound part rather than a prop, because only the caller knows which
|
|
931
|
+
* of the paragraphs they are putting in is the description. `Drawer.Description`
|
|
932
|
+
* renders a `<p>` and registers its id with the drawer store, so the popup
|
|
933
|
+
* gains `aria-describedby` pointing here with no id plumbing in this file, the
|
|
934
|
+
* way the title already gains `aria-labelledby` through `Drawer.Title`. That is
|
|
935
|
+
* the gap this part closes: before it, the sheet named itself and described
|
|
936
|
+
* nothing, so the scope or purpose a reader must weigh was on screen but not
|
|
937
|
+
* tied to the dialog by aria.
|
|
938
|
+
*
|
|
939
|
+
* It is rendered visibly and is never a hidden string. The consequence of an
|
|
940
|
+
* answer is not something to hide from a reader who is not on a screen reader,
|
|
941
|
+
* and a description held only in an attribute is one the sighted reader never
|
|
942
|
+
* sees. There is at most one. A form sheet that has no such sentence renders
|
|
943
|
+
* none rather than being handed an empty one, because a description that points
|
|
944
|
+
* at no text is worse than the absence it papers over.
|
|
945
|
+
*/
|
|
946
|
+
export function SheetDescription({ children, className }) {
|
|
947
|
+
return (_jsx(Drawer.Description, { "data-slot": "sheet-description", className: cn("m-0", className), children: children }));
|
|
948
|
+
}
|
|
949
|
+
/* Assigned after the declaration, never `Object.assign`, for the reason the
|
|
950
|
+
comment above `Sheet.Content` gives. */
|
|
951
|
+
Sheet.Description = SheetDescription;
|
|
952
|
+
//# sourceMappingURL=sheet.js.map
|