@react-stately/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 +19 -0
- package/dist/main.js +25 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +19 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useDisclosureGroupState.main.js +55 -0
- package/dist/useDisclosureGroupState.main.js.map +1 -0
- package/dist/useDisclosureGroupState.mjs +50 -0
- package/dist/useDisclosureGroupState.module.js +50 -0
- package/dist/useDisclosureGroupState.module.js.map +1 -0
- package/dist/useDisclosureState.main.js +50 -0
- package/dist/useDisclosureState.main.js.map +1 -0
- package/dist/useDisclosureState.mjs +45 -0
- package/dist/useDisclosureState.module.js +45 -0
- package/dist/useDisclosureState.module.js.map +1 -0
- package/package.json +35 -0
- package/src/index.ts +17 -0
- package/src/useDisclosureGroupState.ts +81 -0
- package/src/useDisclosureState.ts +65 -0
package/README.md
ADDED
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {useDisclosureState as $bf996d45f4a36925$export$3fcbf6e4407997e0} from "./useDisclosureState.mjs";
|
|
2
|
+
import {useDisclosureGroupState as $9385b3affbdec831$export$f36461af0ef4707d} from "./useDisclosureGroupState.mjs";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState, $9385b3affbdec831$export$f36461af0ef4707d as useDisclosureGroupState};
|
|
19
|
+
//# sourceMappingURL=module.js.map
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var $be8c72c0f1e8f9cb$exports = require("./useDisclosureState.main.js");
|
|
2
|
+
var $8654db152d40114d$exports = require("./useDisclosureGroupState.main.js");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useDisclosureState", () => $be8c72c0f1e8f9cb$exports.useDisclosureState);
|
|
10
|
+
$parcel$export(module.exports, "useDisclosureGroupState", () => $8654db152d40114d$exports.useDisclosureGroupState);
|
|
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
|
+
|
|
25
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/disclosure/src/index.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\nexport {useDisclosureState} from './useDisclosureState';\nexport {useDisclosureGroupState} from './useDisclosureGroupState';\n\nexport type {DisclosureState, DisclosureProps} from './useDisclosureState';\nexport type {DisclosureGroupState, DisclosureGroupProps} from './useDisclosureGroupState';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {useDisclosureState as $bf996d45f4a36925$export$3fcbf6e4407997e0} from "./useDisclosureState.module.js";
|
|
2
|
+
import {useDisclosureGroupState as $9385b3affbdec831$export$f36461af0ef4707d} from "./useDisclosureGroupState.module.js";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState, $9385b3affbdec831$export$f36461af0ef4707d as useDisclosureGroupState};
|
|
19
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/disclosure/src/index.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\nexport {useDisclosureState} from './useDisclosureState';\nexport {useDisclosureGroupState} from './useDisclosureGroupState';\n\nexport type {DisclosureState, DisclosureProps} from './useDisclosureState';\nexport type {DisclosureGroupState, DisclosureGroupProps} from './useDisclosureGroupState';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Expandable, Key } from "@react-types/shared";
|
|
2
|
+
export interface DisclosureProps {
|
|
3
|
+
/** Whether the disclosure is expanded (controlled). */
|
|
4
|
+
isExpanded?: boolean;
|
|
5
|
+
/** Whether the disclosure is expanded by default (uncontrolled). */
|
|
6
|
+
defaultExpanded?: boolean;
|
|
7
|
+
/** Handler that is called when the disclosure expanded state changes. */
|
|
8
|
+
onExpandedChange?: (isExpanded: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface DisclosureState {
|
|
11
|
+
/** Whether the disclosure is currently expanded. */
|
|
12
|
+
readonly isExpanded: boolean;
|
|
13
|
+
/** Sets whether the disclosure is expanded. */
|
|
14
|
+
setExpanded(isExpanded: boolean): void;
|
|
15
|
+
/** Expand the disclosure. */
|
|
16
|
+
expand(): void;
|
|
17
|
+
/** Collapse the disclosure. */
|
|
18
|
+
collapse(): void;
|
|
19
|
+
/** Toggles the disclosure's visibility. */
|
|
20
|
+
toggle(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Manages state for a disclosure widget. Tracks whether the disclosure is expanded, and provides
|
|
24
|
+
* methods to toggle this state.
|
|
25
|
+
*/
|
|
26
|
+
export function useDisclosureState(props: DisclosureProps): DisclosureState;
|
|
27
|
+
export interface DisclosureGroupProps extends Expandable {
|
|
28
|
+
/** Whether multiple items can be expanded at the same time. */
|
|
29
|
+
allowsMultipleExpanded?: boolean;
|
|
30
|
+
/** Whether all items are disabled. */
|
|
31
|
+
isDisabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface DisclosureGroupState {
|
|
34
|
+
/** Whether multiple items can be expanded at the same time. */
|
|
35
|
+
readonly allowsMultipleExpanded: boolean;
|
|
36
|
+
/** Whether all items are disabled. */
|
|
37
|
+
readonly isDisabled: boolean;
|
|
38
|
+
/** A set of keys for items that are expanded. */
|
|
39
|
+
readonly expandedKeys: Set<Key>;
|
|
40
|
+
/** Toggles the expanded state for an item by its key. */
|
|
41
|
+
toggleKey(key: Key): void;
|
|
42
|
+
/** Replaces the set of expanded keys. */
|
|
43
|
+
setExpandedKeys(keys: Set<Key>): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Manages state for a group of disclosures, e.g. an accordion.
|
|
47
|
+
* It supports both single and multiple expanded items.
|
|
48
|
+
*/
|
|
49
|
+
export function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState;
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAeA;IACE,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oEAAoE;IACpE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAA;CACjD;AAGD;IACE,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,+CAA+C;IAC/C,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IACvC,6BAA6B;IAC7B,MAAM,IAAI,IAAI,CAAC;IACf,+BAA+B;IAC/B,QAAQ,IAAI,IAAI,CAAC;IACjB,2CAA2C;IAC3C,MAAM,IAAI,IAAI,CAAA;CACf;AAED;;;GAGG;AACH,mCAAmC,KAAK,EAAE,eAAe,GAAG,eAAe,CAsB1E;AChDD,qCAAsC,SAAQ,UAAU;IACtD,+DAA+D;IAC/D,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,sCAAsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,+DAA+D;IAC/D,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;IAEzC,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,yDAAyD;IACzD,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE1B,yCAAyC;IACzC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,wCAAwC,KAAK,EAAE,oBAAoB,GAAG,oBAAoB,CAoCzF","sources":["packages/@react-stately/disclosure/src/packages/@react-stately/disclosure/src/useDisclosureState.ts","packages/@react-stately/disclosure/src/packages/@react-stately/disclosure/src/useDisclosureGroupState.ts","packages/@react-stately/disclosure/src/packages/@react-stately/disclosure/src/index.ts","packages/@react-stately/disclosure/src/index.ts"],"sourcesContent":[null,null,null,"/*\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\nexport {useDisclosureState} from './useDisclosureState';\nexport {useDisclosureGroupState} from './useDisclosureGroupState';\n\nexport type {DisclosureState, DisclosureProps} from './useDisclosureState';\nexport type {DisclosureGroupState, DisclosureGroupProps} from './useDisclosureGroupState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var $eOP8W$reactstatelyutils = require("@react-stately/utils");
|
|
2
|
+
var $eOP8W$react = require("react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useDisclosureGroupState", () => $8654db152d40114d$export$f36461af0ef4707d);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function $8654db152d40114d$export$f36461af0ef4707d(props) {
|
|
23
|
+
let { allowsMultipleExpanded: allowsMultipleExpanded = false, isDisabled: isDisabled = false } = props;
|
|
24
|
+
let [expandedKeys, setExpandedKeys] = (0, $eOP8W$reactstatelyutils.useControlledState)((0, $eOP8W$react.useMemo)(()=>props.expandedKeys ? new Set(props.expandedKeys) : undefined, [
|
|
25
|
+
props.expandedKeys
|
|
26
|
+
]), (0, $eOP8W$react.useMemo)(()=>props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [
|
|
27
|
+
props.defaultExpandedKeys
|
|
28
|
+
]), props.onExpandedChange);
|
|
29
|
+
(0, $eOP8W$react.useEffect)(()=>{
|
|
30
|
+
// Ensure only one item is expanded if allowsMultipleExpanded is false.
|
|
31
|
+
if (!allowsMultipleExpanded && expandedKeys.size > 1) setExpandedKeys(new Set([
|
|
32
|
+
expandedKeys.values().next().value
|
|
33
|
+
]));
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
allowsMultipleExpanded: allowsMultipleExpanded,
|
|
37
|
+
isDisabled: isDisabled,
|
|
38
|
+
expandedKeys: expandedKeys,
|
|
39
|
+
setExpandedKeys: setExpandedKeys,
|
|
40
|
+
toggleKey (key) {
|
|
41
|
+
let keys;
|
|
42
|
+
if (allowsMultipleExpanded) {
|
|
43
|
+
keys = new Set(expandedKeys);
|
|
44
|
+
if (keys.has(key)) keys.delete(key);
|
|
45
|
+
else keys.add(key);
|
|
46
|
+
} else keys = new Set(expandedKeys.has(key) ? [] : [
|
|
47
|
+
key
|
|
48
|
+
]);
|
|
49
|
+
setExpandedKeys(keys);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=useDisclosureGroupState.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkCM,SAAS,0CAAwB,KAA2B;IACjE,IAAI,0BAAC,yBAAyB,mBAAO,aAAa,OAAM,GAAG;IAC3D,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,2CAAiB,EACrD,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,gBAAgB;IAGxB,CAAA,GAAA,sBAAQ,EAAE;QACR,uEAAuE;QACvE,IAAI,CAAC,0BAA0B,aAAa,IAAI,GAAG,GACjD,gBAAgB,IAAI,IAAI;YAAC,aAAa,MAAM,GAAG,IAAI,GAAG,KAAK;SAAC;IAEhE;IAEA,OAAO;gCACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,wBAAwB;gBAC1B,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,MACX,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,OAAO,EAAE,GAAG;gBAAC;aAAI;YAGnD,gBAAgB;QAClB;IACF;AACF","sources":["packages/@react-stately/disclosure/src/useDisclosureGroupState.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 {Expandable, Key} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo} from 'react';\n\nexport interface DisclosureGroupProps extends Expandable {\n /** Whether multiple items can be expanded at the same time. */\n allowsMultipleExpanded?: boolean,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface DisclosureGroupState {\n /** Whether multiple items can be expanded at the same time. */\n readonly allowsMultipleExpanded: boolean,\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of disclosures, e.g. an accordion.\n * It supports both single and multiple expanded items.\n */\nexport function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState {\n let {allowsMultipleExpanded = false, isDisabled = false} = props;\n let [expandedKeys, setExpandedKeys] = useControlledState(\n useMemo(() => props.expandedKeys ? new Set(props.expandedKeys) : undefined, [props.expandedKeys]),\n useMemo(() => props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [props.defaultExpandedKeys]),\n props.onExpandedChange\n );\n \n useEffect(() => {\n // Ensure only one item is expanded if allowsMultipleExpanded is false.\n if (!allowsMultipleExpanded && expandedKeys.size > 1) {\n setExpandedKeys(new Set([expandedKeys.values().next().value]));\n }\n });\n\n return {\n allowsMultipleExpanded,\n isDisabled,\n expandedKeys,\n setExpandedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (allowsMultipleExpanded) {\n keys = new Set(expandedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(expandedKeys.has(key) ? [] : [key]);\n }\n \n setExpandedKeys(keys);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosureGroupState.main.js.map"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {useControlledState as $j4gLc$useControlledState} from "@react-stately/utils";
|
|
2
|
+
import {useMemo as $j4gLc$useMemo, useEffect as $j4gLc$useEffect} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $9385b3affbdec831$export$f36461af0ef4707d(props) {
|
|
17
|
+
let { allowsMultipleExpanded: allowsMultipleExpanded = false, isDisabled: isDisabled = false } = props;
|
|
18
|
+
let [expandedKeys, setExpandedKeys] = (0, $j4gLc$useControlledState)((0, $j4gLc$useMemo)(()=>props.expandedKeys ? new Set(props.expandedKeys) : undefined, [
|
|
19
|
+
props.expandedKeys
|
|
20
|
+
]), (0, $j4gLc$useMemo)(()=>props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [
|
|
21
|
+
props.defaultExpandedKeys
|
|
22
|
+
]), props.onExpandedChange);
|
|
23
|
+
(0, $j4gLc$useEffect)(()=>{
|
|
24
|
+
// Ensure only one item is expanded if allowsMultipleExpanded is false.
|
|
25
|
+
if (!allowsMultipleExpanded && expandedKeys.size > 1) setExpandedKeys(new Set([
|
|
26
|
+
expandedKeys.values().next().value
|
|
27
|
+
]));
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
allowsMultipleExpanded: allowsMultipleExpanded,
|
|
31
|
+
isDisabled: isDisabled,
|
|
32
|
+
expandedKeys: expandedKeys,
|
|
33
|
+
setExpandedKeys: setExpandedKeys,
|
|
34
|
+
toggleKey (key) {
|
|
35
|
+
let keys;
|
|
36
|
+
if (allowsMultipleExpanded) {
|
|
37
|
+
keys = new Set(expandedKeys);
|
|
38
|
+
if (keys.has(key)) keys.delete(key);
|
|
39
|
+
else keys.add(key);
|
|
40
|
+
} else keys = new Set(expandedKeys.has(key) ? [] : [
|
|
41
|
+
key
|
|
42
|
+
]);
|
|
43
|
+
setExpandedKeys(keys);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export {$9385b3affbdec831$export$f36461af0ef4707d as useDisclosureGroupState};
|
|
50
|
+
//# sourceMappingURL=useDisclosureGroupState.module.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {useControlledState as $j4gLc$useControlledState} from "@react-stately/utils";
|
|
2
|
+
import {useMemo as $j4gLc$useMemo, useEffect as $j4gLc$useEffect} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $9385b3affbdec831$export$f36461af0ef4707d(props) {
|
|
17
|
+
let { allowsMultipleExpanded: allowsMultipleExpanded = false, isDisabled: isDisabled = false } = props;
|
|
18
|
+
let [expandedKeys, setExpandedKeys] = (0, $j4gLc$useControlledState)((0, $j4gLc$useMemo)(()=>props.expandedKeys ? new Set(props.expandedKeys) : undefined, [
|
|
19
|
+
props.expandedKeys
|
|
20
|
+
]), (0, $j4gLc$useMemo)(()=>props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [
|
|
21
|
+
props.defaultExpandedKeys
|
|
22
|
+
]), props.onExpandedChange);
|
|
23
|
+
(0, $j4gLc$useEffect)(()=>{
|
|
24
|
+
// Ensure only one item is expanded if allowsMultipleExpanded is false.
|
|
25
|
+
if (!allowsMultipleExpanded && expandedKeys.size > 1) setExpandedKeys(new Set([
|
|
26
|
+
expandedKeys.values().next().value
|
|
27
|
+
]));
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
allowsMultipleExpanded: allowsMultipleExpanded,
|
|
31
|
+
isDisabled: isDisabled,
|
|
32
|
+
expandedKeys: expandedKeys,
|
|
33
|
+
setExpandedKeys: setExpandedKeys,
|
|
34
|
+
toggleKey (key) {
|
|
35
|
+
let keys;
|
|
36
|
+
if (allowsMultipleExpanded) {
|
|
37
|
+
keys = new Set(expandedKeys);
|
|
38
|
+
if (keys.has(key)) keys.delete(key);
|
|
39
|
+
else keys.add(key);
|
|
40
|
+
} else keys = new Set(expandedKeys.has(key) ? [] : [
|
|
41
|
+
key
|
|
42
|
+
]);
|
|
43
|
+
setExpandedKeys(keys);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export {$9385b3affbdec831$export$f36461af0ef4707d as useDisclosureGroupState};
|
|
50
|
+
//# sourceMappingURL=useDisclosureGroupState.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkCM,SAAS,0CAAwB,KAA2B;IACjE,IAAI,0BAAC,yBAAyB,mBAAO,aAAa,OAAM,GAAG;IAC3D,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yBAAiB,EACrD,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,gBAAgB;IAGxB,CAAA,GAAA,gBAAQ,EAAE;QACR,uEAAuE;QACvE,IAAI,CAAC,0BAA0B,aAAa,IAAI,GAAG,GACjD,gBAAgB,IAAI,IAAI;YAAC,aAAa,MAAM,GAAG,IAAI,GAAG,KAAK;SAAC;IAEhE;IAEA,OAAO;gCACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,wBAAwB;gBAC1B,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,MACX,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,OAAO,EAAE,GAAG;gBAAC;aAAI;YAGnD,gBAAgB;QAClB;IACF;AACF","sources":["packages/@react-stately/disclosure/src/useDisclosureGroupState.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 {Expandable, Key} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo} from 'react';\n\nexport interface DisclosureGroupProps extends Expandable {\n /** Whether multiple items can be expanded at the same time. */\n allowsMultipleExpanded?: boolean,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface DisclosureGroupState {\n /** Whether multiple items can be expanded at the same time. */\n readonly allowsMultipleExpanded: boolean,\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of disclosures, e.g. an accordion.\n * It supports both single and multiple expanded items.\n */\nexport function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState {\n let {allowsMultipleExpanded = false, isDisabled = false} = props;\n let [expandedKeys, setExpandedKeys] = useControlledState(\n useMemo(() => props.expandedKeys ? new Set(props.expandedKeys) : undefined, [props.expandedKeys]),\n useMemo(() => props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [props.defaultExpandedKeys]),\n props.onExpandedChange\n );\n \n useEffect(() => {\n // Ensure only one item is expanded if allowsMultipleExpanded is false.\n if (!allowsMultipleExpanded && expandedKeys.size > 1) {\n setExpandedKeys(new Set([expandedKeys.values().next().value]));\n }\n });\n\n return {\n allowsMultipleExpanded,\n isDisabled,\n expandedKeys,\n setExpandedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (allowsMultipleExpanded) {\n keys = new Set(expandedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(expandedKeys.has(key) ? [] : [key]);\n }\n \n setExpandedKeys(keys);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosureGroupState.module.js.map"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var $6xCOE$react = require("react");
|
|
2
|
+
var $6xCOE$reactstatelyutils = require("@react-stately/utils");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useDisclosureState", () => $be8c72c0f1e8f9cb$export$3fcbf6e4407997e0);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function $be8c72c0f1e8f9cb$export$3fcbf6e4407997e0(props) {
|
|
23
|
+
let [isExpanded, setExpanded] = (0, $6xCOE$reactstatelyutils.useControlledState)(props.isExpanded, props.defaultExpanded || false, props.onExpandedChange);
|
|
24
|
+
const expand = (0, $6xCOE$react.useCallback)(()=>{
|
|
25
|
+
setExpanded(true);
|
|
26
|
+
}, [
|
|
27
|
+
setExpanded
|
|
28
|
+
]);
|
|
29
|
+
const collapse = (0, $6xCOE$react.useCallback)(()=>{
|
|
30
|
+
setExpanded(false);
|
|
31
|
+
}, [
|
|
32
|
+
setExpanded
|
|
33
|
+
]);
|
|
34
|
+
const toggle = (0, $6xCOE$react.useCallback)(()=>{
|
|
35
|
+
setExpanded(!isExpanded);
|
|
36
|
+
}, [
|
|
37
|
+
setExpanded,
|
|
38
|
+
isExpanded
|
|
39
|
+
]);
|
|
40
|
+
return {
|
|
41
|
+
isExpanded: isExpanded,
|
|
42
|
+
setExpanded: setExpanded,
|
|
43
|
+
expand: expand,
|
|
44
|
+
collapse: collapse,
|
|
45
|
+
toggle: toggle
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=useDisclosureState.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAgCM,SAAS,0CAAmB,KAAsB;IACvD,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,gBAAgB;IAE3H,MAAM,SAAS,CAAA,GAAA,wBAAU,EAAE;QACzB,YAAY;IACd,GAAG;QAAC;KAAY;IAEhB,MAAM,WAAW,CAAA,GAAA,wBAAU,EAAE;QAC3B,YAAY;IACd,GAAG;QAAC;KAAY;IAEhB,MAAM,SAAS,CAAA,GAAA,wBAAU,EAAE;QACzB,YAAY,CAAC;IACf,GAAG;QAAC;QAAa;KAAW;IAE5B,OAAO;oBACL;qBACA;gBACA;kBACA;gBACA;IACF;AACF","sources":["packages/@react-stately/disclosure/src/useDisclosureState.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 {useCallback} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface DisclosureProps {\n /** Whether the disclosure is expanded (controlled). */\n isExpanded?: boolean,\n /** Whether the disclosure is expanded by default (uncontrolled). */\n defaultExpanded?: boolean,\n /** Handler that is called when the disclosure expanded state changes. */\n onExpandedChange?: (isExpanded: boolean) => void\n}\n\n\nexport interface DisclosureState {\n /** Whether the disclosure is currently expanded. */\n readonly isExpanded: boolean,\n /** Sets whether the disclosure is expanded. */\n setExpanded(isExpanded: boolean): void,\n /** Expand the disclosure. */\n expand(): void,\n /** Collapse the disclosure. */\n collapse(): void,\n /** Toggles the disclosure's visibility. */\n toggle(): void\n}\n\n/**\n * Manages state for a disclosure widget. Tracks whether the disclosure is expanded, and provides\n * methods to toggle this state.\n */\nexport function useDisclosureState(props: DisclosureProps): DisclosureState {\n let [isExpanded, setExpanded] = useControlledState(props.isExpanded, props.defaultExpanded || false, props.onExpandedChange);\n\n const expand = useCallback(() => {\n setExpanded(true);\n }, [setExpanded]);\n\n const collapse = useCallback(() => {\n setExpanded(false);\n }, [setExpanded]);\n\n const toggle = useCallback(() => {\n setExpanded(!isExpanded);\n }, [setExpanded, isExpanded]);\n\n return {\n isExpanded,\n setExpanded,\n expand,\n collapse,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useDisclosureState.main.js.map"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {useCallback as $acGV5$useCallback} from "react";
|
|
2
|
+
import {useControlledState as $acGV5$useControlledState} from "@react-stately/utils";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $bf996d45f4a36925$export$3fcbf6e4407997e0(props) {
|
|
17
|
+
let [isExpanded, setExpanded] = (0, $acGV5$useControlledState)(props.isExpanded, props.defaultExpanded || false, props.onExpandedChange);
|
|
18
|
+
const expand = (0, $acGV5$useCallback)(()=>{
|
|
19
|
+
setExpanded(true);
|
|
20
|
+
}, [
|
|
21
|
+
setExpanded
|
|
22
|
+
]);
|
|
23
|
+
const collapse = (0, $acGV5$useCallback)(()=>{
|
|
24
|
+
setExpanded(false);
|
|
25
|
+
}, [
|
|
26
|
+
setExpanded
|
|
27
|
+
]);
|
|
28
|
+
const toggle = (0, $acGV5$useCallback)(()=>{
|
|
29
|
+
setExpanded(!isExpanded);
|
|
30
|
+
}, [
|
|
31
|
+
setExpanded,
|
|
32
|
+
isExpanded
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
isExpanded: isExpanded,
|
|
36
|
+
setExpanded: setExpanded,
|
|
37
|
+
expand: expand,
|
|
38
|
+
collapse: collapse,
|
|
39
|
+
toggle: toggle
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState};
|
|
45
|
+
//# sourceMappingURL=useDisclosureState.module.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {useCallback as $acGV5$useCallback} from "react";
|
|
2
|
+
import {useControlledState as $acGV5$useControlledState} from "@react-stately/utils";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $bf996d45f4a36925$export$3fcbf6e4407997e0(props) {
|
|
17
|
+
let [isExpanded, setExpanded] = (0, $acGV5$useControlledState)(props.isExpanded, props.defaultExpanded || false, props.onExpandedChange);
|
|
18
|
+
const expand = (0, $acGV5$useCallback)(()=>{
|
|
19
|
+
setExpanded(true);
|
|
20
|
+
}, [
|
|
21
|
+
setExpanded
|
|
22
|
+
]);
|
|
23
|
+
const collapse = (0, $acGV5$useCallback)(()=>{
|
|
24
|
+
setExpanded(false);
|
|
25
|
+
}, [
|
|
26
|
+
setExpanded
|
|
27
|
+
]);
|
|
28
|
+
const toggle = (0, $acGV5$useCallback)(()=>{
|
|
29
|
+
setExpanded(!isExpanded);
|
|
30
|
+
}, [
|
|
31
|
+
setExpanded,
|
|
32
|
+
isExpanded
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
isExpanded: isExpanded,
|
|
36
|
+
setExpanded: setExpanded,
|
|
37
|
+
expand: expand,
|
|
38
|
+
collapse: collapse,
|
|
39
|
+
toggle: toggle
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState};
|
|
45
|
+
//# sourceMappingURL=useDisclosureState.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAgCM,SAAS,0CAAmB,KAAsB;IACvD,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,gBAAgB;IAE3H,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE;QACzB,YAAY;IACd,GAAG;QAAC;KAAY;IAEhB,MAAM,WAAW,CAAA,GAAA,kBAAU,EAAE;QAC3B,YAAY;IACd,GAAG;QAAC;KAAY;IAEhB,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE;QACzB,YAAY,CAAC;IACf,GAAG;QAAC;QAAa;KAAW;IAE5B,OAAO;oBACL;qBACA;gBACA;kBACA;gBACA;IACF;AACF","sources":["packages/@react-stately/disclosure/src/useDisclosureState.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 {useCallback} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface DisclosureProps {\n /** Whether the disclosure is expanded (controlled). */\n isExpanded?: boolean,\n /** Whether the disclosure is expanded by default (uncontrolled). */\n defaultExpanded?: boolean,\n /** Handler that is called when the disclosure expanded state changes. */\n onExpandedChange?: (isExpanded: boolean) => void\n}\n\n\nexport interface DisclosureState {\n /** Whether the disclosure is currently expanded. */\n readonly isExpanded: boolean,\n /** Sets whether the disclosure is expanded. */\n setExpanded(isExpanded: boolean): void,\n /** Expand the disclosure. */\n expand(): void,\n /** Collapse the disclosure. */\n collapse(): void,\n /** Toggles the disclosure's visibility. */\n toggle(): void\n}\n\n/**\n * Manages state for a disclosure widget. Tracks whether the disclosure is expanded, and provides\n * methods to toggle this state.\n */\nexport function useDisclosureState(props: DisclosureProps): DisclosureState {\n let [isExpanded, setExpanded] = useControlledState(props.isExpanded, props.defaultExpanded || false, props.onExpandedChange);\n\n const expand = useCallback(() => {\n setExpanded(true);\n }, [setExpanded]);\n\n const collapse = useCallback(() => {\n setExpanded(false);\n }, [setExpanded]);\n\n const toggle = useCallback(() => {\n setExpanded(!isExpanded);\n }, [setExpanded, isExpanded]);\n\n return {\n isExpanded,\n setExpanded,\n expand,\n collapse,\n toggle\n };\n}\n"],"names":[],"version":3,"file":"useDisclosureState.module.js.map"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-stately/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-stately/utils": "^3.10.4",
|
|
26
|
+
"@react-types/shared": "^3.25.0",
|
|
27
|
+
"@swc/helpers": "^0.5.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export {useDisclosureState} from './useDisclosureState';
|
|
14
|
+
export {useDisclosureGroupState} from './useDisclosureGroupState';
|
|
15
|
+
|
|
16
|
+
export type {DisclosureState, DisclosureProps} from './useDisclosureState';
|
|
17
|
+
export type {DisclosureGroupState, DisclosureGroupProps} from './useDisclosureGroupState';
|
|
@@ -0,0 +1,81 @@
|
|
|
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 {Expandable, Key} from '@react-types/shared';
|
|
14
|
+
import {useControlledState} from '@react-stately/utils';
|
|
15
|
+
import {useEffect, useMemo} from 'react';
|
|
16
|
+
|
|
17
|
+
export interface DisclosureGroupProps extends Expandable {
|
|
18
|
+
/** Whether multiple items can be expanded at the same time. */
|
|
19
|
+
allowsMultipleExpanded?: boolean,
|
|
20
|
+
/** Whether all items are disabled. */
|
|
21
|
+
isDisabled?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface DisclosureGroupState {
|
|
25
|
+
/** Whether multiple items can be expanded at the same time. */
|
|
26
|
+
readonly allowsMultipleExpanded: boolean,
|
|
27
|
+
|
|
28
|
+
/** Whether all items are disabled. */
|
|
29
|
+
readonly isDisabled: boolean,
|
|
30
|
+
|
|
31
|
+
/** A set of keys for items that are expanded. */
|
|
32
|
+
readonly expandedKeys: Set<Key>,
|
|
33
|
+
|
|
34
|
+
/** Toggles the expanded state for an item by its key. */
|
|
35
|
+
toggleKey(key: Key): void,
|
|
36
|
+
|
|
37
|
+
/** Replaces the set of expanded keys. */
|
|
38
|
+
setExpandedKeys(keys: Set<Key>): void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Manages state for a group of disclosures, e.g. an accordion.
|
|
43
|
+
* It supports both single and multiple expanded items.
|
|
44
|
+
*/
|
|
45
|
+
export function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState {
|
|
46
|
+
let {allowsMultipleExpanded = false, isDisabled = false} = props;
|
|
47
|
+
let [expandedKeys, setExpandedKeys] = useControlledState(
|
|
48
|
+
useMemo(() => props.expandedKeys ? new Set(props.expandedKeys) : undefined, [props.expandedKeys]),
|
|
49
|
+
useMemo(() => props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [props.defaultExpandedKeys]),
|
|
50
|
+
props.onExpandedChange
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
// Ensure only one item is expanded if allowsMultipleExpanded is false.
|
|
55
|
+
if (!allowsMultipleExpanded && expandedKeys.size > 1) {
|
|
56
|
+
setExpandedKeys(new Set([expandedKeys.values().next().value]));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
allowsMultipleExpanded,
|
|
62
|
+
isDisabled,
|
|
63
|
+
expandedKeys,
|
|
64
|
+
setExpandedKeys,
|
|
65
|
+
toggleKey(key) {
|
|
66
|
+
let keys: Set<Key>;
|
|
67
|
+
if (allowsMultipleExpanded) {
|
|
68
|
+
keys = new Set(expandedKeys);
|
|
69
|
+
if (keys.has(key)) {
|
|
70
|
+
keys.delete(key);
|
|
71
|
+
} else {
|
|
72
|
+
keys.add(key);
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
keys = new Set(expandedKeys.has(key) ? [] : [key]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setExpandedKeys(keys);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 {useCallback} from 'react';
|
|
14
|
+
import {useControlledState} from '@react-stately/utils';
|
|
15
|
+
|
|
16
|
+
export interface DisclosureProps {
|
|
17
|
+
/** Whether the disclosure is expanded (controlled). */
|
|
18
|
+
isExpanded?: boolean,
|
|
19
|
+
/** Whether the disclosure is expanded by default (uncontrolled). */
|
|
20
|
+
defaultExpanded?: boolean,
|
|
21
|
+
/** Handler that is called when the disclosure expanded state changes. */
|
|
22
|
+
onExpandedChange?: (isExpanded: boolean) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export interface DisclosureState {
|
|
27
|
+
/** Whether the disclosure is currently expanded. */
|
|
28
|
+
readonly isExpanded: boolean,
|
|
29
|
+
/** Sets whether the disclosure is expanded. */
|
|
30
|
+
setExpanded(isExpanded: boolean): void,
|
|
31
|
+
/** Expand the disclosure. */
|
|
32
|
+
expand(): void,
|
|
33
|
+
/** Collapse the disclosure. */
|
|
34
|
+
collapse(): void,
|
|
35
|
+
/** Toggles the disclosure's visibility. */
|
|
36
|
+
toggle(): void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Manages state for a disclosure widget. Tracks whether the disclosure is expanded, and provides
|
|
41
|
+
* methods to toggle this state.
|
|
42
|
+
*/
|
|
43
|
+
export function useDisclosureState(props: DisclosureProps): DisclosureState {
|
|
44
|
+
let [isExpanded, setExpanded] = useControlledState(props.isExpanded, props.defaultExpanded || false, props.onExpandedChange);
|
|
45
|
+
|
|
46
|
+
const expand = useCallback(() => {
|
|
47
|
+
setExpanded(true);
|
|
48
|
+
}, [setExpanded]);
|
|
49
|
+
|
|
50
|
+
const collapse = useCallback(() => {
|
|
51
|
+
setExpanded(false);
|
|
52
|
+
}, [setExpanded]);
|
|
53
|
+
|
|
54
|
+
const toggle = useCallback(() => {
|
|
55
|
+
setExpanded(!isExpanded);
|
|
56
|
+
}, [setExpanded, isExpanded]);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
isExpanded,
|
|
60
|
+
setExpanded,
|
|
61
|
+
expand,
|
|
62
|
+
collapse,
|
|
63
|
+
toggle
|
|
64
|
+
};
|
|
65
|
+
}
|