@tamagui/dismissable 2.7.6 → 3.0.0-beta.637.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cjs/Dismissable.cjs +282 -330
  2. package/dist/cjs/Dismissable.native.cjs +61 -0
  3. package/dist/cjs/Dismissable.native.js +33 -37
  4. package/dist/cjs/Dismissable.native.js.map +1 -1
  5. package/dist/cjs/DismissableProps.cjs +10 -11
  6. package/dist/cjs/DismissableProps.native.cjs +19 -0
  7. package/dist/cjs/DismissableProps.native.js +10 -10
  8. package/dist/cjs/DismissableProps.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +10 -11
  10. package/dist/cjs/index.native.cjs +21 -0
  11. package/dist/cjs/index.native.js +10 -10
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/esm/Dismissable.mjs +261 -301
  14. package/dist/esm/Dismissable.mjs.map +1 -1
  15. package/dist/esm/Dismissable.native.js +12 -9
  16. package/dist/esm/Dismissable.native.js.map +1 -1
  17. package/dist/esm/DismissableProps.mjs +0 -2
  18. package/dist/esm/DismissableProps.native.js +0 -2
  19. package/dist/esm/index.js +1 -2
  20. package/dist/esm/index.mjs +1 -2
  21. package/dist/esm/index.native.js +1 -2
  22. package/dist/jsx/Dismissable.mjs +261 -301
  23. package/dist/jsx/Dismissable.mjs.map +1 -1
  24. package/dist/jsx/Dismissable.native.cjs +61 -0
  25. package/dist/jsx/Dismissable.native.js +33 -37
  26. package/dist/jsx/Dismissable.native.js.map +1 -1
  27. package/dist/jsx/DismissableProps.mjs +0 -2
  28. package/dist/jsx/DismissableProps.native.cjs +19 -0
  29. package/dist/jsx/DismissableProps.native.js +10 -10
  30. package/dist/jsx/DismissableProps.native.js.map +1 -1
  31. package/dist/jsx/index.js +1 -2
  32. package/dist/jsx/index.mjs +1 -2
  33. package/dist/jsx/index.native.cjs +21 -0
  34. package/dist/jsx/index.native.js +10 -10
  35. package/dist/jsx/index.native.js.map +1 -1
  36. package/package.json +7 -7
  37. package/src/Dismissable.native.tsx +3 -2
  38. package/src/Dismissable.tsx +90 -92
  39. package/src/DismissableProps.tsx +31 -10
  40. package/types/Dismissable.d.ts +3 -9
  41. package/types/Dismissable.d.ts.map +1 -1
  42. package/types/Dismissable.native.d.ts +2 -2
  43. package/types/Dismissable.native.d.ts.map +1 -1
  44. package/types/DismissableProps.d.ts +22 -10
  45. package/types/DismissableProps.d.ts.map +1 -1
  46. package/dist/esm/DismissableProps.mjs.map +0 -1
  47. package/dist/esm/DismissableProps.native.js.map +0 -1
  48. package/dist/esm/index.js.map +0 -1
  49. package/dist/esm/index.mjs.map +0 -1
  50. package/dist/esm/index.native.js.map +0 -1
  51. package/dist/jsx/DismissableProps.mjs.map +0 -1
  52. package/dist/jsx/index.js.map +0 -1
  53. package/dist/jsx/index.mjs.map +0 -1
@@ -2,7 +2,14 @@
2
2
  // https://github.com/radix-ui/primitives/blob/cfd8dcba5fa6a0e751486af418d05a7b88a7f541/packages/react/dismissable-layer/src/DismissableLayer.tsx#L324
3
3
 
4
4
  import { useComposedRefs } from '@tamagui/compose-refs'
5
- import { Slot, TamaguiElement, View, composeEventHandlers } from '@tamagui/core'
5
+ import {
6
+ Slot,
7
+ TamaguiElement,
8
+ View,
9
+ composeEventHandlers,
10
+ createChangeEventDetails,
11
+ createRefComponent,
12
+ } from '@tamagui/core'
6
13
  import { useEscapeKeydown } from '@tamagui/use-escape-keydown'
7
14
  import { useEvent } from '@tamagui/use-event'
8
15
  import * as React from 'react'
@@ -23,8 +30,6 @@ export function dispatchDiscreteCustomEvent<E extends CustomEvent>(
23
30
 
24
31
  const DISMISSABLE_LAYER_NAME = 'Dismissable'
25
32
  const CONTEXT_UPDATE = 'dismissable.update'
26
- const POINTER_DOWN_OUTSIDE = 'dismissable.pointerDownOutside'
27
- const FOCUS_OUTSIDE = 'dismissable.focusOutside'
28
33
 
29
34
  let originalBodyPointerEvents: string
30
35
 
@@ -148,7 +153,7 @@ export function useDismissableLayersAbove(ref: React.RefObject<HTMLElement | nul
148
153
  return count
149
154
  }
150
155
 
151
- const Dismissable = React.forwardRef<
156
+ const Dismissable = createRefComponent<
152
157
  HTMLElement,
153
158
  DismissableProps & { asChild?: boolean }
154
159
  >((props, forwardedRef) => {
@@ -193,9 +198,12 @@ const Dismissable = React.forwardRef<
193
198
  const branches = branchesProp || context.branches
194
199
  const isPointerDownOnBranch = [...branches].some((branch) => branch.contains(target))
195
200
  if (!isPointerEventsEnabled || isPointerDownOnBranch) return
196
- onPointerDownOutside?.(event)
197
- onInteractOutside?.(event)
198
- if (!event.defaultPrevented) onDismiss?.()
201
+ const details = createChangeEventDetails('outside-press', event, event.target, {
202
+ interaction: 'pointer' as const,
203
+ })
204
+ onPointerDownOutside?.(details)
205
+ onInteractOutside?.(details)
206
+ if (!details.isCanceled) onDismiss?.(details)
199
207
  })
200
208
 
201
209
  const focusOutside = useFocusOutside((event) => {
@@ -204,9 +212,16 @@ const Dismissable = React.forwardRef<
204
212
  const branches = branchesProp || context.branches
205
213
  const isFocusInBranch = [...branches].some((branch) => branch.contains(target))
206
214
  if (isFocusInBranch) return
207
- onFocusOutside?.(event)
208
- onInteractOutside?.(event)
209
- if (!event.defaultPrevented) onDismiss?.()
215
+ // browser focus fixup can move focus to an ancestor of this layer (e.g. the
216
+ // native <dialog> element when its inner active element blurs). an ancestor
217
+ // gaining focus is not the user focusing elsewhere — never dismiss for it
218
+ if (node && target.contains(node)) return
219
+ const details = createChangeEventDetails('focus-out', event, event.target, {
220
+ interaction: 'focus' as const,
221
+ })
222
+ onFocusOutside?.(details)
223
+ onInteractOutside?.(details)
224
+ if (!details.isCanceled) onDismiss?.(details)
210
225
  })
211
226
 
212
227
  // track forceUnmount in a ref so escape handler can check it
@@ -216,6 +231,10 @@ const Dismissable = React.forwardRef<
216
231
  }, [forceUnmount])
217
232
 
218
233
  useEscapeKeydown((event) => {
234
+ // a higher layer may have consumed this same document event and removed
235
+ // itself before this listener runs. don't let the newly-highest layer also
236
+ // dismiss from a single escape press.
237
+ if (event.defaultPrevented) return
219
238
  // skip if this layer is force-unmounted (e.g. dialog closed but still mounted)
220
239
  if (forceUnmountRef.current) return
221
240
  // Check layers at callback time, not render time, to avoid stale closures
@@ -223,68 +242,71 @@ const Dismissable = React.forwardRef<
223
242
  const currentIndex = node ? currentLayers.indexOf(node) : -1
224
243
  const isHighestLayer = currentIndex === currentLayers.length - 1
225
244
  if (!isHighestLayer) return
226
- onEscapeKeyDown?.(event)
227
- if (!event.defaultPrevented && onDismiss) {
245
+ const details = createChangeEventDetails('escape-key', event, event.target)
246
+ onEscapeKeyDown?.(details)
247
+ if (!details.isCanceled && onDismiss) {
248
+ // consuming the escape prevents native defaults (exiting fullscreen etc),
249
+ // matching the pre-details behavior. a canceled dismiss leaves the native
250
+ // event alone; handlers that self-close call preventDefault themselves
228
251
  event.preventDefault()
229
- onDismiss()
252
+ onDismiss(details)
230
253
  }
231
254
  })
232
255
 
256
+ /**
257
+ * Creation-order layer tracking. This effect only runs on mount/unmount (and
258
+ * when the node itself changes), NOT when `disableOutsidePointerEvents`
259
+ * toggles, so a prop change can't remove a layer from the stack and re-add it
260
+ * at the end - the layering order stays _creation order_.
261
+ */
233
262
  React.useEffect(() => {
234
263
  if (!node) return
235
264
  // don't add to layers when force-unmounted (dialog closed but still mounted)
236
265
  if (forceUnmount) return
237
- if (disableOutsidePointerEvents) {
238
- if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
239
- originalBodyPointerEvents = document.body.style.pointerEvents
240
- document.body.style.pointerEvents = 'none'
241
- }
242
- context.layersWithOutsidePointerEventsDisabled.add(node)
243
- layersWithPointerEventsDisabledCount++
244
- }
245
266
  context.layers.add(node)
246
267
  globalLayers.add(node)
247
- // only dispatch position update when pointer-events tracking is active
248
- if (disableOutsidePointerEvents || layersWithPointerEventsDisabledCount > 0) {
249
- dispatchUpdate()
250
- }
268
+ dispatchUpdate()
251
269
  notifyLayerChange()
252
270
  return () => {
253
- if (disableOutsidePointerEvents) {
254
- if (context.layersWithOutsidePointerEventsDisabled.size === 1) {
255
- document.body.style.pointerEvents = originalBodyPointerEvents
256
- }
257
- // decrement AFTER dispatch so other layers still re-render
258
- }
271
+ context.layers.delete(node)
272
+ globalLayers.delete(node)
273
+ dispatchUpdate()
274
+ notifyLayerChange()
259
275
  }
260
- }, [node, disableOutsidePointerEvents, forceUnmount, context])
276
+ }, [node, forceUnmount, context])
261
277
 
262
278
  /**
263
- * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect
264
- * because a change to `disableOutsidePointerEvents` would remove this layer from the stack
265
- * and add it to the end again so the layering order wouldn't be _creation order_.
266
- * We only want them to be removed from context stacks when unmounted.
279
+ * Pointer-events tracking. This owns SYMMETRIC add/remove of the node from
280
+ * `layersWithOutsidePointerEventsDisabled`, the module count, and the body
281
+ * pointer-events style. It reruns on every `disableOutsidePointerEvents`
282
+ * transition, and the cleanup fully reverses the setup, so a true->false->true
283
+ * toggle never leaves a stale Set entry or a divergent count.
267
284
  */
268
285
  React.useEffect(() => {
286
+ if (!node) return
269
287
  if (forceUnmount) return
288
+ if (!disableOutsidePointerEvents) return
289
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
290
+ originalBodyPointerEvents = document.body.style.pointerEvents
291
+ document.body.style.pointerEvents = 'none'
292
+ }
293
+ context.layersWithOutsidePointerEventsDisabled.add(node)
294
+ layersWithPointerEventsDisabledCount++
295
+ dispatchUpdate()
296
+ notifyLayerChange()
270
297
  return () => {
271
- if (!node) return
272
- const hadPointerEventsDisabled =
273
- context.layersWithOutsidePointerEventsDisabled.has(node)
274
- context.layers.delete(node)
275
298
  context.layersWithOutsidePointerEventsDisabled.delete(node)
276
- globalLayers.delete(node)
277
- // only dispatch position update when pointer-events tracking is active
278
- if (layersWithPointerEventsDisabledCount > 0) {
279
- dispatchUpdate()
299
+ // restore the body once this was the last pointer-events-disabling layer
300
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
301
+ document.body.style.pointerEvents = originalBodyPointerEvents
280
302
  }
303
+ // dispatch while the count is still > 0 so other layers re-render, then
304
+ // decrement so they observe the settled count on their next render
305
+ dispatchUpdate()
281
306
  notifyLayerChange()
282
- // decrement count AFTER dispatch so other layers see count > 0 and re-render
283
- if (hadPointerEventsDisabled) {
284
- layersWithPointerEventsDisabledCount--
285
- }
307
+ layersWithPointerEventsDisabledCount--
286
308
  }
287
- }, [node, context, forceUnmount])
309
+ }, [node, disableOutsidePointerEvents, forceUnmount, context])
288
310
 
289
311
  React.useEffect(() => {
290
312
  const handleUpdate = () => {
@@ -339,7 +361,7 @@ Dismissable.displayName = DISMISSABLE_LAYER_NAME
339
361
 
340
362
  const BRANCH_NAME = 'DismissableBranch'
341
363
 
342
- const DismissableBranch = React.forwardRef<TamaguiElement, DismissableBranchProps>(
364
+ const DismissableBranch = createRefComponent<TamaguiElement, DismissableBranchProps>(
343
365
  (props, forwardedRef) => {
344
366
  const { branches: branchesProp, ...rest } = props
345
367
  const context = React.useContext(DismissableContext)
@@ -367,33 +389,23 @@ DismissableBranch.displayName = BRANCH_NAME
367
389
 
368
390
  /* -----------------------------------------------------------------------------------------------*/
369
391
 
370
- export type PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>
371
- export type FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>
372
-
373
392
  /**
374
393
  * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`
375
394
  * to mimic layer dismissing behaviour present in OS.
376
395
  * Returns props to pass to the node we want to check for outside events.
377
396
  */
378
- function usePointerDownOutside(
379
- onPointerDownOutside?: (event: PointerDownOutsideEvent) => void
380
- ) {
381
- const handlePointerDownOutside = useEvent(onPointerDownOutside) as EventListener
397
+ function usePointerDownOutside(onPointerDownOutside?: (event: PointerEvent) => void) {
398
+ const handlePointerDownOutside = useEvent(onPointerDownOutside)
382
399
  const isPointerInsideReactTreeRef = React.useRef(false)
383
400
  const handleClickRef = React.useRef(() => {})
384
401
 
385
402
  React.useEffect(() => {
386
403
  const handlePointerDown = (event: PointerEvent) => {
387
404
  if (event.target && !isPointerInsideReactTreeRef.current) {
388
- const eventDetail = { originalEvent: event }
389
-
390
- function handleAndDispatchPointerDownOutsideEvent() {
391
- handleAndDispatchCustomEvent(
392
- POINTER_DOWN_OUTSIDE,
393
- handlePointerDownOutside,
394
- eventDetail,
395
- { discrete: true }
396
- )
405
+ function handlePointerDownOutsideEvent() {
406
+ if (handlePointerDownOutside) {
407
+ ReactDOM.flushSync(() => handlePointerDownOutside(event))
408
+ }
397
409
  }
398
410
 
399
411
  /**
@@ -410,10 +422,10 @@ function usePointerDownOutside(
410
422
  */
411
423
  if (event.pointerType === 'touch') {
412
424
  document.removeEventListener('click', handleClickRef.current)
413
- handleClickRef.current = handleAndDispatchPointerDownOutsideEvent
425
+ handleClickRef.current = handlePointerDownOutsideEvent
414
426
  document.addEventListener('click', handleClickRef.current, { once: true })
415
427
  } else {
416
- handleAndDispatchPointerDownOutsideEvent()
428
+ handlePointerDownOutsideEvent()
417
429
  }
418
430
  }
419
431
  isPointerInsideReactTreeRef.current = false
@@ -453,17 +465,14 @@ function usePointerDownOutside(
453
465
  * Listens for when focus happens outside a react subtree.
454
466
  * Returns props to pass to the root (node) of the subtree we want to check.
455
467
  */
456
- function useFocusOutside(onFocusOutside?: (event: FocusOutsideEvent) => void) {
457
- const handleFocusOutside = useEvent(onFocusOutside) as EventListener
468
+ function useFocusOutside(onFocusOutside?: (event: FocusEvent) => void) {
469
+ const handleFocusOutside = useEvent(onFocusOutside)
458
470
  const isFocusInsideReactTreeRef = React.useRef(false)
459
471
 
460
472
  React.useEffect(() => {
461
473
  const handleFocus = (event: FocusEvent) => {
462
474
  if (event.target && !isFocusInsideReactTreeRef.current) {
463
- const eventDetail = { originalEvent: event }
464
- handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
465
- discrete: false,
466
- })
475
+ handleFocusOutside?.(event)
467
476
  }
468
477
  }
469
478
  document.addEventListener('focusin', handleFocus)
@@ -485,23 +494,12 @@ function dispatchUpdate() {
485
494
  document.dispatchEvent(event)
486
495
  }
487
496
 
488
- function handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(
489
- name: string,
490
- handler: ((event: E) => void) | undefined,
491
- detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),
492
- { discrete }: { discrete: boolean }
493
- ) {
494
- const target = detail.originalEvent.target
495
- const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail })
496
- if (handler) target.addEventListener(name, handler as EventListener, { once: true })
497
-
498
- if (discrete) {
499
- dispatchDiscreteCustomEvent(target, event)
500
- } else {
501
- target.dispatchEvent(event)
502
- }
503
- }
504
-
505
497
  export { Dismissable, DismissableBranch }
506
498
 
507
- export type { DismissableProps }
499
+ export type {
500
+ DismissableDismissDetails,
501
+ DismissableProps,
502
+ FocusOutsideDetails,
503
+ InteractOutsideDetails,
504
+ PointerDownOutsideDetails,
505
+ } from './DismissableProps'
@@ -1,6 +1,25 @@
1
1
  import type React from 'react'
2
2
 
3
- import type { FocusOutsideEvent, PointerDownOutsideEvent } from './Dismissable'
3
+ import type { TamaguiChangeEventDetails, TamaguiEventDetails } from '@tamagui/core'
4
+
5
+ export type PointerDownOutsideDetails = TamaguiChangeEventDetails<
6
+ 'outside-press',
7
+ PointerEvent,
8
+ { interaction: 'pointer' }
9
+ >
10
+
11
+ export type FocusOutsideDetails = TamaguiChangeEventDetails<
12
+ 'focus-out',
13
+ FocusEvent,
14
+ { interaction: 'focus' }
15
+ >
16
+
17
+ export type InteractOutsideDetails = PointerDownOutsideDetails | FocusOutsideDetails
18
+
19
+ export type DismissableDismissDetails =
20
+ | TamaguiEventDetails<'escape-key', React.KeyboardEvent>
21
+ | TamaguiEventDetails<'outside-press', PointerEvent, { interaction: 'pointer' }>
22
+ | TamaguiEventDetails<'focus-out', FocusEvent, { interaction: 'focus' }>
4
23
 
5
24
  export interface DismissableProps {
6
25
  /**
@@ -16,30 +35,32 @@ export interface DismissableProps {
16
35
  branches?: Set<HTMLElement>
17
36
  /**
18
37
  * Event handler called when the escape key is down.
19
- * Can be prevented.
38
+ * Can be canceled.
20
39
  */
21
- onEscapeKeyDown?: React.KeyboardEventHandler
40
+ onEscapeKeyDown?: (
41
+ details: TamaguiChangeEventDetails<'escape-key', React.KeyboardEvent>
42
+ ) => void
22
43
  /**
23
44
  * Event handler called when the a `pointerdown` event happens outside of the `Dismissable`.
24
- * Can be prevented.
45
+ * Can be canceled.
25
46
  */
26
- onPointerDownOutside?: (event: PointerDownOutsideEvent) => void
47
+ onPointerDownOutside?: (details: PointerDownOutsideDetails) => void
27
48
  /**
28
49
  * Event handler called when the focus moves outside of the `Dismissable`.
29
- * Can be prevented.
50
+ * Can be canceled.
30
51
  */
31
- onFocusOutside?: (event: FocusOutsideEvent) => void
52
+ onFocusOutside?: (details: FocusOutsideDetails) => void
32
53
  /**
33
54
  * Event handler called when an interaction happens outside the `Dismissable`.
34
55
  * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.
35
- * Can be prevented.
56
+ * Can be canceled.
36
57
  */
37
- onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void
58
+ onInteractOutside?: (details: InteractOutsideDetails) => void
38
59
 
39
60
  /**
40
61
  * Handler called when the `Dismissable` should be dismissed
41
62
  */
42
- onDismiss?: () => void
63
+ onDismiss?: (details: DismissableDismissDetails) => void
43
64
 
44
65
  /**
45
66
  * When using animations on exit, may want to simualte force unmount early
@@ -27,16 +27,10 @@ export declare function useIsInsideDismissable(ref: React.RefObject<HTMLElement
27
27
  * returns the count of layers that are ancestors of the element
28
28
  */
29
29
  export declare function useDismissableLayersAbove(ref: React.RefObject<HTMLElement | null>): number;
30
- declare const Dismissable: React.ForwardRefExoticComponent<DismissableProps & {
30
+ declare const Dismissable: import("@tamagui/compose-refs").RefComponent<HTMLElement, DismissableProps & {
31
31
  asChild?: boolean;
32
- } & React.RefAttributes<HTMLElement>>;
33
- declare const DismissableBranch: React.ForwardRefExoticComponent<DismissableBranchProps & React.RefAttributes<TamaguiElement>>;
34
- export type PointerDownOutsideEvent = CustomEvent<{
35
- originalEvent: PointerEvent;
36
- }>;
37
- export type FocusOutsideEvent = CustomEvent<{
38
- originalEvent: FocusEvent;
39
32
  }>;
33
+ declare const DismissableBranch: import("@tamagui/compose-refs").RefComponent<TamaguiElement, DismissableBranchProps>;
40
34
  export { Dismissable, DismissableBranch };
41
- export type { DismissableProps };
35
+ export type { DismissableDismissDetails, DismissableProps, FocusOutsideDetails, InteractOutsideDetails, PointerDownOutsideDetails, } from './DismissableProps';
42
36
  //# sourceMappingURL=Dismissable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dismissable.d.ts","sourceRoot":"","sources":["../src/Dismissable.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAQ,cAAc,EAA8B,MAAM,eAAe,CAAA;AAGhF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAElF,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,WAAW,EAC/D,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,EACnB,KAAK,EAAE,CAAC,QAGT;AA0BD;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,WAAW,EAAE,CAItD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAajD;AAQD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,WA0B9E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,UA0BjF;AAED,QAAA,MAAM,WAAW;cAEgB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AE,CAAA;AAEzC,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAA"}
@@ -5,6 +5,6 @@ export declare function getDismissableLayerCount(): number;
5
5
  export declare function useHasDismissableLayers(): boolean;
6
6
  export declare function useIsInsideDismissable(_ref: React.RefObject<HTMLElement | null>): boolean;
7
7
  export declare function useDismissableLayersAbove(_ref: React.RefObject<HTMLElement | null>): number;
8
- export declare const Dismissable: React.ForwardRefExoticComponent<DismissableProps & React.RefAttributes<unknown>>;
9
- export declare const DismissableBranch: React.ForwardRefExoticComponent<DismissableBranchProps & React.RefAttributes<unknown>>;
8
+ export declare const Dismissable: import("@tamagui/core").RefComponent<unknown, DismissableProps>;
9
+ export declare const DismissableBranch: import("@tamagui/core").RefComponent<unknown, DismissableBranchProps>;
10
10
  //# sourceMappingURL=Dismissable.native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dismissable.native.d.ts","sourceRoot":"","sources":["../src/Dismissable.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGlF,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,WAAW,EAC/D,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,EACpB,MAAM,EAAE,CAAC,QACP;AAEJ,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACxC,OAAO,CAET;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACxC,MAAM,CAER;AAED,eAAO,MAAM,WAAW,kFAEtB,CAAA;AAEF,eAAO,MAAM,iBAAiB,wFAI7B,CAAA"}
1
+ {"version":3,"file":"Dismissable.native.d.ts","sourceRoot":"","sources":["../src/Dismissable.native.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGlF,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,WAAW,EAC/D,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,EACpB,MAAM,EAAE,CAAC,QACP;AAEJ,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACxC,OAAO,CAET;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACxC,MAAM,CAER;AAED,eAAO,MAAM,WAAW,iEAEtB,CAAA;AAEF,eAAO,MAAM,iBAAiB,uEAI7B,CAAA"}
@@ -1,5 +1,17 @@
1
1
  import type React from 'react';
2
- import type { FocusOutsideEvent, PointerDownOutsideEvent } from './Dismissable';
2
+ import type { TamaguiChangeEventDetails, TamaguiEventDetails } from '@tamagui/core';
3
+ export type PointerDownOutsideDetails = TamaguiChangeEventDetails<'outside-press', PointerEvent, {
4
+ interaction: 'pointer';
5
+ }>;
6
+ export type FocusOutsideDetails = TamaguiChangeEventDetails<'focus-out', FocusEvent, {
7
+ interaction: 'focus';
8
+ }>;
9
+ export type InteractOutsideDetails = PointerDownOutsideDetails | FocusOutsideDetails;
10
+ export type DismissableDismissDetails = TamaguiEventDetails<'escape-key', React.KeyboardEvent> | TamaguiEventDetails<'outside-press', PointerEvent, {
11
+ interaction: 'pointer';
12
+ }> | TamaguiEventDetails<'focus-out', FocusEvent, {
13
+ interaction: 'focus';
14
+ }>;
3
15
  export interface DismissableProps {
4
16
  /**
5
17
  * When `true`, hover/focus/click interactions will be disabled on elements outside
@@ -14,29 +26,29 @@ export interface DismissableProps {
14
26
  branches?: Set<HTMLElement>;
15
27
  /**
16
28
  * Event handler called when the escape key is down.
17
- * Can be prevented.
29
+ * Can be canceled.
18
30
  */
19
- onEscapeKeyDown?: React.KeyboardEventHandler;
31
+ onEscapeKeyDown?: (details: TamaguiChangeEventDetails<'escape-key', React.KeyboardEvent>) => void;
20
32
  /**
21
33
  * Event handler called when the a `pointerdown` event happens outside of the `Dismissable`.
22
- * Can be prevented.
34
+ * Can be canceled.
23
35
  */
24
- onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
36
+ onPointerDownOutside?: (details: PointerDownOutsideDetails) => void;
25
37
  /**
26
38
  * Event handler called when the focus moves outside of the `Dismissable`.
27
- * Can be prevented.
39
+ * Can be canceled.
28
40
  */
29
- onFocusOutside?: (event: FocusOutsideEvent) => void;
41
+ onFocusOutside?: (details: FocusOutsideDetails) => void;
30
42
  /**
31
43
  * Event handler called when an interaction happens outside the `Dismissable`.
32
44
  * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.
33
- * Can be prevented.
45
+ * Can be canceled.
34
46
  */
35
- onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;
47
+ onInteractOutside?: (details: InteractOutsideDetails) => void;
36
48
  /**
37
49
  * Handler called when the `Dismissable` should be dismissed
38
50
  */
39
- onDismiss?: () => void;
51
+ onDismiss?: (details: DismissableDismissDetails) => void;
40
52
  /**
41
53
  * When using animations on exit, may want to simualte force unmount early
42
54
  */
@@ -1 +1 @@
1
- {"version":3,"file":"DismissableProps.d.ts","sourceRoot":"","sources":["../src/DismissableProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA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KAAK,CAAC,SAAS,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;CAC5B"}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}