@react-stately/disclosure 3.0.0-nightly-0ddbe6f95-241021 → 3.0.0-nightly-4f85a359f-241022

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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Expandable, Key } from "@react-types/shared";
1
+ import { Key } from "@react-types/shared";
2
2
  export interface DisclosureProps {
3
3
  /** Whether the disclosure is expanded (controlled). */
4
4
  isExpanded?: boolean;
@@ -24,11 +24,17 @@ export interface DisclosureState {
24
24
  * methods to toggle this state.
25
25
  */
26
26
  export function useDisclosureState(props: DisclosureProps): DisclosureState;
27
- export interface DisclosureGroupProps extends Expandable {
27
+ export interface DisclosureGroupProps {
28
28
  /** Whether multiple items can be expanded at the same time. */
29
29
  allowsMultipleExpanded?: boolean;
30
30
  /** Whether all items are disabled. */
31
31
  isDisabled?: boolean;
32
+ /** The currently expanded keys in the group (controlled). */
33
+ expandedKeys?: Iterable<Key>;
34
+ /** The initial expanded keys in the group (uncontrolled). */
35
+ defaultExpandedKeys?: Iterable<Key>;
36
+ /** Handler that is called when items are expanded or collapsed. */
37
+ onExpandedChange?: (keys: Set<Key>) => any;
32
38
  }
33
39
  export interface DisclosureGroupState {
34
40
  /** Whether multiple items can be expanded at the same time. */
@@ -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;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"}
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;IACE,+DAA+D;IAC/D,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,sCAAsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC7B,6DAA6D;IAC7D,mBAAmB,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpC,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;CAC3C;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"}
@@ -1 +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"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAwCM,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 {Key} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo} from 'react';\n\nexport interface DisclosureGroupProps {\n /** Whether multiple items can be expanded at the same time. */\n allowsMultipleExpanded?: boolean,\n /** Whether all items are disabled. */\n isDisabled?: boolean,\n /** The currently expanded keys in the group (controlled). */\n expandedKeys?: Iterable<Key>,\n /** The initial expanded keys in the group (uncontrolled). */\n defaultExpandedKeys?: Iterable<Key>,\n /** Handler that is called when items are expanded or collapsed. */\n onExpandedChange?: (keys: Set<Key>) => any\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"}
@@ -1 +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"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAwCM,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 {Key} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo} from 'react';\n\nexport interface DisclosureGroupProps {\n /** Whether multiple items can be expanded at the same time. */\n allowsMultipleExpanded?: boolean,\n /** Whether all items are disabled. */\n isDisabled?: boolean,\n /** The currently expanded keys in the group (controlled). */\n expandedKeys?: Iterable<Key>,\n /** The initial expanded keys in the group (uncontrolled). */\n defaultExpandedKeys?: Iterable<Key>,\n /** Handler that is called when items are expanded or collapsed. */\n onExpandedChange?: (keys: Set<Key>) => any\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/disclosure",
3
- "version": "3.0.0-nightly-0ddbe6f95-241021",
3
+ "version": "3.0.0-nightly-4f85a359f-241022",
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-0ddbe6f95-241021",
26
- "@react-types/shared": "^3.0.0-nightly-0ddbe6f95-241021",
25
+ "@react-stately/utils": "^3.0.0-nightly-4f85a359f-241022",
26
+ "@react-types/shared": "^3.0.0-nightly-4f85a359f-241022",
27
27
  "@swc/helpers": "^0.5.0"
28
28
  },
29
29
  "peerDependencies": {
@@ -10,15 +10,21 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {Expandable, Key} from '@react-types/shared';
13
+ import {Key} from '@react-types/shared';
14
14
  import {useControlledState} from '@react-stately/utils';
15
15
  import {useEffect, useMemo} from 'react';
16
16
 
17
- export interface DisclosureGroupProps extends Expandable {
17
+ export interface DisclosureGroupProps {
18
18
  /** Whether multiple items can be expanded at the same time. */
19
19
  allowsMultipleExpanded?: boolean,
20
20
  /** Whether all items are disabled. */
21
- isDisabled?: boolean
21
+ isDisabled?: boolean,
22
+ /** The currently expanded keys in the group (controlled). */
23
+ expandedKeys?: Iterable<Key>,
24
+ /** The initial expanded keys in the group (uncontrolled). */
25
+ defaultExpandedKeys?: Iterable<Key>,
26
+ /** Handler that is called when items are expanded or collapsed. */
27
+ onExpandedChange?: (keys: Set<Key>) => any
22
28
  }
23
29
 
24
30
  export interface DisclosureGroupState {