@astryxdesign/lab 0.2.0-canary.f306f13 → 0.2.0-canary.f7ec5f5
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/dist/BottomSheet/BottomSheet.d.ts +41 -35
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +222 -75
- package/dist/BottomSheet/snapOffsets.d.ts +54 -0
- package/dist/BottomSheet/snapOffsets.d.ts.map +1 -0
- package/dist/BottomSheet/snapOffsets.js +101 -0
- package/dist/BottomSheet/useSheetGestures.d.ts +55 -12
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +383 -40
- package/dist/Chart/Chart.d.ts +12 -1
- package/dist/Chart/Chart.d.ts.map +1 -1
- package/dist/Chart/Chart.js +51 -3
- package/dist/CodeEditor/CodeEditor.d.ts +14 -2
- package/dist/CodeEditor/CodeEditor.d.ts.map +1 -1
- package/dist/CodeEditor/CodeEditor.js +110 -9
- package/dist/Radial/RadialChart.d.ts +12 -1
- package/dist/Radial/RadialChart.d.ts.map +1 -1
- package/dist/Radial/RadialChart.js +89 -4
- package/dist/RichTextEditor/RichTextEditor.d.ts +6 -0
- package/dist/RichTextEditor/RichTextEditor.d.ts.map +1 -1
- package/dist/RichTextEditor/RichTextEditor.js +7 -7
- package/dist/RichTextEditor/editorNodes.d.ts +8 -0
- package/dist/RichTextEditor/editorNodes.d.ts.map +1 -0
- package/dist/RichTextEditor/editorNodes.js +23 -0
- package/dist/RichTextEditor/index.d.ts +2 -0
- package/dist/RichTextEditor/index.d.ts.map +1 -1
- package/dist/RichTextEditor/index.js +2 -1
- package/dist/RichTextEditor/markdownSerializers.d.ts +40 -0
- package/dist/RichTextEditor/markdownSerializers.d.ts.map +1 -0
- package/dist/RichTextEditor/markdownSerializers.js +85 -0
- package/dist/Sankey/SankeyChart.d.ts +13 -1
- package/dist/Sankey/SankeyChart.d.ts.map +1 -1
- package/dist/Sankey/SankeyChart.js +53 -5
- package/dist/ThreeD/ThreeDChart.d.ts +16 -3
- package/dist/ThreeD/ThreeDChart.d.ts.map +1 -1
- package/dist/ThreeD/ThreeDChart.js +63 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lab.css +15 -8
- package/package.json +13 -3
- package/src/BottomSheet/BottomSheet.doc.mjs +11 -11
- package/src/BottomSheet/BottomSheet.test.tsx +68 -4
- package/src/BottomSheet/BottomSheet.tsx +331 -97
- package/src/BottomSheet/snapOffsets.test.ts +146 -0
- package/src/BottomSheet/snapOffsets.ts +126 -0
- package/src/BottomSheet/useSheetGestures.doc.mjs +6 -5
- package/src/BottomSheet/useSheetGestures.test.ts +315 -65
- package/src/BottomSheet/useSheetGestures.ts +515 -55
- package/src/Chart/Chart.test.tsx +126 -0
- package/src/Chart/Chart.tsx +59 -0
- package/src/CodeEditor/CodeEditor.test.tsx +172 -2
- package/src/CodeEditor/CodeEditor.tsx +142 -9
- package/src/Radial/RadialChart.test.tsx +157 -0
- package/src/Radial/RadialChart.tsx +102 -1
- package/src/RichTextEditor/RichTextEditor.doc.mjs +6 -1
- package/src/RichTextEditor/RichTextEditor.test.tsx +56 -0
- package/src/RichTextEditor/RichTextEditor.tsx +13 -16
- package/src/RichTextEditor/editorNodes.ts +34 -0
- package/src/RichTextEditor/index.ts +6 -0
- package/src/RichTextEditor/markdownSerializers.ts +105 -0
- package/src/Sankey/SankeyChart.test.tsx +95 -0
- package/src/Sankey/SankeyChart.tsx +55 -1
- package/src/ThreeD/ThreeDChart.test.tsx +251 -0
- package/src/ThreeD/ThreeDChart.tsx +84 -6
- package/src/index.ts +4 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file BottomSheet.tsx
|
|
3
|
-
* @input Uses React, StyleX, theme tokens,
|
|
3
|
+
* @input Uses React, StyleX, theme tokens, core hooks (useScrollLock), utils, useSheetGestures
|
|
4
4
|
* @output Exports BottomSheet component and BottomSheetProps
|
|
5
5
|
* @position Lab implementation; consumed by index.ts, tested by BottomSheet.test.tsx, demonstrated in Storybook
|
|
6
6
|
*
|
|
7
|
-
* A mobile touch surface that rises from the bottom edge
|
|
8
|
-
* and swipe-to-dismiss.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
7
|
+
* A mobile touch surface that rises from the bottom edge: grab handle, snap
|
|
8
|
+
* points, and swipe-to-dismiss. It owns a native modal `<dialog>` directly and
|
|
9
|
+
* composes core primitives (`useScrollLock`, `<dialog>.showModal()` for the
|
|
10
|
+
* top layer + focus trap, a `::backdrop` scrim) rather than delegating to a
|
|
11
|
+
* heavier overlay component — so it controls its own sizing and can render a
|
|
12
|
+
* full-height transparent shell with the visible sheet bottom-anchored inside.
|
|
13
|
+
* That shell is what lets the sheet translate freely (including a little past
|
|
14
|
+
* fully-open) without clipping against a fixed dialog edge.
|
|
14
15
|
*
|
|
15
|
-
* The
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* The drag/snap/dismiss machinery lives in `useSheetGestures`; the offset
|
|
17
|
+
* geometry lives in the pure, tested `snapOffsets` module. Both are internal
|
|
18
|
+
* to BottomSheet and not exported from the lab entry point.
|
|
18
19
|
*
|
|
19
20
|
* SYNC: When modified, update these files to stay in sync:
|
|
20
21
|
* - /packages/lab/src/BottomSheet/BottomSheet.doc.mjs (props table, features, usage)
|
|
@@ -25,15 +26,16 @@
|
|
|
25
26
|
import { type ReactNode } from 'react';
|
|
26
27
|
import type { BaseProps } from '@astryxdesign/core';
|
|
27
28
|
/**
|
|
28
|
-
* Height budget for each named size
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Height budget for each named size, as a fraction of the viewport:
|
|
30
|
+
* - `hug` — fits its content, never taller than 92%.
|
|
31
|
+
* - `capped` — a scrolling mid-height panel (62%).
|
|
32
|
+
* - `tall` — a pinned near-full panel (92%); use when content streams in so
|
|
33
|
+
* the sheet doesn't resize under the user.
|
|
31
34
|
*/
|
|
32
35
|
declare const HEIGHT_BUDGETS: {
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly tall: "
|
|
36
|
-
readonly auto: "90dvh";
|
|
36
|
+
readonly hug: "92dvh";
|
|
37
|
+
readonly capped: "62dvh";
|
|
38
|
+
readonly tall: "92dvh";
|
|
37
39
|
};
|
|
38
40
|
export type BottomSheetHeight = keyof typeof HEIGHT_BUDGETS;
|
|
39
41
|
export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
|
|
@@ -42,8 +44,8 @@ export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
|
|
|
42
44
|
/** Whether the sheet is open. Fully controlled — pair with `onOpenChange`. */
|
|
43
45
|
isOpen: boolean;
|
|
44
46
|
/**
|
|
45
|
-
* Called when the sheet opens or closes. The boolean is the requested
|
|
46
|
-
*
|
|
47
|
+
* Called when the sheet opens or closes. The boolean is the requested next
|
|
48
|
+
* state (`false` on Escape, scrim click, or a swipe past the dismiss
|
|
47
49
|
* threshold). The caller owns the open state.
|
|
48
50
|
*/
|
|
49
51
|
onOpenChange: (isOpen: boolean) => void;
|
|
@@ -55,26 +57,30 @@ export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
|
|
|
55
57
|
/** Sheet content, rendered below the grab handle in a scrollable area. */
|
|
56
58
|
children: ReactNode;
|
|
57
59
|
/**
|
|
58
|
-
* How tall the sheet is:
|
|
59
|
-
* - `'
|
|
60
|
-
* - `'
|
|
61
|
-
* - `'tall'` —
|
|
62
|
-
*
|
|
60
|
+
* How tall the sheet is. A named budget, or any explicit height:
|
|
61
|
+
* - `'hug'` — fits its content, never taller than 92% of the viewport.
|
|
62
|
+
* - `'capped'` — a scrolling mid-height panel (~62%).
|
|
63
|
+
* - `'tall'` — a pinned near-full panel (~92%); use when content streams in
|
|
64
|
+
* so the sheet doesn't resize under the user.
|
|
65
|
+
* - a `number` (px) or CSS length string (e.g. `'70dvh'`, `480`) for a
|
|
66
|
+
* custom budget.
|
|
63
67
|
*
|
|
64
|
-
*
|
|
65
|
-
* height.
|
|
66
|
-
*
|
|
68
|
+
* The user can still drag between snap points regardless of the starting
|
|
69
|
+
* height. On viewports shorter than the budget the sheet fills the
|
|
70
|
+
* available height.
|
|
71
|
+
* @default 'capped'
|
|
67
72
|
*/
|
|
68
|
-
height?: BottomSheetHeight;
|
|
73
|
+
height?: BottomSheetHeight | number | string;
|
|
69
74
|
/** Test ID for the root element. */
|
|
70
75
|
'data-testid'?: string;
|
|
71
76
|
}
|
|
72
77
|
/**
|
|
73
|
-
* A mobile touch sheet that rises from the bottom edge, with a grab handle
|
|
74
|
-
* and swipe-to-dismiss.
|
|
75
|
-
* (
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
+
* A mobile touch sheet that rises from the bottom edge, with a grab handle,
|
|
79
|
+
* drag-to-resize snap points, and swipe-to-dismiss. It owns a native modal
|
|
80
|
+
* `<dialog>` (top layer, focus trap, `::backdrop` scrim) and locks body scroll
|
|
81
|
+
* while open; a slow drag settles to the nearest snap point, a flick down
|
|
82
|
+
* dismisses, and Escape closes — so the swipe always has a keyboard
|
|
83
|
+
* equivalent.
|
|
78
84
|
*
|
|
79
85
|
* @example
|
|
80
86
|
* ```
|
|
@@ -87,7 +93,7 @@ export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
|
|
|
87
93
|
* </BottomSheet>
|
|
88
94
|
* ```
|
|
89
95
|
*/
|
|
90
|
-
export declare function BottomSheet({ isOpen, onOpenChange, label, children, height, xstyle, ...props }: BottomSheetProps): import("react").JSX.Element;
|
|
96
|
+
export declare function BottomSheet({ ref, isOpen, onOpenChange, label, children, height, xstyle, ...props }: BottomSheetProps): import("react").JSX.Element;
|
|
91
97
|
export declare namespace BottomSheet {
|
|
92
98
|
var displayName: string;
|
|
93
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAiC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAqBlD;;;;;;GAMG;AACH,QAAA,MAAM,cAAc;;;;CAIV,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,cAAc,CAAC;AAuJ5D,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IACpE,wDAAwD;IACxD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAEnC,8EAA8E;IAC9E,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAExC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd,0EAA0E;IAC1E,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;IAE7C,oCAAoC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,GAAG,EACH,MAAM,EACN,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,MAAiB,EACjB,MAAM,EACN,GAAG,KAAK,EACT,EAAE,gBAAgB,+BAyKlB;yBAlLe,WAAW"}
|
|
@@ -4,21 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file BottomSheet.tsx
|
|
7
|
-
* @input Uses React, StyleX, theme tokens,
|
|
7
|
+
* @input Uses React, StyleX, theme tokens, core hooks (useScrollLock), utils, useSheetGestures
|
|
8
8
|
* @output Exports BottomSheet component and BottomSheetProps
|
|
9
9
|
* @position Lab implementation; consumed by index.ts, tested by BottomSheet.test.tsx, demonstrated in Storybook
|
|
10
10
|
*
|
|
11
|
-
* A mobile touch surface that rises from the bottom edge
|
|
12
|
-
* and swipe-to-dismiss.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* A mobile touch surface that rises from the bottom edge: grab handle, snap
|
|
12
|
+
* points, and swipe-to-dismiss. It owns a native modal `<dialog>` directly and
|
|
13
|
+
* composes core primitives (`useScrollLock`, `<dialog>.showModal()` for the
|
|
14
|
+
* top layer + focus trap, a `::backdrop` scrim) rather than delegating to a
|
|
15
|
+
* heavier overlay component — so it controls its own sizing and can render a
|
|
16
|
+
* full-height transparent shell with the visible sheet bottom-anchored inside.
|
|
17
|
+
* That shell is what lets the sheet translate freely (including a little past
|
|
18
|
+
* fully-open) without clipping against a fixed dialog edge.
|
|
18
19
|
*
|
|
19
|
-
* The
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* The drag/snap/dismiss machinery lives in `useSheetGestures`; the offset
|
|
21
|
+
* geometry lives in the pure, tested `snapOffsets` module. Both are internal
|
|
22
|
+
* to BottomSheet and not exported from the lab entry point.
|
|
22
23
|
*
|
|
23
24
|
* SYNC: When modified, update these files to stay in sync:
|
|
24
25
|
* - /packages/lab/src/BottomSheet/BottomSheet.doc.mjs (props table, features, usage)
|
|
@@ -26,64 +27,100 @@
|
|
|
26
27
|
* - /packages/lab/src/BottomSheet/index.ts (exports if types change)
|
|
27
28
|
* - /apps/storybook/stories/BottomSheet.stories.tsx (examples and visual coverage)
|
|
28
29
|
*/
|
|
30
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
29
31
|
import * as stylex from '@stylexjs/stylex';
|
|
30
32
|
import '@astryxdesign/core/theme/tokens.stylex';
|
|
31
|
-
import { colorVars, radiusVars, spacingVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
33
|
+
import { colorVars, durationVars, easeVars, radiusVars, shadowVars, sizeVars, spacingVars } from '@astryxdesign/core/theme/tokens.stylex';
|
|
34
|
+
import { useDevWarning, useScrollLock } from '@astryxdesign/core/hooks';
|
|
35
|
+
import { mergeProps, mergeRefs, themeProps } from '@astryxdesign/core/utils';
|
|
34
36
|
import { useSheetGestures } from "./useSheetGestures.js";
|
|
35
37
|
|
|
38
|
+
// Detent fractions of the viewport, ascending (peek / mid / full). Detents
|
|
39
|
+
// that land within DETENT_DEDUP_PX of each other (e.g. a hug height next to a
|
|
40
|
+
// snap) are de-duped in the gesture hook, and any taller than the sheet are
|
|
41
|
+
// dropped, so a full set is safe to offer. The shortest is a glance "peek";
|
|
42
|
+
// the scrim hides as the sheet collapses onto it (see onScrimOpacity).
|
|
43
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
44
|
+
const SNAP_FRACTIONS = [0.14, 0.5, 0.92];
|
|
45
|
+
|
|
36
46
|
/**
|
|
37
|
-
* Height budget for each named size
|
|
38
|
-
*
|
|
39
|
-
*
|
|
47
|
+
* Height budget for each named size, as a fraction of the viewport:
|
|
48
|
+
* - `hug` — fits its content, never taller than 92%.
|
|
49
|
+
* - `capped` — a scrolling mid-height panel (62%).
|
|
50
|
+
* - `tall` — a pinned near-full panel (92%); use when content streams in so
|
|
51
|
+
* the sheet doesn't resize under the user.
|
|
40
52
|
*/
|
|
41
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
42
53
|
const HEIGHT_BUDGETS = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
hug: '92dvh',
|
|
55
|
+
// upper bound only; the sheet hugs its content beneath it
|
|
56
|
+
capped: '62dvh',
|
|
57
|
+
tall: '92dvh'
|
|
47
58
|
};
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
const
|
|
59
|
+
// px the sheet extends below its budget as reserved padding, revealed by an
|
|
60
|
+
// upward overdrag rather than showing a gap.
|
|
61
|
+
// SYNC: must match OVERSCROLL_MAX in useSheetGestures.ts (the drag cap).
|
|
62
|
+
const OVERSCROLL_PADDING = 48;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Default snap detents in px, resolved against the *visual* viewport (like iOS
|
|
66
|
+
* detents), so a mid rest point is ~half the screen regardless of the sheet's
|
|
67
|
+
* own height budget. Read lazily at drag start (no persistent listener) so it
|
|
68
|
+
* reflects the live viewport after a rotation or the virtual keyboard opening.
|
|
69
|
+
* SSR-safe: returns `[]` off the client.
|
|
70
|
+
*/
|
|
71
|
+
function defaultSnapHeights() {
|
|
72
|
+
if (typeof window === 'undefined') {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const vh = window.visualViewport?.height ?? window.innerHeight;
|
|
76
|
+
return SNAP_FRACTIONS.map(f => f * vh);
|
|
77
|
+
}
|
|
52
78
|
const styles = {
|
|
53
79
|
sheet: {
|
|
80
|
+
kfzvcC: "x67bb7w",
|
|
81
|
+
kB7OPa: "x9f619",
|
|
54
82
|
k1xSpc: "x78zum5",
|
|
55
83
|
kXwgrk: "xdt5ytf",
|
|
56
84
|
kAzted: "x2lwn1j",
|
|
57
|
-
kZKoxP: "x5yr21d",
|
|
58
85
|
kzqmXN: "xh8yej3",
|
|
59
86
|
ks0D6T: "x11gisft",
|
|
60
|
-
kUOVxO: "xvueqy4",
|
|
61
87
|
kWkggS: "x10xzikg",
|
|
62
|
-
krdFHd: "
|
|
63
|
-
kfmiAY: "
|
|
88
|
+
krdFHd: "x81l70g",
|
|
89
|
+
kfmiAY: "x7hs6f1",
|
|
90
|
+
kGVxlE: "x1kcpxr7",
|
|
91
|
+
kI3sdo: "x1a2a7pz",
|
|
64
92
|
kVQacm: "xb3r6kr",
|
|
65
|
-
kGO01o: "
|
|
93
|
+
kGO01o: "x1wkw6tp",
|
|
94
|
+
k1K539: "x1if0o47",
|
|
95
|
+
k3aq6I: "xnn1q72 xhbqy3z",
|
|
96
|
+
k1ekBW: "x11xpdln",
|
|
97
|
+
kIyJzY: "x80gvsz",
|
|
98
|
+
kAMwcw: "xlr8y92",
|
|
66
99
|
k6sLGO: "x1so62im",
|
|
100
|
+
k6CgDc: "xzg1mie",
|
|
101
|
+
$$css: true
|
|
102
|
+
},
|
|
103
|
+
sheetClosing: {
|
|
104
|
+
k3aq6I: "x1weeur4",
|
|
67
105
|
$$css: true
|
|
68
106
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
kGVxlE: "x1gnnqk1",
|
|
72
|
-
kEafiO: "x972fbf",
|
|
107
|
+
budget: {
|
|
108
|
+
kZKoxP: "x1tpcejd",
|
|
73
109
|
$$css: true
|
|
74
110
|
},
|
|
75
|
-
|
|
111
|
+
hugHeight: {
|
|
76
112
|
kZKoxP: "xg7h5cd",
|
|
77
|
-
kskxy: "
|
|
113
|
+
kskxy: "x14bu9tk",
|
|
78
114
|
$$css: true
|
|
79
115
|
}
|
|
80
116
|
};
|
|
81
117
|
/**
|
|
82
|
-
* A mobile touch sheet that rises from the bottom edge, with a grab handle
|
|
83
|
-
* and swipe-to-dismiss.
|
|
84
|
-
* (
|
|
85
|
-
*
|
|
86
|
-
*
|
|
118
|
+
* A mobile touch sheet that rises from the bottom edge, with a grab handle,
|
|
119
|
+
* drag-to-resize snap points, and swipe-to-dismiss. It owns a native modal
|
|
120
|
+
* `<dialog>` (top layer, focus trap, `::backdrop` scrim) and locks body scroll
|
|
121
|
+
* while open; a slow drag settles to the nearest snap point, a flick down
|
|
122
|
+
* dismisses, and Escape closes — so the swipe always has a keyboard
|
|
123
|
+
* equivalent.
|
|
87
124
|
*
|
|
88
125
|
* @example
|
|
89
126
|
* ```
|
|
@@ -97,53 +134,163 @@ const styles = {
|
|
|
97
134
|
* ```
|
|
98
135
|
*/
|
|
99
136
|
export function BottomSheet({
|
|
137
|
+
ref,
|
|
100
138
|
isOpen,
|
|
101
139
|
onOpenChange,
|
|
102
140
|
label,
|
|
103
141
|
children,
|
|
104
|
-
height = '
|
|
142
|
+
height = 'capped',
|
|
105
143
|
xstyle,
|
|
106
144
|
...props
|
|
107
145
|
}) {
|
|
108
|
-
const
|
|
146
|
+
const dialogRef = useRef(null);
|
|
147
|
+
const triggerRef = useRef(null);
|
|
148
|
+
const sheetNodeRef = useRef(null);
|
|
149
|
+
const close = useCallback(() => onOpenChange(false), [onOpenChange]);
|
|
150
|
+
|
|
151
|
+
// Set imperatively (not via state) so a 60fps drag doesn't re-render. The
|
|
152
|
+
// hook reports the scrim opacity for the current detent (hidden at the peek).
|
|
153
|
+
const handleScrimOpacity = useCallback(opacity => {
|
|
154
|
+
dialogRef.current?.style.setProperty('--_sheet-scrim-opacity', String(opacity));
|
|
155
|
+
}, []);
|
|
109
156
|
const {
|
|
110
157
|
contentProps,
|
|
111
|
-
handleProps
|
|
158
|
+
handleProps,
|
|
159
|
+
bodyProps,
|
|
160
|
+
sheetRef
|
|
112
161
|
} = useSheetGestures({
|
|
113
162
|
isOpen,
|
|
114
|
-
onDismiss: close
|
|
163
|
+
onDismiss: close,
|
|
164
|
+
snapHeights: defaultSnapHeights,
|
|
165
|
+
onScrimOpacity: handleScrimOpacity
|
|
115
166
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
167
|
+
|
|
168
|
+
// showModal() enters the top layer with a focus trap + ::backdrop; on close
|
|
169
|
+
// we animate out (below) then restore focus to the opener.
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
const dialog = dialogRef.current;
|
|
172
|
+
if (!dialog) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (isOpen) {
|
|
176
|
+
triggerRef.current = document.activeElement;
|
|
177
|
+
dialog.style.setProperty('--_sheet-scrim-opacity', '1');
|
|
178
|
+
if (!dialog.open) {
|
|
179
|
+
dialog.showModal();
|
|
180
|
+
// Override showModal()'s default (first tabbable) to land on the panel,
|
|
181
|
+
// so AT reads from the label — unless a descendant sets data-autofocus.
|
|
182
|
+
const autofocus = dialog.querySelector('[data-autofocus]');
|
|
183
|
+
if (autofocus) {
|
|
184
|
+
autofocus.focus();
|
|
185
|
+
} else {
|
|
186
|
+
sheetNodeRef.current?.focus();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else if (dialog.open) {
|
|
190
|
+
// Wait for the slide-out (sheetClosing, applied this render) before
|
|
191
|
+
// close() releases the top layer. Timeout backstops a missing
|
|
192
|
+
// transitionend (reduced motion, hidden tab).
|
|
193
|
+
const sheet = sheetNodeRef.current;
|
|
194
|
+
let done = false;
|
|
195
|
+
const finish = () => {
|
|
196
|
+
if (done) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
done = true;
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
sheet?.removeEventListener('transitionend', onEnd);
|
|
202
|
+
if (dialog.open) {
|
|
203
|
+
dialog.close();
|
|
204
|
+
}
|
|
205
|
+
triggerRef.current?.focus();
|
|
206
|
+
triggerRef.current = null;
|
|
207
|
+
};
|
|
208
|
+
const onEnd = event => {
|
|
209
|
+
if (event.target === sheet && event.propertyName === 'transform') {
|
|
210
|
+
finish();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
sheet?.addEventListener('transitionend', onEnd);
|
|
214
|
+
// Backstop above --duration-medium (410ms) so transitionend normally
|
|
215
|
+
// fires first; this only covers environments that don't emit it.
|
|
216
|
+
const timer = setTimeout(finish, 450);
|
|
217
|
+
return () => {
|
|
218
|
+
clearTimeout(timer);
|
|
219
|
+
sheet?.removeEventListener('transitionend', onEnd);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}, [isOpen]);
|
|
223
|
+
useScrollLock(isOpen);
|
|
224
|
+
|
|
225
|
+
// Enforce an accessible name: label is required by types, but a JS caller
|
|
226
|
+
// can still pass an empty string, leaving the sheet unnamed.
|
|
227
|
+
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);
|
|
228
|
+
const handleCancel = useCallback(event => {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
close();
|
|
231
|
+
}, [close]);
|
|
232
|
+
// Explicit Escape handler in addition to the native `cancel` event, for
|
|
233
|
+
// environments that don't synthesize `cancel`.
|
|
234
|
+
const handleKeyDown = useCallback(event => {
|
|
235
|
+
if (event.key === 'Escape') {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
close();
|
|
238
|
+
}
|
|
239
|
+
}, [close]);
|
|
240
|
+
const handleClick = useCallback(event => {
|
|
241
|
+
if (event.target === event.currentTarget) {
|
|
242
|
+
close();
|
|
243
|
+
}
|
|
244
|
+
}, [close]);
|
|
245
|
+
const isNamed = typeof height === 'string' && height in HEIGHT_BUDGETS;
|
|
246
|
+
const budget = isNamed ? HEIGHT_BUDGETS[height] : typeof height === 'number' ? `${height}px` : height;
|
|
247
|
+
const isHug = height === 'hug';
|
|
248
|
+
return /*#__PURE__*/_jsx("dialog", {
|
|
249
|
+
...{
|
|
250
|
+
0: {
|
|
251
|
+
className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x47corl x1s85apg x1a2a7pz xnixb3f x1abwkk1 xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w"
|
|
252
|
+
},
|
|
253
|
+
1: {
|
|
254
|
+
className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x47corl x1a2a7pz x1lliihq xnixb3f x1abwkk1 xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w"
|
|
255
|
+
}
|
|
256
|
+
}[!!isOpen << 0],
|
|
257
|
+
ref: mergeRefs(ref, dialogRef),
|
|
258
|
+
"aria-label": label,
|
|
259
|
+
"aria-modal": "true",
|
|
260
|
+
onCancel: handleCancel,
|
|
261
|
+
onClick: handleClick,
|
|
262
|
+
onKeyDown: handleKeyDown,
|
|
125
263
|
...props,
|
|
126
|
-
children: /*#__PURE__*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
264
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
265
|
+
...{
|
|
266
|
+
className: "x10l6tqk x17y0mx6 x1ey2m1c x78zum5 xl56j7k x47corl"
|
|
267
|
+
},
|
|
268
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
269
|
+
ref: mergeRefs(sheetRef, sheetNodeRef),
|
|
270
|
+
tabIndex: -1,
|
|
271
|
+
...mergeProps(themeProps('bottom-sheet'), stylex.props(styles.sheet, isHug ? styles.hugHeight : styles.budget, !isOpen && styles.sheetClosing, xstyle), undefined, {
|
|
272
|
+
['--_sheet-budget']: budget,
|
|
273
|
+
...contentProps.style
|
|
274
|
+
}),
|
|
275
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
276
|
+
...{
|
|
277
|
+
className: "x2lah0s x78zum5 x6s0dn4 xl56j7k x1k15mir x5ve5x3 x1jm3nie"
|
|
278
|
+
},
|
|
279
|
+
...handleProps,
|
|
280
|
+
"aria-hidden": "true",
|
|
281
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
282
|
+
...{
|
|
283
|
+
className: "x1m747yf x11c6zpc xjspbzw x1m4xfpy"
|
|
284
|
+
}
|
|
285
|
+
})
|
|
286
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
137
287
|
...{
|
|
138
|
-
className: "
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
},
|
|
145
|
-
children: children
|
|
146
|
-
})]
|
|
288
|
+
className: "x1iyjqo2 x2lwn1j x1odjw0f x8du1vd xx69xxh"
|
|
289
|
+
},
|
|
290
|
+
...bodyProps,
|
|
291
|
+
children: children
|
|
292
|
+
})]
|
|
293
|
+
})
|
|
147
294
|
})
|
|
148
295
|
});
|
|
149
296
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file snapOffsets.ts
|
|
3
|
+
* @input Pure geometry helpers — no React, no DOM.
|
|
4
|
+
* @output Converts snap points to translateY offsets for the sheet surface.
|
|
5
|
+
* @position Internal to BottomSheet; consumed by useSheetGestures, tested by
|
|
6
|
+
* snapOffsets.test.ts.
|
|
7
|
+
*
|
|
8
|
+
* The sheet is rendered at its full (fully-open) height and *translated down*
|
|
9
|
+
* to express shorter detents — translate is GPU-composited, so this is cheaper
|
|
10
|
+
* than animating layout height. A detent is therefore a translateY offset in
|
|
11
|
+
* px from the fully-open position (0 = fully open, larger = more collapsed).
|
|
12
|
+
* These helpers turn snap points into that offset list; they are pure so the
|
|
13
|
+
* geometry can be unit-tested without a DOM.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Detents whose resting offsets land within this many px of each other are
|
|
17
|
+
* treated as the same stop (the taller one wins). Stops the sheet from having
|
|
18
|
+
* two near-identical rest positions — e.g. when a content-hugging height sits
|
|
19
|
+
* a hair away from a fractional snap point.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DETENT_DEDUP_PX = 48;
|
|
22
|
+
/** Resolve snap points given as viewport fractions (0, 1] to px heights. */
|
|
23
|
+
export declare function snapFractionsToHeights(fractions: readonly number[], viewportPx: number): number[];
|
|
24
|
+
/**
|
|
25
|
+
* Given the sheet's full height (px, as rendered fully open) and a set of
|
|
26
|
+
* candidate detent *visible heights* (px), return the resting translateY
|
|
27
|
+
* offsets from fully-open, ascending and de-duplicated.
|
|
28
|
+
*
|
|
29
|
+
* - `0` (fully open) is always the first detent.
|
|
30
|
+
* - Only heights strictly shorter than the sheet become collapsed detents; a
|
|
31
|
+
* height >= the sheet can't be shown by translating down, so it's dropped.
|
|
32
|
+
* - Offsets closer than `dedupPx` collapse to the smaller (taller) offset, so
|
|
33
|
+
* near-identical detents — e.g. a hug height ≈ a snap point — become one stop.
|
|
34
|
+
*/
|
|
35
|
+
export declare function computeDetentOffsets(sheetHeight: number, detentHeights: readonly number[], dedupPx?: number): number[];
|
|
36
|
+
/** Nearest value in `offsets` to `value` (offsets must be non-empty). */
|
|
37
|
+
export declare function nearestOffset(value: number, offsets: readonly number[]): number;
|
|
38
|
+
/**
|
|
39
|
+
* Scrim opacity (1 = fully visible, 0 = hidden) for a drag/settle `offset`.
|
|
40
|
+
* The scrim stays full while the sheet is at or above its second-shortest
|
|
41
|
+
* detent, then fades to 0 as it collapses onto the shortest ("peek") detent —
|
|
42
|
+
* a glance state that reveals the content behind — and stays hidden below it.
|
|
43
|
+
* A single-detent sheet has no peek, so it instead fades across the dismiss
|
|
44
|
+
* overshoot toward `dismissOffset`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function scrimOpacityForOffset(offset: number, offsets: readonly number[], dismissOffset: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* Settle target for a released drag. Restricts candidates to the drag
|
|
49
|
+
* direction so a committed drag never snaps *back past* where it started
|
|
50
|
+
* (a down-drag settles at/below the start, an up-drag at/above), then picks
|
|
51
|
+
* the nearest remaining detent. `dir`: 1 = dragged down, -1 = up, 0 = neither.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveSettleOffset(value: number, offsets: readonly number[], dir: number, baseOffset: number): number;
|
|
54
|
+
//# sourceMappingURL=snapOffsets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapOffsets.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/snapOffsets.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,4EAA4E;AAC5E,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,UAAU,EAAE,MAAM,GACjB,MAAM,EAAE,CAEV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,OAAO,GAAE,MAAwB,GAChC,MAAM,EAAE,CAcV;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,CAKR;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,aAAa,EAAE,MAAM,GACpB,MAAM,CAWR;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,MAAM,CAcR"}
|