asma-ui-core 3.136.1 → 3.136.2
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/asma-ui-core.css +1 -1
- package/dist/components/utils/bottom-sheet/StyledBottomSheet.js +180 -135
- package/dist/components/utils/bottom-sheet/useDragToDismiss.hook.js +111 -31
- package/dist/src/components/utils/bottom-sheet/StyledBottomSheet.d.ts +8 -2
- package/dist/src/components/utils/bottom-sheet/useDragToDismiss.hook.d.ts +14 -3
- package/package.json +1 -1
|
@@ -1,163 +1,198 @@
|
|
|
1
|
-
import { cn as
|
|
2
|
-
import { registerOpenModalDialog as
|
|
3
|
-
import { CloseIcon as
|
|
4
|
-
import { BackIcon as
|
|
5
|
-
import { StyledButton as
|
|
6
|
-
import { OverlayBackOwnerContext as
|
|
7
|
-
import { isKeyboardModality as
|
|
8
|
-
import { useDebouncedValue as
|
|
9
|
-
import { useFocusTrap as
|
|
10
|
-
import { useShortViewportMediaQuery as
|
|
11
|
-
import { SHEET_HEADER_TEXT as
|
|
12
|
-
import { formatResultsLabel as
|
|
13
|
-
import { useBodyScrollLock as
|
|
14
|
-
import
|
|
15
|
-
import { useDragToDismiss as
|
|
16
|
-
import { useEffect as
|
|
17
|
-
import { jsx as t, jsxs as
|
|
18
|
-
var
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
h
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { cn as u } from "../../../helpers/cn.js";
|
|
2
|
+
import { registerOpenModalDialog as Se } from "../../../hooks/useTopLayer.hook.js";
|
|
3
|
+
import { CloseIcon as _e } from "../../icons/close-icon/CloseIcon.js";
|
|
4
|
+
import { BackIcon as Te } from "../../icons/back-icon/BackIcon.js";
|
|
5
|
+
import { StyledButton as I } from "../../inputs/button/StyledButton.js";
|
|
6
|
+
import { OverlayBackOwnerContext as Le, isOverlayBackEnabled as oe, requestCloseTopOverlayBack as M, useBackCloses as Re } from "../../../hooks/useBackCloses.hook.js";
|
|
7
|
+
import { isKeyboardModality as Ce, trackInputModality as Oe } from "../../inputs/full-screen-picker/inputModality.js";
|
|
8
|
+
import { useDebouncedValue as Be } from "../../../hooks/useDebouncedValue.hook.js";
|
|
9
|
+
import { useFocusTrap as He } from "../../../hooks/useFocusTrap.hook.js";
|
|
10
|
+
import { useShortViewportMediaQuery as Ie } from "../../../hooks/useMediaQuery.hook.js";
|
|
11
|
+
import { SHEET_HEADER_TEXT as Me, SHEET_TEXT as $e } from "./sheetCopy.js";
|
|
12
|
+
import { formatResultsLabel as De } from "./formatResultsLabel.js";
|
|
13
|
+
import { useBodyScrollLock as Ae } from "../../../hooks/useBodyScrollLock.hook.js";
|
|
14
|
+
import je from "./StyledBottomSheet.module.js";
|
|
15
|
+
import { useDragToDismiss as Fe } from "./useDragToDismiss.hook.js";
|
|
16
|
+
import { useCallback as ae, useEffect as b, useId as Pe, useLayoutEffect as qe, useRef as c, useState as m } from "react";
|
|
17
|
+
import { jsx as t, jsxs as p } from "react/jsx-runtime";
|
|
18
|
+
var ze = 500, se = "duration-[250ms] ease-[cubic-bezier(0.05,0.7,0.1,1)]", ie = "duration-[200ms] ease-[cubic-bezier(0.3,0,0.8,0.15)]", Ke = 200, Ve = 300, dt = ({ dataTest: s, id: le, open: n, onClose: d, title: x, ariaLabel: ce, titleIcon: $, onBack: D, backLabel: de, children: ue, viewResultsAction: A, resetAction: fe, footerActions: me, resultCount: j, locale: S = "en", closeLabel: pe = $e[S].close, className: he, registerBackClose: ve = !0, ownerRef: be, triggerRef: F }) => {
|
|
19
|
+
const P = Pe(), f = c(null), _ = c(null), q = c(null), z = be ?? f, T = c(!1), [w, K] = m(!1), [V, X] = m(n);
|
|
20
|
+
n && !V && X(!0);
|
|
21
|
+
const U = c(void 0), y = Ie(), G = c(null), [xe, we] = m(null), ye = ae((e) => {
|
|
22
|
+
G.current = e, we(e);
|
|
23
|
+
}, []), [l, h] = m(!1), [ge, Ee] = m(!1), [v, L] = m(!1), Q = !y && (l || ge || v), Y = ae(() => {
|
|
24
|
+
L(!0), h(!1);
|
|
25
|
+
}, []), R = Me[S], g = c(d), J = c(n);
|
|
26
|
+
b(() => {
|
|
27
|
+
g.current = d, J.current = n;
|
|
28
|
+
}, [d, n]);
|
|
29
|
+
const { dragHandleProps: ke, dragOffset: W, dragRatio: C, liftedHeight: Z } = Fe(_, () => {
|
|
30
|
+
g.current("drag");
|
|
31
|
+
}, Q && !l ? () => h(!0) : void 0, l && !y ? Y : void 0, xe);
|
|
32
|
+
b(() => {
|
|
33
|
+
const e = G.current;
|
|
34
|
+
if (!n || l || v || !e) return;
|
|
35
|
+
let o = e.scrollHeight;
|
|
36
|
+
const r = () => {
|
|
37
|
+
const i = e.scrollHeight > e.clientHeight + 1, N = e.scrollHeight > o + 1;
|
|
38
|
+
o = e.scrollHeight, i && N && e.contains(document.activeElement) ? h(!0) : Ee(i);
|
|
32
39
|
};
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
for (const
|
|
37
|
-
return () =>
|
|
38
|
-
}, [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
r();
|
|
41
|
+
const a = new ResizeObserver(r);
|
|
42
|
+
a.observe(e);
|
|
43
|
+
for (const i of Array.from(e.children)) a.observe(i);
|
|
44
|
+
return () => a.disconnect();
|
|
45
|
+
}, [
|
|
46
|
+
n,
|
|
47
|
+
l,
|
|
48
|
+
v
|
|
49
|
+
]), b(() => {
|
|
50
|
+
const e = _.current;
|
|
51
|
+
if (!v || !e) return;
|
|
52
|
+
const o = () => {
|
|
53
|
+
L(!1);
|
|
54
|
+
}, r = (i) => {
|
|
55
|
+
i.target === e && i.propertyName === "max-height" && o();
|
|
56
|
+
}, a = window.setTimeout(o, Ve);
|
|
57
|
+
return e.addEventListener("transitionend", r), () => {
|
|
58
|
+
window.clearTimeout(a), e.removeEventListener("transitionend", r);
|
|
59
|
+
};
|
|
60
|
+
}, [v]), Ae(n), He(n, f), b(() => {
|
|
61
|
+
if (!n) return;
|
|
62
|
+
const e = (r) => {
|
|
63
|
+
r.key === "Escape" && (T.current = !0, window.setTimeout(() => {
|
|
64
|
+
T.current = !1;
|
|
43
65
|
}, 0));
|
|
44
|
-
},
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
|
|
66
|
+
}, o = (r) => {
|
|
67
|
+
if (r.key !== "Escape" || r.defaultPrevented) return;
|
|
68
|
+
const a = document.activeElement;
|
|
69
|
+
a instanceof Element && a.closest("dialog[open]") !== f.current || (r.preventDefault(), r.stopImmediatePropagation(), M(r));
|
|
48
70
|
};
|
|
49
|
-
return window.addEventListener("keydown", e, !0), window.addEventListener("keydown",
|
|
50
|
-
window.removeEventListener("keydown", e, !0), window.removeEventListener("keydown",
|
|
71
|
+
return window.addEventListener("keydown", e, !0), window.addEventListener("keydown", o), () => {
|
|
72
|
+
window.removeEventListener("keydown", e, !0), window.removeEventListener("keydown", o);
|
|
51
73
|
};
|
|
52
|
-
}, [
|
|
53
|
-
active:
|
|
54
|
-
requestClose: () =>
|
|
55
|
-
ownerRef:
|
|
56
|
-
}),
|
|
57
|
-
const e =
|
|
58
|
-
if (!
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
}),
|
|
74
|
+
}, [n]), Re({
|
|
75
|
+
active: n && ve,
|
|
76
|
+
requestClose: () => g.current("escape"),
|
|
77
|
+
ownerRef: z
|
|
78
|
+
}), qe(() => {
|
|
79
|
+
const e = f.current;
|
|
80
|
+
if (!n || !e) return;
|
|
81
|
+
Oe();
|
|
82
|
+
const o = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
83
|
+
window.clearTimeout(U.current), q.current = F?.current ?? o, e.open || e.showModal(), e.focus({ preventScroll: !0 });
|
|
84
|
+
const r = requestAnimationFrame(() => {
|
|
85
|
+
K(!0);
|
|
86
|
+
}), a = Se(e);
|
|
65
87
|
return () => {
|
|
66
|
-
cancelAnimationFrame(
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
cancelAnimationFrame(r), a(), K(!1);
|
|
89
|
+
const i = () => {
|
|
90
|
+
X(!1), h(!1), L(!1), e.open && e.close();
|
|
91
|
+
const N = q.current;
|
|
92
|
+
N?.isConnected && N.focus({
|
|
93
|
+
preventScroll: !0,
|
|
94
|
+
focusVisible: Ce()
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
98
|
+
i();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
U.current = window.setTimeout(i, Ke);
|
|
72
102
|
};
|
|
73
|
-
}, [
|
|
74
|
-
const e =
|
|
75
|
-
if (!e || !
|
|
76
|
-
let
|
|
77
|
-
const
|
|
103
|
+
}, [n, F]), b(() => {
|
|
104
|
+
const e = f.current;
|
|
105
|
+
if (!e || !n) return;
|
|
106
|
+
let o = !1;
|
|
107
|
+
const r = () => {
|
|
78
108
|
requestAnimationFrame(() => {
|
|
79
|
-
|
|
109
|
+
o = !1, J.current && e.isConnected && !e.open && (e.showModal(), e.focus({ preventScroll: !0 }));
|
|
80
110
|
});
|
|
81
|
-
},
|
|
82
|
-
|
|
111
|
+
}, a = () => {
|
|
112
|
+
o || (o = !0, oe() && M(), r());
|
|
83
113
|
};
|
|
84
|
-
return e.addEventListener("close",
|
|
85
|
-
}, [
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
} },
|
|
114
|
+
return e.addEventListener("close", a), () => e.removeEventListener("close", a);
|
|
115
|
+
}, [n]);
|
|
116
|
+
const ee = De(Be(j, ze), S);
|
|
117
|
+
if (!V) return null;
|
|
118
|
+
const Ne = { close: () => {
|
|
119
|
+
d("action");
|
|
120
|
+
} }, E = (e) => typeof e == "function" ? e(Ne) : e, te = j !== void 0, O = A !== void 0 ? E(A) : te ? /* @__PURE__ */ t(I, {
|
|
91
121
|
dataTest: `${s}-view-results`,
|
|
92
122
|
type: "button",
|
|
93
123
|
variant: "text",
|
|
94
124
|
onClick: () => {
|
|
95
|
-
|
|
125
|
+
d("viewResults");
|
|
96
126
|
},
|
|
97
|
-
children:
|
|
98
|
-
}) : void 0,
|
|
127
|
+
children: ee
|
|
128
|
+
}) : void 0, re = E(fe), k = E(me), B = !!(O ?? re), H = Z !== null, ne = W > 0 || H;
|
|
99
129
|
return /* @__PURE__ */ t("dialog", {
|
|
100
|
-
ref:
|
|
101
|
-
id:
|
|
130
|
+
ref: f,
|
|
131
|
+
id: le,
|
|
102
132
|
tabIndex: -1,
|
|
103
133
|
"aria-modal": "true",
|
|
104
|
-
"aria-labelledby":
|
|
105
|
-
"aria-label":
|
|
134
|
+
"aria-labelledby": x ? P : void 0,
|
|
135
|
+
"aria-label": x ? void 0 : ce,
|
|
106
136
|
"data-test": s,
|
|
107
137
|
"data-testid": s,
|
|
108
138
|
onCancel: (e) => {
|
|
109
|
-
if (e.cancelable && e.preventDefault(), !
|
|
110
|
-
if (!
|
|
111
|
-
|
|
139
|
+
if (e.cancelable && e.preventDefault(), !T.current) {
|
|
140
|
+
if (!oe()) {
|
|
141
|
+
g.current("escape");
|
|
112
142
|
return;
|
|
113
143
|
}
|
|
114
|
-
|
|
144
|
+
M();
|
|
115
145
|
}
|
|
116
146
|
},
|
|
117
|
-
className:
|
|
118
|
-
children: /* @__PURE__ */
|
|
119
|
-
value:
|
|
147
|
+
className: u(je.StyledBottomSheet, "fixed inset-0 m-0 h-full max-h-none w-full max-w-none flex-col items-center justify-end overflow-visible border-0 bg-transparent p-0 outline-none open:flex"),
|
|
148
|
+
children: /* @__PURE__ */ p(Le.Provider, {
|
|
149
|
+
value: z,
|
|
120
150
|
children: [/* @__PURE__ */ t("div", {
|
|
121
151
|
"aria-hidden": "true",
|
|
122
152
|
"data-testid": `${s}-scrim`,
|
|
123
153
|
onClick: () => {
|
|
124
|
-
|
|
154
|
+
d("scrim");
|
|
125
155
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
156
|
+
style: C > 0 ? { opacity: 1 - C } : void 0,
|
|
157
|
+
className: u("absolute inset-0 bg-[#626e7eb2]", C === 0 && ["transition-opacity motion-reduce:duration-150", w ? ["opacity-100", se] : ["opacity-0", ie]])
|
|
158
|
+
}), /* @__PURE__ */ p("div", {
|
|
159
|
+
ref: _,
|
|
160
|
+
"data-state": w ? "open" : "closed",
|
|
161
|
+
style: H ? { maxHeight: `min(${Z}px, 90dvh)` } : ne ? { transform: `translateY(${W}px)` } : void 0,
|
|
162
|
+
className: u("relative box-border flex w-full max-w-[640px] flex-col bg-white text-delta-700 outline-none", y ? "h-full max-h-none rounded-none" : u("rounded-t-[28px]", !H && (l ? "max-h-[90dvh]" : "max-h-[50dvh]")), !ne && [
|
|
163
|
+
"motion-safe:transition-[transform,max-height] motion-reduce:transition-opacity motion-reduce:duration-150",
|
|
164
|
+
w ? se : ie,
|
|
165
|
+
w ? "translate-y-0 opacity-100" : "motion-safe:translate-y-full motion-reduce:opacity-0"
|
|
166
|
+
], he),
|
|
132
167
|
children: [
|
|
133
|
-
/* @__PURE__ */
|
|
168
|
+
/* @__PURE__ */ p("div", {
|
|
134
169
|
className: "border-b-solid shrink-0 border-b border-delta-200 pb-2",
|
|
135
|
-
children: [/* @__PURE__ */
|
|
136
|
-
...
|
|
170
|
+
children: [/* @__PURE__ */ p("div", {
|
|
171
|
+
...ke,
|
|
137
172
|
className: "relative flex h-12 touch-none items-center gap-2 px-2",
|
|
138
173
|
children: [
|
|
139
174
|
/* @__PURE__ */ t("div", {
|
|
140
175
|
className: "flex min-w-0 flex-1 items-center",
|
|
141
|
-
children:
|
|
176
|
+
children: D && /* @__PURE__ */ t(I, {
|
|
142
177
|
dataTest: `${s}-back`,
|
|
143
178
|
variant: "textGray",
|
|
144
179
|
type: "button",
|
|
145
|
-
"aria-label":
|
|
146
|
-
onClick:
|
|
147
|
-
startIcon: /* @__PURE__ */ t(
|
|
180
|
+
"aria-label": de ?? R.back,
|
|
181
|
+
onClick: D,
|
|
182
|
+
startIcon: /* @__PURE__ */ t(Te, {
|
|
148
183
|
width: 24,
|
|
149
184
|
height: 24
|
|
150
185
|
})
|
|
151
186
|
})
|
|
152
187
|
}),
|
|
153
|
-
|
|
188
|
+
Q ? /* @__PURE__ */ t("button", {
|
|
154
189
|
type: "button",
|
|
155
190
|
"data-drag-handle": !0,
|
|
156
191
|
"data-testid": `${s}-drag-handle`,
|
|
157
|
-
"aria-label":
|
|
158
|
-
"aria-expanded":
|
|
192
|
+
"aria-label": l ? R.collapse : R.expand,
|
|
193
|
+
"aria-expanded": l,
|
|
159
194
|
onClick: () => {
|
|
160
|
-
|
|
195
|
+
l ? Y() : h(!0);
|
|
161
196
|
},
|
|
162
197
|
className: "absolute left-1/2 top-1/2 flex h-6 w-12 -translate-x-1/2 -translate-y-1/2 cursor-grab items-center justify-center rounded border-0 bg-transparent p-0 outline-none focus-visible:[box-shadow:inset_0_0_0_2px_var(--colors-focus-ring)]",
|
|
163
198
|
children: /* @__PURE__ */ t("span", {
|
|
@@ -169,55 +204,65 @@ var Ce = 500, ze = ({ dataTest: s, id: Q, open: r, onClose: i, title: m, ariaLab
|
|
|
169
204
|
"data-testid": `${s}-drag-handle`,
|
|
170
205
|
className: "pointer-events-none absolute left-1/2 top-1/2 h-1 w-8 -translate-x-1/2 -translate-y-1/2 rounded-full bg-delta-700"
|
|
171
206
|
}),
|
|
172
|
-
/* @__PURE__ */ t(
|
|
207
|
+
/* @__PURE__ */ t(I, {
|
|
173
208
|
dataTest: `${s}-close`,
|
|
174
209
|
variant: "textGray",
|
|
175
210
|
type: "button",
|
|
176
|
-
"aria-label":
|
|
211
|
+
"aria-label": pe,
|
|
177
212
|
onClick: () => {
|
|
178
|
-
|
|
213
|
+
d("closeButton");
|
|
179
214
|
},
|
|
180
|
-
startIcon: /* @__PURE__ */ t(
|
|
215
|
+
startIcon: /* @__PURE__ */ t(_e, {
|
|
181
216
|
width: 24,
|
|
182
217
|
height: 24
|
|
183
218
|
})
|
|
184
219
|
})
|
|
185
220
|
]
|
|
186
|
-
}),
|
|
221
|
+
}), x && /* @__PURE__ */ p("div", {
|
|
187
222
|
className: "flex items-center gap-1 px-4",
|
|
188
|
-
children: [
|
|
223
|
+
children: [$ && /* @__PURE__ */ t("span", {
|
|
189
224
|
"aria-hidden": "true",
|
|
190
225
|
className: "flex size-5 shrink-0 items-center justify-center text-delta-700",
|
|
191
|
-
children:
|
|
226
|
+
children: $
|
|
192
227
|
}), /* @__PURE__ */ t("div", {
|
|
193
|
-
id:
|
|
228
|
+
id: P,
|
|
194
229
|
className: "min-w-0 flex-1 truncate text-lg font-semibold leading-7 text-delta-800",
|
|
195
|
-
children:
|
|
230
|
+
children: x
|
|
196
231
|
})]
|
|
197
232
|
})]
|
|
198
233
|
}),
|
|
199
234
|
/* @__PURE__ */ t("div", {
|
|
200
|
-
ref:
|
|
201
|
-
className:
|
|
202
|
-
children:
|
|
235
|
+
ref: ye,
|
|
236
|
+
className: u("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain pl-4 pr-2 pt-2", B || k ? "pb-2" : "pb-[max(0.5rem,env(safe-area-inset-bottom))]"),
|
|
237
|
+
children: E(ue)
|
|
203
238
|
}),
|
|
204
|
-
|
|
205
|
-
className:
|
|
239
|
+
B && /* @__PURE__ */ p("div", {
|
|
240
|
+
className: u("border-t-solid flex shrink-0 items-start border-t border-delta-200 bg-white p-1", O ? "justify-between" : "justify-end", "max-xs:flex-wrap max-xs:gap-y-2 max-xs:[&>:nth-child(2)]:ml-auto", !k && "pb-[max(0.25rem,env(safe-area-inset-bottom))]"),
|
|
206
241
|
children: [
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
242
|
+
O,
|
|
243
|
+
re,
|
|
244
|
+
te && /* @__PURE__ */ t("span", {
|
|
210
245
|
className: "sr-only",
|
|
211
246
|
role: "status",
|
|
212
247
|
"aria-live": "polite",
|
|
213
248
|
"aria-atomic": "true",
|
|
214
|
-
children:
|
|
249
|
+
children: ee
|
|
215
250
|
})
|
|
216
251
|
]
|
|
217
252
|
}),
|
|
218
|
-
|
|
219
|
-
className:
|
|
220
|
-
children:
|
|
253
|
+
k && /* @__PURE__ */ t("div", {
|
|
254
|
+
className: u("flex shrink-0 flex-col items-end bg-white p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]", B && "max-xs:pt-1"),
|
|
255
|
+
children: k
|
|
256
|
+
}),
|
|
257
|
+
!y && /* @__PURE__ */ t("span", {
|
|
258
|
+
"aria-hidden": "true",
|
|
259
|
+
"data-testid": `${s}-skirt`,
|
|
260
|
+
className: "pointer-events-none absolute inset-x-0 top-full h-[100lvh] bg-white"
|
|
261
|
+
}),
|
|
262
|
+
/* @__PURE__ */ t("span", {
|
|
263
|
+
"aria-hidden": "true",
|
|
264
|
+
"data-testid": `${s}-edge`,
|
|
265
|
+
className: "pointer-events-none absolute inset-0 rounded-[inherit] [box-shadow:inset_0_0_0_1px_var(--colors-delta-300)]"
|
|
221
266
|
})
|
|
222
267
|
]
|
|
223
268
|
})]
|
|
@@ -225,5 +270,5 @@ var Ce = 500, ze = ({ dataTest: s, id: Q, open: r, onClose: i, title: m, ariaLab
|
|
|
225
270
|
});
|
|
226
271
|
};
|
|
227
272
|
export {
|
|
228
|
-
|
|
273
|
+
dt as StyledBottomSheet
|
|
229
274
|
};
|
|
@@ -1,46 +1,126 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
var
|
|
3
|
-
const [
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { useEffect as v, useRef as w, useState as m } from "react";
|
|
2
|
+
var S = 0.3, O = 48, g = 4, E = 0.5, N = 80, B = (H, f, p, d, a) => {
|
|
3
|
+
const [R, I] = m(0), [_, Y] = m(0), [x, D] = m(null), h = w(null), u = w({
|
|
4
|
+
onDismiss: f,
|
|
5
|
+
onDragUp: p,
|
|
6
|
+
onCollapse: d
|
|
7
|
+
});
|
|
8
|
+
v(() => {
|
|
9
|
+
u.current = {
|
|
10
|
+
onDismiss: f,
|
|
11
|
+
onDragUp: p,
|
|
12
|
+
onCollapse: d
|
|
13
|
+
};
|
|
14
|
+
}, [
|
|
15
|
+
f,
|
|
16
|
+
p,
|
|
17
|
+
d
|
|
18
|
+
]);
|
|
19
|
+
const L = (t) => {
|
|
20
|
+
const e = H.current;
|
|
21
|
+
if (!e) return null;
|
|
22
|
+
const n = performance.now();
|
|
23
|
+
return {
|
|
24
|
+
startY: t,
|
|
25
|
+
height: e.getBoundingClientRect().height,
|
|
26
|
+
captured: !1,
|
|
27
|
+
onDragUp: u.current.onDragUp,
|
|
28
|
+
onCollapse: u.current.onCollapse,
|
|
29
|
+
samples: [{
|
|
30
|
+
y: t,
|
|
31
|
+
t: n
|
|
32
|
+
}]
|
|
33
|
+
};
|
|
34
|
+
}, T = (t, e) => {
|
|
35
|
+
const n = performance.now();
|
|
36
|
+
for (t.samples.push({
|
|
37
|
+
y: e,
|
|
38
|
+
t: n
|
|
39
|
+
}); t.samples.length > 2 && n - (t.samples[0]?.t ?? n) > N; ) t.samples.shift();
|
|
40
|
+
const c = e - t.startY, i = Math.max(0, c);
|
|
41
|
+
I(i), Y(t.height ? Math.min(1, i / t.height) : 0), D(t.onDragUp && c < 0 ? t.height - c : null);
|
|
42
|
+
}, M = (t, e) => {
|
|
43
|
+
if (I(0), Y(0), D(null), !t.captured || e === null) return;
|
|
44
|
+
const n = e - t.startY, c = t.samples[0], i = c ? performance.now() - c.t : 0, s = c && i > 0 ? (e - c.y) / i : 0;
|
|
45
|
+
if (t.onCollapse && n > 0) {
|
|
46
|
+
const r = window.innerHeight / 2;
|
|
47
|
+
s >= 0 && t.height - n < r * (1 - S) ? u.current.onDismiss() : (s > E || s >= 0 && n > O) && t.onCollapse();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
s > E || s >= 0 && n > t.height * S ? u.current.onDismiss() : (s < -E || n < -O) && t.onDragUp?.();
|
|
51
|
+
};
|
|
52
|
+
v(() => {
|
|
53
|
+
if (!a) return;
|
|
54
|
+
let t = null, e = !1, n = 0;
|
|
55
|
+
const c = (r) => {
|
|
56
|
+
const o = r.touches[0];
|
|
57
|
+
r.touches.length !== 1 || !o || (r.target instanceof Element ? r.target : null)?.closest('input, textarea, select, [contenteditable="true"]') || (t = L(o.clientY), e = !1, n = o.clientX);
|
|
58
|
+
}, i = (r) => {
|
|
59
|
+
const o = r.touches[0];
|
|
60
|
+
if (!t || !o) return;
|
|
61
|
+
const l = o.clientY - t.startY;
|
|
62
|
+
if (!e) {
|
|
63
|
+
const P = o.clientX - n;
|
|
64
|
+
if (Math.abs(l) < g && Math.abs(P) < g) return;
|
|
65
|
+
e = !0;
|
|
66
|
+
const A = l > 0 && a.scrollTop <= 0, U = l < 0 && !!t.onDragUp;
|
|
67
|
+
if (Math.abs(l) <= Math.abs(P) || !A && !U) {
|
|
68
|
+
t = null;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
t.captured = !0, t.startY = o.clientY;
|
|
72
|
+
}
|
|
73
|
+
r.cancelable && r.preventDefault(), T(t, o.clientY);
|
|
74
|
+
}, s = (r) => {
|
|
75
|
+
const o = t;
|
|
76
|
+
if (t = null, !o) return;
|
|
77
|
+
const l = r.changedTouches[0];
|
|
78
|
+
M(o, r.type === "touchcancel" || !l ? null : l.clientY);
|
|
79
|
+
};
|
|
80
|
+
return a.addEventListener("touchstart", c, { passive: !0 }), a.addEventListener("touchmove", i, { passive: !1 }), a.addEventListener("touchend", s), a.addEventListener("touchcancel", s), () => {
|
|
81
|
+
a.removeEventListener("touchstart", c), a.removeEventListener("touchmove", i), a.removeEventListener("touchend", s), a.removeEventListener("touchcancel", s);
|
|
82
|
+
};
|
|
83
|
+
}, [a]);
|
|
84
|
+
const C = (t, e) => {
|
|
85
|
+
const n = h.current;
|
|
86
|
+
n?.pointerId === t.pointerId && (h.current = null, t.currentTarget.hasPointerCapture(t.pointerId) && t.currentTarget.releasePointerCapture(t.pointerId), M(n, e));
|
|
6
87
|
};
|
|
7
88
|
return {
|
|
8
|
-
dragOffset:
|
|
89
|
+
dragOffset: R,
|
|
90
|
+
dragRatio: _,
|
|
91
|
+
liftedHeight: x,
|
|
9
92
|
dragHandleProps: {
|
|
10
|
-
onPointerDown: (
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
height: t.getBoundingClientRect().height,
|
|
17
|
-
captured: !1
|
|
93
|
+
onPointerDown: (t) => {
|
|
94
|
+
if (t.pointerType === "mouse" && t.button !== 0 || t.target instanceof Element && t.target.closest("button:not([data-drag-handle])")) return;
|
|
95
|
+
const e = L(t.clientY);
|
|
96
|
+
e && (h.current = {
|
|
97
|
+
...e,
|
|
98
|
+
pointerId: t.pointerId
|
|
18
99
|
});
|
|
19
100
|
},
|
|
20
|
-
onPointerMove: (
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
101
|
+
onPointerMove: (t) => {
|
|
102
|
+
const e = h.current;
|
|
103
|
+
if (e?.pointerId === t.pointerId) {
|
|
104
|
+
if (!e.captured) {
|
|
105
|
+
if (Math.abs(t.clientY - e.startY) < g) return;
|
|
106
|
+
e.captured = !0;
|
|
107
|
+
try {
|
|
108
|
+
t.currentTarget.setPointerCapture(t.pointerId);
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
30
111
|
}
|
|
112
|
+
T(e, t.clientY);
|
|
31
113
|
}
|
|
32
|
-
o(Math.max(0, e));
|
|
33
114
|
},
|
|
34
|
-
onPointerUp: (
|
|
35
|
-
|
|
36
|
-
a(r, t ? r.clientY - t.startY : 0);
|
|
115
|
+
onPointerUp: (t) => {
|
|
116
|
+
C(t, t.clientY);
|
|
37
117
|
},
|
|
38
|
-
onPointerCancel: (
|
|
39
|
-
|
|
118
|
+
onPointerCancel: (t) => {
|
|
119
|
+
C(t, null);
|
|
40
120
|
}
|
|
41
121
|
}
|
|
42
122
|
};
|
|
43
123
|
};
|
|
44
124
|
export {
|
|
45
|
-
|
|
125
|
+
B as useDragToDismiss
|
|
46
126
|
};
|
|
@@ -73,8 +73,14 @@ export interface StyledBottomSheetProps {
|
|
|
73
73
|
* can be expanded to 90vh — by dragging the handle up, or by activating it (Tab lands on it, Space /
|
|
74
74
|
* Enter toggle between the two heights) — and scrolls internally from there. Below 480px of viewport
|
|
75
75
|
* height (a phone in landscape) it becomes a full-screen dialog instead. Five equivalent dismiss
|
|
76
|
-
* routes — close button, "Vis resultater", scrim, Escape, dragging down past 30%
|
|
77
|
-
* commits or discards anything: filters apply as the user goes and actions commit on
|
|
76
|
+
* routes — close button, "Vis resultater", scrim, Escape, dragging down past 30% or flinging down — and
|
|
77
|
+
* none of them commits or discards anything: filters apply as the user goes and actions commit on
|
|
78
|
+
* activation.
|
|
79
|
+
*
|
|
80
|
+
* Motion follows Material 3: the sheet tracks the finger (on the handle, or on the body while it is
|
|
81
|
+
* scrolled to the top or can still expand), the scrim fades with a downward drag, a release settles on
|
|
82
|
+
* emphasized-decelerate, and closing slides the sheet out on emphasized-accelerate before the dialog
|
|
83
|
+
* closes. `prefers-reduced-motion` keeps all of it instant.
|
|
78
84
|
*
|
|
79
85
|
* Interaction model is the popover's: `role="dialog"`, `Tab` only, no `role="menu"`, no arrow keys.
|
|
80
86
|
* Focus moves to the sheet on open (so the title is announced first) and back to the trigger on
|
|
@@ -10,15 +10,26 @@ interface DragToDismiss {
|
|
|
10
10
|
dragHandleProps: DragHandleProps;
|
|
11
11
|
/** How far the sheet is currently dragged down, in px. `0` when at rest. */
|
|
12
12
|
dragOffset: number;
|
|
13
|
+
/** `dragOffset` as a share of the sheet's height, for the scrim to fade with the drag. */
|
|
14
|
+
dragRatio: number;
|
|
15
|
+
/** While the sheet is dragged up and can expand: its height under the finger, in px. */
|
|
16
|
+
liftedHeight: number | null;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
|
-
* Drag the sheet down past 30% of its height to dismiss it; release earlier and it
|
|
16
|
-
*
|
|
19
|
+
* Drag the sheet down past 30% of its height, or fling it down, to dismiss it; release earlier and it
|
|
20
|
+
* settles back. Dragged up, a sheet that could expand when the gesture started follows the finger
|
|
21
|
+
* (`liftedHeight`); released after 48px or flung up, `onDragUp` expands it, otherwise it settles back.
|
|
22
|
+
* The way back is a drag too: an expanded sheet (`onCollapse`) dragged down 48px or flung down returns
|
|
23
|
+
* to half height, and only a drag that leaves less than 70% of that half on screen dismisses it.
|
|
24
|
+
*
|
|
25
|
+
* The drag starts on the handle row (any pointer) or, on touch, anywhere in the `body` while
|
|
26
|
+
* the body is scrolled to its top and the finger moves down, or while the sheet can still expand and the
|
|
27
|
+
* finger moves up — as Material's bottom sheet does. Otherwise the body just scrolls.
|
|
17
28
|
*
|
|
18
29
|
* Deliberately never the only exit or the only way to resize (WCAG 2.5.7): the close button, the scrim
|
|
19
30
|
* and Escape close it, and the drag handle toggles the height as a button. A press that starts on any
|
|
20
31
|
* other button in the drag zone is left alone, so the close control keeps working as a plain click.
|
|
21
32
|
* The pointer is captured only once it has moved, so a tap on the drag handle stays a click.
|
|
22
33
|
*/
|
|
23
|
-
export declare const useDragToDismiss: (sheetRef: RefObject<HTMLElement | null>, onDismiss: () => void, onDragUp?: () => void) => DragToDismiss;
|
|
34
|
+
export declare const useDragToDismiss: (sheetRef: RefObject<HTMLElement | null>, onDismiss: () => void, onDragUp?: () => void, onCollapse?: () => void, body?: HTMLElement | null) => DragToDismiss;
|
|
24
35
|
export {};
|