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.
@@ -1,163 +1,198 @@
1
- import { cn as l } from "../../../helpers/cn.js";
2
- import { registerOpenModalDialog as ce } from "../../../hooks/useTopLayer.hook.js";
3
- import { CloseIcon as de } from "../../icons/close-icon/CloseIcon.js";
4
- import { BackIcon as ue } from "../../icons/back-icon/BackIcon.js";
5
- import { StyledButton as N } from "../../inputs/button/StyledButton.js";
6
- import { OverlayBackOwnerContext as fe, isOverlayBackEnabled as X, requestCloseTopOverlayBack as R, useBackCloses as me } from "../../../hooks/useBackCloses.hook.js";
7
- import { isKeyboardModality as pe, trackInputModality as he } from "../../inputs/full-screen-picker/inputModality.js";
8
- import { useDebouncedValue as ve } from "../../../hooks/useDebouncedValue.hook.js";
9
- import { useFocusTrap as be } from "../../../hooks/useFocusTrap.hook.js";
10
- import { useShortViewportMediaQuery as xe } from "../../../hooks/useMediaQuery.hook.js";
11
- import { SHEET_HEADER_TEXT as ye, SHEET_TEXT as we } from "./sheetCopy.js";
12
- import { formatResultsLabel as ge } from "./formatResultsLabel.js";
13
- import { useBodyScrollLock as Ee } from "../../../hooks/useBodyScrollLock.hook.js";
14
- import ke from "./StyledBottomSheet.module.js";
15
- import { useDragToDismiss as Se } from "./useDragToDismiss.hook.js";
16
- import { useEffect as x, useId as Ne, useLayoutEffect as Re, useRef as c, useState as C } from "react";
17
- import { jsx as t, jsxs as f } from "react/jsx-runtime";
18
- var Ce = 500, ze = ({ dataTest: s, id: Q, open: r, onClose: i, title: m, ariaLabel: Y, titleIcon: _, onBack: B, backLabel: J, children: W, viewResultsAction: L, resetAction: Z, footerActions: ee, resultCount: O, locale: y = "en", closeLabel: te = we[y].close, className: re, registerBackClose: oe = !0, ownerRef: ne, triggerRef: T }) => {
19
- const D = Ne(), d = c(null), H = c(null), I = c(null), M = ne ?? d, w = c(!1), [g, j] = C(!1), $ = xe(), F = c(null), [u, p] = C(!1), [ae, se] = C(!1), A = !$ && (u || ae), E = ye[y], h = c(i), P = c(r);
20
- x(() => {
21
- h.current = i, P.current = r;
22
- }, [i, r]);
23
- const { dragHandleProps: ie, dragOffset: q } = Se(H, () => {
24
- h.current("drag");
25
- }, A ? () => p(!0) : void 0);
26
- x(() => {
27
- const e = F.current;
28
- if (!r || u || !e) return;
29
- const a = () => {
30
- const n = e.scrollHeight > e.clientHeight + 1;
31
- n && e.contains(document.activeElement) ? p(!0) : se(n);
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
- a();
34
- const o = new ResizeObserver(a);
35
- o.observe(e);
36
- for (const n of Array.from(e.children)) o.observe(n);
37
- return () => o.disconnect();
38
- }, [r, u]), Ee(r), be(r, d), x(() => {
39
- if (!r) return;
40
- const e = (o) => {
41
- o.key === "Escape" && (w.current = !0, window.setTimeout(() => {
42
- w.current = !1;
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
- }, a = (o) => {
45
- if (o.key !== "Escape" || o.defaultPrevented) return;
46
- const n = document.activeElement;
47
- n instanceof Element && n.closest("dialog[open]") !== d.current || (o.preventDefault(), o.stopImmediatePropagation(), R(o));
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", a), () => {
50
- window.removeEventListener("keydown", e, !0), window.removeEventListener("keydown", a);
71
+ return window.addEventListener("keydown", e, !0), window.addEventListener("keydown", o), () => {
72
+ window.removeEventListener("keydown", e, !0), window.removeEventListener("keydown", o);
51
73
  };
52
- }, [r]), me({
53
- active: r && oe,
54
- requestClose: () => h.current("escape"),
55
- ownerRef: M
56
- }), Re(() => {
57
- const e = d.current;
58
- if (!r || !e) return;
59
- he();
60
- const a = document.activeElement instanceof HTMLElement ? document.activeElement : null;
61
- I.current = T?.current ?? a, e.open || e.showModal(), e.focus({ preventScroll: !0 });
62
- const o = requestAnimationFrame(() => {
63
- j(!0);
64
- }), n = ce(e);
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(o), n(), j(!1), p(!1), e.open && e.close();
67
- const G = I.current;
68
- G?.isConnected && G.focus({
69
- preventScroll: !0,
70
- focusVisible: pe()
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
- }, [r, T]), x(() => {
74
- const e = d.current;
75
- if (!e || !r) return;
76
- let a = !1;
77
- const o = () => {
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
- a = !1, P.current && e.isConnected && !e.open && (e.showModal(), e.focus({ preventScroll: !0 }));
109
+ o = !1, J.current && e.isConnected && !e.open && (e.showModal(), e.focus({ preventScroll: !0 }));
80
110
  });
81
- }, n = () => {
82
- a || (a = !0, X() && R(), o());
111
+ }, a = () => {
112
+ o || (o = !0, oe() && M(), r());
83
113
  };
84
- return e.addEventListener("close", n), () => e.removeEventListener("close", n);
85
- }, [r]);
86
- const V = ge(ve(O, Ce), y);
87
- if (!r) return null;
88
- const le = { close: () => {
89
- i("action");
90
- } }, v = (e) => typeof e == "function" ? e(le) : e, K = O !== void 0, k = L !== void 0 ? v(L) : K ? /* @__PURE__ */ t(N, {
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
- i("viewResults");
125
+ d("viewResults");
96
126
  },
97
- children: V
98
- }) : void 0, U = v(Z), b = v(ee), S = !!(k ?? U), z = q > 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: d,
101
- id: Q,
130
+ ref: f,
131
+ id: le,
102
132
  tabIndex: -1,
103
133
  "aria-modal": "true",
104
- "aria-labelledby": m ? D : void 0,
105
- "aria-label": m ? void 0 : Y,
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(), !w.current) {
110
- if (!X()) {
111
- h.current("escape");
139
+ if (e.cancelable && e.preventDefault(), !T.current) {
140
+ if (!oe()) {
141
+ g.current("escape");
112
142
  return;
113
143
  }
114
- R();
144
+ M();
115
145
  }
116
146
  },
117
- className: l(ke.StyledBottomSheet, "fixed inset-0 m-0 h-full max-h-none w-full max-w-none flex-col items-center justify-end overflow-hidden border-0 bg-transparent p-0 outline-none open:flex"),
118
- children: /* @__PURE__ */ f(fe.Provider, {
119
- value: M,
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
- i("scrim");
154
+ d("scrim");
125
155
  },
126
- className: l("absolute inset-0 bg-[#626e7eb2] transition-opacity duration-[250ms] ease-out motion-reduce:duration-150", g ? "opacity-100" : "opacity-0")
127
- }), /* @__PURE__ */ f("div", {
128
- ref: H,
129
- "data-state": g ? "open" : "closed",
130
- style: z ? { transform: `translateY(${q}px)` } : void 0,
131
- className: l("relative box-border flex w-full max-w-[640px] flex-col border border-solid border-delta-300 bg-white text-delta-700 outline-none", $ ? "h-full max-h-none rounded-none" : l("rounded-t-[28px]", u ? "max-h-[90dvh]" : "max-h-[50dvh]"), !z && ["ease-out motion-safe:transition-transform motion-safe:duration-[250ms] motion-reduce:transition-opacity motion-reduce:duration-150", g ? "translate-y-0 opacity-100" : "motion-safe:translate-y-full motion-reduce:opacity-0"], re),
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__ */ f("div", {
168
+ /* @__PURE__ */ p("div", {
134
169
  className: "border-b-solid shrink-0 border-b border-delta-200 pb-2",
135
- children: [/* @__PURE__ */ f("div", {
136
- ...ie,
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: B && /* @__PURE__ */ t(N, {
176
+ children: D && /* @__PURE__ */ t(I, {
142
177
  dataTest: `${s}-back`,
143
178
  variant: "textGray",
144
179
  type: "button",
145
- "aria-label": J ?? E.back,
146
- onClick: B,
147
- startIcon: /* @__PURE__ */ t(ue, {
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
- A ? /* @__PURE__ */ t("button", {
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": u ? E.collapse : E.expand,
158
- "aria-expanded": u,
192
+ "aria-label": l ? R.collapse : R.expand,
193
+ "aria-expanded": l,
159
194
  onClick: () => {
160
- p((e) => !e);
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(N, {
207
+ /* @__PURE__ */ t(I, {
173
208
  dataTest: `${s}-close`,
174
209
  variant: "textGray",
175
210
  type: "button",
176
- "aria-label": te,
211
+ "aria-label": pe,
177
212
  onClick: () => {
178
- i("closeButton");
213
+ d("closeButton");
179
214
  },
180
- startIcon: /* @__PURE__ */ t(de, {
215
+ startIcon: /* @__PURE__ */ t(_e, {
181
216
  width: 24,
182
217
  height: 24
183
218
  })
184
219
  })
185
220
  ]
186
- }), m && /* @__PURE__ */ f("div", {
221
+ }), x && /* @__PURE__ */ p("div", {
187
222
  className: "flex items-center gap-1 px-4",
188
- children: [_ && /* @__PURE__ */ t("span", {
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: D,
228
+ id: P,
194
229
  className: "min-w-0 flex-1 truncate text-lg font-semibold leading-7 text-delta-800",
195
- children: m
230
+ children: x
196
231
  })]
197
232
  })]
198
233
  }),
199
234
  /* @__PURE__ */ t("div", {
200
- ref: F,
201
- className: l("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain pl-4 pr-2 pt-2", S || b ? "pb-2" : "pb-[max(0.5rem,env(safe-area-inset-bottom))]"),
202
- children: v(W)
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
- S && /* @__PURE__ */ f("div", {
205
- className: l("border-t-solid flex shrink-0 items-start border-t border-delta-200 bg-white p-1", k ? "justify-between" : "justify-end", "max-xs:flex-wrap max-xs:gap-y-2 max-xs:[&>:nth-child(2)]:ml-auto", !b && "pb-[max(0.25rem,env(safe-area-inset-bottom))]"),
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
- k,
208
- U,
209
- K && /* @__PURE__ */ t("span", {
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: V
249
+ children: ee
215
250
  })
216
251
  ]
217
252
  }),
218
- b && /* @__PURE__ */ t("div", {
219
- className: l("flex shrink-0 flex-col items-end bg-white p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]", S && "max-xs:pt-1"),
220
- children: b
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
- ze as StyledBottomSheet
273
+ dt as StyledBottomSheet
229
274
  };
@@ -1,46 +1,126 @@
1
- import { useRef as d, useState as p } from "react";
2
- var f = 0.3, g = 48, l = 4, h = (i, u, c) => {
3
- const [s, o] = p(0), n = d(null), a = (r, t) => {
4
- const e = n.current;
5
- e?.pointerId === r.pointerId && (n.current = null, r.currentTarget.hasPointerCapture(r.pointerId) && r.currentTarget.releasePointerCapture(r.pointerId), o(0), e.captured && (t > e.height * f ? u() : t < -g && c?.()));
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: s,
89
+ dragOffset: R,
90
+ dragRatio: _,
91
+ liftedHeight: x,
9
92
  dragHandleProps: {
10
- onPointerDown: (r) => {
11
- if (r.pointerType === "mouse" && r.button !== 0 || r.target instanceof Element && r.target.closest("button:not([data-drag-handle])")) return;
12
- const t = i.current;
13
- t && (n.current = {
14
- pointerId: r.pointerId,
15
- startY: r.clientY,
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: (r) => {
21
- const t = n.current;
22
- if (t?.pointerId !== r.pointerId) return;
23
- const e = r.clientY - t.startY;
24
- if (!t.captured) {
25
- if (Math.abs(e) < l) return;
26
- t.captured = !0;
27
- try {
28
- r.currentTarget.setPointerCapture(r.pointerId);
29
- } catch {
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: (r) => {
35
- const t = n.current;
36
- a(r, t ? r.clientY - t.startY : 0);
115
+ onPointerUp: (t) => {
116
+ C(t, t.clientY);
37
117
  },
38
- onPointerCancel: (r) => {
39
- a(r, 0);
118
+ onPointerCancel: (t) => {
119
+ C(t, null);
40
120
  }
41
121
  }
42
122
  };
43
123
  };
44
124
  export {
45
- h as useDragToDismiss
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% — and none of them
77
- * commits or discards anything: filters apply as the user goes and actions commit on activation.
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 snaps back. Drag it
16
- * up by 48px and `onDragUp` runs, which expands a sheet that has a taller height.
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 {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.136.1",
6
+ "version": "3.136.2",
7
7
  "type": "module",
8
8
  "sideEffects": [
9
9
  "**/*.css",