@tamagui/dismissable 1.0.1-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Dismissable.js +278 -0
- package/dist/cjs/Dismissable.js.map +7 -0
- package/dist/cjs/Dismissable.native.js +36 -0
- package/dist/cjs/Dismissable.native.js.map +7 -0
- package/dist/cjs/DismissableProps.js +16 -0
- package/dist/cjs/DismissableProps.js.map +7 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/Dismissable.js +251 -0
- package/dist/esm/Dismissable.js.map +7 -0
- package/dist/esm/Dismissable.native.js +12 -0
- package/dist/esm/Dismissable.native.js.map +7 -0
- package/dist/esm/DismissableProps.js +1 -0
- package/dist/esm/DismissableProps.js.map +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/jsx/Dismissable.js +205 -0
- package/dist/jsx/Dismissable.js.map +7 -0
- package/dist/jsx/Dismissable.native.js +12 -0
- package/dist/jsx/Dismissable.native.js.map +7 -0
- package/dist/jsx/DismissableProps.js +1 -0
- package/dist/jsx/DismissableProps.js.map +7 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/package.json +39 -0
- package/src/Dismissable.native.tsx +11 -0
- package/src/Dismissable.tsx +330 -0
- package/src/DismissableProps.tsx +43 -0
- package/src/index.tsx +1 -0
- package/types/Dismissable.d.ts +15 -0
- package/types/Dismissable.d.ts.map +1 -0
- package/types/Dismissable.native.d.ts +5 -0
- package/types/Dismissable.native.d.ts.map +1 -0
- package/types/DismissableProps.d.ts +15 -0
- package/types/DismissableProps.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/dismissable",
|
|
3
|
+
"version": "1.0.1-beta.100",
|
|
4
|
+
"sideEffects": true,
|
|
5
|
+
"source": "src/index.ts",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"main": "dist/cjs",
|
|
8
|
+
"module": "dist/esm",
|
|
9
|
+
"module:jsx": "dist/jsx",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"types",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tamagui-build",
|
|
17
|
+
"watch": "tamagui-build --watch",
|
|
18
|
+
"clean": "tamagui-build clean",
|
|
19
|
+
"clean:build": "tamagui-build clean:build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@radix-ui/react-use-callback-ref": "^0.1.0",
|
|
23
|
+
"@radix-ui/react-use-escape-keydown": "^0.1.0",
|
|
24
|
+
"@tamagui/compose-refs": "^1.0.1-beta.100",
|
|
25
|
+
"@tamagui/core": "^1.0.1-beta.100"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "*",
|
|
29
|
+
"react-dom": "*"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@tamagui/build": "^1.0.1-beta.100",
|
|
33
|
+
"react": "*",
|
|
34
|
+
"react-dom": "*"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import { DismissableBranchProps, DismissableProps } from './DismissableProps'
|
|
4
|
+
|
|
5
|
+
export const Dismissable = forwardRef((props: DismissableProps, _ref) => {
|
|
6
|
+
return props.children as any
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export const DismissableBranch = forwardRef((props: DismissableBranchProps, _ref) => {
|
|
10
|
+
return props.children as any
|
|
11
|
+
})
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// forked from radix-ui
|
|
2
|
+
// https://github.com/radix-ui/primitives/blob/cfd8dcba5fa6a0e751486af418d05a7b88a7f541/packages/react/dismissable-layer/src/DismissableLayer.tsx#L324
|
|
3
|
+
|
|
4
|
+
import { useCallbackRef } from '@radix-ui/react-use-callback-ref'
|
|
5
|
+
import { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown'
|
|
6
|
+
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
7
|
+
import { composeEventHandlers } from '@tamagui/core'
|
|
8
|
+
import * as React from 'react'
|
|
9
|
+
import * as ReactDOM from 'react-dom'
|
|
10
|
+
|
|
11
|
+
import { DismissableBranchProps, DismissableProps } from './DismissableProps'
|
|
12
|
+
|
|
13
|
+
function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E) {
|
|
14
|
+
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* -------------------------------------------------------------------------------------------------
|
|
18
|
+
* Dismissable
|
|
19
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
20
|
+
|
|
21
|
+
const DISMISSABLE_LAYER_NAME = 'Dismissable'
|
|
22
|
+
const CONTEXT_UPDATE = 'dismissable.update'
|
|
23
|
+
const POINTER_DOWN_OUTSIDE = 'dismissable.pointerDownOutside'
|
|
24
|
+
const FOCUS_OUTSIDE = 'dismissable.focusOutside'
|
|
25
|
+
|
|
26
|
+
let originalBodyPointerEvents: string
|
|
27
|
+
|
|
28
|
+
const DismissableContext = React.createContext({
|
|
29
|
+
layers: new Set<HTMLDivElement>(),
|
|
30
|
+
layersWithOutsidePointerEventsDisabled: new Set<HTMLDivElement>(),
|
|
31
|
+
branches: new Set<HTMLDivElement>(),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const Dismissable = React.forwardRef<HTMLDivElement, DismissableProps>((props, forwardedRef) => {
|
|
35
|
+
const {
|
|
36
|
+
disableOutsidePointerEvents = false,
|
|
37
|
+
onEscapeKeyDown,
|
|
38
|
+
onPointerDownOutside,
|
|
39
|
+
onFocusOutside,
|
|
40
|
+
onInteractOutside,
|
|
41
|
+
onDismiss,
|
|
42
|
+
...layerProps
|
|
43
|
+
} = props
|
|
44
|
+
const context = React.useContext(DismissableContext)
|
|
45
|
+
const [node, setNode] = React.useState<HTMLDivElement | null>(null)
|
|
46
|
+
const [, force] = React.useState({})
|
|
47
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))
|
|
48
|
+
const layers = Array.from(context.layers)
|
|
49
|
+
const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); // prettier-ignore
|
|
50
|
+
const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore
|
|
51
|
+
const index = node ? layers.indexOf(node) : -1
|
|
52
|
+
const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0
|
|
53
|
+
const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex
|
|
54
|
+
|
|
55
|
+
const pointerDownOutside = usePointerDownOutside((event) => {
|
|
56
|
+
const target = event.target as HTMLDivElement
|
|
57
|
+
const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target))
|
|
58
|
+
if (!isPointerEventsEnabled || isPointerDownOnBranch) return
|
|
59
|
+
onPointerDownOutside?.(event)
|
|
60
|
+
onInteractOutside?.(event)
|
|
61
|
+
if (!event.defaultPrevented) onDismiss?.()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const focusOutside = useFocusOutside((event) => {
|
|
65
|
+
const target = event.target as HTMLDivElement
|
|
66
|
+
const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target))
|
|
67
|
+
if (isFocusInBranch) return
|
|
68
|
+
onFocusOutside?.(event)
|
|
69
|
+
onInteractOutside?.(event)
|
|
70
|
+
if (!event.defaultPrevented) onDismiss?.()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
useEscapeKeydown((event) => {
|
|
74
|
+
const isHighestLayer = index === context.layers.size - 1
|
|
75
|
+
if (!isHighestLayer) return
|
|
76
|
+
onEscapeKeyDown?.(event)
|
|
77
|
+
if (!event.defaultPrevented && onDismiss) {
|
|
78
|
+
event.preventDefault()
|
|
79
|
+
onDismiss()
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
React.useEffect(() => {
|
|
84
|
+
if (!node) return
|
|
85
|
+
if (disableOutsidePointerEvents) {
|
|
86
|
+
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
87
|
+
originalBodyPointerEvents = document.body.style.pointerEvents
|
|
88
|
+
document.body.style.pointerEvents = 'none'
|
|
89
|
+
}
|
|
90
|
+
context.layersWithOutsidePointerEventsDisabled.add(node)
|
|
91
|
+
}
|
|
92
|
+
context.layers.add(node)
|
|
93
|
+
dispatchUpdate()
|
|
94
|
+
return () => {
|
|
95
|
+
if (
|
|
96
|
+
disableOutsidePointerEvents &&
|
|
97
|
+
context.layersWithOutsidePointerEventsDisabled.size === 1
|
|
98
|
+
) {
|
|
99
|
+
document.body.style.pointerEvents = originalBodyPointerEvents
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, [node, disableOutsidePointerEvents, context])
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect
|
|
106
|
+
* because a change to `disableOutsidePointerEvents` would remove this layer from the stack
|
|
107
|
+
* and add it to the end again so the layering order wouldn't be _creation order_.
|
|
108
|
+
* We only want them to be removed from context stacks when unmounted.
|
|
109
|
+
*/
|
|
110
|
+
React.useEffect(() => {
|
|
111
|
+
return () => {
|
|
112
|
+
if (!node) return
|
|
113
|
+
context.layers.delete(node)
|
|
114
|
+
context.layersWithOutsidePointerEventsDisabled.delete(node)
|
|
115
|
+
dispatchUpdate()
|
|
116
|
+
}
|
|
117
|
+
}, [node, context])
|
|
118
|
+
|
|
119
|
+
React.useEffect(() => {
|
|
120
|
+
const handleUpdate = () => force({})
|
|
121
|
+
document.addEventListener(CONTEXT_UPDATE, handleUpdate)
|
|
122
|
+
return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate)
|
|
123
|
+
}, [])
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
{...layerProps}
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
ref={composedRefs}
|
|
130
|
+
style={{
|
|
131
|
+
display: 'contents',
|
|
132
|
+
pointerEvents: isBodyPointerEventsDisabled
|
|
133
|
+
? isPointerEventsEnabled
|
|
134
|
+
? 'auto'
|
|
135
|
+
: 'none'
|
|
136
|
+
: undefined,
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
...props.style,
|
|
139
|
+
}}
|
|
140
|
+
onFocusCapture={composeEventHandlers(
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
props.onFocusCapture,
|
|
143
|
+
focusOutside.onFocusCapture
|
|
144
|
+
)}
|
|
145
|
+
onBlurCapture={composeEventHandlers(
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
props.onBlurCapture,
|
|
148
|
+
focusOutside.onBlurCapture
|
|
149
|
+
)}
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
onPointerDownCapture={composeEventHandlers(
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
props.onPointerDownCapture,
|
|
154
|
+
pointerDownOutside.onPointerDownCapture
|
|
155
|
+
)}
|
|
156
|
+
/>
|
|
157
|
+
)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
Dismissable.displayName = DISMISSABLE_LAYER_NAME
|
|
161
|
+
|
|
162
|
+
/* -------------------------------------------------------------------------------------------------
|
|
163
|
+
* DismissableBranch
|
|
164
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
165
|
+
|
|
166
|
+
const BRANCH_NAME = 'DismissableBranch'
|
|
167
|
+
|
|
168
|
+
const DismissableBranch = React.forwardRef<HTMLDivElement, DismissableBranchProps>(
|
|
169
|
+
(props, forwardedRef) => {
|
|
170
|
+
const context = React.useContext(DismissableContext)
|
|
171
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
172
|
+
const composedRefs = useComposedRefs(forwardedRef, ref)
|
|
173
|
+
|
|
174
|
+
React.useEffect(() => {
|
|
175
|
+
const node = ref.current
|
|
176
|
+
if (node) {
|
|
177
|
+
context.branches.add(node)
|
|
178
|
+
return () => {
|
|
179
|
+
context.branches.delete(node)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, [context.branches])
|
|
183
|
+
|
|
184
|
+
return <div style={{ display: 'contents' }} {...props} ref={composedRefs} />
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
DismissableBranch.displayName = BRANCH_NAME
|
|
189
|
+
|
|
190
|
+
/* -----------------------------------------------------------------------------------------------*/
|
|
191
|
+
|
|
192
|
+
export type PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>
|
|
193
|
+
export type FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`
|
|
197
|
+
* to mimic layer dismissing behaviour present in OS.
|
|
198
|
+
* Returns props to pass to the node we want to check for outside events.
|
|
199
|
+
*/
|
|
200
|
+
function usePointerDownOutside(onPointerDownOutside?: (event: PointerDownOutsideEvent) => void) {
|
|
201
|
+
const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener
|
|
202
|
+
const isPointerInsideReactTreeRef = React.useRef(false)
|
|
203
|
+
const handleClickRef = React.useRef(() => {})
|
|
204
|
+
|
|
205
|
+
React.useEffect(() => {
|
|
206
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
207
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
208
|
+
const eventDetail = { originalEvent: event }
|
|
209
|
+
|
|
210
|
+
function handleAndDispatchPointerDownOutsideEvent() {
|
|
211
|
+
handleAndDispatchCustomEvent(
|
|
212
|
+
POINTER_DOWN_OUTSIDE,
|
|
213
|
+
handlePointerDownOutside,
|
|
214
|
+
eventDetail,
|
|
215
|
+
{ discrete: true }
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* On touch devices, we need to wait for a click event because browsers implement
|
|
221
|
+
* a ~350ms delay between the time the user stops touching the display and when the
|
|
222
|
+
* browser executres events. We need to ensure we don't reactivate pointer-events within
|
|
223
|
+
* this timeframe otherwise the browser may execute events that should have been prevented.
|
|
224
|
+
*
|
|
225
|
+
* Additionally, this also lets us deal automatically with cancellations when a click event
|
|
226
|
+
* isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.
|
|
227
|
+
*
|
|
228
|
+
* This is why we also continuously remove the previous listener, because we cannot be
|
|
229
|
+
* certain that it was raised, and therefore cleaned-up.
|
|
230
|
+
*/
|
|
231
|
+
if (event.pointerType === 'touch') {
|
|
232
|
+
document.removeEventListener('click', handleClickRef.current)
|
|
233
|
+
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent
|
|
234
|
+
document.addEventListener('click', handleClickRef.current, { once: true })
|
|
235
|
+
} else {
|
|
236
|
+
handleAndDispatchPointerDownOutsideEvent()
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
isPointerInsideReactTreeRef.current = false
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* if this hook executes in a component that mounts via a `pointerdown` event, the event
|
|
243
|
+
* would bubble up to the document and trigger a `pointerDownOutside` event. We avoid
|
|
244
|
+
* this by delaying the event listener registration on the document.
|
|
245
|
+
* This is not React specific, but rather how the DOM works, ie:
|
|
246
|
+
* ```
|
|
247
|
+
* button.addEventListener('pointerdown', () => {
|
|
248
|
+
* console.log('I will log');
|
|
249
|
+
* document.addEventListener('pointerdown', () => {
|
|
250
|
+
* console.log('I will also log');
|
|
251
|
+
* })
|
|
252
|
+
* });
|
|
253
|
+
*/
|
|
254
|
+
const timerId = window.setTimeout(() => {
|
|
255
|
+
document.addEventListener('pointerdown', handlePointerDown)
|
|
256
|
+
}, 0)
|
|
257
|
+
return () => {
|
|
258
|
+
window.clearTimeout(timerId)
|
|
259
|
+
document.removeEventListener('pointerdown', handlePointerDown)
|
|
260
|
+
document.removeEventListener('click', handleClickRef.current)
|
|
261
|
+
}
|
|
262
|
+
}, [handlePointerDownOutside])
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
// ensures we check React component tree (not just DOM tree)
|
|
266
|
+
onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Listens for when focus happens outside a react subtree.
|
|
272
|
+
* Returns props to pass to the root (node) of the subtree we want to check.
|
|
273
|
+
*/
|
|
274
|
+
function useFocusOutside(onFocusOutside?: (event: FocusOutsideEvent) => void) {
|
|
275
|
+
const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener
|
|
276
|
+
const isFocusInsideReactTreeRef = React.useRef(false)
|
|
277
|
+
|
|
278
|
+
React.useEffect(() => {
|
|
279
|
+
const handleFocus = (event: FocusEvent) => {
|
|
280
|
+
if (event.target && !isFocusInsideReactTreeRef.current) {
|
|
281
|
+
const eventDetail = { originalEvent: event }
|
|
282
|
+
handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
283
|
+
discrete: false,
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
document.addEventListener('focusin', handleFocus)
|
|
288
|
+
return () => document.removeEventListener('focusin', handleFocus)
|
|
289
|
+
}, [handleFocusOutside])
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),
|
|
293
|
+
onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function dispatchUpdate() {
|
|
298
|
+
const event = new CustomEvent(CONTEXT_UPDATE)
|
|
299
|
+
document.dispatchEvent(event)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(
|
|
303
|
+
name: string,
|
|
304
|
+
handler: ((event: E) => void) | undefined,
|
|
305
|
+
detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),
|
|
306
|
+
{ discrete }: { discrete: boolean }
|
|
307
|
+
) {
|
|
308
|
+
const target = detail.originalEvent.target
|
|
309
|
+
const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail })
|
|
310
|
+
if (handler) target.addEventListener(name, handler as EventListener, { once: true })
|
|
311
|
+
|
|
312
|
+
if (discrete) {
|
|
313
|
+
dispatchDiscreteCustomEvent(target, event)
|
|
314
|
+
} else {
|
|
315
|
+
target.dispatchEvent(event)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const Root = Dismissable
|
|
320
|
+
const Branch = DismissableBranch
|
|
321
|
+
|
|
322
|
+
export {
|
|
323
|
+
Dismissable,
|
|
324
|
+
DismissableBranch,
|
|
325
|
+
//
|
|
326
|
+
Root,
|
|
327
|
+
Branch,
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export type { DismissableProps }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { FocusOutsideEvent, PointerDownOutsideEvent } from './Dismissable'
|
|
4
|
+
|
|
5
|
+
export interface DismissableProps {
|
|
6
|
+
/**
|
|
7
|
+
* When `true`, hover/focus/click interactions will be disabled on elements outside
|
|
8
|
+
* the `Dismissable`. Users will need to click twice on outside elements to
|
|
9
|
+
* interact with them: once to close the `Dismissable`, and again to trigger the element.
|
|
10
|
+
*/
|
|
11
|
+
disableOutsidePointerEvents?: boolean
|
|
12
|
+
/**
|
|
13
|
+
* Event handler called when the escape key is down.
|
|
14
|
+
* Can be prevented.
|
|
15
|
+
*/
|
|
16
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void
|
|
17
|
+
/**
|
|
18
|
+
* Event handler called when the a `pointerdown` event happens outside of the `Dismissable`.
|
|
19
|
+
* Can be prevented.
|
|
20
|
+
*/
|
|
21
|
+
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void
|
|
22
|
+
/**
|
|
23
|
+
* Event handler called when the focus moves outside of the `Dismissable`.
|
|
24
|
+
* Can be prevented.
|
|
25
|
+
*/
|
|
26
|
+
onFocusOutside?: (event: FocusOutsideEvent) => void
|
|
27
|
+
/**
|
|
28
|
+
* Event handler called when an interaction happens outside the `Dismissable`.
|
|
29
|
+
* Specifically, when a `pointerdown` event happens outside or focus moves outside of it.
|
|
30
|
+
* Can be prevented.
|
|
31
|
+
*/
|
|
32
|
+
onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void
|
|
33
|
+
/**
|
|
34
|
+
* Handler called when the `Dismissable` should be dismissed
|
|
35
|
+
*/
|
|
36
|
+
onDismiss?: () => void
|
|
37
|
+
|
|
38
|
+
children?: React.ReactNode
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DismissableBranchProps {
|
|
42
|
+
children?: React.ReactNode
|
|
43
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Dismissable'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DismissableBranchProps, DismissableProps } from './DismissableProps';
|
|
3
|
+
declare const Dismissable: React.ForwardRefExoticComponent<DismissableProps & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
declare const DismissableBranch: React.ForwardRefExoticComponent<DismissableBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
export declare type PointerDownOutsideEvent = CustomEvent<{
|
|
6
|
+
originalEvent: PointerEvent;
|
|
7
|
+
}>;
|
|
8
|
+
export declare type FocusOutsideEvent = CustomEvent<{
|
|
9
|
+
originalEvent: FocusEvent;
|
|
10
|
+
}>;
|
|
11
|
+
declare const Root: React.ForwardRefExoticComponent<DismissableProps & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
+
declare const Branch: React.ForwardRefExoticComponent<DismissableBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export { Dismissable, DismissableBranch, Root, Branch, };
|
|
14
|
+
export type { DismissableProps };
|
|
15
|
+
//# sourceMappingURL=Dismissable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dismissable.d.ts","sourceRoot":"","sources":["../src/Dismissable.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAuB7E,QAAA,MAAM,WAAW,yFA4Hf,CAAA;AAUF,QAAA,MAAM,iBAAiB,+FAkBtB,CAAA;AAMD,oBAAY,uBAAuB,GAAG,WAAW,CAAC;IAAE,aAAa,EAAE,YAAY,CAAA;CAAE,CAAC,CAAA;AAClF,oBAAY,iBAAiB,GAAG,WAAW,CAAC;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,CAAC,CAAA;AA8H1E,QAAA,MAAM,IAAI,yFAAc,CAAA;AACxB,QAAA,MAAM,MAAM,+FAAoB,CAAA;AAEhC,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,IAAI,EACJ,MAAM,GACP,CAAA;AAED,YAAY,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DismissableBranchProps, DismissableProps } from './DismissableProps';
|
|
3
|
+
export declare const Dismissable: import("react").ForwardRefExoticComponent<DismissableProps & import("react").RefAttributes<unknown>>;
|
|
4
|
+
export declare const DismissableBranch: import("react").ForwardRefExoticComponent<DismissableBranchProps & import("react").RefAttributes<unknown>>;
|
|
5
|
+
//# sourceMappingURL=Dismissable.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dismissable.native.d.ts","sourceRoot":"","sources":["../src/Dismissable.native.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE7E,eAAO,MAAM,WAAW,sGAEtB,CAAA;AAEF,eAAO,MAAM,iBAAiB,4GAE5B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FocusOutsideEvent, PointerDownOutsideEvent } from './Dismissable';
|
|
3
|
+
export interface DismissableProps {
|
|
4
|
+
disableOutsidePointerEvents?: boolean;
|
|
5
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
6
|
+
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
|
|
7
|
+
onFocusOutside?: (event: FocusOutsideEvent) => void;
|
|
8
|
+
onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;
|
|
9
|
+
onDismiss?: () => void;
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export interface DismissableBranchProps {
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=DismissableProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DismissableProps.d.ts","sourceRoot":"","sources":["../src/DismissableProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAE1E,MAAM,WAAW,gBAAgB;IAM/B,2BAA2B,CAAC,EAAE,OAAO,CAAA;IAKrC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAKhD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAA;IAK/D,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAA;IAMnD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,GAAG,iBAAiB,KAAK,IAAI,CAAA;IAIhF,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAEtB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|