@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.
Files changed (200) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +79 -45
  3. package/dist/Banner/Banner.d.ts +3 -0
  4. package/dist/Banner/Banner.d.ts.map +1 -1
  5. package/dist/Banner/Banner.js +13 -3
  6. package/dist/BottomSheet/BottomSheet.d.ts +66 -0
  7. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -0
  8. package/dist/BottomSheet/BottomSheet.js +392 -0
  9. package/dist/BottomSheet/BottomSheetPanel.d.ts +60 -0
  10. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -0
  11. package/dist/BottomSheet/BottomSheetPanel.js +398 -0
  12. package/dist/BottomSheet/BottomSheetSwitcher.d.ts +61 -0
  13. package/dist/BottomSheet/BottomSheetSwitcher.d.ts.map +1 -0
  14. package/dist/BottomSheet/BottomSheetSwitcher.js +410 -0
  15. package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts +21 -0
  16. package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts.map +1 -0
  17. package/dist/BottomSheet/BottomSheetSwitcherContext.js +13 -0
  18. package/dist/BottomSheet/index.d.ts +11 -0
  19. package/dist/BottomSheet/index.d.ts.map +1 -0
  20. package/dist/BottomSheet/index.js +12 -0
  21. package/dist/BottomSheet/snapOffsets.d.ts +72 -0
  22. package/dist/BottomSheet/snapOffsets.d.ts.map +1 -0
  23. package/dist/BottomSheet/snapOffsets.js +130 -0
  24. package/dist/BottomSheet/useMobileKeyboard.d.ts +35 -0
  25. package/dist/BottomSheet/useMobileKeyboard.d.ts.map +1 -0
  26. package/dist/BottomSheet/useMobileKeyboard.js +373 -0
  27. package/dist/BottomSheet/useSheetGestures.d.ts +180 -0
  28. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -0
  29. package/dist/BottomSheet/useSheetGestures.js +989 -0
  30. package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
  31. package/dist/Chat/ChatComposerInput.js +3 -4
  32. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  33. package/dist/ComplexSelector/ComplexSelector.js +12 -6
  34. package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
  35. package/dist/ContextMenu/ContextMenu.js +4 -2
  36. package/dist/DateInput/DateInput.d.ts.map +1 -1
  37. package/dist/DateInput/DateInput.js +9 -1
  38. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  39. package/dist/DateTimeInput/DateTimeInput.js +31 -1
  40. package/dist/Dialog/Dialog.d.ts.map +1 -1
  41. package/dist/Dialog/Dialog.js +2 -1
  42. package/dist/Field/InputClearButton.d.ts +2 -1
  43. package/dist/Field/InputClearButton.d.ts.map +1 -1
  44. package/dist/Field/InputClearButton.js +6 -1
  45. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  46. package/dist/Lightbox/Lightbox.js +9 -3
  47. package/dist/MobileNav/MobileNav.d.ts +12 -0
  48. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  49. package/dist/MobileNav/MobileNav.js +102 -30
  50. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  51. package/dist/MultiSelector/MultiSelector.js +21 -7
  52. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  53. package/dist/NumberInput/NumberInput.js +9 -1
  54. package/dist/PowerSearch/PowerSearchEditPopover.js +1 -1
  55. package/dist/Selector/Selector.d.ts.map +1 -1
  56. package/dist/Selector/Selector.js +14 -3
  57. package/dist/StatusDot/StatusDot.d.ts +43 -3
  58. package/dist/StatusDot/StatusDot.d.ts.map +1 -1
  59. package/dist/StatusDot/StatusDot.js +42 -5
  60. package/dist/Switch/Switch.d.ts.map +1 -1
  61. package/dist/Switch/Switch.js +5 -1
  62. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
  63. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +7 -2
  64. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  65. package/dist/TimeInput/TimeInput.js +8 -1
  66. package/dist/Tokenizer/Tokenizer.js +11 -5
  67. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  68. package/dist/Tooltip/useTooltip.js +4 -1
  69. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  70. package/dist/Typeahead/BaseTypeahead.js +5 -3
  71. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  72. package/dist/Typeahead/Typeahead.js +10 -1
  73. package/dist/astryx.css +21 -0
  74. package/dist/hooks/index.d.ts +8 -1
  75. package/dist/hooks/index.d.ts.map +1 -1
  76. package/dist/hooks/index.js +8 -1
  77. package/dist/hooks/useFocusTrap.d.ts +0 -11
  78. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  79. package/dist/hooks/useFocusTrap.js +1 -11
  80. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  81. package/dist/hooks/useInputStatusIcon.js +1 -0
  82. package/dist/index.d.ts +1 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +1 -0
  85. package/dist/theme/defineTheme.d.ts +22 -4
  86. package/dist/theme/defineTheme.d.ts.map +1 -1
  87. package/dist/theme/expandColorScale.d.ts +17 -2
  88. package/dist/theme/expandColorScale.d.ts.map +1 -1
  89. package/dist/theme/expandColorScale.js +63 -33
  90. package/dist/utils/ime.d.ts +5 -0
  91. package/dist/utils/ime.d.ts.map +1 -0
  92. package/dist/utils/ime.js +63 -0
  93. package/dist/utils/index.d.ts +1 -0
  94. package/dist/utils/index.d.ts.map +1 -1
  95. package/dist/utils/index.js +2 -1
  96. package/locales/af-ZA.json +958 -0
  97. package/locales/ar-SA.json +998 -0
  98. package/locales/ca-ES.json +974 -0
  99. package/locales/cs-CZ.json +990 -0
  100. package/locales/da-DK.json +966 -0
  101. package/locales/de-DE.json +966 -0
  102. package/locales/el-GR.json +990 -0
  103. package/locales/en.json +48 -0
  104. package/locales/es-ES.json +978 -0
  105. package/locales/fi-FI.json +990 -0
  106. package/locales/fr-FR.json +928 -0
  107. package/locales/he-IL.json +990 -0
  108. package/locales/hu-HU.json +990 -0
  109. package/locales/it-IT.json +978 -0
  110. package/locales/ja-JP.json +998 -0
  111. package/locales/ko-KR.json +990 -0
  112. package/locales/nl-NL.json +954 -0
  113. package/locales/no-NO.json +978 -0
  114. package/locales/pl-PL.json +982 -0
  115. package/locales/pseudo.json +36 -0
  116. package/locales/pt-BR.json +982 -0
  117. package/locales/pt-PT.json +982 -0
  118. package/locales/ro-RO.json +982 -0
  119. package/locales/ru-RU.json +990 -0
  120. package/locales/sr-SP.json +990 -0
  121. package/locales/sv-SE.json +986 -0
  122. package/locales/tr-TR.json +990 -0
  123. package/locales/uk-UA.json +990 -0
  124. package/locales/vi-VN.json +986 -0
  125. package/locales/zh-CN.json +998 -0
  126. package/locales/zh-TW.json +998 -0
  127. package/package.json +9 -8
  128. package/src/Banner/Banner.doc.mjs +3 -3
  129. package/src/Banner/Banner.test.tsx +40 -0
  130. package/src/Banner/Banner.tsx +27 -2
  131. package/src/BottomSheet/BottomSheet.doc.mjs +266 -0
  132. package/src/BottomSheet/BottomSheet.test.tsx +2114 -0
  133. package/src/BottomSheet/BottomSheet.tsx +545 -0
  134. package/src/BottomSheet/BottomSheetPanel.test.tsx +240 -0
  135. package/src/BottomSheet/BottomSheetPanel.tsx +547 -0
  136. package/src/BottomSheet/BottomSheetSwitcher.doc.mjs +219 -0
  137. package/src/BottomSheet/BottomSheetSwitcher.test.tsx +850 -0
  138. package/src/BottomSheet/BottomSheetSwitcher.tsx +628 -0
  139. package/src/BottomSheet/BottomSheetSwitcherContext.ts +51 -0
  140. package/src/BottomSheet/index.ts +15 -0
  141. package/src/BottomSheet/snapOffsets.test.ts +187 -0
  142. package/src/BottomSheet/snapOffsets.ts +159 -0
  143. package/src/BottomSheet/useMobileKeyboard.ts +499 -0
  144. package/src/BottomSheet/useSheetGestures.test.ts +1059 -0
  145. package/src/BottomSheet/useSheetGestures.ts +1459 -0
  146. package/src/Chat/ChatComposerInput.tsx +3 -4
  147. package/src/ComplexSelector/ComplexSelector.tsx +12 -5
  148. package/src/ContextMenu/ContextMenu.tsx +4 -2
  149. package/src/DateInput/DateInput.test.tsx +21 -0
  150. package/src/DateInput/DateInput.tsx +9 -1
  151. package/src/DateTimeInput/DateTimeInput.doc.mjs +4 -0
  152. package/src/DateTimeInput/DateTimeInput.test.tsx +137 -0
  153. package/src/DateTimeInput/DateTimeInput.tsx +39 -2
  154. package/src/Dialog/Dialog.tsx +2 -1
  155. package/src/Field/Field.doc.mjs +1 -0
  156. package/src/Field/InputClearButton.test.tsx +25 -0
  157. package/src/Field/InputClearButton.tsx +4 -1
  158. package/src/FileInput/FileInput.test.tsx +53 -9
  159. package/src/Lightbox/Lightbox.test.tsx +49 -28
  160. package/src/Lightbox/Lightbox.tsx +7 -3
  161. package/src/MobileNav/MobileNav.tsx +128 -37
  162. package/src/MobileNav/MobileNavCloseEdgeCases.test.tsx +426 -0
  163. package/src/MobileNav/MobileNavCloseTiming.test.ts +58 -0
  164. package/src/MobileNav/MobileNavCloseVisibility.test.tsx +172 -0
  165. package/src/MultiSelector/MultiSelector.test.tsx +195 -51
  166. package/src/MultiSelector/MultiSelector.tsx +22 -8
  167. package/src/NumberInput/NumberInput.test.tsx +18 -0
  168. package/src/NumberInput/NumberInput.tsx +9 -1
  169. package/src/PowerSearch/PowerSearchEditPopover.tsx +1 -1
  170. package/src/Selector/Selector.test.tsx +85 -26
  171. package/src/Selector/Selector.tsx +13 -4
  172. package/src/StatusDot/StatusDot.doc.mjs +13 -0
  173. package/src/StatusDot/StatusDot.test.tsx +115 -8
  174. package/src/StatusDot/StatusDot.tsx +74 -9
  175. package/src/Switch/Switch.test.tsx +16 -0
  176. package/src/Switch/Switch.tsx +7 -0
  177. package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +20 -2
  178. package/src/TimeInput/TimeInput.test.tsx +23 -0
  179. package/src/TimeInput/TimeInput.tsx +8 -0
  180. package/src/Tokenizer/Tokenizer.test.tsx +50 -32
  181. package/src/Tokenizer/Tokenizer.tsx +5 -5
  182. package/src/Tooltip/useTooltip.tsx +4 -1
  183. package/src/Typeahead/BaseTypeahead.tsx +10 -3
  184. package/src/Typeahead/Typeahead.test.tsx +116 -7
  185. package/src/Typeahead/Typeahead.tsx +10 -1
  186. package/src/__tests__/stubMatchMedia.test.ts +79 -0
  187. package/src/__tests__/stubMatchMedia.ts +95 -0
  188. package/src/hooks/index.ts +9 -5
  189. package/src/hooks/useFocusTrap.ts +1 -14
  190. package/src/hooks/useInputStatusIcon.test.tsx +19 -0
  191. package/src/hooks/useInputStatusIcon.tsx +7 -0
  192. package/src/index.ts +1 -0
  193. package/src/theme/defineTheme.ts +22 -4
  194. package/src/theme/expandColorScale.test.ts +138 -0
  195. package/src/theme/expandColorScale.ts +89 -44
  196. package/src/utils/ime.test.ts +32 -0
  197. package/src/utils/ime.ts +69 -0
  198. package/src/utils/index.ts +2 -0
  199. package/dist/astryx.umd.js +0 -147
  200. package/dist/astryx.umd.js.map +0 -7
@@ -0,0 +1,392 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file BottomSheet.tsx
7
+ * @input Uses React, StyleX, core hooks/utils, BottomSheetPanel, BottomSheetSwitcherContext
8
+ * @output Exports BottomSheet component and BottomSheetProps
9
+ * @position Public BottomSheet router plus private standalone/switcher hosts
10
+ *
11
+ * BottomSheet selects one of two focused hosts. A standalone host owns its
12
+ * native dialog lifecycle; a switcher item participates in the parent's shared
13
+ * dialog and transition state machine. Both render the same BottomSheetPanel,
14
+ * which owns sheet presentation, gestures, mobile-keyboard accommodation, and
15
+ * motion completion.
16
+ *
17
+ * SYNC: When modified, update these files to stay in sync:
18
+ * - /packages/core/src/BottomSheet/BottomSheetPanel.tsx
19
+ * - /packages/core/src/BottomSheet/BottomSheet.doc.mjs
20
+ * - /packages/core/src/BottomSheet/BottomSheet.test.tsx
21
+ * - /packages/core/src/BottomSheet/BottomSheetSwitcher.tsx
22
+ * - /packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx
23
+ * - /apps/storybook/stories/BottomSheet.stories.tsx
24
+ * - /packages/cli/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.tsx
25
+ */
26
+ import { use, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
27
+ import * as stylex from '@stylexjs/stylex';
28
+ import "../theme/tokens.stylex.js";
29
+ import { colorVars, durationVars, easeVars } from "../theme/tokens.stylex.js";
30
+ import { useDevWarning, useScrollLock } from "../hooks/index.js";
31
+ import { BottomSheetPanel } from "./BottomSheetPanel.js";
32
+ import { BottomSheetSwitcherContext } from "./BottomSheetSwitcherContext.js";
33
+ import { jsx as _jsx } from "react/jsx-runtime";
34
+ function panelStateForSwitcherPhase(phase, alignmentOffset) {
35
+ switch (phase) {
36
+ case 'active':
37
+ return {
38
+ kind: 'open',
39
+ entering: false
40
+ };
41
+ case 'entering':
42
+ return {
43
+ kind: 'open',
44
+ entering: true
45
+ };
46
+ case 'covered':
47
+ case 'aligning':
48
+ case 'fading':
49
+ return {
50
+ kind: 'retained',
51
+ motion: phase,
52
+ alignmentOffset
53
+ };
54
+ case 'exiting':
55
+ return {
56
+ kind: 'exiting'
57
+ };
58
+ case 'hidden':
59
+ return {
60
+ kind: 'hidden'
61
+ };
62
+ }
63
+ }
64
+
65
+ // preventScroll on both: presenting a sheet must not scroll the page to reveal
66
+ // what it just focused. For an autofocused field that reveal is the mobile
67
+ // keyboard's, and it moves the document under a fixed sheet; useMobileKeyboard
68
+ // brings the field into view within the sheet instead.
69
+ function focusPanel(panel, isModal) {
70
+ const activeElement = document.activeElement;
71
+ if (activeElement != null && panel?.contains(activeElement)) {
72
+ return;
73
+ }
74
+ const autofocus = panel?.querySelector('[data-autofocus]');
75
+ if (autofocus != null) {
76
+ autofocus.focus({
77
+ preventScroll: true
78
+ });
79
+ } else if (isModal) {
80
+ panel?.focus({
81
+ preventScroll: true
82
+ });
83
+ }
84
+ }
85
+ function StandaloneBottomSheet({
86
+ ref,
87
+ isOpen,
88
+ onOpenChange,
89
+ label,
90
+ children,
91
+ height = 'capped',
92
+ hasScrim = true,
93
+ purpose = 'info',
94
+ xstyle,
95
+ ...props
96
+ }) {
97
+ const dialogRef = useRef(null);
98
+ const panelRef = useRef(null);
99
+ const triggerRef = useRef(null);
100
+ const [isPresented, setIsPresented] = useState(isOpen);
101
+ const shouldPresent = isOpen || isPresented;
102
+ const panelState = isOpen ? {
103
+ kind: 'open',
104
+ entering: false
105
+ } : isPresented ? {
106
+ kind: 'exiting'
107
+ } : {
108
+ kind: 'hidden'
109
+ };
110
+ const dismissOnEscape = useCallback(() => {
111
+ if (purpose !== 'required') {
112
+ onOpenChange(false);
113
+ }
114
+ }, [onOpenChange, purpose]);
115
+ const dismissOnLightInteraction = useCallback(() => {
116
+ if (purpose === 'info') {
117
+ onOpenChange(false);
118
+ }
119
+ }, [onOpenChange, purpose]);
120
+ const handlePanelElementChange = useCallback(element => {
121
+ panelRef.current = element;
122
+ }, []);
123
+ const handleScrimOpacity = useCallback(opacity => {
124
+ dialogRef.current?.style.setProperty('--_sheet-scrim-opacity', String(opacity));
125
+ }, []);
126
+ useEffect(() => {
127
+ const dialog = dialogRef.current;
128
+ if (dialog == null || !isOpen) {
129
+ return;
130
+ }
131
+
132
+ // The controlled prop opens an already-mounted dialog; presentation state
133
+ // must latch here so a later close can keep it mounted through its exit.
134
+ // eslint-disable-next-line @eslint-react/set-state-in-effect -- latches controlled open state for exit animation
135
+ setIsPresented(true);
136
+ dialog.style.setProperty('--_sheet-scrim-opacity', '1');
137
+ const wasOpen = dialog.open;
138
+ if (!wasOpen) {
139
+ if (hasScrim) {
140
+ triggerRef.current = document.activeElement;
141
+ dialog.showModal();
142
+ } else {
143
+ dialog.show();
144
+ }
145
+ focusPanel(panelRef.current, hasScrim);
146
+ }
147
+ }, [hasScrim, isOpen]);
148
+ useEffect(() => {
149
+ if (!isOpen && isPresented && hasScrim) {
150
+ handleScrimOpacity(0);
151
+ }
152
+ }, [handleScrimOpacity, hasScrim, isOpen, isPresented]);
153
+ const handleMotionComplete = useCallback(motion => {
154
+ if (motion !== 'exiting' || isOpen) {
155
+ return;
156
+ }
157
+ const dialog = dialogRef.current;
158
+ if (dialog?.open) {
159
+ dialog.close();
160
+ }
161
+ setIsPresented(false);
162
+ triggerRef.current?.focus();
163
+ triggerRef.current = null;
164
+ }, [isOpen]);
165
+ useScrollLock(shouldPresent && hasScrim);
166
+ useDevWarning('BottomSheet', 'requires a non-empty `label` for an accessible name; the open sheet ' + 'has no built-in heading to derive one from.', isOpen && !label);
167
+ const handleCancel = useCallback(event => {
168
+ event.preventDefault();
169
+ dismissOnEscape();
170
+ }, [dismissOnEscape]);
171
+ const handleKeyDown = useCallback(event => {
172
+ if (event.key === 'Escape') {
173
+ event.preventDefault();
174
+ dismissOnEscape();
175
+ }
176
+ }, [dismissOnEscape]);
177
+ const handleClick = useCallback(event => {
178
+ if (hasScrim && event.target === event.currentTarget) {
179
+ dismissOnLightInteraction();
180
+ }
181
+ }, [dismissOnLightInteraction, hasScrim]);
182
+ return /*#__PURE__*/_jsx("dialog", {
183
+ ...{
184
+ 0: {
185
+ className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1s85apg x1a2a7pz"
186
+ },
187
+ 4: {
188
+ className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1a2a7pz x1lliihq"
189
+ },
190
+ 2: {
191
+ className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1s85apg x1a2a7pz xnixb3f xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w"
192
+ },
193
+ 6: {
194
+ className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1a2a7pz x1lliihq xnixb3f xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w"
195
+ },
196
+ 1: {
197
+ className: "xixxii4 x10a8y8t x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1s85apg x1a2a7pz x47corl xfo81ep xh8yej3 x5yr21d"
198
+ },
199
+ 5: {
200
+ className: "xixxii4 x10a8y8t x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1a2a7pz x1lliihq x47corl xfo81ep xh8yej3 x5yr21d"
201
+ },
202
+ 3: {
203
+ className: "xixxii4 x10a8y8t x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1s85apg x1a2a7pz xnixb3f xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w x47corl xfo81ep xh8yej3 x5yr21d"
204
+ },
205
+ 7: {
206
+ className: "xixxii4 x10a8y8t x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1a2a7pz x1lliihq xnixb3f xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w x47corl xfo81ep xh8yej3 x5yr21d"
207
+ }
208
+ }[!!shouldPresent << 2 | !!hasScrim << 1 | !!!hasScrim << 0],
209
+ ref: dialogRef,
210
+ "aria-label": label,
211
+ "aria-hidden": !isOpen && isPresented ? 'true' : undefined,
212
+ "aria-modal": hasScrim && isOpen ? 'true' : undefined,
213
+ role: purpose === 'required' ? 'alertdialog' : undefined,
214
+ inert: !isOpen && isPresented ? true : undefined,
215
+ onCancel: handleCancel,
216
+ onClick: handleClick,
217
+ onKeyDown: handleKeyDown,
218
+ children: /*#__PURE__*/_jsx("div", {
219
+ ...{
220
+ className: "x10l6tqk x17y0mx6 x1ey2m1c x78zum5 xl56j7k x47corl"
221
+ },
222
+ children: /*#__PURE__*/_jsx(BottomSheetPanel, {
223
+ ...props,
224
+ ref: ref,
225
+ state: panelState,
226
+ height: height,
227
+ isSwipeDismissAllowed: purpose === 'info',
228
+ isPageScrollLocked: shouldPresent && hasScrim,
229
+ xstyle: xstyle,
230
+ onDismiss: dismissOnLightInteraction,
231
+ onScrimOpacity: handleScrimOpacity,
232
+ onElementChange: handlePanelElementChange,
233
+ onMotionComplete: handleMotionComplete,
234
+ children: children
235
+ })
236
+ })
237
+ });
238
+ }
239
+ function SwitcherBottomSheetItem({
240
+ switcher,
241
+ ref,
242
+ sheetId,
243
+ label,
244
+ children,
245
+ height = 'capped',
246
+ purpose = 'info',
247
+ xstyle,
248
+ ...props
249
+ }) {
250
+ const {
251
+ activeSheet,
252
+ hasScrim,
253
+ onActiveSheetChange,
254
+ getSheetPhase,
255
+ getSheetAlignmentOffset,
256
+ registerSheetElement,
257
+ registerSheetLabel,
258
+ registerSheetPurpose,
259
+ onSheetEnterStart,
260
+ onSheetTransitionComplete,
261
+ onSheetScrimOpacityChange
262
+ } = switcher;
263
+ const hasValidSheetId = typeof sheetId === 'string' && sheetId.length > 0;
264
+ const phase = hasValidSheetId ? getSheetPhase(sheetId) : 'hidden';
265
+ const alignmentOffset = hasValidSheetId ? getSheetAlignmentOffset(sheetId) : 0;
266
+ const panelState = panelStateForSwitcherPhase(phase, alignmentOffset);
267
+ const isInteractive = phase === 'active' || phase === 'entering';
268
+ const isInactive = phase === 'covered' || phase === 'aligning' || phase === 'fading' || phase === 'exiting';
269
+ const isPresented = phase !== 'hidden';
270
+ const isTopSheet = phase === 'active' || phase === 'entering';
271
+ const panelRef = useRef(null);
272
+ const previousPhaseRef = useRef(phase);
273
+ const previousPhase = previousPhaseRef.current;
274
+ const hasPresentedRef = useRef(false);
275
+ useLayoutEffect(() => {
276
+ previousPhaseRef.current = phase;
277
+ }, [phase]);
278
+ const dismissOnSwipe = useCallback(() => {
279
+ if (purpose === 'info' && hasValidSheetId && activeSheet === sheetId) {
280
+ onActiveSheetChange(null);
281
+ }
282
+ }, [activeSheet, hasValidSheetId, onActiveSheetChange, purpose, sheetId]);
283
+ const handlePanelElementChange = useCallback(element => {
284
+ panelRef.current = element;
285
+ if (hasValidSheetId) {
286
+ registerSheetElement(sheetId, element);
287
+ }
288
+ }, [hasValidSheetId, registerSheetElement, sheetId]);
289
+ const handleMotionStart = useCallback(motion => {
290
+ if (motion === 'entering' && hasValidSheetId) {
291
+ onSheetEnterStart(sheetId);
292
+ }
293
+ }, [hasValidSheetId, onSheetEnterStart, sheetId]);
294
+ const handleMotionComplete = useCallback(motion => {
295
+ if (hasValidSheetId) {
296
+ onSheetTransitionComplete({
297
+ sheetId,
298
+ phase: motion
299
+ });
300
+ }
301
+ }, [hasValidSheetId, onSheetTransitionComplete, sheetId]);
302
+ const handleScrimOpacity = useCallback(opacity => {
303
+ if (hasValidSheetId) {
304
+ onSheetScrimOpacityChange(sheetId, opacity);
305
+ }
306
+ }, [hasValidSheetId, onSheetScrimOpacityChange, sheetId]);
307
+ useLayoutEffect(() => {
308
+ if (!hasValidSheetId) {
309
+ return;
310
+ }
311
+ registerSheetLabel(sheetId, label);
312
+ return () => registerSheetLabel(sheetId, null);
313
+ }, [hasValidSheetId, label, registerSheetLabel, sheetId]);
314
+ useLayoutEffect(() => {
315
+ if (!hasValidSheetId) {
316
+ return;
317
+ }
318
+ registerSheetPurpose(sheetId, purpose);
319
+ return () => registerSheetPurpose(sheetId, null);
320
+ }, [hasValidSheetId, purpose, registerSheetPurpose, sheetId]);
321
+ useEffect(() => {
322
+ if (isInteractive) {
323
+ const wasInteractive = previousPhase === 'active' || previousPhase === 'entering';
324
+ if (!hasPresentedRef.current || !wasInteractive) {
325
+ focusPanel(panelRef.current, hasScrim);
326
+ }
327
+ hasPresentedRef.current = true;
328
+ } else if (phase === 'hidden') {
329
+ hasPresentedRef.current = false;
330
+ }
331
+ }, [hasScrim, isInteractive, phase, previousPhase]);
332
+ useDevWarning('BottomSheet', 'requires a non-empty `label` for an accessible name; the open sheet ' + 'has no built-in heading to derive one from.', isInteractive && !label);
333
+ return /*#__PURE__*/_jsx("div", {
334
+ ...{
335
+ 0: {
336
+ className: "x10l6tqk x17y0mx6 x1ey2m1c x78zum5 xl56j7k x47corl"
337
+ },
338
+ 2: {
339
+ className: "x10l6tqk x17y0mx6 x1ey2m1c xl56j7k x47corl x1s85apg"
340
+ },
341
+ 1: {
342
+ className: "x10l6tqk x17y0mx6 x1ey2m1c x78zum5 xl56j7k x47corl x1vjfegm"
343
+ },
344
+ 3: {
345
+ className: "x10l6tqk x17y0mx6 x1ey2m1c xl56j7k x47corl x1s85apg x1vjfegm"
346
+ }
347
+ }[!!!isPresented << 1 | !!isTopSheet << 0],
348
+ hidden: !isPresented,
349
+ "aria-hidden": isInactive ? 'true' : undefined,
350
+ inert: isInactive ? true : undefined,
351
+ children: /*#__PURE__*/_jsx(BottomSheetPanel, {
352
+ ...props,
353
+ ref: ref,
354
+ state: panelState,
355
+ height: height,
356
+ isSwipeDismissAllowed: purpose === 'info',
357
+ isPageScrollLocked: hasScrim,
358
+ xstyle: xstyle,
359
+ onDismiss: dismissOnSwipe,
360
+ onScrimOpacity: handleScrimOpacity,
361
+ onElementChange: handlePanelElementChange,
362
+ onMotionStart: handleMotionStart,
363
+ onMotionComplete: handleMotionComplete,
364
+ children: /*#__PURE__*/_jsx(BottomSheetSwitcherContext, {
365
+ value: null,
366
+ children: children
367
+ })
368
+ })
369
+ });
370
+ }
371
+
372
+ /**
373
+ * A mobile touch sheet that either owns a native dialog or participates in a
374
+ * BottomSheetSwitcher shared dialog when given a sheetId inside that context.
375
+ */
376
+ export function BottomSheet(props) {
377
+ const switcher = use(BottomSheetSwitcherContext);
378
+ const runtimeSheetId = props.sheetId;
379
+ const hasValidSheetId = typeof runtimeSheetId === 'string' && runtimeSheetId.length > 0;
380
+ useDevWarning('BottomSheet', 'requires a non-empty `sheetId` when nested in ' + 'BottomSheetSwitcher; standalone `isOpen` / `onOpenChange` props are ' + 'ignored there.', switcher != null && !hasValidSheetId);
381
+ useDevWarning('BottomSheet', '`sheetId` only works inside BottomSheetSwitcher. Use `isOpen` and ' + '`onOpenChange` for a standalone sheet.', switcher == null && runtimeSheetId != null);
382
+ if (switcher != null) {
383
+ return /*#__PURE__*/_jsx(SwitcherBottomSheetItem, {
384
+ ...props,
385
+ switcher: switcher
386
+ });
387
+ }
388
+ return /*#__PURE__*/_jsx(StandaloneBottomSheet, {
389
+ ...props
390
+ });
391
+ }
392
+ BottomSheet.displayName = 'BottomSheet';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @file BottomSheetPanel.tsx
3
+ * @input Uses React, StyleX, theme tokens, useSheetGestures
4
+ * @output Internal BottomSheetPanel surface and motion-state types
5
+ * @position Shared presentation layer for standalone and switcher BottomSheets
6
+ *
7
+ * This component owns everything intrinsic to a sheet surface: height budgets,
8
+ * drag and snap gestures, the handle and scrolling body, motion styles, and
9
+ * transition completion. It deliberately does not own a dialog, focus, inert
10
+ * state, or switcher registration; those belong to the hosting controller.
11
+ *
12
+ * SYNC: When modified, update these files to stay in sync:
13
+ * - /packages/core/src/BottomSheet/BottomSheet.tsx
14
+ * - /packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
15
+ * - /packages/core/src/BottomSheet/useMobileKeyboard.ts
16
+ * - /packages/core/src/BottomSheet/useSheetGestures.ts
17
+ */
18
+ import { type ReactNode } from 'react';
19
+ import type { BaseProps } from '../BaseProps';
20
+ declare const HEIGHT_BUDGETS: {
21
+ readonly hug: "92dvh";
22
+ readonly capped: "62dvh";
23
+ readonly tall: "92dvh";
24
+ };
25
+ export type BottomSheetHeight = keyof typeof HEIGHT_BUDGETS;
26
+ export type BottomSheetPanelMotion = 'entering' | 'aligning' | 'fading' | 'exiting';
27
+ export type BottomSheetPanelState = {
28
+ kind: 'hidden';
29
+ } | {
30
+ kind: 'open';
31
+ entering: boolean;
32
+ } | {
33
+ kind: 'retained';
34
+ motion: 'covered' | 'aligning' | 'fading';
35
+ alignmentOffset: number;
36
+ } | {
37
+ kind: 'exiting';
38
+ };
39
+ interface BottomSheetPanelProps extends BaseProps<HTMLDivElement> {
40
+ /** Ref forwarded to the visual sheet panel. */
41
+ ref?: React.Ref<HTMLDivElement>;
42
+ state: BottomSheetPanelState;
43
+ height: BottomSheetHeight | number | string;
44
+ children: ReactNode;
45
+ isSwipeDismissAllowed?: boolean;
46
+ /** Whether the host has locked page scrolling (a modal, scrim-backed sheet). */
47
+ isPageScrollLocked?: boolean;
48
+ onDismiss: () => void;
49
+ onScrimOpacity: (opacity: number) => void;
50
+ onElementChange?: (element: HTMLDivElement | null) => void;
51
+ onMotionStart?: (motion: BottomSheetPanelMotion) => void;
52
+ onMotionComplete?: (motion: BottomSheetPanelMotion) => void;
53
+ }
54
+ /** Internal visual and gesture surface shared by every BottomSheet host. */
55
+ export declare function BottomSheetPanel({ ref, state, height, children, className, style, tabIndex, xstyle, isSwipeDismissAllowed, isPageScrollLocked, onDismiss, onScrimOpacity, onElementChange, onMotionStart, onMotionComplete, ...props }: BottomSheetPanelProps): import("react").JSX.Element;
56
+ export declare namespace BottomSheetPanel {
57
+ var displayName: string;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=BottomSheetPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BottomSheetPanel.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheetPanel.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAgB5C,QAAA,MAAM,cAAc;;;;CAIV,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,cAAc,CAAC;AAqG5D,MAAM,MAAM,sBAAsB,GAChC,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAC7B;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAC,GAChB;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAC,GACjC;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC1C,eAAe,EAAE,MAAM,CAAC;CACzB,GACD;IAAC,IAAI,EAAE,SAAS,CAAA;CAAC,CAAC;AAEtB,UAAU,qBAAsB,SAAQ,SAAS,CAAC,cAAc,CAAC;IAC/D,+CAA+C;IAC/C,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC,KAAK,EAAE,qBAAqB,CAAC;IAC7B,MAAM,EAAE,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5C,QAAQ,EAAE,SAAS,CAAC;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3D,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACzD,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;CAC7D;AA+GD,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,KAAK,EACL,MAAM,EACN,QAAQ,EACR,SAAS,EACT,KAAK,EACL,QAAQ,EACR,MAAM,EACN,qBAA4B,EAC5B,kBAA0B,EAC1B,SAAS,EACT,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,GAAG,KAAK,EACT,EAAE,qBAAqB,+BA0OvB;yBA3Pe,gBAAgB"}