@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,547 @@
|
|
|
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
|
+
|
|
23
|
+
import {
|
|
24
|
+
useCallback,
|
|
25
|
+
useEffect,
|
|
26
|
+
useImperativeHandle,
|
|
27
|
+
useLayoutEffect,
|
|
28
|
+
useRef,
|
|
29
|
+
type ReactNode,
|
|
30
|
+
} from 'react';
|
|
31
|
+
import * as stylex from '@stylexjs/stylex';
|
|
32
|
+
import type {BaseProps} from '../BaseProps';
|
|
33
|
+
import {
|
|
34
|
+
colorVars,
|
|
35
|
+
durationVars,
|
|
36
|
+
easeVars,
|
|
37
|
+
radiusVars,
|
|
38
|
+
shadowVars,
|
|
39
|
+
sizeVars,
|
|
40
|
+
spacingVars,
|
|
41
|
+
} from '../theme/tokens.stylex';
|
|
42
|
+
import {mergeProps, themeProps} from '../utils';
|
|
43
|
+
import {useMobileKeyboard} from './useMobileKeyboard';
|
|
44
|
+
import {useSheetGestures} from './useSheetGestures';
|
|
45
|
+
|
|
46
|
+
const SNAP_FRACTIONS = [0.14, 0.5, 0.92];
|
|
47
|
+
|
|
48
|
+
const HEIGHT_BUDGETS = {
|
|
49
|
+
hug: '92dvh',
|
|
50
|
+
capped: '62dvh',
|
|
51
|
+
tall: '92dvh',
|
|
52
|
+
} as const;
|
|
53
|
+
|
|
54
|
+
export type BottomSheetHeight = keyof typeof HEIGHT_BUDGETS;
|
|
55
|
+
|
|
56
|
+
// SYNC: must match OVERSCROLL_MAX in useSheetGestures.ts.
|
|
57
|
+
const OVERSCROLL_PADDING = 48;
|
|
58
|
+
const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
|
|
59
|
+
const TRANSITION_BACKSTOP_BUFFER_MS = 50;
|
|
60
|
+
|
|
61
|
+
function defaultSnapHeights(): number[] {
|
|
62
|
+
if (typeof window === 'undefined') {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
// Measure the same viewport the height budgets are written against. Those
|
|
66
|
+
// are `dvh`, which the virtual keyboard does not shrink, so reading
|
|
67
|
+
// `visualViewport` here made the two disagree by exactly the keyboard's
|
|
68
|
+
// height: every detent moved while the sheet it was measuring did not. A
|
|
69
|
+
// keyboard is `useMobileKeyboard`'s business — it holds the sheet still and
|
|
70
|
+
// scrolls the body — and it does not redefine the sheet's detents.
|
|
71
|
+
return SNAP_FRACTIONS.map(fraction => fraction * window.innerHeight);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const styles = stylex.create({
|
|
75
|
+
sheet: {
|
|
76
|
+
pointerEvents: 'auto',
|
|
77
|
+
boxSizing: 'border-box',
|
|
78
|
+
display: 'flex',
|
|
79
|
+
flexDirection: 'column',
|
|
80
|
+
minHeight: 0,
|
|
81
|
+
width: '100%',
|
|
82
|
+
maxWidth: 640,
|
|
83
|
+
backgroundColor: colorVars['--color-background-surface'],
|
|
84
|
+
borderStartStartRadius: radiusVars['--radius-container'],
|
|
85
|
+
borderStartEndRadius: radiusVars['--radius-container'],
|
|
86
|
+
boxShadow: shadowVars['--shadow-high'],
|
|
87
|
+
outline: 'none',
|
|
88
|
+
overflow: 'hidden',
|
|
89
|
+
paddingBlockEnd: `calc(env(safe-area-inset-bottom, 0px) + ${OVERSCROLL_PADDING}px)`,
|
|
90
|
+
marginBlockEnd: `${-OVERSCROLL_PADDING}px`,
|
|
91
|
+
transform: {
|
|
92
|
+
default: 'translateY(0)',
|
|
93
|
+
'@starting-style': 'translateY(100%)',
|
|
94
|
+
},
|
|
95
|
+
opacity: 1,
|
|
96
|
+
transitionProperty: 'transform, opacity',
|
|
97
|
+
transitionDuration: durationVars['--duration-medium'],
|
|
98
|
+
transitionTimingFunction: easeVars['--ease-standard'],
|
|
99
|
+
willChange: 'transform, opacity',
|
|
100
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
101
|
+
transitionDuration: '0.01s',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
sheetClosing: {
|
|
105
|
+
transform: 'translateY(100%)',
|
|
106
|
+
},
|
|
107
|
+
sheetFading: {
|
|
108
|
+
opacity: 0,
|
|
109
|
+
},
|
|
110
|
+
sheetInactive: {
|
|
111
|
+
pointerEvents: 'none',
|
|
112
|
+
},
|
|
113
|
+
handleBar: {
|
|
114
|
+
flexShrink: 0,
|
|
115
|
+
display: 'flex',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
justifyContent: 'center',
|
|
118
|
+
height: spacingVars['--spacing-12'],
|
|
119
|
+
touchAction: 'none',
|
|
120
|
+
cursor: 'grab',
|
|
121
|
+
},
|
|
122
|
+
handlePill: {
|
|
123
|
+
width: sizeVars['--size-element-lg'],
|
|
124
|
+
height: spacingVars['--spacing-1'],
|
|
125
|
+
borderRadius: radiusVars['--radius-full'],
|
|
126
|
+
backgroundColor: colorVars['--color-border'],
|
|
127
|
+
},
|
|
128
|
+
body: {
|
|
129
|
+
flexGrow: 1,
|
|
130
|
+
minHeight: 0,
|
|
131
|
+
boxSizing: 'border-box',
|
|
132
|
+
overflowY: 'auto',
|
|
133
|
+
overscrollBehavior: 'none',
|
|
134
|
+
touchAction: 'pan-y',
|
|
135
|
+
paddingBlockEnd: 0,
|
|
136
|
+
},
|
|
137
|
+
tallKeyboardBody: {
|
|
138
|
+
scrollPaddingBlockEnd: MOBILE_KEYBOARD_BOTTOM_CLEARANCE,
|
|
139
|
+
'::after': {
|
|
140
|
+
content: '""',
|
|
141
|
+
display: 'block',
|
|
142
|
+
blockSize: 'var(--_sheet-keyboard-inset, 0px)',
|
|
143
|
+
pointerEvents: 'none',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
budget: {
|
|
147
|
+
height: `calc(var(--_sheet-budget) + ${OVERSCROLL_PADDING}px)`,
|
|
148
|
+
},
|
|
149
|
+
hugHeight: {
|
|
150
|
+
height: 'fit-content',
|
|
151
|
+
maxHeight: `calc(${HEIGHT_BUDGETS.hug} + ${OVERSCROLL_PADDING}px)`,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export type BottomSheetPanelMotion =
|
|
156
|
+
'entering' | 'aligning' | 'fading' | 'exiting';
|
|
157
|
+
|
|
158
|
+
export type BottomSheetPanelState =
|
|
159
|
+
| {kind: 'hidden'}
|
|
160
|
+
| {kind: 'open'; entering: boolean}
|
|
161
|
+
| {
|
|
162
|
+
kind: 'retained';
|
|
163
|
+
motion: 'covered' | 'aligning' | 'fading';
|
|
164
|
+
alignmentOffset: number;
|
|
165
|
+
}
|
|
166
|
+
| {kind: 'exiting'};
|
|
167
|
+
|
|
168
|
+
interface BottomSheetPanelProps extends BaseProps<HTMLDivElement> {
|
|
169
|
+
/** Ref forwarded to the visual sheet panel. */
|
|
170
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
171
|
+
state: BottomSheetPanelState;
|
|
172
|
+
height: BottomSheetHeight | number | string;
|
|
173
|
+
children: ReactNode;
|
|
174
|
+
isSwipeDismissAllowed?: boolean;
|
|
175
|
+
/** Whether the host has locked page scrolling (a modal, scrim-backed sheet). */
|
|
176
|
+
isPageScrollLocked?: boolean;
|
|
177
|
+
onDismiss: () => void;
|
|
178
|
+
onScrimOpacity: (opacity: number) => void;
|
|
179
|
+
onElementChange?: (element: HTMLDivElement | null) => void;
|
|
180
|
+
onMotionStart?: (motion: BottomSheetPanelMotion) => void;
|
|
181
|
+
onMotionComplete?: (motion: BottomSheetPanelMotion) => void;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function motionForState(
|
|
185
|
+
state: BottomSheetPanelState,
|
|
186
|
+
): BottomSheetPanelMotion | null {
|
|
187
|
+
if (state.kind === 'open') {
|
|
188
|
+
return state.entering ? 'entering' : null;
|
|
189
|
+
}
|
|
190
|
+
if (state.kind === 'retained') {
|
|
191
|
+
return state.motion === 'covered' ? null : state.motion;
|
|
192
|
+
}
|
|
193
|
+
return state.kind === 'exiting' ? 'exiting' : null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function waitForTransition(
|
|
197
|
+
element: HTMLElement | null,
|
|
198
|
+
propertyName: 'transform' | 'opacity',
|
|
199
|
+
complete: () => void,
|
|
200
|
+
): () => void {
|
|
201
|
+
if (element == null) {
|
|
202
|
+
complete();
|
|
203
|
+
return () => {};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let done = false;
|
|
207
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
208
|
+
const finish = () => {
|
|
209
|
+
if (done) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
done = true;
|
|
213
|
+
if (timer != null) {
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
}
|
|
216
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
217
|
+
element.removeEventListener('transitioncancel', handleTransitionEnd);
|
|
218
|
+
complete();
|
|
219
|
+
};
|
|
220
|
+
const handleTransitionEnd = (event: TransitionEvent) => {
|
|
221
|
+
if (event.target === element && event.propertyName === propertyName) {
|
|
222
|
+
finish();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
element.addEventListener('transitionend', handleTransitionEnd);
|
|
226
|
+
element.addEventListener('transitioncancel', handleTransitionEnd);
|
|
227
|
+
|
|
228
|
+
const computedStyle = getComputedStyle(element);
|
|
229
|
+
if (
|
|
230
|
+
element.style.transition.trim() === 'none' ||
|
|
231
|
+
computedStyle.transition.trim() === 'none'
|
|
232
|
+
) {
|
|
233
|
+
finish();
|
|
234
|
+
return () => {};
|
|
235
|
+
}
|
|
236
|
+
const properties = computedStyle.transitionProperty
|
|
237
|
+
.split(',')
|
|
238
|
+
.map(value => value.trim());
|
|
239
|
+
const durations = computedStyle.transitionDuration
|
|
240
|
+
.split(',')
|
|
241
|
+
.map(parseTransitionTime);
|
|
242
|
+
const delays = computedStyle.transitionDelay
|
|
243
|
+
.split(',')
|
|
244
|
+
.map(parseTransitionTime);
|
|
245
|
+
let hasUnresolvedTiming = false;
|
|
246
|
+
const transitionMs = properties.reduce((longest, property, index) => {
|
|
247
|
+
if (property !== propertyName && property !== 'all') {
|
|
248
|
+
return longest;
|
|
249
|
+
}
|
|
250
|
+
const duration = durations[index % durations.length];
|
|
251
|
+
const delay = delays[index % delays.length];
|
|
252
|
+
if (duration == null || delay == null) {
|
|
253
|
+
hasUnresolvedTiming = true;
|
|
254
|
+
return longest;
|
|
255
|
+
}
|
|
256
|
+
return Math.max(longest, duration + delay);
|
|
257
|
+
}, 0);
|
|
258
|
+
|
|
259
|
+
if (hasUnresolvedTiming) {
|
|
260
|
+
// JSDOM can leave CSS variables unresolved. In that case the native event
|
|
261
|
+
// remains authoritative; choosing a fixed timeout here would make an
|
|
262
|
+
// assumption about the consumer's theme.
|
|
263
|
+
return () => {
|
|
264
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
265
|
+
element.removeEventListener('transitioncancel', handleTransitionEnd);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (transitionMs <= 0) {
|
|
270
|
+
finish();
|
|
271
|
+
return () => {};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
timer = setTimeout(finish, transitionMs + TRANSITION_BACKSTOP_BUFFER_MS);
|
|
275
|
+
return () => {
|
|
276
|
+
if (timer != null) {
|
|
277
|
+
clearTimeout(timer);
|
|
278
|
+
}
|
|
279
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
280
|
+
element.removeEventListener('transitioncancel', handleTransitionEnd);
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function parseTransitionTime(value: string): number | null {
|
|
285
|
+
const normalizedValue = value.trim();
|
|
286
|
+
if (!/^-?(?:\d+|\d*\.\d+)(?:ms|s)$/.test(normalizedValue)) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
const time = Number.parseFloat(value);
|
|
290
|
+
return normalizedValue.endsWith('ms') ? time : time * 1000;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Internal visual and gesture surface shared by every BottomSheet host. */
|
|
294
|
+
export function BottomSheetPanel({
|
|
295
|
+
ref,
|
|
296
|
+
state,
|
|
297
|
+
height,
|
|
298
|
+
children,
|
|
299
|
+
className,
|
|
300
|
+
style,
|
|
301
|
+
tabIndex,
|
|
302
|
+
xstyle,
|
|
303
|
+
isSwipeDismissAllowed = true,
|
|
304
|
+
isPageScrollLocked = false,
|
|
305
|
+
onDismiss,
|
|
306
|
+
onScrimOpacity,
|
|
307
|
+
onElementChange,
|
|
308
|
+
onMotionStart,
|
|
309
|
+
onMotionComplete,
|
|
310
|
+
...props
|
|
311
|
+
}: BottomSheetPanelProps) {
|
|
312
|
+
const elementRef = useRef<HTMLDivElement | null>(null);
|
|
313
|
+
const previousStateRef = useRef(state);
|
|
314
|
+
const reactivatedEntranceRef = useRef(false);
|
|
315
|
+
const onMotionStartRef = useRef(onMotionStart);
|
|
316
|
+
const onMotionCompleteRef = useRef(onMotionComplete);
|
|
317
|
+
const startedMotionRef = useRef<BottomSheetPanelMotion | null>(null);
|
|
318
|
+
const pendingMotionCompleteRef = useRef<BottomSheetPanelMotion | null>(null);
|
|
319
|
+
|
|
320
|
+
const isEntering = state.kind === 'open' && state.entering;
|
|
321
|
+
const previousState = previousStateRef.current;
|
|
322
|
+
const wasEntering = previousState.kind === 'open' && previousState.entering;
|
|
323
|
+
if (isEntering && !wasEntering) {
|
|
324
|
+
reactivatedEntranceRef.current = previousState.kind === 'retained';
|
|
325
|
+
} else if (!isEntering) {
|
|
326
|
+
reactivatedEntranceRef.current = false;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
useLayoutEffect(() => {
|
|
330
|
+
previousStateRef.current = state;
|
|
331
|
+
onMotionStartRef.current = onMotionStart;
|
|
332
|
+
onMotionCompleteRef.current = onMotionComplete;
|
|
333
|
+
}, [onMotionComplete, onMotionStart, state]);
|
|
334
|
+
|
|
335
|
+
const isInteractive = state.kind === 'open';
|
|
336
|
+
const isPresented = state.kind !== 'hidden';
|
|
337
|
+
const isRetained = state.kind === 'retained';
|
|
338
|
+
const isInactive = isRetained || state.kind === 'exiting';
|
|
339
|
+
const isClosing = state.kind === 'exiting';
|
|
340
|
+
const isFading = isRetained && state.motion === 'fading';
|
|
341
|
+
const alignmentOffset = isRetained ? state.alignmentOffset : 0;
|
|
342
|
+
|
|
343
|
+
const {
|
|
344
|
+
contentProps,
|
|
345
|
+
handleProps,
|
|
346
|
+
bodyProps,
|
|
347
|
+
bodyElementRef,
|
|
348
|
+
sheetRef,
|
|
349
|
+
dragOffset,
|
|
350
|
+
settledOffset,
|
|
351
|
+
isDragging,
|
|
352
|
+
sheetHeight,
|
|
353
|
+
scrollPreservationInset,
|
|
354
|
+
settlingLayoutOffset,
|
|
355
|
+
settledLayoutOffset,
|
|
356
|
+
completeScrollAreaSettle,
|
|
357
|
+
} = useSheetGestures({
|
|
358
|
+
isOpen: isInteractive,
|
|
359
|
+
canDismiss: isSwipeDismissAllowed,
|
|
360
|
+
offscreenBlockEndInset: OVERSCROLL_PADDING,
|
|
361
|
+
onDismiss,
|
|
362
|
+
snapHeights: defaultSnapHeights,
|
|
363
|
+
onScrimOpacity,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const setElement = useCallback(
|
|
367
|
+
(element: HTMLDivElement | null) => {
|
|
368
|
+
sheetRef(element);
|
|
369
|
+
elementRef.current = element;
|
|
370
|
+
onElementChange?.(element);
|
|
371
|
+
},
|
|
372
|
+
[onElementChange, sheetRef],
|
|
373
|
+
);
|
|
374
|
+
useMobileKeyboard({
|
|
375
|
+
bodyRef: bodyElementRef,
|
|
376
|
+
bottomClearance: MOBILE_KEYBOARD_BOTTOM_CLEARANCE,
|
|
377
|
+
isEnabled: height === 'tall',
|
|
378
|
+
isFullyExpanded: settledOffset === 0,
|
|
379
|
+
isPageScrollLocked,
|
|
380
|
+
isSheetTraveling: isDragging && dragOffset !== settledOffset,
|
|
381
|
+
isOpen: isInteractive,
|
|
382
|
+
isPresented,
|
|
383
|
+
sheetRef: elementRef,
|
|
384
|
+
});
|
|
385
|
+
// Keep controller registration attached to one stable host ref. React
|
|
386
|
+
// detaches an old callback ref when a consumer supplies a new identity; if
|
|
387
|
+
// that public ref were merged with setElement, an ordinary parent rerender
|
|
388
|
+
// could be mistaken for the panel unmounting and cancel a sheet handoff.
|
|
389
|
+
useImperativeHandle(ref, () => elementRef.current as HTMLDivElement, []);
|
|
390
|
+
|
|
391
|
+
const motion = motionForState(state);
|
|
392
|
+
useLayoutEffect(() => {
|
|
393
|
+
if (motion == null) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
startedMotionRef.current = null;
|
|
397
|
+
pendingMotionCompleteRef.current = null;
|
|
398
|
+
if (motion === 'entering' && reactivatedEntranceRef.current) {
|
|
399
|
+
pendingMotionCompleteRef.current = motion;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
return waitForTransition(
|
|
403
|
+
elementRef.current,
|
|
404
|
+
motion === 'fading' ? 'opacity' : 'transform',
|
|
405
|
+
() => {
|
|
406
|
+
if (startedMotionRef.current === motion) {
|
|
407
|
+
onMotionCompleteRef.current?.(motion);
|
|
408
|
+
} else {
|
|
409
|
+
pendingMotionCompleteRef.current = motion;
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
);
|
|
413
|
+
}, [motion]);
|
|
414
|
+
// The snap is transform-only; the layout height reconciles when it lands.
|
|
415
|
+
// waitForTransition — the same helper the motion states use — resolves that
|
|
416
|
+
// even when no `transitionend` is coming: inline or computed
|
|
417
|
+
// `transition: none`, a zero duration, and a timer backstop otherwise.
|
|
418
|
+
useLayoutEffect(() => {
|
|
419
|
+
if (settlingLayoutOffset == null) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
return waitForTransition(
|
|
423
|
+
elementRef.current,
|
|
424
|
+
'transform',
|
|
425
|
+
completeScrollAreaSettle,
|
|
426
|
+
);
|
|
427
|
+
}, [completeScrollAreaSettle, settlingLayoutOffset]);
|
|
428
|
+
useEffect(() => {
|
|
429
|
+
if (motion == null) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
onMotionStartRef.current?.(motion);
|
|
433
|
+
startedMotionRef.current = motion;
|
|
434
|
+
if (pendingMotionCompleteRef.current === motion) {
|
|
435
|
+
pendingMotionCompleteRef.current = null;
|
|
436
|
+
onMotionCompleteRef.current?.(motion);
|
|
437
|
+
}
|
|
438
|
+
return () => {
|
|
439
|
+
if (startedMotionRef.current === motion) {
|
|
440
|
+
startedMotionRef.current = null;
|
|
441
|
+
}
|
|
442
|
+
if (pendingMotionCompleteRef.current === motion) {
|
|
443
|
+
pendingMotionCompleteRef.current = null;
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}, [motion]);
|
|
447
|
+
|
|
448
|
+
const isNamedHeight = typeof height === 'string' && height in HEIGHT_BUDGETS;
|
|
449
|
+
const budget = isNamedHeight
|
|
450
|
+
? HEIGHT_BUDGETS[height as BottomSheetHeight]
|
|
451
|
+
: typeof height === 'number'
|
|
452
|
+
? `${height}px`
|
|
453
|
+
: height;
|
|
454
|
+
const hasMeasuredSheet = sheetHeight > 0;
|
|
455
|
+
let gestureTransform = contentProps.style.transform;
|
|
456
|
+
let resizedHeight: string | undefined;
|
|
457
|
+
if (hasMeasuredSheet) {
|
|
458
|
+
// The sheet's travel is split across two properties: `layoutOffset` is the
|
|
459
|
+
// part the scrolling area gives up as layout height, and the remainder is
|
|
460
|
+
// a compositor transform. Live gestures and snaps only ever move the
|
|
461
|
+
// transform — the layout height changes at rest, in one reconciling render
|
|
462
|
+
// whose visible geometry is identical (see useSheetGestures).
|
|
463
|
+
// - dragging above the base restores the full height below the viewport
|
|
464
|
+
// - a peek settles with layout 0, so it slides rather than reflowing
|
|
465
|
+
const layoutOffset = isDragging
|
|
466
|
+
? dragOffset < settledOffset
|
|
467
|
+
? 0
|
|
468
|
+
: settledLayoutOffset
|
|
469
|
+
: (settlingLayoutOffset ?? settledLayoutOffset);
|
|
470
|
+
const activeOffset = isDragging ? dragOffset : settledOffset;
|
|
471
|
+
const translation = activeOffset - layoutOffset;
|
|
472
|
+
|
|
473
|
+
// At layout 0 the sheet is its natural height, so leave that to CSS —
|
|
474
|
+
// `hug` sheets must stay fit-content. While the sheet is in motion it is
|
|
475
|
+
// pinned in px instead: content reflowing mid-gesture would move the
|
|
476
|
+
// surface out from under the finger, or under the snap.
|
|
477
|
+
const isTraveling = isDragging || settlingLayoutOffset != null;
|
|
478
|
+
resizedHeight =
|
|
479
|
+
layoutOffset > 0 || isTraveling
|
|
480
|
+
? `${Math.max(0, sheetHeight - Math.max(0, layoutOffset))}px`
|
|
481
|
+
: undefined;
|
|
482
|
+
gestureTransform =
|
|
483
|
+
translation !== 0 ? `translateY(${translation}px)` : undefined;
|
|
484
|
+
}
|
|
485
|
+
const retainedTransform =
|
|
486
|
+
alignmentOffset > 0
|
|
487
|
+
? [gestureTransform, `translateY(${alignmentOffset}px)`]
|
|
488
|
+
.filter(Boolean)
|
|
489
|
+
.join(' ')
|
|
490
|
+
: gestureTransform;
|
|
491
|
+
const gestureStyle = {
|
|
492
|
+
...contentProps.style,
|
|
493
|
+
transform: gestureTransform,
|
|
494
|
+
height: resizedHeight,
|
|
495
|
+
};
|
|
496
|
+
return (
|
|
497
|
+
<div
|
|
498
|
+
{...props}
|
|
499
|
+
ref={setElement}
|
|
500
|
+
tabIndex={tabIndex ?? -1}
|
|
501
|
+
{...mergeProps(
|
|
502
|
+
themeProps('bottom-sheet'),
|
|
503
|
+
stylex.props(
|
|
504
|
+
styles.sheet,
|
|
505
|
+
height === 'hug' ? styles.hugHeight : styles.budget,
|
|
506
|
+
isClosing && styles.sheetClosing,
|
|
507
|
+
isFading && styles.sheetFading,
|
|
508
|
+
isInactive && styles.sheetInactive,
|
|
509
|
+
xstyle,
|
|
510
|
+
),
|
|
511
|
+
className,
|
|
512
|
+
{
|
|
513
|
+
['--_sheet-budget' as string]: budget,
|
|
514
|
+
...(isInteractive
|
|
515
|
+
? gestureStyle
|
|
516
|
+
: isRetained
|
|
517
|
+
? {transform: retainedTransform, height: resizedHeight}
|
|
518
|
+
: isClosing
|
|
519
|
+
? {height: resizedHeight}
|
|
520
|
+
: {}),
|
|
521
|
+
...style,
|
|
522
|
+
},
|
|
523
|
+
)}>
|
|
524
|
+
<div
|
|
525
|
+
{...stylex.props(styles.handleBar)}
|
|
526
|
+
{...handleProps}
|
|
527
|
+
aria-hidden="true">
|
|
528
|
+
<div {...stylex.props(styles.handlePill)} />
|
|
529
|
+
</div>
|
|
530
|
+
<div
|
|
531
|
+
{...mergeProps(
|
|
532
|
+
stylex.props(
|
|
533
|
+
styles.body,
|
|
534
|
+
height === 'tall' && styles.tallKeyboardBody,
|
|
535
|
+
),
|
|
536
|
+
scrollPreservationInset > 0
|
|
537
|
+
? {style: {paddingBlockEnd: `${scrollPreservationInset}px`}}
|
|
538
|
+
: {},
|
|
539
|
+
)}
|
|
540
|
+
{...bodyProps}>
|
|
541
|
+
{children}
|
|
542
|
+
</div>
|
|
543
|
+
</div>
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
BottomSheetPanel.displayName = 'BottomSheetPanel';
|