@astryxdesign/core 0.4.3 → 0.4.4-canary.0f4d45f
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 +60 -0
- package/README.md +79 -45
- package/dist/Banner/Banner.d.ts +3 -0
- package/dist/Banner/Banner.d.ts.map +1 -1
- package/dist/Banner/Banner.js +13 -3
- package/dist/BottomSheet/BottomSheet.d.ts +66 -0
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheet.js +392 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts +60 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetPanel.js +398 -0
- package/dist/BottomSheet/BottomSheetSwitcher.d.ts +61 -0
- package/dist/BottomSheet/BottomSheetSwitcher.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetSwitcher.js +410 -0
- package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts +21 -0
- package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetSwitcherContext.js +13 -0
- package/dist/BottomSheet/index.d.ts +11 -0
- package/dist/BottomSheet/index.d.ts.map +1 -0
- package/dist/BottomSheet/index.js +12 -0
- package/dist/BottomSheet/snapOffsets.d.ts +72 -0
- package/dist/BottomSheet/snapOffsets.d.ts.map +1 -0
- package/dist/BottomSheet/snapOffsets.js +130 -0
- package/dist/BottomSheet/useMobileKeyboard.d.ts +35 -0
- package/dist/BottomSheet/useMobileKeyboard.d.ts.map +1 -0
- package/dist/BottomSheet/useMobileKeyboard.js +373 -0
- package/dist/BottomSheet/useSheetGestures.d.ts +180 -0
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -0
- package/dist/BottomSheet/useSheetGestures.js +989 -0
- package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
- package/dist/Chat/ChatComposerInput.js +3 -4
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +12 -6
- package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
- package/dist/ContextMenu/ContextMenu.js +4 -2
- package/dist/DateInput/DateInput.d.ts.map +1 -1
- package/dist/DateInput/DateInput.js +9 -1
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +31 -1
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +2 -1
- package/dist/Field/InputClearButton.d.ts +2 -1
- package/dist/Field/InputClearButton.d.ts.map +1 -1
- package/dist/Field/InputClearButton.js +6 -1
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +9 -3
- package/dist/MobileNav/MobileNav.d.ts +12 -0
- package/dist/MobileNav/MobileNav.d.ts.map +1 -1
- package/dist/MobileNav/MobileNav.js +102 -30
- package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
- package/dist/MultiSelector/MultiSelector.js +21 -7
- package/dist/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/NumberInput/NumberInput.js +9 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +1 -1
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +14 -3
- package/dist/StatusDot/StatusDot.d.ts +43 -3
- package/dist/StatusDot/StatusDot.d.ts.map +1 -1
- package/dist/StatusDot/StatusDot.js +42 -5
- package/dist/Switch/Switch.d.ts.map +1 -1
- package/dist/Switch/Switch.js +5 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +7 -2
- package/dist/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/TimeInput/TimeInput.js +8 -1
- package/dist/Tokenizer/Tokenizer.js +11 -5
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +4 -1
- package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
- package/dist/Typeahead/BaseTypeahead.js +5 -3
- package/dist/Typeahead/Typeahead.d.ts.map +1 -1
- package/dist/Typeahead/Typeahead.js +10 -1
- package/dist/astryx.css +21 -0
- package/dist/hooks/index.d.ts +8 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +8 -1
- package/dist/hooks/useFocusTrap.d.ts +0 -11
- package/dist/hooks/useFocusTrap.d.ts.map +1 -1
- package/dist/hooks/useFocusTrap.js +1 -11
- package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
- package/dist/hooks/useInputStatusIcon.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/theme/defineTheme.d.ts +22 -4
- package/dist/theme/defineTheme.d.ts.map +1 -1
- package/dist/theme/expandColorScale.d.ts +17 -2
- package/dist/theme/expandColorScale.d.ts.map +1 -1
- package/dist/theme/expandColorScale.js +63 -33
- package/dist/utils/ime.d.ts +5 -0
- package/dist/utils/ime.d.ts.map +1 -0
- package/dist/utils/ime.js +63 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/locales/af-ZA.json +958 -0
- package/locales/ar-SA.json +998 -0
- package/locales/ca-ES.json +974 -0
- package/locales/cs-CZ.json +990 -0
- package/locales/da-DK.json +966 -0
- package/locales/de-DE.json +966 -0
- package/locales/el-GR.json +990 -0
- package/locales/en.json +48 -0
- package/locales/es-ES.json +978 -0
- package/locales/fi-FI.json +990 -0
- package/locales/fr-FR.json +928 -0
- package/locales/he-IL.json +990 -0
- package/locales/hu-HU.json +990 -0
- package/locales/it-IT.json +978 -0
- package/locales/ja-JP.json +998 -0
- package/locales/ko-KR.json +990 -0
- package/locales/nl-NL.json +954 -0
- package/locales/no-NO.json +978 -0
- package/locales/pl-PL.json +982 -0
- package/locales/pseudo.json +36 -0
- package/locales/pt-BR.json +982 -0
- package/locales/pt-PT.json +982 -0
- package/locales/ro-RO.json +982 -0
- package/locales/ru-RU.json +990 -0
- package/locales/sr-SP.json +990 -0
- package/locales/sv-SE.json +986 -0
- package/locales/tr-TR.json +990 -0
- package/locales/uk-UA.json +990 -0
- package/locales/vi-VN.json +986 -0
- package/locales/zh-CN.json +998 -0
- package/locales/zh-TW.json +998 -0
- package/package.json +9 -8
- package/src/Banner/Banner.doc.mjs +3 -3
- package/src/Banner/Banner.test.tsx +40 -0
- package/src/Banner/Banner.tsx +27 -2
- package/src/BottomSheet/BottomSheet.doc.mjs +266 -0
- package/src/BottomSheet/BottomSheet.test.tsx +2114 -0
- package/src/BottomSheet/BottomSheet.tsx +545 -0
- package/src/BottomSheet/BottomSheetPanel.test.tsx +240 -0
- package/src/BottomSheet/BottomSheetPanel.tsx +547 -0
- package/src/BottomSheet/BottomSheetSwitcher.doc.mjs +219 -0
- package/src/BottomSheet/BottomSheetSwitcher.test.tsx +850 -0
- package/src/BottomSheet/BottomSheetSwitcher.tsx +628 -0
- package/src/BottomSheet/BottomSheetSwitcherContext.ts +51 -0
- package/src/BottomSheet/index.ts +15 -0
- package/src/BottomSheet/snapOffsets.test.ts +187 -0
- package/src/BottomSheet/snapOffsets.ts +159 -0
- package/src/BottomSheet/useMobileKeyboard.ts +499 -0
- package/src/BottomSheet/useSheetGestures.test.ts +1059 -0
- package/src/BottomSheet/useSheetGestures.ts +1459 -0
- package/src/Chat/ChatComposerInput.tsx +3 -4
- package/src/ComplexSelector/ComplexSelector.tsx +12 -5
- package/src/ContextMenu/ContextMenu.tsx +4 -2
- package/src/DateInput/DateInput.test.tsx +21 -0
- package/src/DateInput/DateInput.tsx +9 -1
- package/src/DateTimeInput/DateTimeInput.doc.mjs +4 -0
- package/src/DateTimeInput/DateTimeInput.test.tsx +137 -0
- package/src/DateTimeInput/DateTimeInput.tsx +39 -2
- package/src/Dialog/Dialog.tsx +2 -1
- package/src/Field/Field.doc.mjs +1 -0
- package/src/Field/InputClearButton.test.tsx +25 -0
- package/src/Field/InputClearButton.tsx +4 -1
- package/src/FileInput/FileInput.test.tsx +53 -9
- package/src/Lightbox/Lightbox.test.tsx +49 -28
- package/src/Lightbox/Lightbox.tsx +7 -3
- package/src/MobileNav/MobileNav.tsx +128 -37
- package/src/MobileNav/MobileNavCloseEdgeCases.test.tsx +426 -0
- package/src/MobileNav/MobileNavCloseTiming.test.ts +58 -0
- package/src/MobileNav/MobileNavCloseVisibility.test.tsx +172 -0
- package/src/MultiSelector/MultiSelector.test.tsx +195 -51
- package/src/MultiSelector/MultiSelector.tsx +22 -8
- package/src/NumberInput/NumberInput.test.tsx +18 -0
- package/src/NumberInput/NumberInput.tsx +9 -1
- package/src/PowerSearch/PowerSearchEditPopover.tsx +1 -1
- package/src/Selector/Selector.test.tsx +85 -26
- package/src/Selector/Selector.tsx +13 -4
- package/src/StatusDot/StatusDot.doc.mjs +13 -0
- package/src/StatusDot/StatusDot.test.tsx +115 -8
- package/src/StatusDot/StatusDot.tsx +74 -9
- package/src/Switch/Switch.test.tsx +16 -0
- package/src/Switch/Switch.tsx +7 -0
- package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +20 -2
- package/src/TimeInput/TimeInput.test.tsx +23 -0
- package/src/TimeInput/TimeInput.tsx +8 -0
- package/src/Tokenizer/Tokenizer.test.tsx +50 -32
- package/src/Tokenizer/Tokenizer.tsx +5 -5
- package/src/Tooltip/useTooltip.tsx +4 -1
- package/src/Typeahead/BaseTypeahead.tsx +10 -3
- package/src/Typeahead/Typeahead.test.tsx +116 -7
- package/src/Typeahead/Typeahead.tsx +10 -1
- package/src/__tests__/stubMatchMedia.test.ts +79 -0
- package/src/__tests__/stubMatchMedia.ts +95 -0
- package/src/hooks/index.ts +9 -5
- package/src/hooks/useFocusTrap.ts +1 -14
- package/src/hooks/useInputStatusIcon.test.tsx +19 -0
- package/src/hooks/useInputStatusIcon.tsx +7 -0
- package/src/index.ts +1 -0
- package/src/theme/defineTheme.ts +22 -4
- package/src/theme/expandColorScale.test.ts +138 -0
- package/src/theme/expandColorScale.ts +89 -44
- package/src/utils/ime.test.ts +32 -0
- package/src/utils/ime.ts +69 -0
- package/src/utils/index.ts +2 -0
- package/dist/astryx.umd.js +0 -147
- package/dist/astryx.umd.js.map +0 -7
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file BottomSheetPanel.tsx
|
|
7
|
+
* @input Uses React, StyleX, theme tokens, useSheetGestures
|
|
8
|
+
* @output Internal BottomSheetPanel surface and motion-state types
|
|
9
|
+
* @position Shared presentation layer for standalone and switcher BottomSheets
|
|
10
|
+
*
|
|
11
|
+
* This component owns everything intrinsic to a sheet surface: height budgets,
|
|
12
|
+
* drag and snap gestures, the handle and scrolling body, motion styles, and
|
|
13
|
+
* transition completion. It deliberately does not own a dialog, focus, inert
|
|
14
|
+
* state, or switcher registration; those belong to the hosting controller.
|
|
15
|
+
*
|
|
16
|
+
* SYNC: When modified, update these files to stay in sync:
|
|
17
|
+
* - /packages/core/src/BottomSheet/BottomSheet.tsx
|
|
18
|
+
* - /packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
|
|
19
|
+
* - /packages/core/src/BottomSheet/useMobileKeyboard.ts
|
|
20
|
+
* - /packages/core/src/BottomSheet/useSheetGestures.ts
|
|
21
|
+
*/
|
|
22
|
+
import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef } from 'react';
|
|
23
|
+
import * as stylex from '@stylexjs/stylex';
|
|
24
|
+
import "../theme/tokens.stylex.js";
|
|
25
|
+
import { colorVars, durationVars, easeVars, radiusVars, shadowVars, sizeVars, spacingVars } from "../theme/tokens.stylex.js";
|
|
26
|
+
import { mergeProps, themeProps } from "../utils/index.js";
|
|
27
|
+
import { useMobileKeyboard } from "./useMobileKeyboard.js";
|
|
28
|
+
import { useSheetGestures } from "./useSheetGestures.js";
|
|
29
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
30
|
+
const SNAP_FRACTIONS = [0.14, 0.5, 0.92];
|
|
31
|
+
const HEIGHT_BUDGETS = {
|
|
32
|
+
hug: '92dvh',
|
|
33
|
+
capped: '62dvh',
|
|
34
|
+
tall: '92dvh'
|
|
35
|
+
};
|
|
36
|
+
// SYNC: must match OVERSCROLL_MAX in useSheetGestures.ts.
|
|
37
|
+
const OVERSCROLL_PADDING = 48;
|
|
38
|
+
const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
|
|
39
|
+
const TRANSITION_BACKSTOP_BUFFER_MS = 50;
|
|
40
|
+
function defaultSnapHeights() {
|
|
41
|
+
if (typeof window === 'undefined') {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
// Measure the same viewport the height budgets are written against. Those
|
|
45
|
+
// are `dvh`, which the virtual keyboard does not shrink, so reading
|
|
46
|
+
// `visualViewport` here made the two disagree by exactly the keyboard's
|
|
47
|
+
// height: every detent moved while the sheet it was measuring did not. A
|
|
48
|
+
// keyboard is `useMobileKeyboard`'s business — it holds the sheet still and
|
|
49
|
+
// scrolls the body — and it does not redefine the sheet's detents.
|
|
50
|
+
return SNAP_FRACTIONS.map(fraction => fraction * window.innerHeight);
|
|
51
|
+
}
|
|
52
|
+
const styles = {
|
|
53
|
+
sheet: {
|
|
54
|
+
kfzvcC: "x67bb7w",
|
|
55
|
+
kB7OPa: "x9f619",
|
|
56
|
+
k1xSpc: "x78zum5",
|
|
57
|
+
kXwgrk: "xdt5ytf",
|
|
58
|
+
kAzted: "x2lwn1j",
|
|
59
|
+
kzqmXN: "xh8yej3",
|
|
60
|
+
ks0D6T: "x11gisft",
|
|
61
|
+
kWkggS: "x10xzikg",
|
|
62
|
+
krdFHd: "x81l70g",
|
|
63
|
+
kfmiAY: "x7hs6f1",
|
|
64
|
+
kGVxlE: "x1kcpxr7",
|
|
65
|
+
kI3sdo: "x1a2a7pz",
|
|
66
|
+
kVQacm: "xb3r6kr",
|
|
67
|
+
kGO01o: "x1wkw6tp",
|
|
68
|
+
k1K539: "x1if0o47",
|
|
69
|
+
k3aq6I: "xnn1q72 xhbqy3z",
|
|
70
|
+
kSiTet: "x1hc1fzr",
|
|
71
|
+
k1ekBW: "xwcsmn1",
|
|
72
|
+
kIyJzY: "x80gvsz",
|
|
73
|
+
kAMwcw: "xlr8y92",
|
|
74
|
+
k6sLGO: "x1q1rmc8",
|
|
75
|
+
k6CgDc: "xzg1mie",
|
|
76
|
+
$$css: true
|
|
77
|
+
},
|
|
78
|
+
sheetClosing: {
|
|
79
|
+
k3aq6I: "x1weeur4",
|
|
80
|
+
$$css: true
|
|
81
|
+
},
|
|
82
|
+
sheetFading: {
|
|
83
|
+
kSiTet: "xg01cxk",
|
|
84
|
+
$$css: true
|
|
85
|
+
},
|
|
86
|
+
sheetInactive: {
|
|
87
|
+
kfzvcC: "x47corl",
|
|
88
|
+
$$css: true
|
|
89
|
+
},
|
|
90
|
+
budget: {
|
|
91
|
+
kZKoxP: "x1tpcejd",
|
|
92
|
+
$$css: true
|
|
93
|
+
},
|
|
94
|
+
hugHeight: {
|
|
95
|
+
kZKoxP: "xg7h5cd",
|
|
96
|
+
kskxy: "x14bu9tk",
|
|
97
|
+
$$css: true
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
function motionForState(state) {
|
|
101
|
+
if (state.kind === 'open') {
|
|
102
|
+
return state.entering ? 'entering' : null;
|
|
103
|
+
}
|
|
104
|
+
if (state.kind === 'retained') {
|
|
105
|
+
return state.motion === 'covered' ? null : state.motion;
|
|
106
|
+
}
|
|
107
|
+
return state.kind === 'exiting' ? 'exiting' : null;
|
|
108
|
+
}
|
|
109
|
+
function waitForTransition(element, propertyName, complete) {
|
|
110
|
+
if (element == null) {
|
|
111
|
+
complete();
|
|
112
|
+
return () => {};
|
|
113
|
+
}
|
|
114
|
+
let done = false;
|
|
115
|
+
let timer = null;
|
|
116
|
+
const finish = () => {
|
|
117
|
+
if (done) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
done = true;
|
|
121
|
+
if (timer != null) {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
}
|
|
124
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
125
|
+
element.removeEventListener('transitioncancel', handleTransitionEnd);
|
|
126
|
+
complete();
|
|
127
|
+
};
|
|
128
|
+
const handleTransitionEnd = event => {
|
|
129
|
+
if (event.target === element && event.propertyName === propertyName) {
|
|
130
|
+
finish();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
element.addEventListener('transitionend', handleTransitionEnd);
|
|
134
|
+
element.addEventListener('transitioncancel', handleTransitionEnd);
|
|
135
|
+
const computedStyle = getComputedStyle(element);
|
|
136
|
+
if (element.style.transition.trim() === 'none' || computedStyle.transition.trim() === 'none') {
|
|
137
|
+
finish();
|
|
138
|
+
return () => {};
|
|
139
|
+
}
|
|
140
|
+
const properties = computedStyle.transitionProperty.split(',').map(value => value.trim());
|
|
141
|
+
const durations = computedStyle.transitionDuration.split(',').map(parseTransitionTime);
|
|
142
|
+
const delays = computedStyle.transitionDelay.split(',').map(parseTransitionTime);
|
|
143
|
+
let hasUnresolvedTiming = false;
|
|
144
|
+
const transitionMs = properties.reduce((longest, property, index) => {
|
|
145
|
+
if (property !== propertyName && property !== 'all') {
|
|
146
|
+
return longest;
|
|
147
|
+
}
|
|
148
|
+
const duration = durations[index % durations.length];
|
|
149
|
+
const delay = delays[index % delays.length];
|
|
150
|
+
if (duration == null || delay == null) {
|
|
151
|
+
hasUnresolvedTiming = true;
|
|
152
|
+
return longest;
|
|
153
|
+
}
|
|
154
|
+
return Math.max(longest, duration + delay);
|
|
155
|
+
}, 0);
|
|
156
|
+
if (hasUnresolvedTiming) {
|
|
157
|
+
// JSDOM can leave CSS variables unresolved. In that case the native event
|
|
158
|
+
// remains authoritative; choosing a fixed timeout here would make an
|
|
159
|
+
// assumption about the consumer's theme.
|
|
160
|
+
return () => {
|
|
161
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
162
|
+
element.removeEventListener('transitioncancel', handleTransitionEnd);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (transitionMs <= 0) {
|
|
166
|
+
finish();
|
|
167
|
+
return () => {};
|
|
168
|
+
}
|
|
169
|
+
timer = setTimeout(finish, transitionMs + TRANSITION_BACKSTOP_BUFFER_MS);
|
|
170
|
+
return () => {
|
|
171
|
+
if (timer != null) {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
175
|
+
element.removeEventListener('transitioncancel', handleTransitionEnd);
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function parseTransitionTime(value) {
|
|
179
|
+
const normalizedValue = value.trim();
|
|
180
|
+
if (!/^-?(?:\d+|\d*\.\d+)(?:ms|s)$/.test(normalizedValue)) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const time = Number.parseFloat(value);
|
|
184
|
+
return normalizedValue.endsWith('ms') ? time : time * 1000;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Internal visual and gesture surface shared by every BottomSheet host. */
|
|
188
|
+
export function BottomSheetPanel({
|
|
189
|
+
ref,
|
|
190
|
+
state,
|
|
191
|
+
height,
|
|
192
|
+
children,
|
|
193
|
+
className,
|
|
194
|
+
style,
|
|
195
|
+
tabIndex,
|
|
196
|
+
xstyle,
|
|
197
|
+
isSwipeDismissAllowed = true,
|
|
198
|
+
isPageScrollLocked = false,
|
|
199
|
+
onDismiss,
|
|
200
|
+
onScrimOpacity,
|
|
201
|
+
onElementChange,
|
|
202
|
+
onMotionStart,
|
|
203
|
+
onMotionComplete,
|
|
204
|
+
...props
|
|
205
|
+
}) {
|
|
206
|
+
const elementRef = useRef(null);
|
|
207
|
+
const previousStateRef = useRef(state);
|
|
208
|
+
const reactivatedEntranceRef = useRef(false);
|
|
209
|
+
const onMotionStartRef = useRef(onMotionStart);
|
|
210
|
+
const onMotionCompleteRef = useRef(onMotionComplete);
|
|
211
|
+
const startedMotionRef = useRef(null);
|
|
212
|
+
const pendingMotionCompleteRef = useRef(null);
|
|
213
|
+
const isEntering = state.kind === 'open' && state.entering;
|
|
214
|
+
const previousState = previousStateRef.current;
|
|
215
|
+
const wasEntering = previousState.kind === 'open' && previousState.entering;
|
|
216
|
+
if (isEntering && !wasEntering) {
|
|
217
|
+
reactivatedEntranceRef.current = previousState.kind === 'retained';
|
|
218
|
+
} else if (!isEntering) {
|
|
219
|
+
reactivatedEntranceRef.current = false;
|
|
220
|
+
}
|
|
221
|
+
useLayoutEffect(() => {
|
|
222
|
+
previousStateRef.current = state;
|
|
223
|
+
onMotionStartRef.current = onMotionStart;
|
|
224
|
+
onMotionCompleteRef.current = onMotionComplete;
|
|
225
|
+
}, [onMotionComplete, onMotionStart, state]);
|
|
226
|
+
const isInteractive = state.kind === 'open';
|
|
227
|
+
const isPresented = state.kind !== 'hidden';
|
|
228
|
+
const isRetained = state.kind === 'retained';
|
|
229
|
+
const isInactive = isRetained || state.kind === 'exiting';
|
|
230
|
+
const isClosing = state.kind === 'exiting';
|
|
231
|
+
const isFading = isRetained && state.motion === 'fading';
|
|
232
|
+
const alignmentOffset = isRetained ? state.alignmentOffset : 0;
|
|
233
|
+
const {
|
|
234
|
+
contentProps,
|
|
235
|
+
handleProps,
|
|
236
|
+
bodyProps,
|
|
237
|
+
bodyElementRef,
|
|
238
|
+
sheetRef,
|
|
239
|
+
dragOffset,
|
|
240
|
+
settledOffset,
|
|
241
|
+
isDragging,
|
|
242
|
+
sheetHeight,
|
|
243
|
+
scrollPreservationInset,
|
|
244
|
+
settlingLayoutOffset,
|
|
245
|
+
settledLayoutOffset,
|
|
246
|
+
completeScrollAreaSettle
|
|
247
|
+
} = useSheetGestures({
|
|
248
|
+
isOpen: isInteractive,
|
|
249
|
+
canDismiss: isSwipeDismissAllowed,
|
|
250
|
+
offscreenBlockEndInset: OVERSCROLL_PADDING,
|
|
251
|
+
onDismiss,
|
|
252
|
+
snapHeights: defaultSnapHeights,
|
|
253
|
+
onScrimOpacity
|
|
254
|
+
});
|
|
255
|
+
const setElement = useCallback(element => {
|
|
256
|
+
sheetRef(element);
|
|
257
|
+
elementRef.current = element;
|
|
258
|
+
onElementChange?.(element);
|
|
259
|
+
}, [onElementChange, sheetRef]);
|
|
260
|
+
useMobileKeyboard({
|
|
261
|
+
bodyRef: bodyElementRef,
|
|
262
|
+
bottomClearance: MOBILE_KEYBOARD_BOTTOM_CLEARANCE,
|
|
263
|
+
isEnabled: height === 'tall',
|
|
264
|
+
isFullyExpanded: settledOffset === 0,
|
|
265
|
+
isPageScrollLocked,
|
|
266
|
+
isSheetTraveling: isDragging && dragOffset !== settledOffset,
|
|
267
|
+
isOpen: isInteractive,
|
|
268
|
+
isPresented,
|
|
269
|
+
sheetRef: elementRef
|
|
270
|
+
});
|
|
271
|
+
// Keep controller registration attached to one stable host ref. React
|
|
272
|
+
// detaches an old callback ref when a consumer supplies a new identity; if
|
|
273
|
+
// that public ref were merged with setElement, an ordinary parent rerender
|
|
274
|
+
// could be mistaken for the panel unmounting and cancel a sheet handoff.
|
|
275
|
+
useImperativeHandle(ref, () => elementRef.current, []);
|
|
276
|
+
const motion = motionForState(state);
|
|
277
|
+
useLayoutEffect(() => {
|
|
278
|
+
if (motion == null) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
startedMotionRef.current = null;
|
|
282
|
+
pendingMotionCompleteRef.current = null;
|
|
283
|
+
if (motion === 'entering' && reactivatedEntranceRef.current) {
|
|
284
|
+
pendingMotionCompleteRef.current = motion;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
return waitForTransition(elementRef.current, motion === 'fading' ? 'opacity' : 'transform', () => {
|
|
288
|
+
if (startedMotionRef.current === motion) {
|
|
289
|
+
onMotionCompleteRef.current?.(motion);
|
|
290
|
+
} else {
|
|
291
|
+
pendingMotionCompleteRef.current = motion;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}, [motion]);
|
|
295
|
+
// The snap is transform-only; the layout height reconciles when it lands.
|
|
296
|
+
// waitForTransition — the same helper the motion states use — resolves that
|
|
297
|
+
// even when no `transitionend` is coming: inline or computed
|
|
298
|
+
// `transition: none`, a zero duration, and a timer backstop otherwise.
|
|
299
|
+
useLayoutEffect(() => {
|
|
300
|
+
if (settlingLayoutOffset == null) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
return waitForTransition(elementRef.current, 'transform', completeScrollAreaSettle);
|
|
304
|
+
}, [completeScrollAreaSettle, settlingLayoutOffset]);
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
if (motion == null) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
onMotionStartRef.current?.(motion);
|
|
310
|
+
startedMotionRef.current = motion;
|
|
311
|
+
if (pendingMotionCompleteRef.current === motion) {
|
|
312
|
+
pendingMotionCompleteRef.current = null;
|
|
313
|
+
onMotionCompleteRef.current?.(motion);
|
|
314
|
+
}
|
|
315
|
+
return () => {
|
|
316
|
+
if (startedMotionRef.current === motion) {
|
|
317
|
+
startedMotionRef.current = null;
|
|
318
|
+
}
|
|
319
|
+
if (pendingMotionCompleteRef.current === motion) {
|
|
320
|
+
pendingMotionCompleteRef.current = null;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}, [motion]);
|
|
324
|
+
const isNamedHeight = typeof height === 'string' && height in HEIGHT_BUDGETS;
|
|
325
|
+
const budget = isNamedHeight ? HEIGHT_BUDGETS[height] : typeof height === 'number' ? `${height}px` : height;
|
|
326
|
+
const hasMeasuredSheet = sheetHeight > 0;
|
|
327
|
+
let gestureTransform = contentProps.style.transform;
|
|
328
|
+
let resizedHeight;
|
|
329
|
+
if (hasMeasuredSheet) {
|
|
330
|
+
// The sheet's travel is split across two properties: `layoutOffset` is the
|
|
331
|
+
// part the scrolling area gives up as layout height, and the remainder is
|
|
332
|
+
// a compositor transform. Live gestures and snaps only ever move the
|
|
333
|
+
// transform — the layout height changes at rest, in one reconciling render
|
|
334
|
+
// whose visible geometry is identical (see useSheetGestures).
|
|
335
|
+
// - dragging above the base restores the full height below the viewport
|
|
336
|
+
// - a peek settles with layout 0, so it slides rather than reflowing
|
|
337
|
+
const layoutOffset = isDragging ? dragOffset < settledOffset ? 0 : settledLayoutOffset : settlingLayoutOffset ?? settledLayoutOffset;
|
|
338
|
+
const activeOffset = isDragging ? dragOffset : settledOffset;
|
|
339
|
+
const translation = activeOffset - layoutOffset;
|
|
340
|
+
|
|
341
|
+
// At layout 0 the sheet is its natural height, so leave that to CSS —
|
|
342
|
+
// `hug` sheets must stay fit-content. While the sheet is in motion it is
|
|
343
|
+
// pinned in px instead: content reflowing mid-gesture would move the
|
|
344
|
+
// surface out from under the finger, or under the snap.
|
|
345
|
+
const isTraveling = isDragging || settlingLayoutOffset != null;
|
|
346
|
+
resizedHeight = layoutOffset > 0 || isTraveling ? `${Math.max(0, sheetHeight - Math.max(0, layoutOffset))}px` : undefined;
|
|
347
|
+
gestureTransform = translation !== 0 ? `translateY(${translation}px)` : undefined;
|
|
348
|
+
}
|
|
349
|
+
const retainedTransform = alignmentOffset > 0 ? [gestureTransform, `translateY(${alignmentOffset}px)`].filter(Boolean).join(' ') : gestureTransform;
|
|
350
|
+
const gestureStyle = {
|
|
351
|
+
...contentProps.style,
|
|
352
|
+
transform: gestureTransform,
|
|
353
|
+
height: resizedHeight
|
|
354
|
+
};
|
|
355
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
356
|
+
...props,
|
|
357
|
+
ref: setElement,
|
|
358
|
+
tabIndex: tabIndex ?? -1,
|
|
359
|
+
...mergeProps(themeProps('bottom-sheet'), stylex.props(styles.sheet, height === 'hug' ? styles.hugHeight : styles.budget, isClosing && styles.sheetClosing, isFading && styles.sheetFading, isInactive && styles.sheetInactive, xstyle), className, {
|
|
360
|
+
['--_sheet-budget']: budget,
|
|
361
|
+
...(isInteractive ? gestureStyle : isRetained ? {
|
|
362
|
+
transform: retainedTransform,
|
|
363
|
+
height: resizedHeight
|
|
364
|
+
} : isClosing ? {
|
|
365
|
+
height: resizedHeight
|
|
366
|
+
} : {}),
|
|
367
|
+
...style
|
|
368
|
+
}),
|
|
369
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
370
|
+
...{
|
|
371
|
+
className: "x2lah0s x78zum5 x6s0dn4 xl56j7k x1k15mir x5ve5x3 x1jm3nie"
|
|
372
|
+
},
|
|
373
|
+
...handleProps,
|
|
374
|
+
"aria-hidden": "true",
|
|
375
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
376
|
+
...{
|
|
377
|
+
className: "x1m747yf x11c6zpc xjspbzw x1m4xfpy"
|
|
378
|
+
}
|
|
379
|
+
})
|
|
380
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
381
|
+
...mergeProps({
|
|
382
|
+
0: {
|
|
383
|
+
className: "x1iyjqo2 x2lwn1j x9f619 x1odjw0f x8du1vd xx69xxh x18d9i69"
|
|
384
|
+
},
|
|
385
|
+
1: {
|
|
386
|
+
className: "x1iyjqo2 x2lwn1j x9f619 x1odjw0f x8du1vd xx69xxh x18d9i69 xrw9175 x1s928wv xhkezso xu6fald x2q1x1w"
|
|
387
|
+
}
|
|
388
|
+
}[!!(height === 'tall') << 0], scrollPreservationInset > 0 ? {
|
|
389
|
+
style: {
|
|
390
|
+
paddingBlockEnd: `${scrollPreservationInset}px`
|
|
391
|
+
}
|
|
392
|
+
} : {}),
|
|
393
|
+
...bodyProps,
|
|
394
|
+
children: children
|
|
395
|
+
})]
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
BottomSheetPanel.displayName = 'BottomSheetPanel';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file BottomSheetSwitcher.tsx
|
|
3
|
+
* @input Uses React context, StyleX, theme tokens, focus/scroll-lock hooks, BottomSheetSwitcherContext
|
|
4
|
+
* @output Exports BottomSheetSwitcher and BottomSheetSwitcherProps
|
|
5
|
+
* @position Core switcher for mutually exclusive BottomSheet flows
|
|
6
|
+
*
|
|
7
|
+
* The switcher turns a set of declaratively nested BottomSheets into a
|
|
8
|
+
* controlled single-selection group: `activeSheet` names the one interactive
|
|
9
|
+
* child, or is null when the flow is closed. During a handoff the new sheet
|
|
10
|
+
* enters above the previous sheet. If it is shorter, the previous sheet moves
|
|
11
|
+
* down at the same time until their top edges align; otherwise it stays
|
|
12
|
+
* stationary. The previous sheet fades only after both motions complete.
|
|
13
|
+
*
|
|
14
|
+
* All child sheets render as panels inside one switcher-owned `<dialog>`. A
|
|
15
|
+
* scrim flow calls showModal() once and keeps that native top-layer dialog open
|
|
16
|
+
* across every handoff. A no-scrim flow calls show() on the same non-modal shell.
|
|
17
|
+
* This keeps one modal boundary and one native ::backdrop without a portal.
|
|
18
|
+
*
|
|
19
|
+
* SYNC: When modified, update these files to stay in sync:
|
|
20
|
+
* - /packages/core/src/BottomSheet/BottomSheet.tsx
|
|
21
|
+
* - /packages/core/src/BottomSheet/BottomSheetSwitcher.doc.mjs
|
|
22
|
+
* - /packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx
|
|
23
|
+
* - /packages/core/src/BottomSheet/index.ts
|
|
24
|
+
* - /apps/storybook/stories/BottomSheetSwitcher.stories.tsx
|
|
25
|
+
* - /packages/cli/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx
|
|
26
|
+
*/
|
|
27
|
+
import { type ReactNode, type SyntheticEvent } from 'react';
|
|
28
|
+
import type { BaseProps } from '../BaseProps';
|
|
29
|
+
export interface BottomSheetSwitcherProps extends BaseProps<HTMLDialogElement> {
|
|
30
|
+
/** Ref forwarded to the shared native dialog. */
|
|
31
|
+
ref?: React.Ref<HTMLDialogElement>;
|
|
32
|
+
/** Called when the shared native dialog receives a cancel event. */
|
|
33
|
+
onCancel?: (event: SyntheticEvent<HTMLDialogElement>) => void;
|
|
34
|
+
/**
|
|
35
|
+
* ID of the interactive BottomSheet, or null when the flow should close.
|
|
36
|
+
* Must match a nested BottomSheet's `sheetId`. The previous sheet may remain
|
|
37
|
+
* visually present and inert while the new sheet enters, moving downward at
|
|
38
|
+
* the same time if the new sheet is shorter, then fade away.
|
|
39
|
+
*/
|
|
40
|
+
activeSheet: string | null;
|
|
41
|
+
/** Called with null when the active sheet requests dismissal. */
|
|
42
|
+
onActiveSheetChange: (sheetId: string | null) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Whether to open the shared dialog modally with its native ::backdrop.
|
|
45
|
+
* Disable for a viewport-anchored, non-modal flow over an interactive page.
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
hasScrim?: boolean;
|
|
49
|
+
/** BottomSheets identified by unique `sheetId` values. */
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Coordinates a set of BottomSheets so zero or one is active at a time inside
|
|
54
|
+
* one shared native dialog. During a handoff the previous panel stays visible
|
|
55
|
+
* and inert beneath the entering panel, then fades after motion completes.
|
|
56
|
+
*/
|
|
57
|
+
export declare function BottomSheetSwitcher({ activeSheet, onActiveSheetChange, hasScrim, children, ref, xstyle, className, style, onCancel, onClick, onKeyDown, ...props }: BottomSheetSwitcherProps): import("react").JSX.Element;
|
|
58
|
+
export declare namespace BottomSheetSwitcher {
|
|
59
|
+
var displayName: string;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=BottomSheetSwitcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BottomSheetSwitcher.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheetSwitcher.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAQL,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AA2H5C,MAAM,WAAW,wBAAyB,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IAC5E,iDAAiD;IACjD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAEnC,oEAAoE;IACpE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAE9D;;;;;OAKG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B,iEAAiE;IACjE,mBAAmB,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAEtD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0DAA0D;IAC1D,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,mBAAmB,EACnB,QAAe,EACf,QAAQ,EACR,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,QAAQ,EACR,OAAO,EACP,SAAS,EACT,GAAG,KAAK,EACT,EAAE,wBAAwB,+BA4Z1B;yBAzae,mBAAmB"}
|