@astryxdesign/core 0.4.4 → 0.4.5-canary.1dc3e5d

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 (176) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/BottomSheet/BottomSheet.d.ts +11 -2
  3. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  4. package/dist/BottomSheet/BottomSheet.js +4 -0
  5. package/dist/BottomSheet/BottomSheetPanel.d.ts +5 -2
  6. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  7. package/dist/BottomSheet/BottomSheetPanel.js +56 -13
  8. package/dist/BottomSheet/index.d.ts +1 -1
  9. package/dist/BottomSheet/index.d.ts.map +1 -1
  10. package/dist/BottomSheet/snapOffsets.d.ts +57 -20
  11. package/dist/BottomSheet/snapOffsets.d.ts.map +1 -1
  12. package/dist/BottomSheet/snapOffsets.js +106 -30
  13. package/dist/BottomSheet/useSheetGestures.d.ts +13 -8
  14. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  15. package/dist/BottomSheet/useSheetGestures.js +160 -64
  16. package/dist/Calendar/Calendar.d.ts +17 -0
  17. package/dist/Calendar/Calendar.d.ts.map +1 -1
  18. package/dist/Calendar/Calendar.js +34 -3
  19. package/dist/Calendar/getStandaloneShortWeekdayNames.d.ts +14 -0
  20. package/dist/Calendar/getStandaloneShortWeekdayNames.d.ts.map +1 -0
  21. package/dist/Calendar/getStandaloneShortWeekdayNames.js +26 -0
  22. package/dist/Calendar/hooks/useCalendarConstraints.d.ts +22 -1
  23. package/dist/Calendar/hooks/useCalendarConstraints.d.ts.map +1 -1
  24. package/dist/Calendar/hooks/useCalendarConstraints.js +26 -4
  25. package/dist/Calendar/hooks/useCalendarDays.d.ts.map +1 -1
  26. package/dist/Calendar/hooks/useCalendarDays.js +14 -10
  27. package/dist/Calendar/standaloneShortWeekdayNames.generated.d.ts +47 -0
  28. package/dist/Calendar/standaloneShortWeekdayNames.generated.d.ts.map +1 -0
  29. package/dist/Calendar/standaloneShortWeekdayNames.generated.js +40 -0
  30. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  31. package/dist/CheckboxInput/CheckboxInput.js +9 -0
  32. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  33. package/dist/ComplexSelector/ComplexSelector.js +6 -1
  34. package/dist/DateInput/DateInput.d.ts.map +1 -1
  35. package/dist/DateInput/DateInput.js +6 -1
  36. package/dist/DateRangeInput/DateRangeInput.d.ts +23 -1
  37. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  38. package/dist/DateRangeInput/DateRangeInput.js +38 -3
  39. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  40. package/dist/DateTimeInput/DateTimeInput.js +7 -2
  41. package/dist/Field/FieldLabel.d.ts +2 -1
  42. package/dist/Field/FieldLabel.d.ts.map +1 -1
  43. package/dist/Field/FieldLabel.js +21 -3
  44. package/dist/Field/InputClearButton.d.ts +2 -1
  45. package/dist/Field/InputClearButton.d.ts.map +1 -1
  46. package/dist/Field/InputClearButton.js +6 -1
  47. package/dist/FormLayout/FormLayout.d.ts +24 -2
  48. package/dist/FormLayout/FormLayout.d.ts.map +1 -1
  49. package/dist/FormLayout/FormLayout.js +7 -2
  50. package/dist/FormLayout/FormLayoutContext.d.ts +15 -2
  51. package/dist/FormLayout/FormLayoutContext.d.ts.map +1 -1
  52. package/dist/FormLayout/FormLayoutContext.js +19 -4
  53. package/dist/FormLayout/index.d.ts +1 -1
  54. package/dist/FormLayout/index.d.ts.map +1 -1
  55. package/dist/Markdown/Markdown.d.ts +8 -0
  56. package/dist/Markdown/Markdown.d.ts.map +1 -1
  57. package/dist/Markdown/Markdown.js +31 -3
  58. package/dist/Markdown/parser.d.ts +14 -2
  59. package/dist/Markdown/parser.d.ts.map +1 -1
  60. package/dist/Markdown/parser.js +50 -2
  61. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  62. package/dist/MultiSelector/MultiSelector.js +6 -1
  63. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  64. package/dist/NumberInput/NumberInput.js +6 -1
  65. package/dist/Outline/parseOutlineFromMarkdown.d.ts +2 -0
  66. package/dist/Outline/parseOutlineFromMarkdown.d.ts.map +1 -1
  67. package/dist/Outline/parseOutlineFromMarkdown.js +5 -31
  68. package/dist/RadioList/RadioList.d.ts.map +1 -1
  69. package/dist/RadioList/RadioList.js +12 -1
  70. package/dist/Selector/Selector.d.ts.map +1 -1
  71. package/dist/Selector/Selector.js +6 -1
  72. package/dist/StatusDot/StatusDot.d.ts +43 -3
  73. package/dist/StatusDot/StatusDot.d.ts.map +1 -1
  74. package/dist/StatusDot/StatusDot.js +42 -5
  75. package/dist/Switch/Switch.d.ts.map +1 -1
  76. package/dist/Switch/Switch.js +9 -0
  77. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
  78. package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +7 -2
  79. package/dist/TextArea/TextArea.d.ts.map +1 -1
  80. package/dist/TextArea/TextArea.js +6 -1
  81. package/dist/TextInput/TextInput.d.ts.map +1 -1
  82. package/dist/TextInput/TextInput.js +6 -1
  83. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  84. package/dist/TimeInput/TimeInput.js +6 -1
  85. package/dist/hooks/useResolvedRequired.d.ts +19 -0
  86. package/dist/hooks/useResolvedRequired.d.ts.map +1 -0
  87. package/dist/hooks/useResolvedRequired.js +40 -0
  88. package/dist/utils/plainDate.d.ts +6 -0
  89. package/dist/utils/plainDate.d.ts.map +1 -1
  90. package/dist/utils/plainDate.js +12 -0
  91. package/locales/af-ZA.json +958 -0
  92. package/locales/ar-SA.json +998 -0
  93. package/locales/ca-ES.json +974 -0
  94. package/locales/cs-CZ.json +990 -0
  95. package/locales/da-DK.json +966 -0
  96. package/locales/de-DE.json +966 -0
  97. package/locales/el-GR.json +990 -0
  98. package/locales/en.json +4 -0
  99. package/locales/es-ES.json +978 -0
  100. package/locales/fi-FI.json +990 -0
  101. package/locales/fr-FR.json +928 -0
  102. package/locales/he-IL.json +990 -0
  103. package/locales/hu-HU.json +990 -0
  104. package/locales/it-IT.json +978 -0
  105. package/locales/ja-JP.json +998 -0
  106. package/locales/ko-KR.json +990 -0
  107. package/locales/nl-NL.json +954 -0
  108. package/locales/no-NO.json +978 -0
  109. package/locales/pl-PL.json +982 -0
  110. package/locales/pseudo.json +3 -0
  111. package/locales/pt-BR.json +982 -0
  112. package/locales/pt-PT.json +982 -0
  113. package/locales/ro-RO.json +982 -0
  114. package/locales/ru-RU.json +990 -0
  115. package/locales/sr-SP.json +990 -0
  116. package/locales/sv-SE.json +986 -0
  117. package/locales/tr-TR.json +990 -0
  118. package/locales/uk-UA.json +990 -0
  119. package/locales/vi-VN.json +986 -0
  120. package/locales/zh-CN.json +998 -0
  121. package/locales/zh-TW.json +998 -0
  122. package/package.json +3 -3
  123. package/src/BottomSheet/BottomSheet.doc.mjs +36 -3
  124. package/src/BottomSheet/BottomSheet.test.tsx +153 -2
  125. package/src/BottomSheet/BottomSheet.tsx +16 -2
  126. package/src/BottomSheet/BottomSheetPanel.tsx +67 -13
  127. package/src/BottomSheet/index.ts +5 -1
  128. package/src/BottomSheet/snapOffsets.test.ts +114 -47
  129. package/src/BottomSheet/snapOffsets.ts +119 -33
  130. package/src/BottomSheet/useSheetGestures.test.ts +113 -15
  131. package/src/BottomSheet/useSheetGestures.ts +196 -100
  132. package/src/Calendar/Calendar.doc.mjs +16 -0
  133. package/src/Calendar/Calendar.test.tsx +137 -0
  134. package/src/Calendar/Calendar.tsx +65 -2
  135. package/src/Calendar/getStandaloneShortWeekdayNames.test.ts +54 -0
  136. package/src/Calendar/getStandaloneShortWeekdayNames.ts +38 -0
  137. package/src/Calendar/hooks/useCalendarConstraints.ts +54 -3
  138. package/src/Calendar/hooks/useCalendarDays.ts +13 -10
  139. package/src/Calendar/standaloneShortWeekdayNames.generated.ts +50 -0
  140. package/src/CheckboxInput/CheckboxInput.tsx +6 -0
  141. package/src/ComplexSelector/ComplexSelector.tsx +3 -1
  142. package/src/DateInput/DateInput.tsx +3 -1
  143. package/src/DateRangeInput/DateRangeInput.doc.mjs +16 -0
  144. package/src/DateRangeInput/DateRangeInput.test.tsx +81 -1
  145. package/src/DateRangeInput/DateRangeInput.tsx +72 -1
  146. package/src/DateTimeInput/DateTimeInput.tsx +4 -2
  147. package/src/Field/Field.doc.mjs +1 -0
  148. package/src/Field/FieldLabel.tsx +20 -4
  149. package/src/Field/InputClearButton.test.tsx +25 -0
  150. package/src/Field/InputClearButton.tsx +4 -1
  151. package/src/FormLayout/FormLayout.doc.mjs +13 -0
  152. package/src/FormLayout/FormLayout.test.tsx +181 -4
  153. package/src/FormLayout/FormLayout.tsx +33 -2
  154. package/src/FormLayout/FormLayoutContext.ts +22 -7
  155. package/src/FormLayout/index.ts +1 -1
  156. package/src/Markdown/Markdown.doc.mjs +3 -0
  157. package/src/Markdown/Markdown.test.tsx +78 -0
  158. package/src/Markdown/Markdown.tsx +41 -1
  159. package/src/Markdown/parser.ts +60 -2
  160. package/src/MultiSelector/MultiSelector.tsx +3 -1
  161. package/src/NumberInput/NumberInput.tsx +3 -1
  162. package/src/Outline/Outline.doc.mjs +2 -0
  163. package/src/Outline/parseOutlineFromMarkdown.ts +10 -40
  164. package/src/RadioList/RadioList.tsx +9 -1
  165. package/src/Selector/Selector.tsx +3 -1
  166. package/src/StatusDot/StatusDot.doc.mjs +13 -0
  167. package/src/StatusDot/StatusDot.test.tsx +115 -8
  168. package/src/StatusDot/StatusDot.tsx +74 -9
  169. package/src/Switch/Switch.tsx +6 -0
  170. package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +20 -2
  171. package/src/TextArea/TextArea.tsx +3 -1
  172. package/src/TextInput/TextInput.tsx +3 -1
  173. package/src/TimeInput/TimeInput.tsx +3 -1
  174. package/src/hooks/useResolvedRequired.ts +42 -0
  175. package/src/utils/plainDate.test.ts +50 -0
  176. package/src/utils/plainDate.ts +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/core",
3
- "version": "0.4.4",
3
+ "version": "0.4.5-canary.1dc3e5d",
4
4
  "displayName": "Astryx Core",
5
5
  "description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
6
6
  "author": "Meta Open Source",
@@ -656,6 +656,7 @@
656
656
  "react-dom": ">=19.0.0"
657
657
  },
658
658
  "devDependencies": {
659
+ "@astryxdesign/cli": "0.4.5-canary.1dc3e5d",
659
660
  "@babel/cli": "^8.0.4",
660
661
  "@babel/core": "^7.29.7",
661
662
  "@babel/preset-react": "^8.0.1",
@@ -664,8 +665,7 @@
664
665
  "@testing-library/dom": "^10.0.0",
665
666
  "@testing-library/jest-dom": "^6.6.0",
666
667
  "@testing-library/react": "^16.3.2",
667
- "rimraf": "^6.0.1",
668
- "@astryxdesign/cli": "0.4.4"
668
+ "rimraf": "^6.0.1"
669
669
  },
670
670
  "dependencies": {
671
671
  "intl-messageformat": "^11.2.9"
@@ -13,6 +13,9 @@ export const docs = {
13
13
  'touch',
14
14
  'drag',
15
15
  'swipe',
16
+ 'snap point',
17
+ 'detent',
18
+ 'resize',
16
19
  'dismiss',
17
20
  'grab handle',
18
21
  'dialog',
@@ -54,7 +57,7 @@ export const docs = {
54
57
  targets: [{className: 'astryx-bottom-sheet', visualProps: []}],
55
58
  },
56
59
  description:
57
- "A mobile touch sheet that rises from the bottom edge, with animated entrance and exit, a grab handle, drag-to-resize snap points, and purpose-controlled dismissal. A standalone sheet owns a native <dialog>; inside BottomSheetSwitcher it renders a panel in the switcher's shared dialog. In both modes, ref and shared DOM props target the visual panel <div>.",
60
+ "A mobile touch sheet that rises from the bottom edge, with animated entrance and exit, a grab handle, optional drag-to-resize snap points, and purpose-controlled dismissal. A standalone sheet owns a native <dialog>; inside BottomSheetSwitcher it renders a panel in the switcher's shared dialog. In both modes, ref and shared DOM props target the visual panel <div>.",
58
61
  props: [
59
62
  {
60
63
  name: 'isOpen',
@@ -99,9 +102,15 @@ export const docs = {
99
102
  name: 'height',
100
103
  type: "'hug' | 'capped' | 'tall' | number | string",
101
104
  description:
102
- "How tall the sheet is. Named budgets: 'hug' fits its content up to 92% of the viewport, 'capped' is a scrolling mid-height panel (~62%), and 'tall' is a pinned near-full panel (~92%) for content that streams in. Or pass a number (px) / CSS length for a custom budget. The user can drag between snap points regardless. On shorter viewports the sheet fills the available height. Only a fully expanded 'tall' sheet provides mobile-keyboard accommodation: it stays put and scrolls each focused control above the keyboard. Hug, Capped, numeric and CSS-length heights never do, and a Tall sheet stops doing it the moment the user drags it to a shorter detent — resuming when they drag it back. Outside that state the sheet neither moves nor adds keyboard scroll space, and the browser's own focus reveal is left in place; on iOS that reveal can shift the whole page.",
105
+ "How tall the sheet is. Named budgets: 'hug' fits its content up to 92% of the viewport, 'capped' is a scrolling mid-height panel (~62%), and 'tall' is a pinned near-full panel (~92%) for content that streams in. Or pass a number (px) / CSS length for a custom budget. Give snapPoints to let the user drag between heights. On shorter viewports the sheet fills the available height. Only a fully expanded 'tall' sheet provides mobile-keyboard accommodation: it stays put and scrolls each focused control above the keyboard. Hug, Capped, numeric and CSS-length heights never do, and a Tall sheet stops doing it the moment the user drags it to a shorter detent — resuming when they drag it back. Outside that state the sheet neither moves nor adds keyboard scroll space, and the browser's own focus reveal is left in place; on iOS that reveal can shift the whole page.",
103
106
  default: "'capped'",
104
107
  },
108
+ {
109
+ name: 'snapPoints',
110
+ type: 'ReadonlyArray<number | string>',
111
+ description:
112
+ "Extra heights the sheet can rest at when dragged; its own height is always the tallest stop, and omitting this gives a sheet that only opens and closes. Each stop is the sheet's visible height: a number is a viewport fraction (0.5 is half the screen), '50%' the same in CSS, '320px' an absolute length. A stop of a quarter of the sheet or less is a peek — it slides away instead of reflowing, and thins the scrim.",
113
+ },
105
114
  {
106
115
  name: 'hasScrim',
107
116
  type: 'boolean',
@@ -156,6 +165,30 @@ export const docs = {
156
165
  label="Nearby places"
157
166
  height="tall">
158
167
  <PlaceList />
168
+ </BottomSheet>`,
169
+ },
170
+ {
171
+ label: 'Collapsible to half the screen',
172
+ code: `const [isOpen, setIsOpen] = useState(false);
173
+ <BottomSheet
174
+ isOpen={isOpen}
175
+ onOpenChange={setIsOpen}
176
+ label="Nearby places"
177
+ height="tall"
178
+ snapPoints={[0.5]}>
179
+ <PlaceList />
180
+ </BottomSheet>`,
181
+ },
182
+ {
183
+ label: 'A peek, a working height, and full',
184
+ code: `const [isOpen, setIsOpen] = useState(false);
185
+ <BottomSheet
186
+ isOpen={isOpen}
187
+ onOpenChange={setIsOpen}
188
+ label="Route"
189
+ height="tall"
190
+ snapPoints={['96px', '50%']}>
191
+ <RouteDetails />
159
192
  </BottomSheet>`,
160
193
  },
161
194
  {
@@ -236,7 +269,7 @@ export const docs = {
236
269
  /** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
237
270
  export const docsDense = {
238
271
  description:
239
- 'mobile touch sheet rising from the bottom edge (native <dialog>): grab handle, transform-based drag-to-resize snap points, scrolling area resizes to the snapped visible height on release (the peek detent keeps the full height and slides instead), Dialog-aligned dismissal purpose (info/form/required), purpose-gated swipe-to-dismiss, fully-expanded Tall visual-viewport mobile-keyboard handling, named height scale, modal (default) or non-modal (hasScrim={false}) presentation',
272
+ 'mobile touch sheet rising from the bottom edge (native <dialog>): grab handle, opt-in transform-based drag-to-resize snap points (snapPoints: viewport fraction, percent or px length), scrolling area resizes to the snapped visible height on release (a peek stop — a quarter of the sheet or less — keeps the full height and slides instead), Dialog-aligned dismissal purpose (info/form/required), purpose-gated swipe-to-dismiss, fully-expanded Tall visual-viewport mobile-keyboard handling, named height scale, modal (default) or non-modal (hasScrim={false}) presentation',
240
273
  usage: {
241
274
  description:
242
275
  'Mobile touch surface for filters, actions, forms, and detail views that should rise from the bottom of the viewport; use BottomSheetSwitcher for multi-step flows.',
@@ -15,6 +15,12 @@ import {createRef, useState} from 'react';
15
15
  import {BottomSheet} from './BottomSheet';
16
16
  import {BottomSheetSwitcher} from './BottomSheetSwitcher';
17
17
 
18
+ // A sheet has no stops unless its host asks for them, so the tests that
19
+ // exercise detents pass their own. These three — a 14% peek, a half-height
20
+ // stop, and a 92% stop the Tall budget already covers — are the geometry the
21
+ // height assertions below are written against.
22
+ const SNAP_POINTS: ReadonlyArray<number> = [0.14, 0.5, 0.92];
23
+
18
24
  // jsdom doesn't implement <dialog> open/close or pointer capture; stub them.
19
25
  beforeEach(() => {
20
26
  HTMLDialogElement.prototype.showModal = vi.fn(function (
@@ -178,13 +184,20 @@ function finishSheetExit() {
178
184
  fireEvent.transitionEnd(getSheet(), {propertyName: 'transform'});
179
185
  }
180
186
 
181
- function ExitHarness({hasScrim}: {hasScrim?: boolean}) {
187
+ function ExitHarness({
188
+ hasScrim,
189
+ snapPoints,
190
+ }: {
191
+ hasScrim?: boolean;
192
+ snapPoints?: ReadonlyArray<number>;
193
+ }) {
182
194
  const [isOpen, setIsOpen] = useState(true);
183
195
  return (
184
196
  <BottomSheet
185
197
  isOpen={isOpen}
186
198
  onOpenChange={setIsOpen}
187
199
  label="Filters"
200
+ snapPoints={snapPoints}
188
201
  hasScrim={hasScrim}>
189
202
  <button type="button" onClick={() => setIsOpen(false)}>
190
203
  Close sheet
@@ -616,6 +629,7 @@ describe('BottomSheet', () => {
616
629
  isOpen
617
630
  onOpenChange={() => {}}
618
631
  label="Release notes"
632
+ snapPoints={SNAP_POINTS}
619
633
  height="tall">
620
634
  Content
621
635
  </BottomSheet>,
@@ -667,6 +681,7 @@ describe('BottomSheet', () => {
667
681
  isOpen
668
682
  onOpenChange={() => {}}
669
683
  label="Release notes"
684
+ snapPoints={SNAP_POINTS}
670
685
  height="tall">
671
686
  Content
672
687
  </BottomSheet>,
@@ -720,6 +735,7 @@ describe('BottomSheet', () => {
720
735
  isOpen
721
736
  onOpenChange={() => {}}
722
737
  label="Release notes"
738
+ snapPoints={SNAP_POINTS}
723
739
  height="tall">
724
740
  Content
725
741
  </BottomSheet>,
@@ -797,6 +813,7 @@ describe('BottomSheet', () => {
797
813
  isOpen
798
814
  onOpenChange={() => {}}
799
815
  label="Release notes"
816
+ snapPoints={SNAP_POINTS}
800
817
  height="tall"
801
818
  style={{transition: 'none'}}>
802
819
  Content
@@ -830,6 +847,7 @@ describe('BottomSheet', () => {
830
847
  isOpen
831
848
  onOpenChange={() => {}}
832
849
  label="Release notes"
850
+ snapPoints={SNAP_POINTS}
833
851
  height="tall">
834
852
  Content
835
853
  </BottomSheet>,
@@ -890,7 +908,7 @@ describe('BottomSheet', () => {
890
908
  const observers = mockResizeObserverInstances();
891
909
  mockVisualViewport(800);
892
910
  mockWindowHeight(800);
893
- render(<ExitHarness />);
911
+ render(<ExitHarness snapPoints={SNAP_POINTS} />);
894
912
  const sheet = getSheet();
895
913
  const sheetObserver = observers.find(instance =>
896
914
  instance.observed.has(sheet),
@@ -936,6 +954,7 @@ describe('BottomSheet', () => {
936
954
  isOpen
937
955
  onOpenChange={() => {}}
938
956
  label="Release notes"
957
+ snapPoints={SNAP_POINTS}
939
958
  height="tall">
940
959
  Content
941
960
  </BottomSheet>,
@@ -1000,6 +1019,7 @@ describe('BottomSheet', () => {
1000
1019
  isOpen
1001
1020
  onOpenChange={() => {}}
1002
1021
  label="Release notes"
1022
+ snapPoints={SNAP_POINTS}
1003
1023
  height="tall">
1004
1024
  Content
1005
1025
  </BottomSheet>,
@@ -1039,6 +1059,136 @@ describe('BottomSheet', () => {
1039
1059
  });
1040
1060
  });
1041
1061
 
1062
+ describe('snapPoints', () => {
1063
+ // A Tall sheet in an 800px window: a 784px border box, 48px of which is
1064
+ // the reserve below the fold, so 736px of it is visible.
1065
+ function renderTallSheet(
1066
+ snapPoints?: ReadonlyArray<number | string>,
1067
+ onOpenChange: (isOpen: boolean) => void = () => {},
1068
+ ) {
1069
+ const observers = mockResizeObserverInstances();
1070
+ mockVisualViewport(800);
1071
+ mockWindowHeight(800);
1072
+ const view = render(
1073
+ <BottomSheet
1074
+ isOpen
1075
+ onOpenChange={onOpenChange}
1076
+ label="Release notes"
1077
+ snapPoints={snapPoints}
1078
+ height="tall">
1079
+ Content
1080
+ </BottomSheet>,
1081
+ );
1082
+ const sheet = getSheet();
1083
+ const sheetObserver = observers.find(instance =>
1084
+ instance.observed.has(sheet),
1085
+ );
1086
+ act(() => {
1087
+ sheetObserver?.callback(
1088
+ [resizeEntry(784, 736)],
1089
+ sheetObserver as unknown as ResizeObserver,
1090
+ );
1091
+ });
1092
+ return {sheet, view};
1093
+ }
1094
+
1095
+ function dragHandleTo(y: number) {
1096
+ fireTimedPointer(getHandle(), 'pointerdown', {time: 0, y: 0});
1097
+ fireTimedPointer(getHandle(), 'pointermove', {time: 1000, y});
1098
+ fireTimedPointer(getHandle(), 'pointerup', {time: 2000, y});
1099
+ fireEvent.transitionEnd(getSheet(), {propertyName: 'transform'});
1100
+ }
1101
+
1102
+ it('has no stops of its own, so a released drag springs back', () => {
1103
+ const onOpenChange = vi.fn();
1104
+ const {sheet} = renderTallSheet(undefined, onOpenChange);
1105
+
1106
+ // 200px down is well short of the dismiss threshold, and there is no
1107
+ // stop to catch it, so the sheet returns to fully open.
1108
+ dragHandleTo(200);
1109
+
1110
+ expect(sheet.style.transform).toBe('');
1111
+ expect(sheet.style.height).toBe('');
1112
+ expect(onOpenChange).not.toHaveBeenCalled();
1113
+ });
1114
+
1115
+ it('rests at a stop given as a fraction of the viewport', () => {
1116
+ const {sheet} = renderTallSheet([0.5]);
1117
+
1118
+ // Half of the 800px window is 400px of visible sheet: 736 - 400 = 336px
1119
+ // of travel, taken as layout height once the snap lands.
1120
+ dragHandleTo(336);
1121
+
1122
+ expect(sheet.style.height).toBe('448px');
1123
+ expect(sheet.style.transform).toBe('');
1124
+ });
1125
+
1126
+ it('reads a percentage as the same stop as the fraction', () => {
1127
+ const {sheet} = renderTallSheet(['50%']);
1128
+ dragHandleTo(336);
1129
+ expect(sheet.style.height).toBe('448px');
1130
+ });
1131
+
1132
+ it('rests at a stop given as an absolute px length', () => {
1133
+ const {sheet} = renderTallSheet(['320px']);
1134
+
1135
+ // A 320px stop sits 736 - 320 = 416px down, whatever the window does.
1136
+ dragHandleTo(416);
1137
+
1138
+ expect(sheet.style.height).toBe('368px');
1139
+ expect(sheet.style.transform).toBe('');
1140
+ });
1141
+
1142
+ it('re-anchors to the same stop when the points change under a resting sheet', () => {
1143
+ const {sheet, view} = renderTallSheet([0.5]);
1144
+ dragHandleTo(336);
1145
+ expect(sheet.style.height).toBe('448px');
1146
+
1147
+ // Without an inline height the sheet renders its natural 92dvh budget.
1148
+ vi.spyOn(sheet, 'getBoundingClientRect').mockImplementation(() =>
1149
+ rect({
1150
+ top: 0,
1151
+ bottom: sheet.style.height
1152
+ ? Number.parseFloat(sheet.style.height)
1153
+ : 784,
1154
+ }),
1155
+ );
1156
+
1157
+ // The host moves its one stop from half the window to a quarter of it.
1158
+ // The sheet is resting on that stop, so it follows — no gesture, and
1159
+ // nothing to animate.
1160
+ view.rerender(
1161
+ <BottomSheet
1162
+ isOpen
1163
+ onOpenChange={() => {}}
1164
+ label="Release notes"
1165
+ snapPoints={[0.25]}
1166
+ height="tall">
1167
+ Content
1168
+ </BottomSheet>,
1169
+ );
1170
+
1171
+ // 200px of visible sheet is 736 - 200 = 536px of travel.
1172
+ expect(sheet.style.height).toBe('248px');
1173
+ expect(sheet.style.transform).toBe('');
1174
+ });
1175
+
1176
+ it('ignores a stop it cannot resolve, and warns which one', () => {
1177
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
1178
+ // 200 is the px mistake: a bare number is a fraction, never a length.
1179
+ const {sheet} = renderTallSheet([0.5, 200]);
1180
+
1181
+ expect(
1182
+ warn.mock.calls.some(args => String(args[0]).includes('200')),
1183
+ ).toBe(true);
1184
+
1185
+ // The stop it could read still works.
1186
+ dragHandleTo(336);
1187
+ expect(sheet.style.height).toBe('448px');
1188
+ warn.mockRestore();
1189
+ });
1190
+ });
1191
+
1042
1192
  describe('mobile keyboard', () => {
1043
1193
  it('claims a transition between fields and delivers it with preventScroll', () => {
1044
1194
  mockIOSWebKit();
@@ -1293,6 +1443,7 @@ describe('BottomSheet', () => {
1293
1443
  isOpen
1294
1444
  onOpenChange={() => {}}
1295
1445
  label="Add a comment"
1446
+ snapPoints={SNAP_POINTS}
1296
1447
  height="tall">
1297
1448
  <input aria-label="Comment" />
1298
1449
  </BottomSheet>,
@@ -49,8 +49,8 @@ import {
49
49
  type BottomSheetSwitcherPhase,
50
50
  } from './BottomSheetSwitcherContext';
51
51
 
52
- export type {BottomSheetHeight} from './BottomSheetPanel';
53
- import type {BottomSheetHeight} from './BottomSheetPanel';
52
+ export type {BottomSheetHeight, BottomSheetSnapPoint} from './BottomSheetPanel';
53
+ import type {BottomSheetHeight, BottomSheetSnapPoint} from './BottomSheetPanel';
54
54
 
55
55
  const styles = stylex.create({
56
56
  dialog: {
@@ -122,6 +122,16 @@ interface BottomSheetSharedProps extends BaseProps<HTMLDivElement> {
122
122
  /** Height budget or custom CSS length. Only fully expanded Tall is keyboard-aware. @default 'capped' */
123
123
  height?: BottomSheetHeight | number | string;
124
124
 
125
+ /**
126
+ * Extra heights the sheet can rest at when dragged; its own height is always
127
+ * the tallest stop, and omitting this gives a sheet that only opens and
128
+ * closes. Each stop is the sheet's visible height: a number is a viewport
129
+ * fraction (`0.5` is half the screen), `'50%'` the same in CSS, `'320px'` an
130
+ * absolute length. A stop of a quarter of the sheet or less is a peek — it
131
+ * slides away instead of reflowing, and thins the scrim.
132
+ */
133
+ snapPoints?: ReadonlyArray<BottomSheetSnapPoint>;
134
+
125
135
  /**
126
136
  * Configures implicit dismissal behavior, matching Dialog.
127
137
  * - required: Blocks swipe, scrim click, and Escape
@@ -193,6 +203,7 @@ function StandaloneBottomSheet({
193
203
  label,
194
204
  children,
195
205
  height = 'capped',
206
+ snapPoints,
196
207
  hasScrim = true,
197
208
  purpose = 'info',
198
209
  xstyle,
@@ -333,6 +344,7 @@ function StandaloneBottomSheet({
333
344
  ref={ref}
334
345
  state={panelState}
335
346
  height={height}
347
+ snapPoints={snapPoints}
336
348
  isSwipeDismissAllowed={purpose === 'info'}
337
349
  isPageScrollLocked={shouldPresent && hasScrim}
338
350
  xstyle={xstyle}
@@ -358,6 +370,7 @@ function SwitcherBottomSheetItem({
358
370
  label,
359
371
  children,
360
372
  height = 'capped',
373
+ snapPoints,
361
374
  purpose = 'info',
362
375
  xstyle,
363
376
  ...props
@@ -488,6 +501,7 @@ function SwitcherBottomSheetItem({
488
501
  ref={ref}
489
502
  state={panelState}
490
503
  height={height}
504
+ snapPoints={snapPoints}
491
505
  isSwipeDismissAllowed={purpose === 'info'}
492
506
  isPageScrollLocked={hasScrim}
493
507
  xstyle={xstyle}
@@ -16,6 +16,7 @@
16
16
  * SYNC: When modified, update these files to stay in sync:
17
17
  * - /packages/core/src/BottomSheet/BottomSheet.tsx
18
18
  * - /packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
19
+ * - /packages/core/src/BottomSheet/snapOffsets.ts
19
20
  * - /packages/core/src/BottomSheet/useMobileKeyboard.ts
20
21
  * - /packages/core/src/BottomSheet/useSheetGestures.ts
21
22
  */
@@ -25,11 +26,13 @@ import {
25
26
  useEffect,
26
27
  useImperativeHandle,
27
28
  useLayoutEffect,
29
+ useMemo,
28
30
  useRef,
29
31
  type ReactNode,
30
32
  } from 'react';
31
33
  import * as stylex from '@stylexjs/stylex';
32
34
  import type {BaseProps} from '../BaseProps';
35
+ import {useDevWarning} from '../hooks';
33
36
  import {
34
37
  colorVars,
35
38
  durationVars,
@@ -40,11 +43,14 @@ import {
40
43
  spacingVars,
41
44
  } from '../theme/tokens.stylex';
42
45
  import {mergeProps, themeProps} from '../utils';
46
+ import {
47
+ isValidSnapPoint,
48
+ resolveSnapPoints,
49
+ type BottomSheetSnapPoint,
50
+ } from './snapOffsets';
43
51
  import {useMobileKeyboard} from './useMobileKeyboard';
44
52
  import {useSheetGestures} from './useSheetGestures';
45
53
 
46
- const SNAP_FRACTIONS = [0.14, 0.5, 0.92];
47
-
48
54
  const HEIGHT_BUDGETS = {
49
55
  hug: '92dvh',
50
56
  capped: '62dvh',
@@ -52,23 +58,39 @@ const HEIGHT_BUDGETS = {
52
58
  } as const;
53
59
 
54
60
  export type BottomSheetHeight = keyof typeof HEIGHT_BUDGETS;
61
+ export type {BottomSheetSnapPoint};
55
62
 
56
63
  // SYNC: must match OVERSCROLL_MAX in useSheetGestures.ts.
57
64
  const OVERSCROLL_PADDING = 48;
58
65
  const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
59
66
  const TRANSITION_BACKSTOP_BUFFER_MS = 50;
60
67
 
61
- function defaultSnapHeights(): number[] {
62
- if (typeof window === 'undefined') {
63
- return [];
68
+ // Measure the same viewport the height budgets are written against. Those are
69
+ // `dvh`, which the virtual keyboard does not shrink, so reading
70
+ // `visualViewport` here would make the two disagree by exactly the keyboard's
71
+ // height: every detent would move while the sheet it measures did not. A
72
+ // keyboard is `useMobileKeyboard`'s business — it holds the sheet still and
73
+ // scrolls the body — and it does not redefine the sheet's detents.
74
+ function layoutViewportHeight(): number {
75
+ return typeof window === 'undefined' ? 0 : window.innerHeight;
76
+ }
77
+
78
+ /**
79
+ * A stable identity for a set of snap points. Type-tagged, so the fraction
80
+ * `0.5` and the (invalid) string `'0.5'` cannot collide on one key.
81
+ *
82
+ * Recomputed every render — the panel re-renders on every frame of a drag — so
83
+ * it stays a single pass over a handful of values, and everything derived from
84
+ * the points hangs off it instead of being rebuilt per frame.
85
+ */
86
+ function snapPointsKeyFor(
87
+ points: ReadonlyArray<BottomSheetSnapPoint> | undefined,
88
+ ): string {
89
+ let key = '';
90
+ for (const point of points ?? []) {
91
+ key += `${typeof point}:${point}|`;
64
92
  }
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);
93
+ return key;
72
94
  }
73
95
 
74
96
  const styles = stylex.create({
@@ -171,6 +193,7 @@ interface BottomSheetPanelProps extends BaseProps<HTMLDivElement> {
171
193
  state: BottomSheetPanelState;
172
194
  height: BottomSheetHeight | number | string;
173
195
  children: ReactNode;
196
+ snapPoints?: ReadonlyArray<BottomSheetSnapPoint>;
174
197
  isSwipeDismissAllowed?: boolean;
175
198
  /** Whether the host has locked page scrolling (a modal, scrim-backed sheet). */
176
199
  isPageScrollLocked?: boolean;
@@ -296,6 +319,7 @@ export function BottomSheetPanel({
296
319
  state,
297
320
  height,
298
321
  children,
322
+ snapPoints,
299
323
  className,
300
324
  style,
301
325
  tabIndex,
@@ -340,6 +364,36 @@ export function BottomSheetPanel({
340
364
  const isFading = isRetained && state.motion === 'fading';
341
365
  const alignmentOffset = isRetained ? state.alignmentOffset : 0;
342
366
 
367
+ // Everything derived from the snap points keys off their identity, not the
368
+ // array's: the resolver's identity is the hook's signal that the stops
369
+ // changed, so it must not churn on a re-render the drag caused. The memo
370
+ // reads the points through a ref, so the resolver resolves them at call time
371
+ // — against whatever the viewport is then, not what it was at memo time.
372
+ const snapPointsKey = snapPointsKeyFor(snapPoints);
373
+ const snapPointsRef = useRef(snapPoints);
374
+ snapPointsRef.current = snapPoints;
375
+ const {snapHeights, ignoredSnapPointsMessage} = useMemo(() => {
376
+ if (snapPointsKey === '') {
377
+ return {snapHeights: undefined, ignoredSnapPointsMessage: ''};
378
+ }
379
+ const ignored = (snapPointsRef.current ?? []).filter(
380
+ point => !isValidSnapPoint(point),
381
+ );
382
+ return {
383
+ snapHeights: () =>
384
+ resolveSnapPoints(snapPointsRef.current ?? [], layoutViewportHeight()),
385
+ ignoredSnapPointsMessage:
386
+ ignored.length === 0
387
+ ? ''
388
+ : `snapPoints ignored ${JSON.stringify(ignored)}. A snap point is a viewport fraction above 0 and up to 1 (0.5 is half the screen), a px length ('320px'), or a percentage ('50%').`,
389
+ };
390
+ }, [snapPointsKey]);
391
+ useDevWarning(
392
+ 'BottomSheet',
393
+ ignoredSnapPointsMessage,
394
+ ignoredSnapPointsMessage !== '',
395
+ );
396
+
343
397
  const {
344
398
  contentProps,
345
399
  handleProps,
@@ -359,7 +413,7 @@ export function BottomSheetPanel({
359
413
  canDismiss: isSwipeDismissAllowed,
360
414
  offscreenBlockEndInset: OVERSCROLL_PADDING,
361
415
  onDismiss,
362
- snapHeights: defaultSnapHeights,
416
+ snapHeights,
363
417
  onScrimOpacity,
364
418
  });
365
419
 
@@ -10,6 +10,10 @@
10
10
  */
11
11
 
12
12
  export {BottomSheet} from './BottomSheet';
13
- export type {BottomSheetHeight, BottomSheetProps} from './BottomSheet';
13
+ export type {
14
+ BottomSheetHeight,
15
+ BottomSheetProps,
16
+ BottomSheetSnapPoint,
17
+ } from './BottomSheet';
14
18
  export {BottomSheetSwitcher} from './BottomSheetSwitcher';
15
19
  export type {BottomSheetSwitcherProps} from './BottomSheetSwitcher';