@react-aria/disclosure 3.0.0-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/README.md +3 -0
- package/dist/import.mjs +17 -0
- package/dist/main.js +22 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +17 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useDisclosure.main.js +74 -0
- package/dist/useDisclosure.main.js.map +1 -0
- package/dist/useDisclosure.mjs +69 -0
- package/dist/useDisclosure.module.js +69 -0
- package/dist/useDisclosure.module.js.map +1 -0
- package/package.json +43 -0
- package/src/index.ts +13 -0
- package/src/useDisclosure.ts +93 -0
package/README.md
ADDED
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {useDisclosure as $5e910fae8e128ead$export$6e3e27031a30522f} from "./useDisclosure.mjs";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export {$5e910fae8e128ead$export$6e3e27031a30522f as useDisclosure};
|
|
17
|
+
//# sourceMappingURL=module.js.map
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var $ef53cd1bcef2de68$exports = require("./useDisclosure.main.js");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "useDisclosure", () => $ef53cd1bcef2de68$exports.useDisclosure);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +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 './useDisclosure';\nexport type {DisclosureAria, AriaDisclosureProps} from './useDisclosure';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {useDisclosure as $5e910fae8e128ead$export$6e3e27031a30522f} from "./useDisclosure.module.js";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export {$5e910fae8e128ead$export$6e3e27031a30522f as useDisclosure};
|
|
17
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +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 './useDisclosure';\nexport type {DisclosureAria, AriaDisclosureProps} from './useDisclosure';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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 content.
|
|
25
|
+
*/
|
|
26
|
+
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAkBA;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,CAAC,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,GAAG,cAAc,CAkDjI","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"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var $l3cx6$react = require("react");
|
|
2
|
+
var $l3cx6$reactariautils = require("@react-aria/utils");
|
|
3
|
+
var $l3cx6$reactariassr = require("@react-aria/ssr");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
$parcel$export(module.exports, "useDisclosure", () => $ef53cd1bcef2de68$export$6e3e27031a30522f);
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
|
|
25
|
+
let { isDisabled: isDisabled } = props;
|
|
26
|
+
let triggerId = (0, $l3cx6$reactariautils.useId)();
|
|
27
|
+
let contentId = (0, $l3cx6$reactariautils.useId)();
|
|
28
|
+
let isControlled = props.isExpanded !== undefined;
|
|
29
|
+
let isSSR = (0, $l3cx6$reactariassr.useIsSSR)();
|
|
30
|
+
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
31
|
+
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
32
|
+
(0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
|
|
33
|
+
(0, $l3cx6$react.useEffect)(()=>{
|
|
34
|
+
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
|
|
35
|
+
if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
|
|
36
|
+
if (state.isExpanded) ref.current.removeAttribute('hidden');
|
|
37
|
+
else ref.current.setAttribute('hidden', 'until-found');
|
|
38
|
+
}
|
|
39
|
+
}, [
|
|
40
|
+
isControlled,
|
|
41
|
+
ref,
|
|
42
|
+
props.isExpanded,
|
|
43
|
+
state,
|
|
44
|
+
supportsBeforeMatch,
|
|
45
|
+
isDisabled
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
buttonProps: {
|
|
49
|
+
id: triggerId,
|
|
50
|
+
'aria-expanded': state.isExpanded,
|
|
51
|
+
'aria-controls': contentId,
|
|
52
|
+
onPress: (e)=>{
|
|
53
|
+
if (!isDisabled && e.pointerType !== 'keyboard') state.toggle();
|
|
54
|
+
},
|
|
55
|
+
isDisabled: isDisabled,
|
|
56
|
+
onKeyDown (e) {
|
|
57
|
+
if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
state.toggle();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
panelProps: {
|
|
64
|
+
id: contentId,
|
|
65
|
+
// This can be overridden at the panel element level.
|
|
66
|
+
role: 'group',
|
|
67
|
+
'aria-labelledby': triggerId,
|
|
68
|
+
hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=useDisclosure.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAgCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAA+B;IAC/G,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,eAAe,MAAM,UAAU,KAAK;IACxC,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,sBAAsB,CAAC,SAAS,mBAAmB,SAAS,IAAI;IAEpE,0DAA0D;IAC1D,CAAA,GAAA,8BAAO,EAAE,KAAK,eAAe,uBAAuB,CAAC,eAAe,IAAM,MAAM,MAAM,KAAK;IAE3F,CAAA,GAAA,sBAAQ,EAAE;QACR,0FAA0F;QAC1F,IAAI,wBAAuB,gBAAA,0BAAA,IAAK,OAAO,KAAI,CAAC,gBAAgB,CAAC;YAC3D,IAAI,MAAM,UAAU,EAClB,IAAI,OAAO,CAAC,eAAe,CAAC;iBAE5B,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;;IAGzC,GAAG;QAAC;QAAc;QAAK,MAAM,UAAU;QAAE;QAAO;QAAqB;KAAW;IAEhF,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,WAAU,CAAC;gBACT,IAAI,CAAC,cAAe,CAAA,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,GAAE,GAAI;oBACvD,EAAE,cAAc;oBAChB,MAAM,MAAM;gBACd;YACF;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,QAAQ,AAAC,CAAC,uBAAuB,eAAgB,CAAC,MAAM,UAAU,GAAG;QACvE;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 {HTMLAttributes, RefObject, useEffect} from 'react';\nimport {useEvent, useId} 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 content.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let contentId = useId();\n let isControlled = props.isExpanded !== undefined;\n let isSSR = useIsSSR();\n let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);\n\n useEffect(() => {\n // Until React supports hidden=\"until-found\": https://github.com/facebook/react/pull/24741\n if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {\n if (state.isExpanded) {\n ref.current.removeAttribute('hidden');\n } else {\n ref.current.setAttribute('hidden', 'until-found');\n }\n }\n }, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': contentId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onKeyDown(e) {\n if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {\n e.preventDefault();\n state.toggle();\n }\n }\n },\n panelProps: {\n id: contentId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.main.js.map"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {useEffect as $6wN6e$useEffect} from "react";
|
|
2
|
+
import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent} from "@react-aria/utils";
|
|
3
|
+
import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
19
|
+
let { isDisabled: isDisabled } = props;
|
|
20
|
+
let triggerId = (0, $6wN6e$useId)();
|
|
21
|
+
let contentId = (0, $6wN6e$useId)();
|
|
22
|
+
let isControlled = props.isExpanded !== undefined;
|
|
23
|
+
let isSSR = (0, $6wN6e$useIsSSR)();
|
|
24
|
+
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
25
|
+
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
26
|
+
(0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
|
|
27
|
+
(0, $6wN6e$useEffect)(()=>{
|
|
28
|
+
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
|
|
29
|
+
if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
|
|
30
|
+
if (state.isExpanded) ref.current.removeAttribute('hidden');
|
|
31
|
+
else ref.current.setAttribute('hidden', 'until-found');
|
|
32
|
+
}
|
|
33
|
+
}, [
|
|
34
|
+
isControlled,
|
|
35
|
+
ref,
|
|
36
|
+
props.isExpanded,
|
|
37
|
+
state,
|
|
38
|
+
supportsBeforeMatch,
|
|
39
|
+
isDisabled
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
buttonProps: {
|
|
43
|
+
id: triggerId,
|
|
44
|
+
'aria-expanded': state.isExpanded,
|
|
45
|
+
'aria-controls': contentId,
|
|
46
|
+
onPress: (e)=>{
|
|
47
|
+
if (!isDisabled && e.pointerType !== 'keyboard') state.toggle();
|
|
48
|
+
},
|
|
49
|
+
isDisabled: isDisabled,
|
|
50
|
+
onKeyDown (e) {
|
|
51
|
+
if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
state.toggle();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
panelProps: {
|
|
58
|
+
id: contentId,
|
|
59
|
+
// This can be overridden at the panel element level.
|
|
60
|
+
role: 'group',
|
|
61
|
+
'aria-labelledby': triggerId,
|
|
62
|
+
hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
export {$5e910fae8e128ead$export$6e3e27031a30522f as useDisclosure};
|
|
69
|
+
//# sourceMappingURL=useDisclosure.module.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {useEffect as $6wN6e$useEffect} from "react";
|
|
2
|
+
import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent} from "@react-aria/utils";
|
|
3
|
+
import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
19
|
+
let { isDisabled: isDisabled } = props;
|
|
20
|
+
let triggerId = (0, $6wN6e$useId)();
|
|
21
|
+
let contentId = (0, $6wN6e$useId)();
|
|
22
|
+
let isControlled = props.isExpanded !== undefined;
|
|
23
|
+
let isSSR = (0, $6wN6e$useIsSSR)();
|
|
24
|
+
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
25
|
+
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
26
|
+
(0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
|
|
27
|
+
(0, $6wN6e$useEffect)(()=>{
|
|
28
|
+
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
|
|
29
|
+
if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
|
|
30
|
+
if (state.isExpanded) ref.current.removeAttribute('hidden');
|
|
31
|
+
else ref.current.setAttribute('hidden', 'until-found');
|
|
32
|
+
}
|
|
33
|
+
}, [
|
|
34
|
+
isControlled,
|
|
35
|
+
ref,
|
|
36
|
+
props.isExpanded,
|
|
37
|
+
state,
|
|
38
|
+
supportsBeforeMatch,
|
|
39
|
+
isDisabled
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
buttonProps: {
|
|
43
|
+
id: triggerId,
|
|
44
|
+
'aria-expanded': state.isExpanded,
|
|
45
|
+
'aria-controls': contentId,
|
|
46
|
+
onPress: (e)=>{
|
|
47
|
+
if (!isDisabled && e.pointerType !== 'keyboard') state.toggle();
|
|
48
|
+
},
|
|
49
|
+
isDisabled: isDisabled,
|
|
50
|
+
onKeyDown (e) {
|
|
51
|
+
if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
state.toggle();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
panelProps: {
|
|
58
|
+
id: contentId,
|
|
59
|
+
// This can be overridden at the panel element level.
|
|
60
|
+
role: 'group',
|
|
61
|
+
'aria-labelledby': triggerId,
|
|
62
|
+
hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
export {$5e910fae8e128ead$export$6e3e27031a30522f as useDisclosure};
|
|
69
|
+
//# sourceMappingURL=useDisclosure.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAgCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAA+B;IAC/G,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,eAAe,MAAM,UAAU,KAAK;IACxC,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,sBAAsB,CAAC,SAAS,mBAAmB,SAAS,IAAI;IAEpE,0DAA0D;IAC1D,CAAA,GAAA,eAAO,EAAE,KAAK,eAAe,uBAAuB,CAAC,eAAe,IAAM,MAAM,MAAM,KAAK;IAE3F,CAAA,GAAA,gBAAQ,EAAE;QACR,0FAA0F;QAC1F,IAAI,wBAAuB,gBAAA,0BAAA,IAAK,OAAO,KAAI,CAAC,gBAAgB,CAAC;YAC3D,IAAI,MAAM,UAAU,EAClB,IAAI,OAAO,CAAC,eAAe,CAAC;iBAE5B,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;;IAGzC,GAAG;QAAC;QAAc;QAAK,MAAM,UAAU;QAAE;QAAO;QAAqB;KAAW;IAEhF,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,WAAU,CAAC;gBACT,IAAI,CAAC,cAAe,CAAA,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,GAAE,GAAI;oBACvD,EAAE,cAAc;oBAChB,MAAM,MAAM;gBACd;YACF;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,QAAQ,AAAC,CAAC,uBAAuB,eAAgB,CAAC,MAAM,UAAU,GAAG;QACvE;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 {HTMLAttributes, RefObject, useEffect} from 'react';\nimport {useEvent, useId} 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 content.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let contentId = useId();\n let isControlled = props.isExpanded !== undefined;\n let isSSR = useIsSSR();\n let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);\n\n useEffect(() => {\n // Until React supports hidden=\"until-found\": https://github.com/facebook/react/pull/24741\n if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {\n if (state.isExpanded) {\n ref.current.removeAttribute('hidden');\n } else {\n ref.current.setAttribute('hidden', 'until-found');\n }\n }\n }, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': contentId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onKeyDown(e) {\n if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {\n e.preventDefault();\n state.toggle();\n }\n }\n },\n panelProps: {\n id: contentId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.module.js.map"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-aria/disclosure",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "Spectrum UI components in React",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/types.d.ts",
|
|
14
|
+
"source": "src/index.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-aria/button": "^3.10.0",
|
|
26
|
+
"@react-aria/selection": "^3.20.0",
|
|
27
|
+
"@react-aria/ssr": "^3.9.6",
|
|
28
|
+
"@react-aria/utils": "^3.25.3",
|
|
29
|
+
"@react-stately/disclosure": "3.0.0-alpha.0",
|
|
30
|
+
"@react-stately/toggle": "^3.7.8",
|
|
31
|
+
"@react-stately/tree": "^3.8.5",
|
|
32
|
+
"@react-types/button": "^3.10.0",
|
|
33
|
+
"@react-types/shared": "^3.25.0",
|
|
34
|
+
"@swc/helpers": "^0.5.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
|
|
38
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 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
|
+
export {useDisclosure} from './useDisclosure';
|
|
13
|
+
export type {DisclosureAria, AriaDisclosureProps} from './useDisclosure';
|
|
@@ -0,0 +1,93 @@
|
|
|
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 {HTMLAttributes, RefObject, useEffect} from 'react';
|
|
16
|
+
import {useEvent, useId} from '@react-aria/utils';
|
|
17
|
+
import {useIsSSR} from '@react-aria/ssr';
|
|
18
|
+
|
|
19
|
+
export interface AriaDisclosureProps {
|
|
20
|
+
/** Whether the disclosure is disabled. */
|
|
21
|
+
isDisabled?: boolean,
|
|
22
|
+
/** Handler that is called when the disclosure's expanded state changes. */
|
|
23
|
+
onExpandedChange?: (isExpanded: boolean) => void,
|
|
24
|
+
/** Whether the disclosure is expanded (controlled). */
|
|
25
|
+
isExpanded?: boolean,
|
|
26
|
+
/** Whether the disclosure is expanded by default (uncontrolled). */
|
|
27
|
+
defaultExpanded?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DisclosureAria {
|
|
31
|
+
/** Props for the disclosure button. */
|
|
32
|
+
buttonProps: AriaButtonProps,
|
|
33
|
+
/** Props for the disclosure panel. */
|
|
34
|
+
panelProps: HTMLAttributes<HTMLElement>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Provides the behavior and accessibility implementation for a disclosure component.
|
|
39
|
+
* @param props - Props for the disclosure.
|
|
40
|
+
* @param state - State for the disclosure, as returned by `useDisclosureState`.
|
|
41
|
+
* @param ref - A ref for the disclosure content.
|
|
42
|
+
*/
|
|
43
|
+
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {
|
|
44
|
+
let {
|
|
45
|
+
isDisabled
|
|
46
|
+
} = props;
|
|
47
|
+
let triggerId = useId();
|
|
48
|
+
let contentId = useId();
|
|
49
|
+
let isControlled = props.isExpanded !== undefined;
|
|
50
|
+
let isSSR = useIsSSR();
|
|
51
|
+
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
52
|
+
|
|
53
|
+
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
54
|
+
useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
|
|
58
|
+
if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {
|
|
59
|
+
if (state.isExpanded) {
|
|
60
|
+
ref.current.removeAttribute('hidden');
|
|
61
|
+
} else {
|
|
62
|
+
ref.current.setAttribute('hidden', 'until-found');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
buttonProps: {
|
|
69
|
+
id: triggerId,
|
|
70
|
+
'aria-expanded': state.isExpanded,
|
|
71
|
+
'aria-controls': contentId,
|
|
72
|
+
onPress: (e) => {
|
|
73
|
+
if (!isDisabled && e.pointerType !== 'keyboard') {
|
|
74
|
+
state.toggle();
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
isDisabled,
|
|
78
|
+
onKeyDown(e) {
|
|
79
|
+
if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
state.toggle();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
panelProps: {
|
|
86
|
+
id: contentId,
|
|
87
|
+
// This can be overridden at the panel element level.
|
|
88
|
+
role: 'group',
|
|
89
|
+
'aria-labelledby': triggerId,
|
|
90
|
+
hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|