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oBAAC,MAAM;gBAAI;gBAExC;QACJ;IACF;IAEA,IAAI,OAA2B,wCAAkB,CAAC,MAAM,gBAAgB,CAAC,aAAa,CAAC;IACvF,IAAI,eAAe,SAAS,WAC1B,OAAO;IAET,OAAO;QACL,kBAAkB;YAChB,GAAG,CAAA,GAAA,wCAAa,EAAE,OAAO;gBAAC,WAAW;YAAI,EAAE;kBAC3C;YACA,oBAAoB,SAAS,YAAY,cAAc;YACvD,iBAAiB;uBACjB;QACF;IACF;AACF","sources":["packages/react-aria/src/actiongroup/useActionGroup.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMAttributes, DOMProps, FocusableElement, ItemElement, ItemRenderer, Key, MultipleSelection, Orientation, RefObject} from '@react-types/shared';\nimport {createFocusManager} from '../focus/FocusScope';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {KeyboardEventHandler, useState} from 'react';\nimport {ListState} from 'react-stately/useListState';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocale} from '../i18n/I18nProvider';\n\nconst BUTTON_GROUP_ROLES = {\n  'none': 'toolbar',\n  'single': 'radiogroup',\n  'multiple': 'toolbar'\n};\n\n// Not extending CollectionBase to avoid async loading props\nexport interface ActionGroupProps<T> extends MultipleSelection {\n  /**\n   * The axis the ActionGroup should align with.\n   * @default 'horizontal'\n   */\n  orientation?: Orientation,\n  /** An list of `Item` elements or a function. If the latter, a list of items must be provided using the `items` prop. */\n  children: ItemElement<T> | ItemElement<T>[] | ItemRenderer<T>,\n  /** A list of items to display as children. Must be used with a function as the sole child. */\n  items?: Iterable<T>,\n  /** A list of keys to disable. */\n  disabledKeys?: Iterable<Key>,\n  /**\n   * Whether the ActionGroup is disabled.\n   * Shows that a selection exists, but is not available in that circumstance.\n   */\n  isDisabled?: boolean,\n  /**\n   * Invoked when an action is taken on a child. Especially useful when `selectionMode` is none.\n   * The sole argument `key` is the key for the item.\n   */\n  onAction?: (key: Key) => void\n}\n\nexport interface AriaActionGroupProps<T> extends ActionGroupProps<T>, DOMProps, AriaLabelingProps {}\n\nexport interface ActionGroupAria {\n  actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement | null>): ActionGroupAria {\n  let {\n    isDisabled,\n    orientation = 'horizontal' as Orientation\n  } = props;\n\n  let [isInToolbar, setInToolbar] = useState(false);\n  useLayoutEffect(() => {\n    setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n  }, [ref]);\n\n  let allKeys = [...state.collection.getKeys()];\n  if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n    isDisabled = true;\n  }\n\n  let {direction} = useLocale();\n  let focusManager = createFocusManager(ref);\n  let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n  let onKeyDown: KeyboardEventHandler = (e) => {\n    if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n      return;\n    }\n\n    switch (e.key) {\n      case 'ArrowRight':\n      case 'ArrowDown':\n        e.preventDefault();\n        e.stopPropagation();\n        if (e.key === 'ArrowRight' && flipDirection) {\n          focusManager.focusPrevious({wrap: true});\n        } else {\n          focusManager.focusNext({wrap: true});\n        }\n        break;\n      case 'ArrowLeft':\n      case 'ArrowUp':\n        e.preventDefault();\n        e.stopPropagation();\n        if (e.key === 'ArrowLeft' && flipDirection) {\n          focusManager.focusNext({wrap: true});\n        } else {\n          focusManager.focusPrevious({wrap: true});\n        }\n        break;\n    }\n  };\n\n  let role: string | undefined = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n  if (isInToolbar && role === 'toolbar') {\n    role = 'group';\n  }\n  return {\n    actionGroupProps: {\n      ...filterDOMProps(props, {labelable: true}),\n      role,\n      'aria-orientation': role === 'toolbar' ? orientation : undefined,\n      'aria-disabled': isDisabled,\n      onKeyDown\n    }\n  };\n}\n"],"names":[],"version":3,"file":"useActionGroup.cjs.map"}