@kanso-labs/kanso-ui 0.35.0 → 0.37.0
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/README.md +90 -9
- package/dist/button/context.js +7 -0
- package/dist/button/context.js.map +1 -0
- package/dist/button/group.js +25 -0
- package/dist/button/group.js.map +1 -0
- package/dist/button/hooks.js +81 -0
- package/dist/button/hooks.js.map +1 -0
- package/dist/button/index.d.ts +11 -0
- package/dist/button/index.js +273 -0
- package/dist/button/index.js.map +1 -0
- package/dist/button/styles.js +23 -0
- package/dist/button/styles.js.map +1 -0
- package/dist/calendar/index.js +473 -7
- package/dist/calendar/index.js.map +1 -1
- package/dist/calendar/styles.js +132 -4
- package/dist/calendar/styles.js.map +1 -1
- package/dist/chip/index.js +74 -9
- package/dist/chip/index.js.map +1 -1
- package/dist/chip/styles.js +78 -4
- package/dist/chip/styles.js.map +1 -1
- package/dist/collection/index.js +12 -9
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/styles.js +21 -2
- package/dist/collection/styles.js.map +1 -1
- package/dist/color-scheme.d.ts +29 -0
- package/dist/color-scheme.js +32 -0
- package/dist/color-scheme.js.map +1 -0
- package/dist/components/avatar/index.js +35 -22
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/badge/index.d.ts +40 -0
- package/dist/components/badge/index.js +102 -0
- package/dist/components/badge/index.js.map +1 -0
- package/dist/components/breadcrumbs/index.d.ts +1 -1
- package/dist/components/breadcrumbs/index.js +1 -1
- package/dist/components/breadcrumbs/index.js.map +1 -1
- package/dist/components/button/index.d.ts +58 -14
- package/dist/components/button/index.js +400 -147
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button-group/index.d.ts +54 -0
- package/dist/components/button-group/index.js +272 -0
- package/dist/components/button-group/index.js.map +1 -0
- package/dist/components/calendar/index.d.ts +9 -1
- package/dist/components/calendar/index.js +71 -44
- package/dist/components/calendar/index.js.map +1 -1
- package/dist/components/card/index.d.ts +1 -1
- package/dist/components/card/index.js +4 -4
- package/dist/components/card/index.js.map +1 -1
- package/dist/components/checkbox/index.js +15 -1
- package/dist/components/checkbox/index.js.map +1 -1
- package/dist/components/checkbox-group/index.js +1 -0
- package/dist/components/checkbox-group/index.js.map +1 -1
- package/dist/components/chip/index.d.ts +55 -8
- package/dist/components/chip/index.js +174 -63
- package/dist/components/chip/index.js.map +1 -1
- package/dist/components/chip-group/index.d.ts +16 -7
- package/dist/components/chip-group/index.js +58 -35
- package/dist/components/chip-group/index.js.map +1 -1
- package/dist/components/color-field/index.js +25 -23
- package/dist/components/color-field/index.js.map +1 -1
- package/dist/components/color-picker/index.js +42 -31
- package/dist/components/color-picker/index.js.map +1 -1
- package/dist/components/color-swatch-picker/index.d.ts +1 -1
- package/dist/components/color-swatch-picker/index.js +17 -13
- package/dist/components/color-swatch-picker/index.js.map +1 -1
- package/dist/components/combo-box/index.d.ts +5 -3
- package/dist/components/combo-box/index.js +63 -58
- package/dist/components/combo-box/index.js.map +1 -1
- package/dist/components/copy-field/index.d.ts +7 -6
- package/dist/components/copy-field/index.js +92 -90
- package/dist/components/copy-field/index.js.map +1 -1
- package/dist/components/currency/index.d.ts +8 -7
- package/dist/components/currency/index.js +43 -65
- package/dist/components/currency/index.js.map +1 -1
- package/dist/components/date-field/index.js +24 -22
- package/dist/components/date-field/index.js.map +1 -1
- package/dist/components/date-picker/index.d.ts +10 -2
- package/dist/components/date-picker/index.js +76 -69
- package/dist/components/date-picker/index.js.map +1 -1
- package/dist/components/date-range-picker/index.d.ts +10 -2
- package/dist/components/date-range-picker/index.js +93 -86
- package/dist/components/date-range-picker/index.js.map +1 -1
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/index.js +2 -2
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/disclosure/index.d.ts +1 -1
- package/dist/components/disclosure/index.js +6 -6
- package/dist/components/disclosure/index.js.map +1 -1
- package/dist/components/fab/index.d.ts +72 -0
- package/dist/components/fab/index.js +89 -0
- package/dist/components/fab/index.js.map +1 -0
- package/dist/components/fab-menu/index.d.ts +90 -0
- package/dist/components/fab-menu/index.js +297 -0
- package/dist/components/fab-menu/index.js.map +1 -0
- package/dist/components/feed/index.d.ts +2 -1
- package/dist/components/feed/index.js +1 -1
- package/dist/components/feed/index.js.map +1 -1
- package/dist/components/icon-button/index.d.ts +11 -8
- package/dist/components/icon-button/index.js +244 -181
- package/dist/components/icon-button/index.js.map +1 -1
- package/dist/components/index.d.ts +30 -21
- package/dist/components/list/index.d.ts +15 -13
- package/dist/components/list/index.js +60 -61
- package/dist/components/list/index.js.map +1 -1
- package/dist/components/list-box/index.d.ts +3 -2
- package/dist/components/list-box/index.js +16 -16
- package/dist/components/list-box/index.js.map +1 -1
- package/dist/components/list-item/index.js +1 -1
- package/dist/components/list-item/index.js.map +1 -1
- package/dist/components/menu/index.d.ts +3 -2
- package/dist/components/menu/index.js +2 -2
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/navigation-bar/index.d.ts +50 -0
- package/dist/components/navigation-bar/index.js +129 -0
- package/dist/components/navigation-bar/index.js.map +1 -0
- package/dist/components/navigation-rail/index.d.ts +59 -0
- package/dist/components/navigation-rail/index.js +166 -0
- package/dist/components/navigation-rail/index.js.map +1 -0
- package/dist/components/navigation-tree/index.d.ts +1 -5
- package/dist/components/navigation-tree/index.js +3 -3
- package/dist/components/navigation-tree/index.js.map +1 -1
- package/dist/components/number-field/index.d.ts +6 -4
- package/dist/components/number-field/index.js +84 -84
- package/dist/components/number-field/index.js.map +1 -1
- package/dist/components/popover/index.d.ts +1 -1
- package/dist/components/popover/index.js +1 -1
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/radio-group/index.js +22 -11
- package/dist/components/radio-group/index.js.map +1 -1
- package/dist/components/range-calendar/index.d.ts +7 -1
- package/dist/components/range-calendar/index.js +71 -44
- package/dist/components/range-calendar/index.js.map +1 -1
- package/dist/components/search-field/index.d.ts +2 -1
- package/dist/components/search-field/index.js +24 -25
- package/dist/components/search-field/index.js.map +1 -1
- package/dist/components/search-view/index.d.ts +79 -0
- package/dist/components/search-view/index.js +255 -0
- package/dist/components/search-view/index.js.map +1 -0
- package/dist/components/segmented-button/index.d.ts +2 -2
- package/dist/components/segmented-button/index.js +60 -31
- package/dist/components/segmented-button/index.js.map +1 -1
- package/dist/components/select/index.js +1 -0
- package/dist/components/select/index.js.map +1 -1
- package/dist/components/sheet/index.d.ts +1 -1
- package/dist/components/sheet/index.js +2 -2
- package/dist/components/sheet/index.js.map +1 -1
- package/dist/components/slider/index.js +1 -1
- package/dist/components/slider/index.js.map +1 -1
- package/dist/components/snackbar/index.d.ts +2 -2
- package/dist/components/snackbar/index.js +28 -13
- package/dist/components/snackbar/index.js.map +1 -1
- package/dist/components/split-button/index.d.ts +83 -0
- package/dist/components/split-button/index.js +341 -0
- package/dist/components/split-button/index.js.map +1 -0
- package/dist/components/switch/index.js +11 -1
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/table/index.d.ts +11 -9
- package/dist/components/table/index.js +87 -31
- package/dist/components/table/index.js.map +1 -1
- package/dist/components/tabs/index.d.ts +35 -4
- package/dist/components/tabs/index.js +403 -93
- package/dist/components/tabs/index.js.map +1 -1
- package/dist/components/tag/index.d.ts +1 -1
- package/dist/components/tag/index.js.map +1 -1
- package/dist/components/text-area/index.d.ts +7 -5
- package/dist/components/text-area/index.js +28 -26
- package/dist/components/text-area/index.js.map +1 -1
- package/dist/components/text-field/index.d.ts +7 -5
- package/dist/components/text-field/index.js +28 -26
- package/dist/components/text-field/index.js.map +1 -1
- package/dist/components/time-field/index.js +24 -22
- package/dist/components/time-field/index.js.map +1 -1
- package/dist/components/tree/index.d.ts +7 -9
- package/dist/components/tree/index.js +15 -16
- package/dist/components/tree/index.js.map +1 -1
- package/dist/drag/index.js.map +1 -1
- package/dist/drag/styles.js +4 -1
- package/dist/drag/styles.js.map +1 -1
- package/dist/fab/styles.js +161 -0
- package/dist/fab/styles.js.map +1 -0
- package/dist/field/index.js +260 -214
- package/dist/field/index.js.map +1 -1
- package/dist/field/styles.js +10 -2
- package/dist/field/styles.js.map +1 -1
- package/dist/glyphs/index.js +55 -1
- package/dist/glyphs/index.js.map +1 -1
- package/dist/hooks/useRipple.js +199 -162
- package/dist/hooks/useRipple.js.map +1 -1
- package/dist/hooks/useToggleGroupDisabled.js +24 -0
- package/dist/hooks/useToggleGroupDisabled.js.map +1 -0
- package/dist/i18n/index.js +43 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/messages.js +387 -0
- package/dist/i18n/messages.js.map +1 -0
- package/dist/index.d.ts +31 -21
- package/dist/index.js +25 -16
- package/dist/navigation/context.js +7 -0
- package/dist/navigation/context.js.map +1 -0
- package/dist/navigation/index.d.ts +28 -0
- package/dist/navigation/index.js +96 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/styles.js +312 -0
- package/dist/navigation/styles.js.map +1 -0
- package/dist/react-aria.d.ts +2 -2
- package/dist/react-aria.js +2 -2
- package/dist/render/useRender.js +0 -1
- package/dist/render/useRender.js.map +1 -1
- package/dist/row/styles.js +33 -11
- package/dist/row/styles.js.map +1 -1
- package/dist/styles/focus.js.map +1 -1
- package/dist/styles/icon-button.js +9 -1
- package/dist/styles/icon-button.js.map +1 -1
- package/dist/styles/overlay.js +1 -0
- package/dist/styles/overlay.js.map +1 -1
- package/dist/styles/picker.js +1 -1
- package/dist/styles/picker.js.map +1 -1
- package/dist/styles.css +1104 -336
- package/dist/tokens/design.tokens.stylex.js +42 -1
- package/dist/tokens/design.tokens.stylex.js.map +1 -1
- package/dist/tokens.css +166 -53
- package/package.json +9 -5
package/dist/hooks/useRipple.js
CHANGED
|
@@ -2,7 +2,7 @@ import { props } from "../node_modules/@stylexjs/stylex/lib/es/stylex.js";
|
|
|
2
2
|
import { rippleStyles as styles } from "../styles/ripple.js";
|
|
3
3
|
import { motionDurationMs, motionEasing, spacingPx } from "../tokens/values.js";
|
|
4
4
|
import { c } from "react/compiler-runtime";
|
|
5
|
-
import { useRef, useState } from "react";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/hooks/useRipple.tsx
|
|
8
8
|
/** How far the ripple grows past the host's corners. `spacing.sm`. */
|
|
@@ -47,7 +47,7 @@ function prefersReducedMotion() {
|
|
|
47
47
|
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
48
48
|
}
|
|
49
49
|
function useRipple(t0, t1, t2) {
|
|
50
|
-
const $ = c(
|
|
50
|
+
const $ = c(52);
|
|
51
51
|
const enabled = t0 === void 0 ? true : t0;
|
|
52
52
|
let t3;
|
|
53
53
|
if ($[0] !== t1) {
|
|
@@ -64,6 +64,7 @@ function useRipple(t0, t1, t2) {
|
|
|
64
64
|
const rippleStartEvent = useRef(void 0);
|
|
65
65
|
const initialSize = useRef(0);
|
|
66
66
|
const rippleScale = useRef("1");
|
|
67
|
+
const removeDocumentListeners = useRef(void 0);
|
|
67
68
|
let t4;
|
|
68
69
|
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
69
70
|
t4 = (event) => {
|
|
@@ -146,6 +147,8 @@ function useRipple(t0, t1, t2) {
|
|
|
146
147
|
let t9;
|
|
147
148
|
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
148
149
|
t9 = async () => {
|
|
150
|
+
removeDocumentListeners.current?.();
|
|
151
|
+
removeDocumentListeners.current = void 0;
|
|
149
152
|
rippleStartEvent.current = void 0;
|
|
150
153
|
state.current = RippleState.Inactive;
|
|
151
154
|
const animation = growAnimation.current;
|
|
@@ -165,230 +168,264 @@ function useRipple(t0, t1, t2) {
|
|
|
165
168
|
const endPressAnimation = t9;
|
|
166
169
|
let t10;
|
|
167
170
|
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
168
|
-
t10 = () =>
|
|
171
|
+
t10 = (host, pointerId) => {
|
|
172
|
+
removeDocumentListeners.current?.();
|
|
173
|
+
const document = host.ownerDocument;
|
|
174
|
+
const handleEnd = (event_1) => {
|
|
175
|
+
if (event_1.pointerId !== pointerId || event_1.composedPath().includes(host)) return;
|
|
176
|
+
endPressAnimation();
|
|
177
|
+
};
|
|
178
|
+
document.addEventListener("pointercancel", handleEnd, true);
|
|
179
|
+
document.addEventListener("pointerup", handleEnd, true);
|
|
180
|
+
removeDocumentListeners.current = () => {
|
|
181
|
+
document.removeEventListener("pointercancel", handleEnd, true);
|
|
182
|
+
document.removeEventListener("pointerup", handleEnd, true);
|
|
183
|
+
};
|
|
184
|
+
};
|
|
169
185
|
$[8] = t10;
|
|
170
186
|
} else t10 = $[8];
|
|
171
|
-
const
|
|
187
|
+
const listenBeyondHost = t10;
|
|
172
188
|
let t11;
|
|
189
|
+
let t12;
|
|
173
190
|
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
|
174
|
-
t11 =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
t11 = () => () => {
|
|
192
|
+
removeDocumentListeners.current?.();
|
|
193
|
+
};
|
|
194
|
+
t12 = [];
|
|
195
|
+
$[9] = t11;
|
|
196
|
+
$[10] = t12;
|
|
197
|
+
} else {
|
|
198
|
+
t11 = $[9];
|
|
199
|
+
t12 = $[10];
|
|
200
|
+
}
|
|
201
|
+
useEffect(t11, t12);
|
|
202
|
+
let t13;
|
|
203
|
+
if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
|
|
204
|
+
t13 = () => state.current;
|
|
205
|
+
$[11] = t13;
|
|
206
|
+
} else t13 = $[11];
|
|
207
|
+
const getState = t13;
|
|
208
|
+
let t14;
|
|
209
|
+
if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
|
|
210
|
+
t14 = async (event_2) => {
|
|
211
|
+
if (!shouldReactToEvent(event_2)) return;
|
|
212
|
+
rippleStartEvent.current = event_2;
|
|
213
|
+
const target_0 = event_2.currentTarget;
|
|
214
|
+
listenBeyondHost(target_0, event_2.pointerId);
|
|
215
|
+
if (!isTouch(event_2)) {
|
|
179
216
|
state.current = RippleState.WaitingForClick;
|
|
180
|
-
startPressAnimation(target_0,
|
|
217
|
+
startPressAnimation(target_0, event_2);
|
|
181
218
|
return;
|
|
182
219
|
}
|
|
183
220
|
state.current = RippleState.TouchDelay;
|
|
184
221
|
await new Promise(_temp);
|
|
185
222
|
if (getState() !== RippleState.TouchDelay) return;
|
|
186
223
|
state.current = RippleState.Holding;
|
|
187
|
-
startPressAnimation(target_0,
|
|
224
|
+
startPressAnimation(target_0, event_2);
|
|
188
225
|
};
|
|
189
|
-
$[
|
|
190
|
-
} else
|
|
191
|
-
const handlePointerDownAsync =
|
|
192
|
-
let
|
|
193
|
-
if ($[
|
|
194
|
-
|
|
195
|
-
handlePointerDownAsync(
|
|
226
|
+
$[12] = t14;
|
|
227
|
+
} else t14 = $[12];
|
|
228
|
+
const handlePointerDownAsync = t14;
|
|
229
|
+
let t15;
|
|
230
|
+
if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
|
|
231
|
+
t15 = (event_3) => {
|
|
232
|
+
handlePointerDownAsync(event_3);
|
|
196
233
|
};
|
|
197
|
-
$[
|
|
198
|
-
} else
|
|
199
|
-
const handlePointerDown =
|
|
200
|
-
let
|
|
201
|
-
if ($[
|
|
202
|
-
|
|
203
|
-
if (endsOnRelease && !isTouch(
|
|
204
|
-
if (isPressPointer(
|
|
234
|
+
$[13] = t15;
|
|
235
|
+
} else t15 = $[13];
|
|
236
|
+
const handlePointerDown = t15;
|
|
237
|
+
let t16;
|
|
238
|
+
if ($[14] !== endsOnRelease) {
|
|
239
|
+
t16 = (event_4) => {
|
|
240
|
+
if (endsOnRelease && !isTouch(event_4)) {
|
|
241
|
+
if (isPressPointer(event_4) && state.current === RippleState.WaitingForClick) endPressAnimation();
|
|
205
242
|
return;
|
|
206
243
|
}
|
|
207
|
-
if (!shouldReactToEvent(
|
|
244
|
+
if (!shouldReactToEvent(event_4)) return;
|
|
208
245
|
if (state.current === RippleState.Holding) state.current = RippleState.WaitingForClick;
|
|
209
246
|
else if (state.current === RippleState.TouchDelay) {
|
|
210
247
|
state.current = RippleState.WaitingForClick;
|
|
211
|
-
startPressAnimation(
|
|
248
|
+
startPressAnimation(event_4.currentTarget, rippleStartEvent.current);
|
|
212
249
|
}
|
|
213
250
|
if (endsOnRelease && state.current === RippleState.WaitingForClick) endPressAnimation();
|
|
214
251
|
};
|
|
215
|
-
$[
|
|
216
|
-
$[
|
|
217
|
-
} else
|
|
218
|
-
const handlePointerUp =
|
|
219
|
-
let
|
|
220
|
-
if ($[
|
|
221
|
-
|
|
222
|
-
if (isTouch(
|
|
252
|
+
$[14] = endsOnRelease;
|
|
253
|
+
$[15] = t16;
|
|
254
|
+
} else t16 = $[15];
|
|
255
|
+
const handlePointerUp = t16;
|
|
256
|
+
let t17;
|
|
257
|
+
if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
|
|
258
|
+
t17 = (event_5) => {
|
|
259
|
+
if (isTouch(event_5) || !shouldReactToEvent(event_5)) return;
|
|
223
260
|
if (state.current !== RippleState.Inactive) endPressAnimation();
|
|
224
261
|
};
|
|
225
|
-
$[
|
|
226
|
-
} else
|
|
227
|
-
const handlePointerLeave =
|
|
228
|
-
let
|
|
229
|
-
if ($[
|
|
230
|
-
|
|
231
|
-
if (!shouldReactToEvent(
|
|
262
|
+
$[16] = t17;
|
|
263
|
+
} else t17 = $[16];
|
|
264
|
+
const handlePointerLeave = t17;
|
|
265
|
+
let t18;
|
|
266
|
+
if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
|
|
267
|
+
t18 = (event_6) => {
|
|
268
|
+
if (!shouldReactToEvent(event_6)) return;
|
|
232
269
|
endPressAnimation();
|
|
233
270
|
};
|
|
234
|
-
$[
|
|
235
|
-
} else
|
|
236
|
-
const handlePointerCancel =
|
|
237
|
-
let
|
|
238
|
-
if ($[
|
|
239
|
-
|
|
271
|
+
$[17] = t18;
|
|
272
|
+
} else t18 = $[17];
|
|
273
|
+
const handlePointerCancel = t18;
|
|
274
|
+
let t19;
|
|
275
|
+
if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
|
|
276
|
+
t19 = (event_7) => {
|
|
240
277
|
if (state.current === RippleState.WaitingForClick) {
|
|
241
278
|
endPressAnimation();
|
|
242
279
|
return;
|
|
243
280
|
}
|
|
244
281
|
if (state.current === RippleState.Inactive) {
|
|
245
|
-
startPressAnimation(
|
|
282
|
+
startPressAnimation(event_7.currentTarget);
|
|
246
283
|
endPressAnimation();
|
|
247
284
|
}
|
|
248
285
|
};
|
|
249
|
-
$[
|
|
250
|
-
} else
|
|
251
|
-
const handleClick =
|
|
252
|
-
let
|
|
253
|
-
if ($[
|
|
254
|
-
|
|
286
|
+
$[18] = t19;
|
|
287
|
+
} else t19 = $[18];
|
|
288
|
+
const handleClick = t19;
|
|
289
|
+
let t20;
|
|
290
|
+
if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
|
|
291
|
+
t20 = () => {
|
|
255
292
|
endPressAnimation();
|
|
256
293
|
};
|
|
257
|
-
$[
|
|
258
|
-
} else
|
|
259
|
-
const handleContextMenu =
|
|
294
|
+
$[19] = t20;
|
|
295
|
+
} else t20 = $[19];
|
|
296
|
+
const handleContextMenu = t20;
|
|
260
297
|
const { onClick: onClickProp, onContextMenu: onContextMenuProp, onPointerCancel: onPointerCancelProp, onPointerDown: onPointerDownProp, onPointerLeave: onPointerLeaveProp, onPointerUp: onPointerUpProp } = externalHandlers;
|
|
261
|
-
let t18;
|
|
262
|
-
if ($[17] !== onClickProp) {
|
|
263
|
-
t18 = (event_7) => {
|
|
264
|
-
handleClick(event_7);
|
|
265
|
-
onClickProp?.(event_7);
|
|
266
|
-
};
|
|
267
|
-
$[17] = onClickProp;
|
|
268
|
-
$[18] = t18;
|
|
269
|
-
} else t18 = $[18];
|
|
270
|
-
const onClick = t18;
|
|
271
|
-
let t19;
|
|
272
|
-
if ($[19] !== onContextMenuProp) {
|
|
273
|
-
t19 = (event_8) => {
|
|
274
|
-
handleContextMenu();
|
|
275
|
-
onContextMenuProp?.(event_8);
|
|
276
|
-
};
|
|
277
|
-
$[19] = onContextMenuProp;
|
|
278
|
-
$[20] = t19;
|
|
279
|
-
} else t19 = $[20];
|
|
280
|
-
const onContextMenu = t19;
|
|
281
|
-
let t20;
|
|
282
|
-
if ($[21] !== onPointerCancelProp) {
|
|
283
|
-
t20 = (event_9) => {
|
|
284
|
-
handlePointerCancel(event_9);
|
|
285
|
-
onPointerCancelProp?.(event_9);
|
|
286
|
-
};
|
|
287
|
-
$[21] = onPointerCancelProp;
|
|
288
|
-
$[22] = t20;
|
|
289
|
-
} else t20 = $[22];
|
|
290
|
-
const onPointerCancel = t20;
|
|
291
298
|
let t21;
|
|
292
|
-
if ($[
|
|
293
|
-
t21 = (
|
|
294
|
-
|
|
295
|
-
|
|
299
|
+
if ($[20] !== onClickProp) {
|
|
300
|
+
t21 = (event_8) => {
|
|
301
|
+
handleClick(event_8);
|
|
302
|
+
onClickProp?.(event_8);
|
|
296
303
|
};
|
|
297
|
-
$[
|
|
298
|
-
$[
|
|
299
|
-
} else t21 = $[
|
|
300
|
-
const
|
|
304
|
+
$[20] = onClickProp;
|
|
305
|
+
$[21] = t21;
|
|
306
|
+
} else t21 = $[21];
|
|
307
|
+
const onClick = t21;
|
|
301
308
|
let t22;
|
|
302
|
-
if ($[
|
|
303
|
-
t22 = (
|
|
304
|
-
|
|
305
|
-
|
|
309
|
+
if ($[22] !== onContextMenuProp) {
|
|
310
|
+
t22 = (event_9) => {
|
|
311
|
+
handleContextMenu();
|
|
312
|
+
onContextMenuProp?.(event_9);
|
|
306
313
|
};
|
|
307
|
-
$[
|
|
308
|
-
$[
|
|
309
|
-
} else t22 = $[
|
|
310
|
-
const
|
|
314
|
+
$[22] = onContextMenuProp;
|
|
315
|
+
$[23] = t22;
|
|
316
|
+
} else t22 = $[23];
|
|
317
|
+
const onContextMenu = t22;
|
|
311
318
|
let t23;
|
|
312
|
-
if ($[
|
|
313
|
-
t23 = (
|
|
314
|
-
|
|
315
|
-
|
|
319
|
+
if ($[24] !== onPointerCancelProp) {
|
|
320
|
+
t23 = (event_10) => {
|
|
321
|
+
handlePointerCancel(event_10);
|
|
322
|
+
onPointerCancelProp?.(event_10);
|
|
316
323
|
};
|
|
317
|
-
$[
|
|
318
|
-
$[
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const onPointerUp = t23;
|
|
324
|
+
$[24] = onPointerCancelProp;
|
|
325
|
+
$[25] = t23;
|
|
326
|
+
} else t23 = $[25];
|
|
327
|
+
const onPointerCancel = t23;
|
|
322
328
|
let t24;
|
|
323
|
-
if ($[
|
|
324
|
-
t24 = {
|
|
329
|
+
if ($[26] !== onPointerDownProp) {
|
|
330
|
+
t24 = (event_11) => {
|
|
331
|
+
handlePointerDown(event_11);
|
|
332
|
+
onPointerDownProp?.(event_11);
|
|
333
|
+
};
|
|
334
|
+
$[26] = onPointerDownProp;
|
|
335
|
+
$[27] = t24;
|
|
336
|
+
} else t24 = $[27];
|
|
337
|
+
const onPointerDown = t24;
|
|
338
|
+
let t25;
|
|
339
|
+
if ($[28] !== onPointerLeaveProp) {
|
|
340
|
+
t25 = (event_12) => {
|
|
341
|
+
handlePointerLeave(event_12);
|
|
342
|
+
onPointerLeaveProp?.(event_12);
|
|
343
|
+
};
|
|
344
|
+
$[28] = onPointerLeaveProp;
|
|
345
|
+
$[29] = t25;
|
|
346
|
+
} else t25 = $[29];
|
|
347
|
+
const onPointerLeave = t25;
|
|
348
|
+
let t26;
|
|
349
|
+
if ($[30] !== handlePointerUp || $[31] !== onPointerUpProp) {
|
|
350
|
+
t26 = (event_13) => {
|
|
351
|
+
handlePointerUp(event_13);
|
|
352
|
+
onPointerUpProp?.(event_13);
|
|
353
|
+
};
|
|
354
|
+
$[30] = handlePointerUp;
|
|
355
|
+
$[31] = onPointerUpProp;
|
|
356
|
+
$[32] = t26;
|
|
357
|
+
} else t26 = $[32];
|
|
358
|
+
const onPointerUp = t26;
|
|
359
|
+
let t27;
|
|
360
|
+
if ($[33] !== onContextMenu || $[34] !== onPointerCancel || $[35] !== onPointerDown || $[36] !== onPointerLeave || $[37] !== onPointerUp) {
|
|
361
|
+
t27 = {
|
|
325
362
|
onContextMenu,
|
|
326
363
|
onPointerCancel,
|
|
327
364
|
onPointerDown,
|
|
328
365
|
onPointerLeave,
|
|
329
366
|
onPointerUp
|
|
330
367
|
};
|
|
331
|
-
$[
|
|
332
|
-
$[
|
|
333
|
-
$[
|
|
334
|
-
$[
|
|
335
|
-
$[
|
|
336
|
-
$[
|
|
337
|
-
} else
|
|
338
|
-
const pointer =
|
|
339
|
-
let
|
|
340
|
-
if ($[
|
|
341
|
-
|
|
368
|
+
$[33] = onContextMenu;
|
|
369
|
+
$[34] = onPointerCancel;
|
|
370
|
+
$[35] = onPointerDown;
|
|
371
|
+
$[36] = onPointerLeave;
|
|
372
|
+
$[37] = onPointerUp;
|
|
373
|
+
$[38] = t27;
|
|
374
|
+
} else t27 = $[38];
|
|
375
|
+
const pointer = t27;
|
|
376
|
+
let t28;
|
|
377
|
+
if ($[39] !== endsOnRelease || $[40] !== onClick || $[41] !== pointer) {
|
|
378
|
+
t28 = endsOnRelease ? pointer : {
|
|
342
379
|
onClick,
|
|
343
380
|
...pointer
|
|
344
381
|
};
|
|
345
|
-
$[
|
|
346
|
-
$[
|
|
347
|
-
$[
|
|
348
|
-
$[
|
|
349
|
-
} else
|
|
350
|
-
const handlers =
|
|
351
|
-
let
|
|
352
|
-
if ($[
|
|
353
|
-
|
|
354
|
-
$[
|
|
355
|
-
$[
|
|
356
|
-
} else
|
|
357
|
-
let
|
|
358
|
-
if ($[
|
|
359
|
-
|
|
382
|
+
$[39] = endsOnRelease;
|
|
383
|
+
$[40] = onClick;
|
|
384
|
+
$[41] = pointer;
|
|
385
|
+
$[42] = t28;
|
|
386
|
+
} else t28 = $[42];
|
|
387
|
+
const handlers = t28;
|
|
388
|
+
let t29;
|
|
389
|
+
if ($[43] !== pressed) {
|
|
390
|
+
t29 = props(styles.press, pressed && styles.pressed);
|
|
391
|
+
$[43] = pressed;
|
|
392
|
+
$[44] = t29;
|
|
393
|
+
} else t29 = $[44];
|
|
394
|
+
let t30;
|
|
395
|
+
if ($[45] !== t29) {
|
|
396
|
+
t30 = /* @__PURE__ */ jsx("span", {
|
|
360
397
|
"aria-hidden": "true",
|
|
361
398
|
...surfaceProps,
|
|
362
399
|
children: /* @__PURE__ */ jsx("span", {
|
|
363
400
|
ref: rippleRef,
|
|
364
|
-
...
|
|
401
|
+
...t29
|
|
365
402
|
})
|
|
366
403
|
});
|
|
367
|
-
$[
|
|
368
|
-
$[
|
|
369
|
-
} else
|
|
370
|
-
const surface =
|
|
371
|
-
let
|
|
372
|
-
if ($[
|
|
373
|
-
|
|
404
|
+
$[45] = t29;
|
|
405
|
+
$[46] = t30;
|
|
406
|
+
} else t30 = $[46];
|
|
407
|
+
const surface = t30;
|
|
408
|
+
let t31;
|
|
409
|
+
if ($[47] !== handlers || $[48] !== surface) {
|
|
410
|
+
t31 = {
|
|
374
411
|
handlers,
|
|
375
412
|
surface
|
|
376
413
|
};
|
|
377
|
-
$[
|
|
378
|
-
$[
|
|
379
|
-
$[
|
|
380
|
-
} else
|
|
381
|
-
const enabledResult =
|
|
382
|
-
let
|
|
383
|
-
if ($[
|
|
384
|
-
|
|
414
|
+
$[47] = handlers;
|
|
415
|
+
$[48] = surface;
|
|
416
|
+
$[49] = t31;
|
|
417
|
+
} else t31 = $[49];
|
|
418
|
+
const enabledResult = t31;
|
|
419
|
+
let t32;
|
|
420
|
+
if ($[50] !== externalHandlers) {
|
|
421
|
+
t32 = {
|
|
385
422
|
handlers: externalHandlers,
|
|
386
423
|
surface: null
|
|
387
424
|
};
|
|
388
|
-
$[
|
|
389
|
-
$[
|
|
390
|
-
} else
|
|
391
|
-
return enabled ? enabledResult :
|
|
425
|
+
$[50] = externalHandlers;
|
|
426
|
+
$[51] = t32;
|
|
427
|
+
} else t32 = $[51];
|
|
428
|
+
return enabled ? enabledResult : t32;
|
|
392
429
|
}
|
|
393
430
|
function _temp(resolve_0) {
|
|
394
431
|
setTimeout(resolve_0, motionDurationMs.short2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRipple.js","names":["MouseEvent","MouseEventHandler","PointerEvent","PointerEventHandler","ReactNode","stylex","useCallback","useMemo","useRef","useState","rippleStyles","motionDurationMs","motionEasing","spacingPx","PADDING","sm","INITIAL_ORIGIN_SCALE","SOFT_EDGE_MINIMUM_SIZE","SOFT_EDGE_CONTAINER_RATIO","surfaceProps","props","surface","RippleState","Holding","Inactive","TouchDelay","WaitingForClick","const","ReleaseHandlers","Element","Omit","RippleEventHandlers","HostElement","onClick","onContextMenu","onPointerCancel","onPointerDown","onPointerLeave","onPointerUp","isTouch","event","pointerType","prefersReducedMotion","window","matchMedia","matches","useRipple","enabled","externalHandlers","endsOnRelease","handlers","t0","t1","t2","$","_c","undefined","t3","pressed","setPressed","rippleRef","state","growAnimation","rippleStartEvent","initialSize","rippleScale","t4","Symbol","for","isPrimary","startEvent","current","pointerId","isPressPointer","t5","event_0","buttons","shouldReactToEvent","t6","rect","height","width","maxDimension","Math","max","softEdgeSize","size","floor","hypotenuse","hypot","maxRadius","determineRippleSize","t7","rect_0","positionEvent","height_0","left","top","width_0","size_0","endPoint","x","y","origin","clientX","clientY","startPoint","getTranslationCoordinates","t8","target","positionEvent_0","ripple","cancel","rect_1","getBoundingClientRect","size_1","endPoint_0","startPoint_0","style","animate","transform","duration","long1","easing","standard","fill","startPressAnimation","t9","animation","elapsed","currentTime","Infinity","medium1","Promise","resolve","setTimeout","endPressAnimation","t10","getState","t11","event_1","target_0","currentTarget","_temp","handlePointerDownAsync","t12","event_2","handlePointerDown","t13","event_3","handlePointerUp","t14","event_4","handlePointerLeave","t15","event_5","handlePointerCancel","t16","event_6","handleClick","t17","handleContextMenu","onClickProp","onContextMenuProp","onPointerCancelProp","onPointerDownProp","onPointerLeaveProp","onPointerUpProp","t18","event_7","t19","event_8","t20","event_9","t21","event_10","t22","event_11","t23","event_12","t24","pointer","t25","t26","press","t27","t28","enabledResult","t29","disabledResult","resolve_0","short2","stylex.props","rippleStyles","_c","disabledResult"],"sources":["../../src/hooks/useRipple.tsx"],"sourcesContent":["import type { MouseEvent, MouseEventHandler, PointerEvent, PointerEventHandler, ReactNode } from 'react';\nimport * as stylex from '@stylexjs/stylex';\nimport { useCallback, useMemo, useRef, useState } from 'react';\nimport { rippleStyles } from '../styles/ripple';\nimport { motionDurationMs, motionEasing, spacingPx } from '../tokens/values';\n\n// Every timing this file drives is a motion token, spent at the point of use\n// below. They come from tokens/values rather than the StyleX theme because\n// element.animate() and setTimeout both reject a token's var() form, and the\n// same is true of the one geometry token: `PADDING` is added to a radius, and\n// a var() would concatenate rather than add. See src/styles/ripple.ts for the\n// opacity half of the mechanism, whose three timings are deliberately not\n// tokens.\n\n/** How far the ripple grows past the host's corners. `spacing.sm`. */\nconst PADDING = spacingPx.sm;\n\n// The rest are ratios and a pixel floor that no token group covers — spacing\n// is layout rhythm, and nothing in the set holds bare geometric ratios.\nconst INITIAL_ORIGIN_SCALE = 0.2;\nconst SOFT_EDGE_MINIMUM_SIZE = 75;\nconst SOFT_EDGE_CONTAINER_RATIO = 0.35;\n\n// Static input, so this is computed once for every consumer of the module\n// rather than once per component instance.\nconst surfaceProps = stylex.props(rippleStyles.surface);\n\n/**\n * On touch: `Inactive -> TouchDelay -> WaitingForClick -> Inactive`, or\n * `Inactive -> TouchDelay -> Holding -> WaitingForClick -> Inactive` for a\n * held press.\n *\n * On mouse or pen: `Inactive -> WaitingForClick -> Inactive`.\n */\nconst RippleState = {\n /** A touch has been confirmed as a press (held past the touch delay). */\n Holding: 2,\n /** No press in progress. Touch down moves to TouchDelay; mouse/pen down moves to WaitingForClick. */\n Inactive: 0,\n /** Touch down received; waiting to see if it's a tap or a scroll/swipe. */\n TouchDelay: 1,\n /** The press has finished growing; waiting for the click that ends it. */\n WaitingForClick: 3\n} as const;\ntype ReleaseHandlers<HostElement extends Element> = Omit<RippleEventHandlers<HostElement>, 'onClick'>;\ninterface RippleEventHandlers<HostElement extends Element> {\n onClick?: MouseEventHandler<HostElement>;\n onContextMenu?: MouseEventHandler<HostElement>;\n onPointerCancel?: PointerEventHandler<HostElement>;\n onPointerDown?: PointerEventHandler<HostElement>;\n onPointerLeave?: PointerEventHandler<HostElement>;\n onPointerUp?: PointerEventHandler<HostElement>;\n}\ntype RippleState = (typeof RippleState)[keyof typeof RippleState];\nfunction isTouch(event: PointerEvent) {\n return event.pointerType === 'touch';\n}\n\n/**\n * Whether the reader has asked the OS for less motion.\n *\n * Growth is a Web Animations call, which makes it the one animation in the\n * library no `@media (prefers-reduced-motion: reduce)` branch can reach — see\n * src/styles/ripple.ts for the opacity half, which is CSS and carries one.\n *\n * Read at the press rather than once at mount, so a reader who changes the\n * setting is answered by their next press rather than by their next reload.\n * The press already reads layout through `getBoundingClientRect`, which costs\n * more than this does.\n */\nfunction prefersReducedMotion() {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n/**\n * Renders a press ripple that grows from the pointer's position, or from\n * the element's center for a keyboard or other non-pointer activation.\n *\n * Growth runs via the Web Animations API on a single reused element (no\n * per-click DOM nodes to clean up), over a fixed duration independent of how\n * long the element is held — a real press-and-hold keeps the ripple\n * growing until release, while a quick tap is still held visible for a\n * minimum duration so it plays a complete animation rather than a flicker.\n *\n * Merges its own handlers with `externalHandlers` (e.g. a component's own\n * consumer-supplied props — ripple's own run first, then the external\n * ones) and returns `handlers` to spread onto the interactive element and\n * `surface`, the node to render as a child. The host element must\n * establish a positioning context (`position: relative` or similar) so\n * `surface`, which fills it via `inset: 0`, clips to its bounds and\n * inherits its shape.\n *\n * Pass `enabled: false` to opt out — no ripple listeners are attached and\n * no surface is rendered, leaving `externalHandlers` and a component's own\n * hover/press state layer (if any) untouched.\n *\n * Pass `endsOnRelease` for a host that never hears its own click: a\n * collection row, whose clicks React Aria's press handling keeps for itself.\n * The press then ends when the pointer is released over the host rather than\n * on the click that would follow, still held for the minimum a short press\n * gets. A keyboard press reaches such a host as no pointer event at all, so\n * it draws no ripple there.\n *\n * `handlers` and `surface` are hand-memoized (not left to build-tool\n * optimization) so a consumer rendering many instances — a list of icon\n * buttons, say — can memoize around them too, and so stability doesn't\n * depend on any particular compiler being configured.\n */\n// A host ending on the release never hears a click, so nothing is taken for\n// one and none is handed back: the handlers are the pointer ones alone, which\n// is also what a collection row's type admits.\nfunction useRipple<HostElement extends Element = Element>(enabled: boolean, externalHandlers: ReleaseHandlers<HostElement>, endsOnRelease: true): {\n handlers: ReleaseHandlers<HostElement>;\n surface: ReactNode;\n};\nfunction useRipple<HostElement extends Element = Element>(enabled?: boolean, externalHandlers?: RippleEventHandlers<HostElement>, endsOnRelease?: false): {\n handlers: RippleEventHandlers<HostElement>;\n surface: ReactNode;\n};\nfunction useRipple<HostElement extends Element = Element>(enabled = true, externalHandlers: RippleEventHandlers<HostElement> = {}, endsOnRelease = false): {\n handlers: RippleEventHandlers<HostElement>;\n surface: ReactNode;\n} {\n const [pressed, setPressed] = useState(false);\n const rippleRef = useRef<HTMLSpanElement>(null);\n const state = useRef<RippleState>(RippleState.Inactive);\n const growAnimation = useRef<Animation | undefined>(undefined);\n const rippleStartEvent = useRef<PointerEvent<HostElement> | undefined>(undefined);\n const initialSize = useRef(0);\n const rippleScale = useRef('1');\n\n // Whether `event` comes from the pointer a press would follow: the primary\n // one, and the one that started the press already in flight, if any.\n const isPressPointer = useCallback((event: PointerEvent<HostElement>) => {\n if (!event.isPrimary) {\n return false;\n }\n const startEvent = rippleStartEvent.current;\n return !startEvent || startEvent.pointerId === event.pointerId;\n }, []);\n const shouldReactToEvent = useCallback((event: PointerEvent<HostElement>) => isPressPointer(event) && (isTouch(event) || event.buttons === 1), [isPressPointer]);\n const determineRippleSize = useCallback((rect: DOMRect) => {\n const {\n height,\n width\n } = rect;\n const maxDimension = Math.max(height, width);\n const softEdgeSize = Math.max(SOFT_EDGE_CONTAINER_RATIO * maxDimension, SOFT_EDGE_MINIMUM_SIZE);\n const size = Math.floor(maxDimension * INITIAL_ORIGIN_SCALE);\n const hypotenuse = Math.hypot(width, height);\n const maxRadius = hypotenuse + PADDING;\n initialSize.current = size;\n rippleScale.current = `${(maxRadius + softEdgeSize) / size}`;\n return `${size}px`;\n }, []);\n const getTranslationCoordinates = useCallback((rect: DOMRect, positionEvent?: PointerEvent<HostElement>) => {\n const {\n height,\n left,\n top,\n width\n } = rect;\n const size = initialSize.current;\n const endPoint = {\n x: (width - size) / 2,\n y: (height - size) / 2\n };\n const origin = positionEvent ? {\n x: positionEvent.clientX - left,\n y: positionEvent.clientY - top\n } : {\n x: width / 2,\n y: height / 2\n };\n const startPoint = {\n x: origin.x - size / 2,\n y: origin.y - size / 2\n };\n return {\n endPoint,\n startPoint\n };\n }, []);\n const startPressAnimation = useCallback((target: HostElement, positionEvent?: PointerEvent<HostElement>) => {\n const ripple = rippleRef.current;\n if (!ripple) {\n return;\n }\n setPressed(true);\n growAnimation.current?.cancel();\n\n // Read once and share: the two helpers below both only need the\n // target's rect, and a second `getBoundingClientRect()` call back to\n // back with the first would be a redundant layout read.\n const rect = target.getBoundingClientRect();\n const size = determineRippleSize(rect);\n const {\n endPoint,\n startPoint\n } = getTranslationCoordinates(rect, positionEvent);\n ripple.style.width = size;\n ripple.style.height = size;\n growAnimation.current = ripple.animate({\n transform: [`translate(${startPoint.x}px, ${startPoint.y}px) scale(1)`, `translate(${endPoint.x}px, ${endPoint.y}px) scale(${rippleScale.current})`]\n }, {\n // Growth runs over a fixed duration regardless of how long the\n // press is held, so the token is spent here rather than named as a\n // constant — element.animate() is one of the two places a StyleX\n // token could not have gone.\n //\n // Zeroed rather than skipped under reduced motion, which lands the\n // disc at its full size with the growth never drawn. Skipping the\n // call outright would leave `growAnimation` unset, and the release\n // below reads its `currentTime` to decide whether the press has\n // been visible long enough — so the press would still be shown, and\n // would stop being held for its minimum.\n duration: prefersReducedMotion() ? 0 : motionDurationMs.long1,\n easing: motionEasing.standard,\n fill: 'forwards'\n });\n }, [determineRippleSize, getTranslationCoordinates]);\n const endPressAnimation = useCallback(async () => {\n rippleStartEvent.current = undefined;\n state.current = RippleState.Inactive;\n const animation = growAnimation.current;\n const elapsed = typeof animation?.currentTime === 'number' ? animation.currentTime : Infinity;\n\n // The floor on how briefly a ripple may be visible, so a quick tap reads\n // as a deliberate ripple rather than a flicker.\n if (elapsed >= motionDurationMs.medium1) {\n setPressed(false);\n return;\n }\n await new Promise(resolve => {\n setTimeout(resolve, motionDurationMs.medium1 - elapsed);\n });\n if (growAnimation.current !== animation) {\n // A newer press started; let it own the pressed state instead.\n return;\n }\n setPressed(false);\n }, []);\n\n // Reads through a function so a stale narrowing of `state.current` from\n // before the `await` below isn't (incorrectly) carried across it — the\n // ref can change via a different handler while this one is suspended.\n const getState = useCallback(() => state.current, []);\n const handlePointerDownAsync = useCallback(async (event: PointerEvent<HostElement>) => {\n if (!shouldReactToEvent(event)) {\n return;\n }\n rippleStartEvent.current = event;\n const target = event.currentTarget;\n if (!isTouch(event)) {\n state.current = RippleState.WaitingForClick;\n startPressAnimation(target, event);\n return;\n }\n\n // Delay so a scroll/swipe starting on the element doesn't flash a\n // ripple — only a held (or quickly released) touch counts as a press.\n state.current = RippleState.TouchDelay;\n await new Promise(resolve => {\n setTimeout(resolve, motionDurationMs.short2);\n });\n if (getState() !== RippleState.TouchDelay) {\n return;\n }\n state.current = RippleState.Holding;\n startPressAnimation(target, event);\n }, [getState, shouldReactToEvent, startPressAnimation]);\n const handlePointerDown = useCallback((event: PointerEvent<HostElement>) => {\n void handlePointerDownAsync(event);\n }, [handlePointerDownAsync]);\n const handlePointerUp = useCallback((event: PointerEvent<HostElement>) => {\n // A mouse or pen release carries no pressed button, so the guard the\n // other handlers share turns it away, which is right while a click\n // follows to end the press. A host ending on the release matches it by\n // its pointer alone.\n if (endsOnRelease && !isTouch(event)) {\n if (isPressPointer(event) && state.current === RippleState.WaitingForClick) {\n void endPressAnimation();\n }\n return;\n }\n if (!shouldReactToEvent(event)) {\n return;\n }\n if (state.current === RippleState.Holding) {\n state.current = RippleState.WaitingForClick;\n } else if (state.current === RippleState.TouchDelay) {\n // Released before the delay elapsed: treat as a completed tap.\n state.current = RippleState.WaitingForClick;\n startPressAnimation(event.currentTarget, rippleStartEvent.current);\n }\n\n // The release is as far as such a host hears, so it is where the\n // press ends — see `endsOnRelease` above.\n if (endsOnRelease && state.current === RippleState.WaitingForClick) {\n void endPressAnimation();\n }\n }, [endPressAnimation, endsOnRelease, isPressPointer, shouldReactToEvent, startPressAnimation]);\n const handlePointerLeave = useCallback((event: PointerEvent<HostElement>) => {\n if (isTouch(event) || !shouldReactToEvent(event)) {\n return;\n }\n if (state.current !== RippleState.Inactive) {\n void endPressAnimation();\n }\n }, [endPressAnimation, shouldReactToEvent]);\n const handlePointerCancel = useCallback((event: PointerEvent<HostElement>) => {\n if (!shouldReactToEvent(event)) {\n return;\n }\n void endPressAnimation();\n }, [endPressAnimation, shouldReactToEvent]);\n const handleClick = useCallback((event: MouseEvent<HostElement>) => {\n if (state.current === RippleState.WaitingForClick) {\n void endPressAnimation();\n return;\n }\n if (state.current === RippleState.Inactive) {\n // No pointerdown preceded this click — keyboard activation, a\n // programmatic `.click()`, or assistive-tech-synthesized activation.\n // Play a complete, centered press immediately.\n startPressAnimation(event.currentTarget);\n void endPressAnimation();\n }\n }, [endPressAnimation, startPressAnimation]);\n const handleContextMenu = useCallback(() => {\n void endPressAnimation();\n }, [endPressAnimation]);\n const {\n onClick: onClickProp,\n onContextMenu: onContextMenuProp,\n onPointerCancel: onPointerCancelProp,\n onPointerDown: onPointerDownProp,\n onPointerLeave: onPointerLeaveProp,\n onPointerUp: onPointerUpProp\n } = externalHandlers;\n const onClick = useCallback((event: MouseEvent<HostElement>) => {\n handleClick(event);\n onClickProp?.(event);\n }, [handleClick, onClickProp]);\n const onContextMenu = useCallback((event: MouseEvent<HostElement>) => {\n handleContextMenu();\n onContextMenuProp?.(event);\n }, [handleContextMenu, onContextMenuProp]);\n const onPointerCancel = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerCancel(event);\n onPointerCancelProp?.(event);\n }, [handlePointerCancel, onPointerCancelProp]);\n const onPointerDown = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerDown(event);\n onPointerDownProp?.(event);\n }, [handlePointerDown, onPointerDownProp]);\n const onPointerLeave = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerLeave(event);\n onPointerLeaveProp?.(event);\n }, [handlePointerLeave, onPointerLeaveProp]);\n const onPointerUp = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerUp(event);\n onPointerUpProp?.(event);\n }, [handlePointerUp, onPointerUpProp]);\n const handlers = useMemo(() => {\n const pointer = {\n onContextMenu,\n onPointerCancel,\n onPointerDown,\n onPointerLeave,\n onPointerUp\n };\n return endsOnRelease ? pointer : {\n onClick,\n ...pointer\n };\n }, [endsOnRelease, onClick, onContextMenu, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp]);\n const surface = useMemo(() => <span aria-hidden=\"true\" {...surfaceProps}>\n <span ref={rippleRef} {...stylex.props(rippleStyles.press, pressed && rippleStyles.pressed)} />\n </span>, [pressed]);\n\n // Two separate memos rather than one branching on `enabled`, so that\n // whichever branch is actually active stays keyed only on its own\n // inputs — the enabled result doesn't get a new identity every time\n // `externalHandlers` does (a component typically passes a fresh object\n // literal each render), and vice versa.\n const enabledResult = useMemo(() => ({\n handlers,\n surface\n }), [handlers, surface]);\n const disabledResult = useMemo(() => ({\n handlers: externalHandlers,\n surface: null\n }), [externalHandlers]);\n return enabled ? enabledResult : disabledResult;\n}\nexport { useRipple };"],"mappings":";;;;;;;;AAeA,MAAMc,UAAUD,UAAUE;AAI1B,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAIlC,MAAMC,eAAed,MAAaK,OAAaW,OAAO;;;;;;;;AAStD,MAAMC,cAAc;;CAElBC,SAAS;;CAETC,UAAU;;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;CAXH,MAAAJ,WAQEoI;CAIuG,IAAAC;CAAA,IAAAjI,EAAA,QAAAI,SAAA;EAEzE6H,MAAAlL,MAAaK,OAAY8K,OAAQ9H,WAAWhD,OAAYgD,OAAQ;EAACJ,EAAA,MAAAI;EAAAJ,EAAA,MAAAiI;CAAA,OAAAA,MAAAjI,EAAA;CAAA,IAAAmI;CAAA,IAAAnI,EAAA,QAAAiI,KAAA;EADnEE,MAAA,oBAAA,QAAA;GAAkB,eAAA;GAAM,GAAKtK;GACrD,UAAA,oBAAA,QAAA;IAAWyC,KAAAA;IAAS,GAAM2H;GAAiE,CAAA;EACtF,CAAA;EAAAjI,EAAA,MAAAiI;EAAAjI,EAAA,MAAAmI;CAAA,OAAAA,MAAAnI,EAAA;CAFX,MAAAjC,UAA8BoK;CAEN,IAAAC;CAAA,IAAApI,EAAA,QAAAJ,YAAAI,EAAA,QAAAjC,SAAA;EAOaqK,MAAA;GAAAxI;GAAA7B;EAGrC;EAACiC,EAAA,MAAAJ;EAAAI,EAAA,MAAAjC;EAAAiC,EAAA,MAAAoI;CAAA,OAAAA,MAAApI,EAAA;CAHD,MAAAqI,gBAAqCD;CAGZ,IAAAE;CAAA,IAAAtI,EAAA,QAAAN,kBAAA;EACa4I,MAAA;GAAA1I,UAC1BF;GAAgB3B,SACjB;EACX;EAACiC,EAAA,MAAAN;EAAAM,EAAA,MAAAsI;CAAA,OAAAA,MAAAtI,EAAA;CAAuB,OACjBP,UAAA4I,gBAAAE;AAAwC;AAnRjD,SAAA9C,MAAA+C,WAAA;CAgJMvD,WAAWD,WAAS3H,iBAAgBoL,MAAO;AAAC"}
|
|
1
|
+
{"version":3,"file":"useRipple.js","names":["MouseEvent","MouseEventHandler","PointerEvent","PointerEventHandler","ReactNode","stylex","useCallback","useEffect","useMemo","useRef","useState","rippleStyles","motionDurationMs","motionEasing","spacingPx","PADDING","sm","INITIAL_ORIGIN_SCALE","SOFT_EDGE_MINIMUM_SIZE","SOFT_EDGE_CONTAINER_RATIO","surfaceProps","props","surface","RippleState","Holding","Inactive","TouchDelay","WaitingForClick","const","ReleaseHandlers","Element","Omit","RippleEventHandlers","HostElement","onClick","onContextMenu","onPointerCancel","onPointerDown","onPointerLeave","onPointerUp","isTouch","event","pointerType","prefersReducedMotion","window","matchMedia","matches","useRipple","enabled","externalHandlers","endsOnRelease","handlers","t0","t1","t2","$","_c","undefined","t3","pressed","setPressed","rippleRef","state","growAnimation","rippleStartEvent","initialSize","rippleScale","removeDocumentListeners","t4","Symbol","for","isPrimary","startEvent","current","pointerId","isPressPointer","t5","event_0","buttons","shouldReactToEvent","t6","rect","height","width","maxDimension","Math","max","softEdgeSize","size","floor","hypotenuse","hypot","maxRadius","determineRippleSize","t7","rect_0","positionEvent","height_0","left","top","width_0","size_0","endPoint","x","y","origin","clientX","clientY","startPoint","getTranslationCoordinates","t8","target","positionEvent_0","ripple","cancel","rect_1","getBoundingClientRect","size_1","endPoint_0","startPoint_0","style","animate","transform","duration","long1","easing","standard","fill","startPressAnimation","t9","animation","elapsed","currentTime","Infinity","medium1","Promise","resolve","setTimeout","endPressAnimation","t10","host","document","ownerDocument","handleEnd","event_1","composedPath","includes","addEventListener","removeEventListener","listenBeyondHost","t11","t12","t13","getState","t14","event_2","target_0","currentTarget","_temp","handlePointerDownAsync","t15","event_3","handlePointerDown","t16","event_4","handlePointerUp","t17","event_5","handlePointerLeave","t18","event_6","handlePointerCancel","t19","event_7","handleClick","t20","handleContextMenu","onClickProp","onContextMenuProp","onPointerCancelProp","onPointerDownProp","onPointerLeaveProp","onPointerUpProp","t21","event_8","t22","event_9","t23","event_10","t24","event_11","t25","event_12","t26","event_13","t27","pointer","t28","t29","press","t30","t31","enabledResult","t32","disabledResult","resolve_0","short2","stylex.props","rippleStyles","_c","disabledResult"],"sources":["../../src/hooks/useRipple.tsx"],"sourcesContent":["import type { MouseEvent, MouseEventHandler, PointerEvent, PointerEventHandler, ReactNode } from 'react';\nimport * as stylex from '@stylexjs/stylex';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { rippleStyles } from '../styles/ripple';\nimport { motionDurationMs, motionEasing, spacingPx } from '../tokens/values';\n\n// Every timing this file drives is a motion token, spent at the point of use\n// below. They come from tokens/values rather than the StyleX theme because\n// element.animate() and setTimeout both reject a token's var() form, and the\n// same is true of the one geometry token: `PADDING` is added to a radius, and\n// a var() would concatenate rather than add. See src/styles/ripple.ts for the\n// opacity half of the mechanism, whose three timings are deliberately not\n// tokens.\n\n/** How far the ripple grows past the host's corners. `spacing.sm`. */\nconst PADDING = spacingPx.sm;\n\n// The rest are ratios and a pixel floor that no token group covers — spacing\n// is layout rhythm, and nothing in the set holds bare geometric ratios.\nconst INITIAL_ORIGIN_SCALE = 0.2;\nconst SOFT_EDGE_MINIMUM_SIZE = 75;\nconst SOFT_EDGE_CONTAINER_RATIO = 0.35;\n\n// Static input, so this is computed once for every consumer of the module\n// rather than once per component instance.\nconst surfaceProps = stylex.props(rippleStyles.surface);\n\n/**\n * On touch: `Inactive -> TouchDelay -> WaitingForClick -> Inactive`, or\n * `Inactive -> TouchDelay -> Holding -> WaitingForClick -> Inactive` for a\n * held press.\n *\n * On mouse or pen: `Inactive -> WaitingForClick -> Inactive`.\n */\nconst RippleState = {\n /** A touch has been confirmed as a press (held past the touch delay). */\n Holding: 2,\n /** No press in progress. Touch down moves to TouchDelay; mouse/pen down moves to WaitingForClick. */\n Inactive: 0,\n /** Touch down received; waiting to see if it's a tap or a scroll/swipe. */\n TouchDelay: 1,\n /** The press has finished growing; waiting for the click that ends it. */\n WaitingForClick: 3\n} as const;\ntype ReleaseHandlers<HostElement extends Element> = Omit<RippleEventHandlers<HostElement>, 'onClick'>;\ninterface RippleEventHandlers<HostElement extends Element> {\n onClick?: MouseEventHandler<HostElement>;\n onContextMenu?: MouseEventHandler<HostElement>;\n onPointerCancel?: PointerEventHandler<HostElement>;\n onPointerDown?: PointerEventHandler<HostElement>;\n onPointerLeave?: PointerEventHandler<HostElement>;\n onPointerUp?: PointerEventHandler<HostElement>;\n}\ntype RippleState = (typeof RippleState)[keyof typeof RippleState];\nfunction isTouch(event: PointerEvent) {\n return event.pointerType === 'touch';\n}\n\n/**\n * Whether the reader has asked the OS for less motion.\n *\n * Growth is a Web Animations call, which makes it the one animation in the\n * library no `@media (prefers-reduced-motion: reduce)` branch can reach — see\n * src/styles/ripple.ts for the opacity half, which is CSS and carries one.\n *\n * Read at the press rather than once at mount, so a reader who changes the\n * setting is answered by their next press rather than by their next reload.\n * The press already reads layout through `getBoundingClientRect`, which costs\n * more than this does.\n */\nfunction prefersReducedMotion() {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n/**\n * Renders a press ripple that grows from the pointer's position, or from\n * the element's center for a keyboard or other non-pointer activation.\n *\n * Growth runs via the Web Animations API on a single reused element (no\n * per-click DOM nodes to clean up), over a fixed duration independent of how\n * long the element is held — a real press-and-hold keeps the ripple\n * growing until release, while a quick tap is still held visible for a\n * minimum duration so it plays a complete animation rather than a flicker.\n *\n * Merges its own handlers with `externalHandlers` (e.g. a component's own\n * consumer-supplied props — ripple's own run first, then the external\n * ones) and returns `handlers` to spread onto the interactive element and\n * `surface`, the node to render as a child. The host element must\n * establish a positioning context (`position: relative` or similar) so\n * `surface`, which fills it via `inset: 0`, clips to its bounds and\n * inherits its shape.\n *\n * Pass `enabled: false` to opt out — no ripple listeners are attached and\n * no surface is rendered, leaving `externalHandlers` and a component's own\n * hover/press state layer (if any) untouched.\n *\n * Pass `endsOnRelease` for a host that never hears its own click: a\n * collection row, whose clicks React Aria's press handling keeps for itself.\n * The press then ends when the pointer is released over the host rather than\n * on the click that would follow, still held for the minimum a short press\n * gets. A keyboard press reaches such a host as no pointer event at all, so\n * it draws no ripple there.\n *\n * `handlers` and `surface` are hand-memoized (not left to build-tool\n * optimization) so a consumer rendering many instances — a list of icon\n * buttons, say — can memoize around them too, and so stability doesn't\n * depend on any particular compiler being configured.\n */\n// A host ending on the release never hears a click, so nothing is taken for\n// one and none is handed back: the handlers are the pointer ones alone, which\n// is also what a collection row's type admits.\nfunction useRipple<HostElement extends Element = Element>(enabled: boolean, externalHandlers: ReleaseHandlers<HostElement>, endsOnRelease: true): {\n handlers: ReleaseHandlers<HostElement>;\n surface: ReactNode;\n};\nfunction useRipple<HostElement extends Element = Element>(enabled?: boolean, externalHandlers?: RippleEventHandlers<HostElement>, endsOnRelease?: false): {\n handlers: RippleEventHandlers<HostElement>;\n surface: ReactNode;\n};\nfunction useRipple<HostElement extends Element = Element>(enabled = true, externalHandlers: RippleEventHandlers<HostElement> = {}, endsOnRelease = false): {\n handlers: RippleEventHandlers<HostElement>;\n surface: ReactNode;\n} {\n const [pressed, setPressed] = useState(false);\n const rippleRef = useRef<HTMLSpanElement>(null);\n const state = useRef<RippleState>(RippleState.Inactive);\n const growAnimation = useRef<Animation | undefined>(undefined);\n const rippleStartEvent = useRef<PointerEvent<HostElement> | undefined>(undefined);\n const initialSize = useRef(0);\n const rippleScale = useRef('1');\n // Removes the listeners a press keeps on its host's document, while one is\n // in flight — see `listenBeyondHost`.\n const removeDocumentListeners = useRef<(() => void) | undefined>(undefined);\n\n // Whether `event` comes from the pointer a press would follow: the primary\n // one, and the one that started the press already in flight, if any.\n const isPressPointer = useCallback((event: PointerEvent<HostElement>) => {\n if (!event.isPrimary) {\n return false;\n }\n const startEvent = rippleStartEvent.current;\n return !startEvent || startEvent.pointerId === event.pointerId;\n }, []);\n const shouldReactToEvent = useCallback((event: PointerEvent<HostElement>) => isPressPointer(event) && (isTouch(event) || event.buttons === 1), [isPressPointer]);\n const determineRippleSize = useCallback((rect: DOMRect) => {\n const {\n height,\n width\n } = rect;\n const maxDimension = Math.max(height, width);\n const softEdgeSize = Math.max(SOFT_EDGE_CONTAINER_RATIO * maxDimension, SOFT_EDGE_MINIMUM_SIZE);\n const size = Math.floor(maxDimension * INITIAL_ORIGIN_SCALE);\n const hypotenuse = Math.hypot(width, height);\n const maxRadius = hypotenuse + PADDING;\n initialSize.current = size;\n rippleScale.current = `${(maxRadius + softEdgeSize) / size}`;\n return `${size}px`;\n }, []);\n const getTranslationCoordinates = useCallback((rect: DOMRect, positionEvent?: PointerEvent<HostElement>) => {\n const {\n height,\n left,\n top,\n width\n } = rect;\n const size = initialSize.current;\n const endPoint = {\n x: (width - size) / 2,\n y: (height - size) / 2\n };\n const origin = positionEvent ? {\n x: positionEvent.clientX - left,\n y: positionEvent.clientY - top\n } : {\n x: width / 2,\n y: height / 2\n };\n const startPoint = {\n x: origin.x - size / 2,\n y: origin.y - size / 2\n };\n return {\n endPoint,\n startPoint\n };\n }, []);\n const startPressAnimation = useCallback((target: HostElement, positionEvent?: PointerEvent<HostElement>) => {\n const ripple = rippleRef.current;\n if (!ripple) {\n return;\n }\n setPressed(true);\n growAnimation.current?.cancel();\n\n // Read once and share: the two helpers below both only need the\n // target's rect, and a second `getBoundingClientRect()` call back to\n // back with the first would be a redundant layout read.\n const rect = target.getBoundingClientRect();\n const size = determineRippleSize(rect);\n const {\n endPoint,\n startPoint\n } = getTranslationCoordinates(rect, positionEvent);\n ripple.style.width = size;\n ripple.style.height = size;\n growAnimation.current = ripple.animate({\n transform: [`translate(${startPoint.x}px, ${startPoint.y}px) scale(1)`, `translate(${endPoint.x}px, ${endPoint.y}px) scale(${rippleScale.current})`]\n }, {\n // Growth runs over a fixed duration regardless of how long the\n // press is held, so the token is spent here rather than named as a\n // constant — element.animate() is one of the two places a StyleX\n // token could not have gone.\n //\n // Zeroed rather than skipped under reduced motion, which lands the\n // disc at its full size with the growth never drawn. Skipping the\n // call outright would leave `growAnimation` unset, and the release\n // below reads its `currentTime` to decide whether the press has\n // been visible long enough — so the press would still be shown, and\n // would stop being held for its minimum.\n duration: prefersReducedMotion() ? 0 : motionDurationMs.long1,\n easing: motionEasing.standard,\n fill: 'forwards'\n });\n }, [determineRippleSize, getTranslationCoordinates]);\n const endPressAnimation = useCallback(async () => {\n removeDocumentListeners.current?.();\n removeDocumentListeners.current = undefined;\n rippleStartEvent.current = undefined;\n state.current = RippleState.Inactive;\n const animation = growAnimation.current;\n const elapsed = typeof animation?.currentTime === 'number' ? animation.currentTime : Infinity;\n\n // The floor on how briefly a ripple may be visible, so a quick tap reads\n // as a deliberate ripple rather than a flicker.\n if (elapsed >= motionDurationMs.medium1) {\n setPressed(false);\n return;\n }\n await new Promise(resolve => {\n setTimeout(resolve, motionDurationMs.medium1 - elapsed);\n });\n if (growAnimation.current !== animation) {\n // A newer press started; let it own the pressed state instead.\n return;\n }\n setPressed(false);\n }, []);\n\n // A press can end somewhere other than its host. React Aria's press\n // handling releases the capture a touch takes on its pointerdown, so that a\n // finger can leave the element, and a press that turns into a scroll — or\n // a finger that slides off and lifts — then ends with a pointercancel or\n // pointerup on whatever is under it, which the host never hears. Left to\n // the host's handlers alone, the ripple held at its pressed opacity until\n // the next press on that host finished a cycle.\n //\n // So the press listens on its host's document, in the capture phase, for\n // its own pointer, the way React Aria's own press handling does. An end the\n // host does hear is left to the host's handlers, which run after these.\n const listenBeyondHost = useCallback((host: HostElement, pointerId: number) => {\n removeDocumentListeners.current?.();\n const document = host.ownerDocument;\n const handleEnd = (event: globalThis.PointerEvent) => {\n if (event.pointerId !== pointerId || event.composedPath().includes(host)) {\n return;\n }\n void endPressAnimation();\n };\n document.addEventListener('pointercancel', handleEnd, true);\n document.addEventListener('pointerup', handleEnd, true);\n removeDocumentListeners.current = () => {\n document.removeEventListener('pointercancel', handleEnd, true);\n document.removeEventListener('pointerup', handleEnd, true);\n };\n }, [endPressAnimation]);\n\n // A host unmounted mid-press leaves nothing listening behind it.\n useEffect(() => () => {\n removeDocumentListeners.current?.();\n }, []);\n\n // Reads through a function so a stale narrowing of `state.current` from\n // before the `await` below isn't (incorrectly) carried across it — the\n // ref can change via a different handler while this one is suspended.\n const getState = useCallback(() => state.current, []);\n const handlePointerDownAsync = useCallback(async (event: PointerEvent<HostElement>) => {\n if (!shouldReactToEvent(event)) {\n return;\n }\n rippleStartEvent.current = event;\n const target = event.currentTarget;\n listenBeyondHost(target, event.pointerId);\n if (!isTouch(event)) {\n state.current = RippleState.WaitingForClick;\n startPressAnimation(target, event);\n return;\n }\n\n // Delay so a scroll/swipe starting on the element doesn't flash a\n // ripple — only a held (or quickly released) touch counts as a press.\n state.current = RippleState.TouchDelay;\n await new Promise(resolve => {\n setTimeout(resolve, motionDurationMs.short2);\n });\n if (getState() !== RippleState.TouchDelay) {\n return;\n }\n state.current = RippleState.Holding;\n startPressAnimation(target, event);\n }, [getState, listenBeyondHost, shouldReactToEvent, startPressAnimation]);\n const handlePointerDown = useCallback((event: PointerEvent<HostElement>) => {\n void handlePointerDownAsync(event);\n }, [handlePointerDownAsync]);\n const handlePointerUp = useCallback((event: PointerEvent<HostElement>) => {\n // A mouse or pen release carries no pressed button, so the guard the\n // other handlers share turns it away, which is right while a click\n // follows to end the press. A host ending on the release matches it by\n // its pointer alone.\n if (endsOnRelease && !isTouch(event)) {\n if (isPressPointer(event) && state.current === RippleState.WaitingForClick) {\n void endPressAnimation();\n }\n return;\n }\n if (!shouldReactToEvent(event)) {\n return;\n }\n if (state.current === RippleState.Holding) {\n state.current = RippleState.WaitingForClick;\n } else if (state.current === RippleState.TouchDelay) {\n // Released before the delay elapsed: treat as a completed tap.\n state.current = RippleState.WaitingForClick;\n startPressAnimation(event.currentTarget, rippleStartEvent.current);\n }\n\n // The release is as far as such a host hears, so it is where the\n // press ends — see `endsOnRelease` above.\n if (endsOnRelease && state.current === RippleState.WaitingForClick) {\n void endPressAnimation();\n }\n }, [endPressAnimation, endsOnRelease, isPressPointer, shouldReactToEvent, startPressAnimation]);\n const handlePointerLeave = useCallback((event: PointerEvent<HostElement>) => {\n if (isTouch(event) || !shouldReactToEvent(event)) {\n return;\n }\n if (state.current !== RippleState.Inactive) {\n void endPressAnimation();\n }\n }, [endPressAnimation, shouldReactToEvent]);\n const handlePointerCancel = useCallback((event: PointerEvent<HostElement>) => {\n if (!shouldReactToEvent(event)) {\n return;\n }\n void endPressAnimation();\n }, [endPressAnimation, shouldReactToEvent]);\n const handleClick = useCallback((event: MouseEvent<HostElement>) => {\n if (state.current === RippleState.WaitingForClick) {\n void endPressAnimation();\n return;\n }\n if (state.current === RippleState.Inactive) {\n // No pointerdown preceded this click — keyboard activation, a\n // programmatic `.click()`, or assistive-tech-synthesized activation.\n // Play a complete, centered press immediately.\n startPressAnimation(event.currentTarget);\n void endPressAnimation();\n }\n }, [endPressAnimation, startPressAnimation]);\n const handleContextMenu = useCallback(() => {\n void endPressAnimation();\n }, [endPressAnimation]);\n const {\n onClick: onClickProp,\n onContextMenu: onContextMenuProp,\n onPointerCancel: onPointerCancelProp,\n onPointerDown: onPointerDownProp,\n onPointerLeave: onPointerLeaveProp,\n onPointerUp: onPointerUpProp\n } = externalHandlers;\n const onClick = useCallback((event: MouseEvent<HostElement>) => {\n handleClick(event);\n onClickProp?.(event);\n }, [handleClick, onClickProp]);\n const onContextMenu = useCallback((event: MouseEvent<HostElement>) => {\n handleContextMenu();\n onContextMenuProp?.(event);\n }, [handleContextMenu, onContextMenuProp]);\n const onPointerCancel = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerCancel(event);\n onPointerCancelProp?.(event);\n }, [handlePointerCancel, onPointerCancelProp]);\n const onPointerDown = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerDown(event);\n onPointerDownProp?.(event);\n }, [handlePointerDown, onPointerDownProp]);\n const onPointerLeave = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerLeave(event);\n onPointerLeaveProp?.(event);\n }, [handlePointerLeave, onPointerLeaveProp]);\n const onPointerUp = useCallback((event: PointerEvent<HostElement>) => {\n handlePointerUp(event);\n onPointerUpProp?.(event);\n }, [handlePointerUp, onPointerUpProp]);\n const handlers = useMemo(() => {\n const pointer = {\n onContextMenu,\n onPointerCancel,\n onPointerDown,\n onPointerLeave,\n onPointerUp\n };\n return endsOnRelease ? pointer : {\n onClick,\n ...pointer\n };\n }, [endsOnRelease, onClick, onContextMenu, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp]);\n const surface = useMemo(() => <span aria-hidden=\"true\" {...surfaceProps}>\n <span ref={rippleRef} {...stylex.props(rippleStyles.press, pressed && rippleStyles.pressed)} />\n </span>, [pressed]);\n\n // Two separate memos rather than one branching on `enabled`, so that\n // whichever branch is actually active stays keyed only on its own\n // inputs — the enabled result doesn't get a new identity every time\n // `externalHandlers` does (a component typically passes a fresh object\n // literal each render), and vice versa.\n const enabledResult = useMemo(() => ({\n handlers,\n surface\n }), [handlers, surface]);\n const disabledResult = useMemo(() => ({\n handlers: externalHandlers,\n surface: null\n }), [externalHandlers]);\n return enabled ? enabledResult : disabledResult;\n}\nexport { useRipple };"],"mappings":";;;;;;;;AAeA,MAAMe,UAAUD,UAAUE;AAI1B,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAIlC,MAAMC,eAAef,MAAaM,OAAaW,OAAO;;;;;;;;AAStD,MAAMC,cAAc;;CAElBC,SAAS;;CAETC,UAAU;;CAEVC,YAAY;;CAEZC,iBAAiB;AACnB;AAWA,SAASa,QAAQC,OAAqB;CACpC,OAAOA,MAAMC,gBAAgB;AAC/B;;;;;;;;;;;;;AAcA,SAASC,uBAAuB;CAC9B,OAAOC,OAAOC,WAAW,kCAAkC,CAAC,CAACC;AAC/D;AA+CA,SAAAC,UAAAK,IAAAC,IAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA0D,MAAAR,UAAAI,OAAAK,KAAAA,IAAA,OAAAL;CAAc,IAAAM;CAAA,IAAAH,EAAA,OAAAF,IAAA;EAAEK,KAAAL,OAAAI,KAAAA,IAAA,CAAsD,IAAtDJ;EAAuDE,EAAA,KAAAF;EAAAE,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAvD,MAAAN,mBAAAS;CAAyD,MAAAR,gBAAAI,OAAAG,KAAAA,IAAA,QAAAH;CAIjI,MAAA,CAAAK,SAAAC,cAA8BlD,SAAS,KAAK;CAC5C,MAAAmD,YA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;EAACiC,EAAA,MAAAN;EAAAM,EAAA,MAAAoJ;CAAA,OAAAA,MAAApJ,EAAA;CAAuB,OACjBP,UAAA0J,gBAAAE;AAAwC;AA1TjD,SAAA9C,MAAA+C,WAAA;CAuLMpE,WAAWD,WAAS5H,iBAAgBkM,MAAO;AAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ToggleGroupStateContext } from "react-aria-components";
|
|
3
|
+
//#region src/hooks/useToggleGroupDisabled.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether the React Aria `ToggleButtonGroup` around a toggle disables it.
|
|
6
|
+
*
|
|
7
|
+
* The group does that through its own state rather than through the toggle's
|
|
8
|
+
* props, so it reaches the toggle's render state and nothing earlier. A
|
|
9
|
+
* ripple has to know earlier than that, since its handlers go on the element
|
|
10
|
+
* outside the render function, and this is where it reads the group.
|
|
11
|
+
*
|
|
12
|
+
* Only a toggle with an `id` belongs to the group: React Aria leaves one
|
|
13
|
+
* without an `id` to keep its own state, enabled whatever the group says.
|
|
14
|
+
* This follows the same rule, so a toggle the group does not disable keeps
|
|
15
|
+
* its ripple.
|
|
16
|
+
*/
|
|
17
|
+
function useToggleGroupDisabled(id) {
|
|
18
|
+
const group = useContext(ToggleGroupStateContext);
|
|
19
|
+
return group !== null && id !== void 0 && group.isDisabled;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { useToggleGroupDisabled };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=useToggleGroupDisabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToggleGroupDisabled.js","names":["Key","useContext","ToggleGroupStateContext","useToggleGroupDisabled","id","group","undefined","isDisabled"],"sources":["../../src/hooks/useToggleGroupDisabled.ts"],"sourcesContent":["import type { Key } from 'react-aria-components'\n\nimport { useContext } from 'react'\nimport { ToggleGroupStateContext } from 'react-aria-components'\n\n/**\n * Whether the React Aria `ToggleButtonGroup` around a toggle disables it.\n *\n * The group does that through its own state rather than through the toggle's\n * props, so it reaches the toggle's render state and nothing earlier. A\n * ripple has to know earlier than that, since its handlers go on the element\n * outside the render function, and this is where it reads the group.\n *\n * Only a toggle with an `id` belongs to the group: React Aria leaves one\n * without an `id` to keep its own state, enabled whatever the group says.\n * This follows the same rule, so a toggle the group does not disable keeps\n * its ripple.\n */\nfunction useToggleGroupDisabled(id: Key | undefined): boolean {\n const group = useContext(ToggleGroupStateContext)\n return group !== null && id !== undefined && group.isDisabled\n}\n\nexport { useToggleGroupDisabled }\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAAG,uBAAAC,IAAA;CACE,MAAAC,QAAcJ,WAAWC,uBAAuB;CAAC,OAC1CG,UAAU,QAAQD,OAAOE,KAAAA,KAAaD,MAAKE;AAAW"}
|