@react-stately/disclosure 3.0.0-nightly-9421c1409-240923 → 3.0.0-nightly-5a0b4fabc-240924

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import {useDisclosureState as $bf996d45f4a36925$export$3fcbf6e4407997e0} from "./useDisclosureState.mjs";
2
+ import {useDisclosureGroupState as $9385b3affbdec831$export$f36461af0ef4707d} from "./useDisclosureGroupState.mjs";
2
3
 
3
4
  /*
4
5
  * Copyright 2024 Adobe. All rights reserved.
@@ -13,5 +14,6 @@ import {useDisclosureState as $bf996d45f4a36925$export$3fcbf6e4407997e0} from ".
13
14
  */
14
15
 
15
16
 
16
- export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState};
17
+
18
+ export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState, $9385b3affbdec831$export$f36461af0ef4707d as useDisclosureGroupState};
17
19
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,4 +1,5 @@
1
1
  var $be8c72c0f1e8f9cb$exports = require("./useDisclosureState.main.js");
2
+ var $8654db152d40114d$exports = require("./useDisclosureGroupState.main.js");
2
3
 
3
4
 
4
5
  function $parcel$export(e, n, v, s) {
@@ -6,6 +7,7 @@ function $parcel$export(e, n, v, s) {
6
7
  }
7
8
 
8
9
  $parcel$export(module.exports, "useDisclosureState", () => $be8c72c0f1e8f9cb$exports.useDisclosureState);
10
+ $parcel$export(module.exports, "useDisclosureGroupState", () => $8654db152d40114d$exports.useDisclosureGroupState);
9
11
  /*
10
12
  * Copyright 2024 Adobe. All rights reserved.
11
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -19,4 +21,5 @@ $parcel$export(module.exports, "useDisclosureState", () => $be8c72c0f1e8f9cb$exp
19
21
  */
20
22
 
21
23
 
24
+
22
25
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +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';\n\nexport type {DisclosureState, DisclosureProps} from './useDisclosureState';\n"],"names":[],"version":3,"file":"main.js.map"}
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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import {useDisclosureState as $bf996d45f4a36925$export$3fcbf6e4407997e0} from "./useDisclosureState.module.js";
2
+ import {useDisclosureGroupState as $9385b3affbdec831$export$f36461af0ef4707d} from "./useDisclosureGroupState.module.js";
2
3
 
3
4
  /*
4
5
  * Copyright 2024 Adobe. All rights reserved.
@@ -13,5 +14,6 @@ import {useDisclosureState as $bf996d45f4a36925$export$3fcbf6e4407997e0} from ".
13
14
  */
14
15
 
15
16
 
16
- export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState};
17
+
18
+ export {$bf996d45f4a36925$export$3fcbf6e4407997e0 as useDisclosureState, $9385b3affbdec831$export$f36461af0ef4707d as useDisclosureGroupState};
17
19
  //# sourceMappingURL=module.js.map
@@ -1 +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';\n\nexport type {DisclosureState, DisclosureProps} from './useDisclosureState';\n"],"names":[],"version":3,"file":"module.js.map"}
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 CHANGED
@@ -1,3 +1,4 @@
1
+ import { Expandable, Key } from "@react-types/shared";
1
2
  export interface DisclosureProps {
2
3
  /** Whether the disclosure is expanded (controlled). */
3
4
  isExpanded?: boolean;
@@ -23,5 +24,24 @@ export interface DisclosureState {
23
24
  * methods to toggle this state.
24
25
  */
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
+ export function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState;
26
46
 
27
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +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","sources":["packages/@react-stately/disclosure/src/packages/@react-stately/disclosure/src/useDisclosureState.ts","packages/@react-stately/disclosure/src/packages/@react-stately/disclosure/src/index.ts","packages/@react-stately/disclosure/src/index.ts"],"sourcesContent":[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';\n\nexport type {DisclosureState, DisclosureProps} from './useDisclosureState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
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,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;;AA8BM,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\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;;AA8BM,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\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/disclosure",
3
- "version": "3.0.0-nightly-9421c1409-240923",
3
+ "version": "3.0.0-nightly-5a0b4fabc-240924",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,8 +22,8 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/utils": "^3.0.0-nightly-9421c1409-240923",
26
- "@react-types/shared": "^3.0.0-nightly-9421c1409-240923",
25
+ "@react-stately/utils": "^3.0.0-nightly-5a0b4fabc-240924",
26
+ "@react-types/shared": "^3.0.0-nightly-5a0b4fabc-240924",
27
27
  "@swc/helpers": "^0.5.0"
28
28
  },
29
29
  "peerDependencies": {
package/src/index.ts CHANGED
@@ -11,5 +11,7 @@
11
11
  */
12
12
 
13
13
  export {useDisclosureState} from './useDisclosureState';
14
+ export {useDisclosureGroupState} from './useDisclosureGroupState';
14
15
 
15
16
  export type {DisclosureState, DisclosureProps} from './useDisclosureState';
17
+ export type {DisclosureGroupState, DisclosureGroupProps} from './useDisclosureGroupState';
@@ -0,0 +1,77 @@
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
+ export function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState {
42
+ let {allowsMultipleExpanded = false, isDisabled = false} = props;
43
+ let [expandedKeys, setExpandedKeys] = useControlledState(
44
+ useMemo(() => props.expandedKeys ? new Set(props.expandedKeys) : undefined, [props.expandedKeys]),
45
+ useMemo(() => props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), [props.defaultExpandedKeys]),
46
+ props.onExpandedChange
47
+ );
48
+
49
+ useEffect(() => {
50
+ // Ensure only one item is expanded if allowsMultipleExpanded is false.
51
+ if (!allowsMultipleExpanded && expandedKeys.size > 1) {
52
+ setExpandedKeys(new Set([expandedKeys.values().next().value]));
53
+ }
54
+ });
55
+
56
+ return {
57
+ allowsMultipleExpanded,
58
+ isDisabled,
59
+ expandedKeys,
60
+ setExpandedKeys,
61
+ toggleKey(key) {
62
+ let keys: Set<Key>;
63
+ if (allowsMultipleExpanded) {
64
+ keys = new Set(expandedKeys);
65
+ if (keys.has(key)) {
66
+ keys.delete(key);
67
+ } else {
68
+ keys.add(key);
69
+ }
70
+ } else {
71
+ keys = new Set(expandedKeys.has(key) ? [] : [key]);
72
+ }
73
+
74
+ setExpandedKeys(keys);
75
+ }
76
+ };
77
+ }