@vx-oss/heroui-v2-use-aria-accordion 2.2.19-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/chunk-AHLWZTIP.mjs +104 -0
- package/dist/chunk-BHM6H4ZD.mjs +22 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +151 -0
- package/dist/index.mjs +10 -0
- package/dist/use-accordion-item.d.mts +19 -0
- package/dist/use-accordion-item.d.ts +19 -0
- package/dist/use-accordion-item.js +128 -0
- package/dist/use-accordion-item.mjs +6 -0
- package/dist/use-accordion.d.mts +21 -0
- package/dist/use-accordion.d.ts +21 -0
- package/dist/use-accordion.js +46 -0
- package/dist/use-accordion.mjs +6 -0
- package/package.json +64 -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-accordion
|
|
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-accordion
|
|
11
|
+
# or
|
|
12
|
+
npm i @vx-oss/heroui-v2-use-aria-accordion
|
|
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).
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/use-accordion-item.ts
|
|
2
|
+
import { focusSafely } from "@react-aria/focus";
|
|
3
|
+
import { useId, useCallback, useEffect } from "react";
|
|
4
|
+
import { useButton } from "@react-aria/button";
|
|
5
|
+
function useReactAriaAccordionItem(props, state, ref) {
|
|
6
|
+
let { item, isDisabled: isDisabledProp } = props;
|
|
7
|
+
let key = item.key;
|
|
8
|
+
let manager = state.selectionManager;
|
|
9
|
+
let buttonId = useId();
|
|
10
|
+
let regionId = useId();
|
|
11
|
+
let isDisabled = state.disabledKeys.has(item.key) || isDisabledProp;
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let isFocused = key === state.focusedKey;
|
|
14
|
+
if (isFocused && document.activeElement !== ref.current) {
|
|
15
|
+
ref.current && focusSafely(ref.current);
|
|
16
|
+
}
|
|
17
|
+
}, [ref, key, state.focusedKey]);
|
|
18
|
+
let onSelect = useCallback(
|
|
19
|
+
(e) => {
|
|
20
|
+
if (!manager.canSelectItem(key)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
manager.select(key, e);
|
|
24
|
+
state.toggleKey(key);
|
|
25
|
+
},
|
|
26
|
+
[key, manager]
|
|
27
|
+
);
|
|
28
|
+
const extendFocusSelection = useCallback(
|
|
29
|
+
(toKey) => {
|
|
30
|
+
if (manager.selectionBehavior === "replace") {
|
|
31
|
+
manager.extendSelection(toKey);
|
|
32
|
+
}
|
|
33
|
+
manager.setFocusedKey(toKey);
|
|
34
|
+
},
|
|
35
|
+
[manager]
|
|
36
|
+
);
|
|
37
|
+
const onKeyDown = useCallback(
|
|
38
|
+
(event) => {
|
|
39
|
+
const keyMap = {
|
|
40
|
+
ArrowDown: () => {
|
|
41
|
+
const nextKey = state.collection.getKeyAfter(key);
|
|
42
|
+
if (nextKey && state.disabledKeys.has(nextKey)) {
|
|
43
|
+
const nextEnabledKey = state.collection.getKeyAfter(nextKey);
|
|
44
|
+
nextEnabledKey && extendFocusSelection(nextEnabledKey);
|
|
45
|
+
} else {
|
|
46
|
+
nextKey && extendFocusSelection(nextKey);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
ArrowUp: () => {
|
|
50
|
+
const prevKey = state.collection.getKeyBefore(key);
|
|
51
|
+
if (prevKey && state.disabledKeys.has(prevKey)) {
|
|
52
|
+
const prevEnabledKey = state.collection.getKeyBefore(prevKey);
|
|
53
|
+
prevEnabledKey && extendFocusSelection(prevEnabledKey);
|
|
54
|
+
} else {
|
|
55
|
+
prevKey && extendFocusSelection(prevKey);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
Home: () => {
|
|
59
|
+
const firstKey = state.collection.getFirstKey();
|
|
60
|
+
firstKey && extendFocusSelection(firstKey);
|
|
61
|
+
},
|
|
62
|
+
End: () => {
|
|
63
|
+
const lastKey = state.collection.getLastKey();
|
|
64
|
+
lastKey && extendFocusSelection(lastKey);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const action = keyMap[event.key];
|
|
68
|
+
if (action) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
if (manager.canSelectItem(key)) {
|
|
71
|
+
action(event);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
[key, manager]
|
|
76
|
+
);
|
|
77
|
+
let { buttonProps } = useButton(
|
|
78
|
+
{
|
|
79
|
+
id: buttonId,
|
|
80
|
+
elementType: "button",
|
|
81
|
+
isDisabled,
|
|
82
|
+
onKeyDown,
|
|
83
|
+
onPress: onSelect
|
|
84
|
+
},
|
|
85
|
+
ref
|
|
86
|
+
);
|
|
87
|
+
let isExpanded = state.selectionManager.isSelected(item.key);
|
|
88
|
+
return {
|
|
89
|
+
buttonProps: {
|
|
90
|
+
...buttonProps,
|
|
91
|
+
"aria-expanded": isExpanded,
|
|
92
|
+
"aria-controls": isExpanded ? regionId : void 0
|
|
93
|
+
},
|
|
94
|
+
regionProps: {
|
|
95
|
+
id: regionId,
|
|
96
|
+
role: "region",
|
|
97
|
+
"aria-labelledby": buttonId
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
useReactAriaAccordionItem
|
|
104
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/use-accordion.ts
|
|
2
|
+
import { useSelectableList } from "@react-aria/selection";
|
|
3
|
+
function useReactAriaAccordion(props, state, ref) {
|
|
4
|
+
let { listProps } = useSelectableList({
|
|
5
|
+
...props,
|
|
6
|
+
...state,
|
|
7
|
+
allowsTabNavigation: true,
|
|
8
|
+
disallowSelectAll: true,
|
|
9
|
+
ref
|
|
10
|
+
});
|
|
11
|
+
delete listProps.onKeyDownCapture;
|
|
12
|
+
return {
|
|
13
|
+
accordionProps: {
|
|
14
|
+
...listProps,
|
|
15
|
+
tabIndex: void 0
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
useReactAriaAccordion
|
|
22
|
+
};
|
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
useReactAriaAccordion: () => useReactAriaAccordion,
|
|
24
|
+
useReactAriaAccordionItem: () => useReactAriaAccordionItem
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/use-accordion.ts
|
|
29
|
+
var import_selection = require("@react-aria/selection");
|
|
30
|
+
function useReactAriaAccordion(props, state, ref) {
|
|
31
|
+
let { listProps } = (0, import_selection.useSelectableList)({
|
|
32
|
+
...props,
|
|
33
|
+
...state,
|
|
34
|
+
allowsTabNavigation: true,
|
|
35
|
+
disallowSelectAll: true,
|
|
36
|
+
ref
|
|
37
|
+
});
|
|
38
|
+
delete listProps.onKeyDownCapture;
|
|
39
|
+
return {
|
|
40
|
+
accordionProps: {
|
|
41
|
+
...listProps,
|
|
42
|
+
tabIndex: void 0
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/use-accordion-item.ts
|
|
48
|
+
var import_focus = require("@react-aria/focus");
|
|
49
|
+
var import_react = require("react");
|
|
50
|
+
var import_button = require("@react-aria/button");
|
|
51
|
+
function useReactAriaAccordionItem(props, state, ref) {
|
|
52
|
+
let { item, isDisabled: isDisabledProp } = props;
|
|
53
|
+
let key = item.key;
|
|
54
|
+
let manager = state.selectionManager;
|
|
55
|
+
let buttonId = (0, import_react.useId)();
|
|
56
|
+
let regionId = (0, import_react.useId)();
|
|
57
|
+
let isDisabled = state.disabledKeys.has(item.key) || isDisabledProp;
|
|
58
|
+
(0, import_react.useEffect)(() => {
|
|
59
|
+
let isFocused = key === state.focusedKey;
|
|
60
|
+
if (isFocused && document.activeElement !== ref.current) {
|
|
61
|
+
ref.current && (0, import_focus.focusSafely)(ref.current);
|
|
62
|
+
}
|
|
63
|
+
}, [ref, key, state.focusedKey]);
|
|
64
|
+
let onSelect = (0, import_react.useCallback)(
|
|
65
|
+
(e) => {
|
|
66
|
+
if (!manager.canSelectItem(key)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
manager.select(key, e);
|
|
70
|
+
state.toggleKey(key);
|
|
71
|
+
},
|
|
72
|
+
[key, manager]
|
|
73
|
+
);
|
|
74
|
+
const extendFocusSelection = (0, import_react.useCallback)(
|
|
75
|
+
(toKey) => {
|
|
76
|
+
if (manager.selectionBehavior === "replace") {
|
|
77
|
+
manager.extendSelection(toKey);
|
|
78
|
+
}
|
|
79
|
+
manager.setFocusedKey(toKey);
|
|
80
|
+
},
|
|
81
|
+
[manager]
|
|
82
|
+
);
|
|
83
|
+
const onKeyDown = (0, import_react.useCallback)(
|
|
84
|
+
(event) => {
|
|
85
|
+
const keyMap = {
|
|
86
|
+
ArrowDown: () => {
|
|
87
|
+
const nextKey = state.collection.getKeyAfter(key);
|
|
88
|
+
if (nextKey && state.disabledKeys.has(nextKey)) {
|
|
89
|
+
const nextEnabledKey = state.collection.getKeyAfter(nextKey);
|
|
90
|
+
nextEnabledKey && extendFocusSelection(nextEnabledKey);
|
|
91
|
+
} else {
|
|
92
|
+
nextKey && extendFocusSelection(nextKey);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
ArrowUp: () => {
|
|
96
|
+
const prevKey = state.collection.getKeyBefore(key);
|
|
97
|
+
if (prevKey && state.disabledKeys.has(prevKey)) {
|
|
98
|
+
const prevEnabledKey = state.collection.getKeyBefore(prevKey);
|
|
99
|
+
prevEnabledKey && extendFocusSelection(prevEnabledKey);
|
|
100
|
+
} else {
|
|
101
|
+
prevKey && extendFocusSelection(prevKey);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
Home: () => {
|
|
105
|
+
const firstKey = state.collection.getFirstKey();
|
|
106
|
+
firstKey && extendFocusSelection(firstKey);
|
|
107
|
+
},
|
|
108
|
+
End: () => {
|
|
109
|
+
const lastKey = state.collection.getLastKey();
|
|
110
|
+
lastKey && extendFocusSelection(lastKey);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const action = keyMap[event.key];
|
|
114
|
+
if (action) {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
if (manager.canSelectItem(key)) {
|
|
117
|
+
action(event);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
[key, manager]
|
|
122
|
+
);
|
|
123
|
+
let { buttonProps } = (0, import_button.useButton)(
|
|
124
|
+
{
|
|
125
|
+
id: buttonId,
|
|
126
|
+
elementType: "button",
|
|
127
|
+
isDisabled,
|
|
128
|
+
onKeyDown,
|
|
129
|
+
onPress: onSelect
|
|
130
|
+
},
|
|
131
|
+
ref
|
|
132
|
+
);
|
|
133
|
+
let isExpanded = state.selectionManager.isSelected(item.key);
|
|
134
|
+
return {
|
|
135
|
+
buttonProps: {
|
|
136
|
+
...buttonProps,
|
|
137
|
+
"aria-expanded": isExpanded,
|
|
138
|
+
"aria-controls": isExpanded ? regionId : void 0
|
|
139
|
+
},
|
|
140
|
+
regionProps: {
|
|
141
|
+
id: regionId,
|
|
142
|
+
role: "region",
|
|
143
|
+
"aria-labelledby": buttonId
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
useReactAriaAccordion,
|
|
150
|
+
useReactAriaAccordionItem
|
|
151
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Key, RefObject, ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import { Node, DOMAttributes } from '@react-types/shared';
|
|
3
|
+
import { TreeState } from '@react-stately/tree';
|
|
4
|
+
|
|
5
|
+
interface AccordionItemAriaProps<T> {
|
|
6
|
+
item: Node<T>;
|
|
7
|
+
isDisabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface AccordionItemAria {
|
|
10
|
+
/** Props for the accordion item button. */
|
|
11
|
+
buttonProps: ButtonHTMLAttributes<HTMLElement>;
|
|
12
|
+
/** Props for the accordion item content element. */
|
|
13
|
+
regionProps: DOMAttributes;
|
|
14
|
+
}
|
|
15
|
+
declare function useReactAriaAccordionItem<T>(props: AccordionItemAriaProps<T>, state: TreeState<T> & {
|
|
16
|
+
focusedKey?: Key | null;
|
|
17
|
+
}, ref: RefObject<HTMLButtonElement>): AccordionItemAria;
|
|
18
|
+
|
|
19
|
+
export { type AccordionItemAria, type AccordionItemAriaProps, useReactAriaAccordionItem };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Key, RefObject, ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import { Node, DOMAttributes } from '@react-types/shared';
|
|
3
|
+
import { TreeState } from '@react-stately/tree';
|
|
4
|
+
|
|
5
|
+
interface AccordionItemAriaProps<T> {
|
|
6
|
+
item: Node<T>;
|
|
7
|
+
isDisabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface AccordionItemAria {
|
|
10
|
+
/** Props for the accordion item button. */
|
|
11
|
+
buttonProps: ButtonHTMLAttributes<HTMLElement>;
|
|
12
|
+
/** Props for the accordion item content element. */
|
|
13
|
+
regionProps: DOMAttributes;
|
|
14
|
+
}
|
|
15
|
+
declare function useReactAriaAccordionItem<T>(props: AccordionItemAriaProps<T>, state: TreeState<T> & {
|
|
16
|
+
focusedKey?: Key | null;
|
|
17
|
+
}, ref: RefObject<HTMLButtonElement>): AccordionItemAria;
|
|
18
|
+
|
|
19
|
+
export { type AccordionItemAria, type AccordionItemAriaProps, useReactAriaAccordionItem };
|
|
@@ -0,0 +1,128 @@
|
|
|
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/use-accordion-item.ts
|
|
21
|
+
var use_accordion_item_exports = {};
|
|
22
|
+
__export(use_accordion_item_exports, {
|
|
23
|
+
useReactAriaAccordionItem: () => useReactAriaAccordionItem
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(use_accordion_item_exports);
|
|
26
|
+
var import_focus = require("@react-aria/focus");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_button = require("@react-aria/button");
|
|
29
|
+
function useReactAriaAccordionItem(props, state, ref) {
|
|
30
|
+
let { item, isDisabled: isDisabledProp } = props;
|
|
31
|
+
let key = item.key;
|
|
32
|
+
let manager = state.selectionManager;
|
|
33
|
+
let buttonId = (0, import_react.useId)();
|
|
34
|
+
let regionId = (0, import_react.useId)();
|
|
35
|
+
let isDisabled = state.disabledKeys.has(item.key) || isDisabledProp;
|
|
36
|
+
(0, import_react.useEffect)(() => {
|
|
37
|
+
let isFocused = key === state.focusedKey;
|
|
38
|
+
if (isFocused && document.activeElement !== ref.current) {
|
|
39
|
+
ref.current && (0, import_focus.focusSafely)(ref.current);
|
|
40
|
+
}
|
|
41
|
+
}, [ref, key, state.focusedKey]);
|
|
42
|
+
let onSelect = (0, import_react.useCallback)(
|
|
43
|
+
(e) => {
|
|
44
|
+
if (!manager.canSelectItem(key)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
manager.select(key, e);
|
|
48
|
+
state.toggleKey(key);
|
|
49
|
+
},
|
|
50
|
+
[key, manager]
|
|
51
|
+
);
|
|
52
|
+
const extendFocusSelection = (0, import_react.useCallback)(
|
|
53
|
+
(toKey) => {
|
|
54
|
+
if (manager.selectionBehavior === "replace") {
|
|
55
|
+
manager.extendSelection(toKey);
|
|
56
|
+
}
|
|
57
|
+
manager.setFocusedKey(toKey);
|
|
58
|
+
},
|
|
59
|
+
[manager]
|
|
60
|
+
);
|
|
61
|
+
const onKeyDown = (0, import_react.useCallback)(
|
|
62
|
+
(event) => {
|
|
63
|
+
const keyMap = {
|
|
64
|
+
ArrowDown: () => {
|
|
65
|
+
const nextKey = state.collection.getKeyAfter(key);
|
|
66
|
+
if (nextKey && state.disabledKeys.has(nextKey)) {
|
|
67
|
+
const nextEnabledKey = state.collection.getKeyAfter(nextKey);
|
|
68
|
+
nextEnabledKey && extendFocusSelection(nextEnabledKey);
|
|
69
|
+
} else {
|
|
70
|
+
nextKey && extendFocusSelection(nextKey);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
ArrowUp: () => {
|
|
74
|
+
const prevKey = state.collection.getKeyBefore(key);
|
|
75
|
+
if (prevKey && state.disabledKeys.has(prevKey)) {
|
|
76
|
+
const prevEnabledKey = state.collection.getKeyBefore(prevKey);
|
|
77
|
+
prevEnabledKey && extendFocusSelection(prevEnabledKey);
|
|
78
|
+
} else {
|
|
79
|
+
prevKey && extendFocusSelection(prevKey);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
Home: () => {
|
|
83
|
+
const firstKey = state.collection.getFirstKey();
|
|
84
|
+
firstKey && extendFocusSelection(firstKey);
|
|
85
|
+
},
|
|
86
|
+
End: () => {
|
|
87
|
+
const lastKey = state.collection.getLastKey();
|
|
88
|
+
lastKey && extendFocusSelection(lastKey);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const action = keyMap[event.key];
|
|
92
|
+
if (action) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
if (manager.canSelectItem(key)) {
|
|
95
|
+
action(event);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
[key, manager]
|
|
100
|
+
);
|
|
101
|
+
let { buttonProps } = (0, import_button.useButton)(
|
|
102
|
+
{
|
|
103
|
+
id: buttonId,
|
|
104
|
+
elementType: "button",
|
|
105
|
+
isDisabled,
|
|
106
|
+
onKeyDown,
|
|
107
|
+
onPress: onSelect
|
|
108
|
+
},
|
|
109
|
+
ref
|
|
110
|
+
);
|
|
111
|
+
let isExpanded = state.selectionManager.isSelected(item.key);
|
|
112
|
+
return {
|
|
113
|
+
buttonProps: {
|
|
114
|
+
...buttonProps,
|
|
115
|
+
"aria-expanded": isExpanded,
|
|
116
|
+
"aria-controls": isExpanded ? regionId : void 0
|
|
117
|
+
},
|
|
118
|
+
regionProps: {
|
|
119
|
+
id: regionId,
|
|
120
|
+
role: "region",
|
|
121
|
+
"aria-labelledby": buttonId
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
useReactAriaAccordionItem
|
|
128
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AriaAccordionProps } from '@react-types/accordion';
|
|
2
|
+
import { RefObject, ButtonHTMLAttributes } from 'react';
|
|
3
|
+
import { DOMAttributes, Node } from '@react-types/shared';
|
|
4
|
+
import { TreeState } from '@react-stately/tree';
|
|
5
|
+
|
|
6
|
+
interface AccordionAria {
|
|
7
|
+
/** Props for the accordion container element. */
|
|
8
|
+
accordionProps: DOMAttributes;
|
|
9
|
+
}
|
|
10
|
+
interface AccordionItemAriaProps<T> {
|
|
11
|
+
item: Node<T>;
|
|
12
|
+
}
|
|
13
|
+
interface AccordionItemAria {
|
|
14
|
+
/** Props for the accordion item button. */
|
|
15
|
+
buttonProps: ButtonHTMLAttributes<HTMLElement>;
|
|
16
|
+
/** Props for the accordion item content element. */
|
|
17
|
+
regionProps: DOMAttributes;
|
|
18
|
+
}
|
|
19
|
+
declare function useReactAriaAccordion<T>(props: AriaAccordionProps<T>, state: TreeState<T>, ref: RefObject<HTMLDivElement>): AccordionAria;
|
|
20
|
+
|
|
21
|
+
export { type AccordionAria, type AccordionItemAria, type AccordionItemAriaProps, useReactAriaAccordion };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AriaAccordionProps } from '@react-types/accordion';
|
|
2
|
+
import { RefObject, ButtonHTMLAttributes } from 'react';
|
|
3
|
+
import { DOMAttributes, Node } from '@react-types/shared';
|
|
4
|
+
import { TreeState } from '@react-stately/tree';
|
|
5
|
+
|
|
6
|
+
interface AccordionAria {
|
|
7
|
+
/** Props for the accordion container element. */
|
|
8
|
+
accordionProps: DOMAttributes;
|
|
9
|
+
}
|
|
10
|
+
interface AccordionItemAriaProps<T> {
|
|
11
|
+
item: Node<T>;
|
|
12
|
+
}
|
|
13
|
+
interface AccordionItemAria {
|
|
14
|
+
/** Props for the accordion item button. */
|
|
15
|
+
buttonProps: ButtonHTMLAttributes<HTMLElement>;
|
|
16
|
+
/** Props for the accordion item content element. */
|
|
17
|
+
regionProps: DOMAttributes;
|
|
18
|
+
}
|
|
19
|
+
declare function useReactAriaAccordion<T>(props: AriaAccordionProps<T>, state: TreeState<T>, ref: RefObject<HTMLDivElement>): AccordionAria;
|
|
20
|
+
|
|
21
|
+
export { type AccordionAria, type AccordionItemAria, type AccordionItemAriaProps, useReactAriaAccordion };
|
|
@@ -0,0 +1,46 @@
|
|
|
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/use-accordion.ts
|
|
21
|
+
var use_accordion_exports = {};
|
|
22
|
+
__export(use_accordion_exports, {
|
|
23
|
+
useReactAriaAccordion: () => useReactAriaAccordion
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(use_accordion_exports);
|
|
26
|
+
var import_selection = require("@react-aria/selection");
|
|
27
|
+
function useReactAriaAccordion(props, state, ref) {
|
|
28
|
+
let { listProps } = (0, import_selection.useSelectableList)({
|
|
29
|
+
...props,
|
|
30
|
+
...state,
|
|
31
|
+
allowsTabNavigation: true,
|
|
32
|
+
disallowSelectAll: true,
|
|
33
|
+
ref
|
|
34
|
+
});
|
|
35
|
+
delete listProps.onKeyDownCapture;
|
|
36
|
+
return {
|
|
37
|
+
accordionProps: {
|
|
38
|
+
...listProps,
|
|
39
|
+
tabIndex: void 0
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
useReactAriaAccordion
|
|
46
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vx-oss/heroui-v2-use-aria-accordion",
|
|
3
|
+
"version": "2.2.19-alpha.0",
|
|
4
|
+
"description": "React-aria useAccordion hooks with custom implementations",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"use-aria-accordion"
|
|
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-accordion"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/vezham/heroui-v2/issues"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@react-aria/button": "3.14.2",
|
|
29
|
+
"@react-aria/focus": "3.21.2",
|
|
30
|
+
"@react-aria/selection": "3.26.0",
|
|
31
|
+
"@react-stately/tree": "3.9.3",
|
|
32
|
+
"@react-types/accordion": "3.0.0-alpha.26",
|
|
33
|
+
"@react-types/shared": "3.32.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=18 || >=19.0.0-rc.0"
|
|
37
|
+
},
|
|
38
|
+
"clean-package": "../../../clean-package.config.json",
|
|
39
|
+
"tsup": {
|
|
40
|
+
"clean": true,
|
|
41
|
+
"target": "es2019",
|
|
42
|
+
"format": [
|
|
43
|
+
"cjs",
|
|
44
|
+
"esm"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
"module": "dist/index.mjs",
|
|
48
|
+
"types": "dist/index.d.ts",
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"types": "./dist/index.d.ts",
|
|
52
|
+
"import": "./dist/index.mjs",
|
|
53
|
+
"require": "./dist/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup src --dts",
|
|
59
|
+
"build:fast": "tsup src",
|
|
60
|
+
"dev": "pnpm build:fast --watch",
|
|
61
|
+
"clean": "rimraf dist .turbo",
|
|
62
|
+
"typecheck": "tsc --noEmit"
|
|
63
|
+
}
|
|
64
|
+
}
|