@react-aria/disclosure 3.1.3 → 3.2.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/dist/import.mjs +2 -2
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +15 -15
- package/src/index.ts +3 -2
- package/dist/types.d.ts +0 -28
- package/dist/types.d.ts.map +0 -1
- package/dist/useDisclosure.main.js +0 -125
- package/dist/useDisclosure.main.js.map +0 -1
- package/dist/useDisclosure.mjs +0 -120
- package/dist/useDisclosure.module.js +0 -120
- package/dist/useDisclosure.module.js.map +0 -1
- package/src/useDisclosure.ts +0 -161
package/dist/import.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useDisclosure as $
|
|
1
|
+
import {useDisclosure as $b706a02f02d9204c$re_export$useDisclosure} from "react-aria/useDisclosure";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -13,5 +13,5 @@ import {useDisclosure as $5e910fae8e128ead$export$6e3e27031a30522f} from "./useD
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
export {$
|
|
16
|
+
export {$b706a02f02d9204c$re_export$useDisclosure as useDisclosure};
|
|
17
17
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $6wAEm$reactariauseDisclosure = require("react-aria/useDisclosure");
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
function $parcel$export(e, n, v, s) {
|
|
5
5
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
$parcel$export(module.exports, "useDisclosure", ()
|
|
8
|
+
$parcel$export(module.exports, "useDisclosure", function () { return $6wAEm$reactariauseDisclosure.useDisclosure; });
|
|
9
9
|
/*
|
|
10
10
|
* Copyright 2020 Adobe. All rights reserved.
|
|
11
11
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/disclosure/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDisclosure} from '
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/disclosure/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDisclosure} from 'react-aria/useDisclosure';\n\nexport type {DisclosureAria, AriaDisclosureProps} from 'react-aria/useDisclosure';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useDisclosure as $
|
|
1
|
+
import {useDisclosure as $b706a02f02d9204c$re_export$useDisclosure} from "react-aria/useDisclosure";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -13,5 +13,5 @@ import {useDisclosure as $5e910fae8e128ead$export$6e3e27031a30522f} from "./useD
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
export {$
|
|
16
|
+
export {$b706a02f02d9204c$re_export$useDisclosure as useDisclosure};
|
|
17
17
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/disclosure/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDisclosure} from '
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/disclosure/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDisclosure} from 'react-aria/useDisclosure';\n\nexport type {DisclosureAria, AriaDisclosureProps} from 'react-aria/useDisclosure';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/disclosure",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"./dist/types.d.ts",
|
|
12
|
-
"./
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"types": "./dist/types/src/index.d.ts",
|
|
12
|
+
"import": "./dist/import.mjs",
|
|
13
|
+
"require": "./dist/main.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
|
-
"types": "dist/types.d.ts",
|
|
17
|
+
"types": "dist/types/src/index.d.ts",
|
|
18
18
|
"source": "src/index.ts",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -26,11 +26,8 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"@react-stately/disclosure": "^3.0.11",
|
|
32
|
-
"@react-types/button": "^3.15.1",
|
|
33
|
-
"@swc/helpers": "^0.5.0"
|
|
29
|
+
"@swc/helpers": "^0.5.0",
|
|
30
|
+
"react-aria": "3.48.0"
|
|
34
31
|
},
|
|
35
32
|
"peerDependencies": {
|
|
36
33
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
@@ -39,5 +36,8 @@
|
|
|
39
36
|
"publishConfig": {
|
|
40
37
|
"access": "public"
|
|
41
38
|
},
|
|
42
|
-
"
|
|
39
|
+
"targets": {
|
|
40
|
+
"types": false
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,5 +9,6 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
export {useDisclosure} from '
|
|
13
|
-
|
|
12
|
+
export {useDisclosure} from 'react-aria/useDisclosure';
|
|
13
|
+
|
|
14
|
+
export type {DisclosureAria, AriaDisclosureProps} from 'react-aria/useDisclosure';
|
package/dist/types.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AriaButtonProps } from "@react-types/button";
|
|
2
|
-
import { DisclosureState } from "@react-stately/disclosure";
|
|
3
|
-
import { HTMLAttributes, RefObject } from "react";
|
|
4
|
-
export interface AriaDisclosureProps {
|
|
5
|
-
/** Whether the disclosure is disabled. */
|
|
6
|
-
isDisabled?: boolean;
|
|
7
|
-
/** Handler that is called when the disclosure's expanded state changes. */
|
|
8
|
-
onExpandedChange?: (isExpanded: boolean) => void;
|
|
9
|
-
/** Whether the disclosure is expanded (controlled). */
|
|
10
|
-
isExpanded?: boolean;
|
|
11
|
-
/** Whether the disclosure is expanded by default (uncontrolled). */
|
|
12
|
-
defaultExpanded?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface DisclosureAria {
|
|
15
|
-
/** Props for the disclosure button. */
|
|
16
|
-
buttonProps: AriaButtonProps;
|
|
17
|
-
/** Props for the disclosure panel. */
|
|
18
|
-
panelProps: HTMLAttributes<HTMLElement>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Provides the behavior and accessibility implementation for a disclosure component.
|
|
22
|
-
* @param props - Props for the disclosure.
|
|
23
|
-
* @param state - State for the disclosure, as returned by `useDisclosureState`.
|
|
24
|
-
* @param ref - A ref for the disclosure panel.
|
|
25
|
-
*/
|
|
26
|
-
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria;
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;AAmBA;IACE,0CAA0C;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oEAAoE;IACpE,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;IACE,uCAAuC;IACvC,WAAW,EAAE,eAAe,CAAC;IAC7B,sCAAsC;IACtC,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAED;;;;;GAKG;AACH,8BAA8B,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,cAAc,CAqHpI","sources":["packages/@react-aria/disclosure/src/packages/@react-aria/disclosure/src/useDisclosure.ts","packages/@react-aria/disclosure/src/packages/@react-aria/disclosure/src/index.ts","packages/@react-aria/disclosure/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDisclosure} from './useDisclosure';\nexport type {DisclosureAria, AriaDisclosureProps} from './useDisclosure';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
var $l3cx6$reactdom = require("react-dom");
|
|
2
|
-
var $l3cx6$react = require("react");
|
|
3
|
-
var $l3cx6$reactariautils = require("@react-aria/utils");
|
|
4
|
-
var $l3cx6$reactariassr = require("@react-aria/ssr");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function $parcel$export(e, n, v, s) {
|
|
8
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
$parcel$export(module.exports, "useDisclosure", () => $ef53cd1bcef2de68$export$6e3e27031a30522f);
|
|
12
|
-
/*
|
|
13
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
14
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
15
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
-
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
-
* governing permissions and limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
|
|
27
|
-
let { isDisabled: isDisabled } = props;
|
|
28
|
-
let triggerId = (0, $l3cx6$reactariautils.useId)();
|
|
29
|
-
let panelId = (0, $l3cx6$reactariautils.useId)();
|
|
30
|
-
let isSSR = (0, $l3cx6$reactariassr.useIsSSR)();
|
|
31
|
-
let raf = (0, $l3cx6$react.useRef)(null);
|
|
32
|
-
let handleBeforeMatch = (0, $l3cx6$react.useCallback)(()=>{
|
|
33
|
-
// Wait a frame to revert browser's removal of hidden attribute
|
|
34
|
-
raf.current = requestAnimationFrame(()=>{
|
|
35
|
-
if (ref.current) ref.current.setAttribute('hidden', 'until-found');
|
|
36
|
-
});
|
|
37
|
-
// Force sync state update
|
|
38
|
-
(0, $l3cx6$reactdom.flushSync)(()=>{
|
|
39
|
-
state.toggle();
|
|
40
|
-
});
|
|
41
|
-
}, [
|
|
42
|
-
ref,
|
|
43
|
-
state
|
|
44
|
-
]);
|
|
45
|
-
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
46
|
-
(0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', handleBeforeMatch);
|
|
47
|
-
let isExpandedRef = (0, $l3cx6$react.useRef)(null);
|
|
48
|
-
(0, $l3cx6$reactariautils.useLayoutEffect)(()=>{
|
|
49
|
-
// Cancel any pending RAF to prevent stale updates
|
|
50
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
51
|
-
if (ref.current && !isSSR) {
|
|
52
|
-
let panel = ref.current;
|
|
53
|
-
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
54
|
-
// On initial render (and in tests), set attributes without animation.
|
|
55
|
-
if (state.isExpanded) {
|
|
56
|
-
panel.removeAttribute('hidden');
|
|
57
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
58
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
59
|
-
} else {
|
|
60
|
-
panel.setAttribute('hidden', 'until-found');
|
|
61
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
62
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
63
|
-
}
|
|
64
|
-
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
65
|
-
if (state.isExpanded) {
|
|
66
|
-
panel.removeAttribute('hidden');
|
|
67
|
-
// Set the width and height as pixels so they can be animated.
|
|
68
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
69
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
70
|
-
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>{
|
|
71
|
-
// After the animations complete, switch back to auto so the content can resize.
|
|
72
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
73
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
74
|
-
}).catch(()=>{});
|
|
75
|
-
} else {
|
|
76
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
77
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
78
|
-
// Force style re-calculation to trigger animations.
|
|
79
|
-
window.getComputedStyle(panel).height;
|
|
80
|
-
// Animate to zero size.
|
|
81
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
82
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
83
|
-
// Wait for animations to apply the hidden attribute.
|
|
84
|
-
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>panel.setAttribute('hidden', 'until-found')).catch(()=>{});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
isExpandedRef.current = state.isExpanded;
|
|
88
|
-
}
|
|
89
|
-
}, [
|
|
90
|
-
isDisabled,
|
|
91
|
-
ref,
|
|
92
|
-
state.isExpanded,
|
|
93
|
-
isSSR
|
|
94
|
-
]);
|
|
95
|
-
(0, $l3cx6$react.useEffect)(()=>{
|
|
96
|
-
return ()=>{
|
|
97
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
98
|
-
};
|
|
99
|
-
}, []);
|
|
100
|
-
return {
|
|
101
|
-
buttonProps: {
|
|
102
|
-
id: triggerId,
|
|
103
|
-
'aria-expanded': state.isExpanded,
|
|
104
|
-
'aria-controls': panelId,
|
|
105
|
-
onPress: (e)=>{
|
|
106
|
-
if (!isDisabled && e.pointerType !== 'keyboard') state.toggle();
|
|
107
|
-
},
|
|
108
|
-
isDisabled: isDisabled,
|
|
109
|
-
onPressStart (e) {
|
|
110
|
-
if (e.pointerType === 'keyboard' && !isDisabled) state.toggle();
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
panelProps: {
|
|
114
|
-
id: panelId,
|
|
115
|
-
// This can be overridden at the panel element level.
|
|
116
|
-
role: 'group',
|
|
117
|
-
'aria-labelledby': triggerId,
|
|
118
|
-
'aria-hidden': !state.isExpanded,
|
|
119
|
-
hidden: isSSR ? !state.isExpanded : undefined
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
//# sourceMappingURL=useDisclosure.main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAAkC;IAClH,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,UAAU,CAAA,GAAA,2BAAI;IAClB,IAAI,QAAQ,CAAA,GAAA,4BAAO;IAEnB,IAAI,MAAM,CAAA,GAAA,mBAAK,EAAiB;IAEhC,IAAI,oBAAoB,CAAA,GAAA,wBAAU,EAAE;QAClC,+DAA+D;QAC/D,IAAI,OAAO,GAAG,sBAAsB;YAClC,IAAI,IAAI,OAAO,EACb,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;QAEvC;QACA,0BAA0B;QAC1B,CAAA,GAAA,yBAAQ,EAAE;YACR,MAAM,MAAM;QACd;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,0DAA0D;IAC1D,CAAA,GAAA,8BAAO,EAAE,KAAK,eAAe;IAE7B,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAkB;IAC3C,CAAA,GAAA,qCAAc,EAAE;QACd,kDAAkD;QAClD,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAElC,IAAI,IAAI,OAAO,IAAI,CAAC,OAAO;YACzB,IAAI,QAAQ,IAAI,OAAO;YAEvB,IAAI,cAAc,OAAO,IAAI,QAAQ,OAAO,MAAM,aAAa,KAAK;gBAClE,sEAAsE;gBACtE,IAAI,MAAM,UAAU,EAAE;oBACpB,MAAM,eAAe,CAAC;oBACtB,MAAM,KAAK,CAAC,WAAW,CAAC,4BAA4B;oBACpD,MAAM,KAAK,CAAC,WAAW,CAAC,6BAA6B;gBACvD,OAAO;oBACL,MAAM,YAAY,CAAC,UAAU;oBAC7B,MAAM,KAAK,CAAC,WAAW,CAAC,4BAA4B;oBACpD,MAAM,KAAK,CAAC,WAAW,CAAC,6BAA6B;gBACvD;mBACK,IAAI,MAAM,UAAU,KAAK,cAAc,OAAO;gBACnD,IAAI,MAAM,UAAU,EAAE;oBACpB,MAAM,eAAe,CAAC;oBAEtB,8DAA8D;oBAC9D,MAAM,KAAK,CAAC,WAAW,CAAC,4BAA4B,MAAM,WAAW,GAAG;oBACxE,MAAM,KAAK,CAAC,WAAW,CAAC,6BAA6B,MAAM,YAAY,GAAG;oBAE1E,QAAQ,GAAG,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,CAAA,IAAK,EAAE,QAAQ,GAClD,IAAI,CAAC;wBACJ,gFAAgF;wBAChF,MAAM,KAAK,CAAC,WAAW,CAAC,4BAA4B;wBACpD,MAAM,KAAK,CAAC,WAAW,CAAC,6BAA6B;oBACvD,GACC,KAAK,CAAC,KAAO;gBAClB,OAAO;oBACL,MAAM,KAAK,CAAC,WAAW,CAAC,4BAA4B,MAAM,WAAW,GAAG;oBACxE,MAAM,KAAK,CAAC,WAAW,CAAC,6BAA6B,MAAM,YAAY,GAAG;oBAE1E,oDAAoD;oBACpD,OAAO,gBAAgB,CAAC,OAAO,MAAM;oBAErC,wBAAwB;oBACxB,MAAM,KAAK,CAAC,WAAW,CAAC,4BAA4B;oBACpD,MAAM,KAAK,CAAC,WAAW,CAAC,6BAA6B;oBAErD,qDAAqD;oBACrD,QAAQ,GAAG,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,CAAA,IAAK,EAAE,QAAQ,GAClD,IAAI,CAAC,IAAM,MAAM,YAAY,CAAC,UAAU,gBACxC,KAAK,CAAC,KAAO;gBAClB;;YAGF,cAAc,OAAO,GAAG,MAAM,UAAU;QAC1C;IACF,GAAG;QAAC;QAAY;QAAK,MAAM,UAAU;QAAE;KAAM;IAE7C,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAEpC;IACF,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YACX,IAAI;YACJ,iBAAiB,MAAM,UAAU;YACjC,iBAAiB;YACjB,SAAS,CAAC;gBACR,IAAI,CAAC,cAAc,EAAE,WAAW,KAAK,YACnC,MAAM,MAAM;YAEhB;wBACA;YACA,cAAa,CAAC;gBACZ,IAAI,EAAE,WAAW,KAAK,cAAc,CAAC,YACnC,MAAM,MAAM;YAEhB;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,eAAe,CAAC,MAAM,UAAU;YAChC,QAAQ,QAAQ,CAAC,MAAM,UAAU,GAAG;QACtC;IACF;AACF","sources":["packages/@react-aria/disclosure/src/useDisclosure.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the 'License');\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DisclosureState} from '@react-stately/disclosure';\nimport {flushSync} from 'react-dom';\nimport {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';\nimport {useEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport interface AriaDisclosureProps {\n /** Whether the disclosure is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the disclosure's expanded state changes. */\n onExpandedChange?: (isExpanded: boolean) => void,\n /** Whether the disclosure is expanded (controlled). */\n isExpanded?: boolean,\n /** Whether the disclosure is expanded by default (uncontrolled). */\n defaultExpanded?: boolean\n}\n\nexport interface DisclosureAria {\n /** Props for the disclosure button. */\n buttonProps: AriaButtonProps,\n /** Props for the disclosure panel. */\n panelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a disclosure component.\n * @param props - Props for the disclosure.\n * @param state - State for the disclosure, as returned by `useDisclosureState`.\n * @param ref - A ref for the disclosure panel.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let panelId = useId();\n let isSSR = useIsSSR();\n\n let raf = useRef<number | null>(null);\n\n let handleBeforeMatch = useCallback(() => {\n // Wait a frame to revert browser's removal of hidden attribute\n raf.current = requestAnimationFrame(() => {\n if (ref.current) {\n ref.current.setAttribute('hidden', 'until-found');\n }\n });\n // Force sync state update\n flushSync(() => {\n state.toggle();\n });\n }, [ref, state]);\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', handleBeforeMatch);\n\n let isExpandedRef = useRef<boolean | null>(null);\n useLayoutEffect(() => {\n // Cancel any pending RAF to prevent stale updates\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n if (ref.current && !isSSR) {\n let panel = ref.current;\n\n if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {\n // On initial render (and in tests), set attributes without animation.\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n } else {\n panel.setAttribute('hidden', 'until-found');\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n }\n } else if (state.isExpanded !== isExpandedRef.current) {\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n\n // Set the width and height as pixels so they can be animated.\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => {\n // After the animations complete, switch back to auto so the content can resize.\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n })\n .catch(() => {});\n } else {\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n // Force style re-calculation to trigger animations.\n window.getComputedStyle(panel).height;\n\n // Animate to zero size.\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n\n // Wait for animations to apply the hidden attribute.\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => panel.setAttribute('hidden', 'until-found'))\n .catch(() => {});\n }\n }\n\n isExpandedRef.current = state.isExpanded;\n }\n }, [isDisabled, ref, state.isExpanded, isSSR]);\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': panelId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onPressStart(e) {\n if (e.pointerType === 'keyboard' && !isDisabled) {\n state.toggle();\n }\n }\n },\n panelProps: {\n id: panelId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n 'aria-hidden': !state.isExpanded,\n hidden: isSSR ? !state.isExpanded : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.main.js.map"}
|
package/dist/useDisclosure.mjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {flushSync as $6wN6e$flushSync} from "react-dom";
|
|
2
|
-
import {useRef as $6wN6e$useRef, useCallback as $6wN6e$useCallback, useEffect as $6wN6e$useEffect} from "react";
|
|
3
|
-
import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent, useLayoutEffect as $6wN6e$useLayoutEffect} from "@react-aria/utils";
|
|
4
|
-
import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
8
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
9
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
-
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
-
* governing permissions and limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
21
|
-
let { isDisabled: isDisabled } = props;
|
|
22
|
-
let triggerId = (0, $6wN6e$useId)();
|
|
23
|
-
let panelId = (0, $6wN6e$useId)();
|
|
24
|
-
let isSSR = (0, $6wN6e$useIsSSR)();
|
|
25
|
-
let raf = (0, $6wN6e$useRef)(null);
|
|
26
|
-
let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
|
|
27
|
-
// Wait a frame to revert browser's removal of hidden attribute
|
|
28
|
-
raf.current = requestAnimationFrame(()=>{
|
|
29
|
-
if (ref.current) ref.current.setAttribute('hidden', 'until-found');
|
|
30
|
-
});
|
|
31
|
-
// Force sync state update
|
|
32
|
-
(0, $6wN6e$flushSync)(()=>{
|
|
33
|
-
state.toggle();
|
|
34
|
-
});
|
|
35
|
-
}, [
|
|
36
|
-
ref,
|
|
37
|
-
state
|
|
38
|
-
]);
|
|
39
|
-
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
40
|
-
(0, $6wN6e$useEvent)(ref, 'beforematch', handleBeforeMatch);
|
|
41
|
-
let isExpandedRef = (0, $6wN6e$useRef)(null);
|
|
42
|
-
(0, $6wN6e$useLayoutEffect)(()=>{
|
|
43
|
-
// Cancel any pending RAF to prevent stale updates
|
|
44
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
45
|
-
if (ref.current && !isSSR) {
|
|
46
|
-
let panel = ref.current;
|
|
47
|
-
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
48
|
-
// On initial render (and in tests), set attributes without animation.
|
|
49
|
-
if (state.isExpanded) {
|
|
50
|
-
panel.removeAttribute('hidden');
|
|
51
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
52
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
53
|
-
} else {
|
|
54
|
-
panel.setAttribute('hidden', 'until-found');
|
|
55
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
56
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
57
|
-
}
|
|
58
|
-
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
59
|
-
if (state.isExpanded) {
|
|
60
|
-
panel.removeAttribute('hidden');
|
|
61
|
-
// Set the width and height as pixels so they can be animated.
|
|
62
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
63
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
64
|
-
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>{
|
|
65
|
-
// After the animations complete, switch back to auto so the content can resize.
|
|
66
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
67
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
68
|
-
}).catch(()=>{});
|
|
69
|
-
} else {
|
|
70
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
71
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
72
|
-
// Force style re-calculation to trigger animations.
|
|
73
|
-
window.getComputedStyle(panel).height;
|
|
74
|
-
// Animate to zero size.
|
|
75
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
76
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
77
|
-
// Wait for animations to apply the hidden attribute.
|
|
78
|
-
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>panel.setAttribute('hidden', 'until-found')).catch(()=>{});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
isExpandedRef.current = state.isExpanded;
|
|
82
|
-
}
|
|
83
|
-
}, [
|
|
84
|
-
isDisabled,
|
|
85
|
-
ref,
|
|
86
|
-
state.isExpanded,
|
|
87
|
-
isSSR
|
|
88
|
-
]);
|
|
89
|
-
(0, $6wN6e$useEffect)(()=>{
|
|
90
|
-
return ()=>{
|
|
91
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
92
|
-
};
|
|
93
|
-
}, []);
|
|
94
|
-
return {
|
|
95
|
-
buttonProps: {
|
|
96
|
-
id: triggerId,
|
|
97
|
-
'aria-expanded': state.isExpanded,
|
|
98
|
-
'aria-controls': panelId,
|
|
99
|
-
onPress: (e)=>{
|
|
100
|
-
if (!isDisabled && e.pointerType !== 'keyboard') state.toggle();
|
|
101
|
-
},
|
|
102
|
-
isDisabled: isDisabled,
|
|
103
|
-
onPressStart (e) {
|
|
104
|
-
if (e.pointerType === 'keyboard' && !isDisabled) state.toggle();
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
panelProps: {
|
|
108
|
-
id: panelId,
|
|
109
|
-
// This can be overridden at the panel element level.
|
|
110
|
-
role: 'group',
|
|
111
|
-
'aria-labelledby': triggerId,
|
|
112
|
-
'aria-hidden': !state.isExpanded,
|
|
113
|
-
hidden: isSSR ? !state.isExpanded : undefined
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
export {$5e910fae8e128ead$export$6e3e27031a30522f as useDisclosure};
|
|
120
|
-
//# sourceMappingURL=useDisclosure.module.js.map
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {flushSync as $6wN6e$flushSync} from "react-dom";
|
|
2
|
-
import {useRef as $6wN6e$useRef, useCallback as $6wN6e$useCallback, useEffect as $6wN6e$useEffect} from "react";
|
|
3
|
-
import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent, useLayoutEffect as $6wN6e$useLayoutEffect} from "@react-aria/utils";
|
|
4
|
-
import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
8
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
9
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
-
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
-
* governing permissions and limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
21
|
-
let { isDisabled: isDisabled } = props;
|
|
22
|
-
let triggerId = (0, $6wN6e$useId)();
|
|
23
|
-
let panelId = (0, $6wN6e$useId)();
|
|
24
|
-
let isSSR = (0, $6wN6e$useIsSSR)();
|
|
25
|
-
let raf = (0, $6wN6e$useRef)(null);
|
|
26
|
-
let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
|
|
27
|
-
// Wait a frame to revert browser's removal of hidden attribute
|
|
28
|
-
raf.current = requestAnimationFrame(()=>{
|
|
29
|
-
if (ref.current) ref.current.setAttribute('hidden', 'until-found');
|
|
30
|
-
});
|
|
31
|
-
// Force sync state update
|
|
32
|
-
(0, $6wN6e$flushSync)(()=>{
|
|
33
|
-
state.toggle();
|
|
34
|
-
});
|
|
35
|
-
}, [
|
|
36
|
-
ref,
|
|
37
|
-
state
|
|
38
|
-
]);
|
|
39
|
-
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
40
|
-
(0, $6wN6e$useEvent)(ref, 'beforematch', handleBeforeMatch);
|
|
41
|
-
let isExpandedRef = (0, $6wN6e$useRef)(null);
|
|
42
|
-
(0, $6wN6e$useLayoutEffect)(()=>{
|
|
43
|
-
// Cancel any pending RAF to prevent stale updates
|
|
44
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
45
|
-
if (ref.current && !isSSR) {
|
|
46
|
-
let panel = ref.current;
|
|
47
|
-
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
48
|
-
// On initial render (and in tests), set attributes without animation.
|
|
49
|
-
if (state.isExpanded) {
|
|
50
|
-
panel.removeAttribute('hidden');
|
|
51
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
52
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
53
|
-
} else {
|
|
54
|
-
panel.setAttribute('hidden', 'until-found');
|
|
55
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
56
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
57
|
-
}
|
|
58
|
-
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
59
|
-
if (state.isExpanded) {
|
|
60
|
-
panel.removeAttribute('hidden');
|
|
61
|
-
// Set the width and height as pixels so they can be animated.
|
|
62
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
63
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
64
|
-
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>{
|
|
65
|
-
// After the animations complete, switch back to auto so the content can resize.
|
|
66
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
67
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
68
|
-
}).catch(()=>{});
|
|
69
|
-
} else {
|
|
70
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
71
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
72
|
-
// Force style re-calculation to trigger animations.
|
|
73
|
-
window.getComputedStyle(panel).height;
|
|
74
|
-
// Animate to zero size.
|
|
75
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
76
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
77
|
-
// Wait for animations to apply the hidden attribute.
|
|
78
|
-
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>panel.setAttribute('hidden', 'until-found')).catch(()=>{});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
isExpandedRef.current = state.isExpanded;
|
|
82
|
-
}
|
|
83
|
-
}, [
|
|
84
|
-
isDisabled,
|
|
85
|
-
ref,
|
|
86
|
-
state.isExpanded,
|
|
87
|
-
isSSR
|
|
88
|
-
]);
|
|
89
|
-
(0, $6wN6e$useEffect)(()=>{
|
|
90
|
-
return ()=>{
|
|
91
|
-
if (raf.current) cancelAnimationFrame(raf.current);
|
|
92
|
-
};
|
|
93
|
-
}, []);
|
|
94
|
-
return {
|
|
95
|
-
buttonProps: {
|
|
96
|
-
id: triggerId,
|
|
97
|
-
'aria-expanded': state.isExpanded,
|
|
98
|
-
'aria-controls': panelId,
|
|
99
|
-
onPress: (e)=>{
|
|
100
|
-
if (!isDisabled && e.pointerType !== 'keyboard') state.toggle();
|
|
101
|
-
},
|
|
102
|
-
isDisabled: isDisabled,
|
|
103
|
-
onPressStart (e) {
|
|
104
|
-
if (e.pointerType === 'keyboard' && !isDisabled) state.toggle();
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
panelProps: {
|
|
108
|
-
id: panelId,
|
|
109
|
-
// This can be overridden at the panel element level.
|
|
110
|
-
role: 'group',
|
|
111
|
-
'aria-labelledby': triggerId,
|
|
112
|
-
'aria-hidden': !state.isExpanded,
|
|
113
|
-
hidden: isSSR ? !state.isExpanded : undefined
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
export {$5e910fae8e128ead$export$6e3e27031a30522f as useDisclosure};
|
|
120
|
-
//# sourceMappingURL=useDisclosure.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"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","sources":["packages/@react-aria/disclosure/src/useDisclosure.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the 'License');\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DisclosureState} from '@react-stately/disclosure';\nimport {flushSync} from 'react-dom';\nimport {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';\nimport {useEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport interface AriaDisclosureProps {\n /** Whether the disclosure is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the disclosure's expanded state changes. */\n onExpandedChange?: (isExpanded: boolean) => void,\n /** Whether the disclosure is expanded (controlled). */\n isExpanded?: boolean,\n /** Whether the disclosure is expanded by default (uncontrolled). */\n defaultExpanded?: boolean\n}\n\nexport interface DisclosureAria {\n /** Props for the disclosure button. */\n buttonProps: AriaButtonProps,\n /** Props for the disclosure panel. */\n panelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a disclosure component.\n * @param props - Props for the disclosure.\n * @param state - State for the disclosure, as returned by `useDisclosureState`.\n * @param ref - A ref for the disclosure panel.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let panelId = useId();\n let isSSR = useIsSSR();\n\n let raf = useRef<number | null>(null);\n\n let handleBeforeMatch = useCallback(() => {\n // Wait a frame to revert browser's removal of hidden attribute\n raf.current = requestAnimationFrame(() => {\n if (ref.current) {\n ref.current.setAttribute('hidden', 'until-found');\n }\n });\n // Force sync state update\n flushSync(() => {\n state.toggle();\n });\n }, [ref, state]);\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', handleBeforeMatch);\n\n let isExpandedRef = useRef<boolean | null>(null);\n useLayoutEffect(() => {\n // Cancel any pending RAF to prevent stale updates\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n if (ref.current && !isSSR) {\n let panel = ref.current;\n\n if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {\n // On initial render (and in tests), set attributes without animation.\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n } else {\n panel.setAttribute('hidden', 'until-found');\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n }\n } else if (state.isExpanded !== isExpandedRef.current) {\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n\n // Set the width and height as pixels so they can be animated.\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => {\n // After the animations complete, switch back to auto so the content can resize.\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n })\n .catch(() => {});\n } else {\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n // Force style re-calculation to trigger animations.\n window.getComputedStyle(panel).height;\n\n // Animate to zero size.\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n\n // Wait for animations to apply the hidden attribute.\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => panel.setAttribute('hidden', 'until-found'))\n .catch(() => {});\n }\n }\n\n isExpandedRef.current = state.isExpanded;\n }\n }, [isDisabled, ref, state.isExpanded, isSSR]);\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': panelId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onPressStart(e) {\n if (e.pointerType === 'keyboard' && !isDisabled) {\n state.toggle();\n }\n }\n },\n panelProps: {\n id: panelId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n 'aria-hidden': !state.isExpanded,\n hidden: isSSR ? !state.isExpanded : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.module.js.map"}
|
package/src/useDisclosure.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaButtonProps} from '@react-types/button';
|
|
14
|
-
import {DisclosureState} from '@react-stately/disclosure';
|
|
15
|
-
import {flushSync} from 'react-dom';
|
|
16
|
-
import {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';
|
|
17
|
-
import {useEvent, useId, useLayoutEffect} from '@react-aria/utils';
|
|
18
|
-
import {useIsSSR} from '@react-aria/ssr';
|
|
19
|
-
|
|
20
|
-
export interface AriaDisclosureProps {
|
|
21
|
-
/** Whether the disclosure is disabled. */
|
|
22
|
-
isDisabled?: boolean,
|
|
23
|
-
/** Handler that is called when the disclosure's expanded state changes. */
|
|
24
|
-
onExpandedChange?: (isExpanded: boolean) => void,
|
|
25
|
-
/** Whether the disclosure is expanded (controlled). */
|
|
26
|
-
isExpanded?: boolean,
|
|
27
|
-
/** Whether the disclosure is expanded by default (uncontrolled). */
|
|
28
|
-
defaultExpanded?: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface DisclosureAria {
|
|
32
|
-
/** Props for the disclosure button. */
|
|
33
|
-
buttonProps: AriaButtonProps,
|
|
34
|
-
/** Props for the disclosure panel. */
|
|
35
|
-
panelProps: HTMLAttributes<HTMLElement>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Provides the behavior and accessibility implementation for a disclosure component.
|
|
40
|
-
* @param props - Props for the disclosure.
|
|
41
|
-
* @param state - State for the disclosure, as returned by `useDisclosureState`.
|
|
42
|
-
* @param ref - A ref for the disclosure panel.
|
|
43
|
-
*/
|
|
44
|
-
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria {
|
|
45
|
-
let {
|
|
46
|
-
isDisabled
|
|
47
|
-
} = props;
|
|
48
|
-
let triggerId = useId();
|
|
49
|
-
let panelId = useId();
|
|
50
|
-
let isSSR = useIsSSR();
|
|
51
|
-
|
|
52
|
-
let raf = useRef<number | null>(null);
|
|
53
|
-
|
|
54
|
-
let handleBeforeMatch = useCallback(() => {
|
|
55
|
-
// Wait a frame to revert browser's removal of hidden attribute
|
|
56
|
-
raf.current = requestAnimationFrame(() => {
|
|
57
|
-
if (ref.current) {
|
|
58
|
-
ref.current.setAttribute('hidden', 'until-found');
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
// Force sync state update
|
|
62
|
-
flushSync(() => {
|
|
63
|
-
state.toggle();
|
|
64
|
-
});
|
|
65
|
-
}, [ref, state]);
|
|
66
|
-
|
|
67
|
-
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
68
|
-
useEvent(ref, 'beforematch', handleBeforeMatch);
|
|
69
|
-
|
|
70
|
-
let isExpandedRef = useRef<boolean | null>(null);
|
|
71
|
-
useLayoutEffect(() => {
|
|
72
|
-
// Cancel any pending RAF to prevent stale updates
|
|
73
|
-
if (raf.current) {
|
|
74
|
-
cancelAnimationFrame(raf.current);
|
|
75
|
-
}
|
|
76
|
-
if (ref.current && !isSSR) {
|
|
77
|
-
let panel = ref.current;
|
|
78
|
-
|
|
79
|
-
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
80
|
-
// On initial render (and in tests), set attributes without animation.
|
|
81
|
-
if (state.isExpanded) {
|
|
82
|
-
panel.removeAttribute('hidden');
|
|
83
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
84
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
85
|
-
} else {
|
|
86
|
-
panel.setAttribute('hidden', 'until-found');
|
|
87
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
88
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
89
|
-
}
|
|
90
|
-
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
91
|
-
if (state.isExpanded) {
|
|
92
|
-
panel.removeAttribute('hidden');
|
|
93
|
-
|
|
94
|
-
// Set the width and height as pixels so they can be animated.
|
|
95
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
96
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
97
|
-
|
|
98
|
-
Promise.all(panel.getAnimations().map(a => a.finished))
|
|
99
|
-
.then(() => {
|
|
100
|
-
// After the animations complete, switch back to auto so the content can resize.
|
|
101
|
-
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
102
|
-
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
103
|
-
})
|
|
104
|
-
.catch(() => {});
|
|
105
|
-
} else {
|
|
106
|
-
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
107
|
-
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
108
|
-
|
|
109
|
-
// Force style re-calculation to trigger animations.
|
|
110
|
-
window.getComputedStyle(panel).height;
|
|
111
|
-
|
|
112
|
-
// Animate to zero size.
|
|
113
|
-
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
114
|
-
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
115
|
-
|
|
116
|
-
// Wait for animations to apply the hidden attribute.
|
|
117
|
-
Promise.all(panel.getAnimations().map(a => a.finished))
|
|
118
|
-
.then(() => panel.setAttribute('hidden', 'until-found'))
|
|
119
|
-
.catch(() => {});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
isExpandedRef.current = state.isExpanded;
|
|
124
|
-
}
|
|
125
|
-
}, [isDisabled, ref, state.isExpanded, isSSR]);
|
|
126
|
-
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
return () => {
|
|
129
|
-
if (raf.current) {
|
|
130
|
-
cancelAnimationFrame(raf.current);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}, []);
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
buttonProps: {
|
|
137
|
-
id: triggerId,
|
|
138
|
-
'aria-expanded': state.isExpanded,
|
|
139
|
-
'aria-controls': panelId,
|
|
140
|
-
onPress: (e) => {
|
|
141
|
-
if (!isDisabled && e.pointerType !== 'keyboard') {
|
|
142
|
-
state.toggle();
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
isDisabled,
|
|
146
|
-
onPressStart(e) {
|
|
147
|
-
if (e.pointerType === 'keyboard' && !isDisabled) {
|
|
148
|
-
state.toggle();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
panelProps: {
|
|
153
|
-
id: panelId,
|
|
154
|
-
// This can be overridden at the panel element level.
|
|
155
|
-
role: 'group',
|
|
156
|
-
'aria-labelledby': triggerId,
|
|
157
|
-
'aria-hidden': !state.isExpanded,
|
|
158
|
-
hidden: isSSR ? !state.isExpanded : undefined
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|