@vx-oss/heroui-v2-use-aria-overlay 2.0.5-alpha.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/LICENSE +32 -0
- package/README.md +24 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +135 -0
- package/dist/index.mjs +110 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
|
|
5
|
+
Parameters
|
|
6
|
+
|
|
7
|
+
Creator / Maintainer : Vezham Technologies Private Limited
|
|
8
|
+
Original Author : NextUI Inc
|
|
9
|
+
Licensor : Vezham Technologies Private Limited
|
|
10
|
+
|
|
11
|
+
Copyright © 2025, Vezham Technologies Private Limited. All rights reserved.
|
|
12
|
+
Copyright (c) 2020, NextUI Inc.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
in the Software without restriction, including without limitation the rights
|
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @vx-oss/heroui-v2-use-aria-overlay
|
|
2
|
+
|
|
3
|
+
A Quick description of the component
|
|
4
|
+
|
|
5
|
+
> This is an internal utility, not intended for public usage.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @vx-oss/heroui-v2-use-aria-overlay
|
|
11
|
+
# or
|
|
12
|
+
npm i @vx-oss/heroui-v2-use-aria-overlay
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Contribution
|
|
16
|
+
|
|
17
|
+
Yes please! See the
|
|
18
|
+
[contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
|
|
19
|
+
for details.
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
This project is licensed under the terms of the
|
|
24
|
+
[MIT license](https://github.com/heroui-inc/heroui/blob/master/LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AriaOverlayProps, OverlayAria } from '@react-aria/overlays';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
interface UseAriaOverlayProps extends AriaOverlayProps {
|
|
5
|
+
/**
|
|
6
|
+
* When `true`, `click/focus` interactions will be disabled on elements outside
|
|
7
|
+
* the `Overlay`. Users need to click twice on outside elements to interact with them:
|
|
8
|
+
* once to close the overlay, and again to trigger the element.
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
disableOutsideEvents?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provides the behavior for overlays such as dialogs, popovers, and menus.
|
|
16
|
+
* Hides the overlay when the user interacts outside it, when the Escape key is pressed,
|
|
17
|
+
* or optionally, on blur. Only the top-most overlay will close at once.
|
|
18
|
+
*/
|
|
19
|
+
declare function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject<Element>): OverlayAria;
|
|
20
|
+
|
|
21
|
+
export { type UseAriaOverlayProps, useAriaOverlay };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AriaOverlayProps, OverlayAria } from '@react-aria/overlays';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
interface UseAriaOverlayProps extends AriaOverlayProps {
|
|
5
|
+
/**
|
|
6
|
+
* When `true`, `click/focus` interactions will be disabled on elements outside
|
|
7
|
+
* the `Overlay`. Users need to click twice on outside elements to interact with them:
|
|
8
|
+
* once to close the overlay, and again to trigger the element.
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
disableOutsideEvents?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provides the behavior for overlays such as dialogs, popovers, and menus.
|
|
16
|
+
* Hides the overlay when the user interacts outside it, when the Escape key is pressed,
|
|
17
|
+
* or optionally, on blur. Only the top-most overlay will close at once.
|
|
18
|
+
*/
|
|
19
|
+
declare function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject<Element>): OverlayAria;
|
|
20
|
+
|
|
21
|
+
export { type UseAriaOverlayProps, useAriaOverlay };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
useAriaOverlay: () => useAriaOverlay
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_focus = require("@react-aria/focus");
|
|
27
|
+
var import_interactions = require("@react-aria/interactions");
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var visibleOverlays = [];
|
|
30
|
+
function useAriaOverlay(props, ref) {
|
|
31
|
+
const {
|
|
32
|
+
disableOutsideEvents = true,
|
|
33
|
+
isDismissable = false,
|
|
34
|
+
isKeyboardDismissDisabled = false,
|
|
35
|
+
isOpen,
|
|
36
|
+
onClose,
|
|
37
|
+
shouldCloseOnBlur,
|
|
38
|
+
shouldCloseOnInteractOutside
|
|
39
|
+
} = props;
|
|
40
|
+
(0, import_react.useEffect)(() => {
|
|
41
|
+
if (isOpen && !visibleOverlays.includes(ref)) {
|
|
42
|
+
visibleOverlays.push(ref);
|
|
43
|
+
return () => {
|
|
44
|
+
let index = visibleOverlays.indexOf(ref);
|
|
45
|
+
if (index >= 0) {
|
|
46
|
+
visibleOverlays.splice(index, 1);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}, [isOpen, ref]);
|
|
51
|
+
const onHide = () => {
|
|
52
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {
|
|
53
|
+
onClose();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const onInteractOutsideStart = (e) => {
|
|
57
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
|
|
58
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
59
|
+
if (disableOutsideEvents) {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (getOverlayInteractionType(ref) !== "pressEnd") {
|
|
65
|
+
onHide();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const onInteractOutside = (e) => {
|
|
70
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
|
|
71
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
72
|
+
if (disableOutsideEvents) {
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
onHide();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const onKeyDown = (e) => {
|
|
81
|
+
if (e.key === "Escape" && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {
|
|
82
|
+
e.stopPropagation();
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
onHide();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
(0, import_interactions.useInteractOutside)({
|
|
88
|
+
isDisabled: !(isDismissable && isOpen),
|
|
89
|
+
onInteractOutside: isDismissable && isOpen ? onInteractOutside : void 0,
|
|
90
|
+
onInteractOutsideStart,
|
|
91
|
+
ref
|
|
92
|
+
});
|
|
93
|
+
const { focusWithinProps } = (0, import_interactions.useFocusWithin)({
|
|
94
|
+
isDisabled: !shouldCloseOnBlur,
|
|
95
|
+
onBlurWithin: (e) => {
|
|
96
|
+
if (!e.relatedTarget || (0, import_focus.isElementInChildOfActiveScope)(e.relatedTarget)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) {
|
|
100
|
+
onHide();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
const onPointerDownUnderlay = (e) => {
|
|
105
|
+
if (e.target === e.currentTarget) {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function getOverlayInteractionType(ref2) {
|
|
110
|
+
const el = ref2.current;
|
|
111
|
+
if (!el) return "unknown";
|
|
112
|
+
const role = (el.getAttribute("role") || "").toLowerCase();
|
|
113
|
+
const ariaModalAttr = el.getAttribute("aria-modal");
|
|
114
|
+
if ((role === "dialog" || role === "alertdialog") && (ariaModalAttr === null || ariaModalAttr.toLowerCase() === "true")) {
|
|
115
|
+
return "pressEnd";
|
|
116
|
+
}
|
|
117
|
+
if (["listbox", "menu", "tree", "grid", "combobox"].includes(role)) {
|
|
118
|
+
return "pressStart";
|
|
119
|
+
}
|
|
120
|
+
return "unknown";
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
overlayProps: {
|
|
124
|
+
onKeyDown,
|
|
125
|
+
...focusWithinProps
|
|
126
|
+
},
|
|
127
|
+
underlayProps: {
|
|
128
|
+
onPointerDown: onPointerDownUnderlay
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
useAriaOverlay
|
|
135
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { isElementInChildOfActiveScope } from "@react-aria/focus";
|
|
3
|
+
import { useFocusWithin, useInteractOutside } from "@react-aria/interactions";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
var visibleOverlays = [];
|
|
6
|
+
function useAriaOverlay(props, ref) {
|
|
7
|
+
const {
|
|
8
|
+
disableOutsideEvents = true,
|
|
9
|
+
isDismissable = false,
|
|
10
|
+
isKeyboardDismissDisabled = false,
|
|
11
|
+
isOpen,
|
|
12
|
+
onClose,
|
|
13
|
+
shouldCloseOnBlur,
|
|
14
|
+
shouldCloseOnInteractOutside
|
|
15
|
+
} = props;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (isOpen && !visibleOverlays.includes(ref)) {
|
|
18
|
+
visibleOverlays.push(ref);
|
|
19
|
+
return () => {
|
|
20
|
+
let index = visibleOverlays.indexOf(ref);
|
|
21
|
+
if (index >= 0) {
|
|
22
|
+
visibleOverlays.splice(index, 1);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}, [isOpen, ref]);
|
|
27
|
+
const onHide = () => {
|
|
28
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {
|
|
29
|
+
onClose();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const onInteractOutsideStart = (e) => {
|
|
33
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
|
|
34
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
35
|
+
if (disableOutsideEvents) {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (getOverlayInteractionType(ref) !== "pressEnd") {
|
|
41
|
+
onHide();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const onInteractOutside = (e) => {
|
|
46
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
|
|
47
|
+
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
48
|
+
if (disableOutsideEvents) {
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
onHide();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const onKeyDown = (e) => {
|
|
57
|
+
if (e.key === "Escape" && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
onHide();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
useInteractOutside({
|
|
64
|
+
isDisabled: !(isDismissable && isOpen),
|
|
65
|
+
onInteractOutside: isDismissable && isOpen ? onInteractOutside : void 0,
|
|
66
|
+
onInteractOutsideStart,
|
|
67
|
+
ref
|
|
68
|
+
});
|
|
69
|
+
const { focusWithinProps } = useFocusWithin({
|
|
70
|
+
isDisabled: !shouldCloseOnBlur,
|
|
71
|
+
onBlurWithin: (e) => {
|
|
72
|
+
if (!e.relatedTarget || isElementInChildOfActiveScope(e.relatedTarget)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) {
|
|
76
|
+
onHide();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const onPointerDownUnderlay = (e) => {
|
|
81
|
+
if (e.target === e.currentTarget) {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function getOverlayInteractionType(ref2) {
|
|
86
|
+
const el = ref2.current;
|
|
87
|
+
if (!el) return "unknown";
|
|
88
|
+
const role = (el.getAttribute("role") || "").toLowerCase();
|
|
89
|
+
const ariaModalAttr = el.getAttribute("aria-modal");
|
|
90
|
+
if ((role === "dialog" || role === "alertdialog") && (ariaModalAttr === null || ariaModalAttr.toLowerCase() === "true")) {
|
|
91
|
+
return "pressEnd";
|
|
92
|
+
}
|
|
93
|
+
if (["listbox", "menu", "tree", "grid", "combobox"].includes(role)) {
|
|
94
|
+
return "pressStart";
|
|
95
|
+
}
|
|
96
|
+
return "unknown";
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
overlayProps: {
|
|
100
|
+
onKeyDown,
|
|
101
|
+
...focusWithinProps
|
|
102
|
+
},
|
|
103
|
+
underlayProps: {
|
|
104
|
+
onPointerDown: onPointerDownUnderlay
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
useAriaOverlay
|
|
110
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vx-oss/heroui-v2-use-aria-overlay",
|
|
3
|
+
"version": "2.0.5-alpha.0",
|
|
4
|
+
"description": "A custom implementation of react aria overlay",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"use-aria-overlay"
|
|
7
|
+
],
|
|
8
|
+
"author": "Vx OSS Devs <oss-developers@vezham.com>",
|
|
9
|
+
"homepage": "https://vezham.com",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/vezham/heroui-v2.git",
|
|
22
|
+
"directory": "packages/hooks/use-aria-overlay"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/vezham/heroui-v2/issues"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@react-aria/focus": "3.21.2",
|
|
29
|
+
"@react-aria/interactions": "3.25.6",
|
|
30
|
+
"@react-aria/overlays": "3.30.0",
|
|
31
|
+
"@react-types/shared": "3.32.1"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=18",
|
|
35
|
+
"react-dom": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"clean-package": "../../../clean-package.config.json",
|
|
38
|
+
"tsup": {
|
|
39
|
+
"clean": true,
|
|
40
|
+
"target": "es2019",
|
|
41
|
+
"format": [
|
|
42
|
+
"cjs",
|
|
43
|
+
"esm"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"module": "dist/index.mjs",
|
|
47
|
+
"types": "dist/index.d.ts",
|
|
48
|
+
"exports": {
|
|
49
|
+
".": {
|
|
50
|
+
"types": "./dist/index.d.ts",
|
|
51
|
+
"import": "./dist/index.mjs",
|
|
52
|
+
"require": "./dist/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./package.json": "./package.json"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup src --dts",
|
|
58
|
+
"build:fast": "tsup src",
|
|
59
|
+
"dev": "pnpm build:fast --watch",
|
|
60
|
+
"clean": "rimraf dist .turbo",
|
|
61
|
+
"typecheck": "tsc --noEmit"
|
|
62
|
+
}
|
|
63
|
+
}
|