{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAwCM,SAAS,0CAAwB,KAA2B;IACjE,IAAI,0BAAC,yBAAyB,mBAAO,aAAa,OAAM,GAAG;IAC3D,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,4CAAiB,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,GAAG;YACpD,IAAI,WAAW,aAAa,MAAM,GAAG,IAAI,GAAG,KAAK;YACjD,IAAI,YAAY,MACd,gBAAgB,IAAI,IAAI;gBAAC;aAAS;QAEtC;IACF;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/src/disclosure/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 '../utils/useControlledState';\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      let firstKey = expandedKeys.values().next().value;\n      if (firstKey != null) {\n        setExpandedKeys(new Set([firstKey]));\n      }\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.cjs.map"}