{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\nimport { mergeProps as $4vDl6$mergeProps, filterDOMProps as $4vDl6$filterDOMProps, useFormReset as $4vDl6$useFormReset, useId as $4vDl6$useId } from \"@react-aria/utils\";\nimport { useFocusable as $4vDl6$useFocusable, getFocusableTreeWalker as $4vDl6$getFocusableTreeWalker } from \"@react-aria/focus\";\nimport { usePress as $4vDl6$usePress, useFocusWithin as $4vDl6$useFocusWithin } from \"@react-aria/interactions\";\nimport { useField as $4vDl6$useField } from \"@react-aria/label\";\nimport { useLocale as $4vDl6$useLocale } from \"@react-aria/i18n\";\nvar $884aeceb3d67f00f$export$3b7b268d09480394 = new WeakMap();\nvar $884aeceb3d67f00f$export$8e8b214e06dd397d = new WeakMap();\nvar $884aeceb3d67f00f$export$61c8d3f0151e21b2 = new WeakMap();\nfunction $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {\n  var value = props.value,\n    children = props.children,\n    ariaLabel = props[\"aria-label\"],\n    ariaLabelledby = props[\"aria-labelledby\"];\n  var isDisabled = props.isDisabled || state.isDisabled;\n  var hasChildren = children != null;\n  var hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n  if (!hasChildren && !hasAriaLabel) console.warn(\"If you do not provide children, you must specify an aria-label for accessibility\");\n  var checked = state.selectedValue === value;\n  var onChange = function onChange(e) {\n    e.stopPropagation();\n    state.setSelectedValue(value);\n  };\n  var _ref = (0, $4vDl6$usePress)({\n      isDisabled: isDisabled\n    }),\n    pressProps = _ref.pressProps,\n    isPressed = _ref.isPressed;\n  var _ref2 = (0, $4vDl6$useFocusable)((0, $4vDl6$mergeProps)(props, {\n      onFocus: function onFocus() {\n        return state.setLastFocusedValue(value);\n      }\n    }), ref),\n    focusableProps = _ref2.focusableProps;\n  var interactions = (0, $4vDl6$mergeProps)(pressProps, focusableProps);\n  var domProps = (0, $4vDl6$filterDOMProps)(props, {\n    labelable: true\n  });\n  var tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n  if (isDisabled) tabIndex = undefined;\n  (0, $4vDl6$useFormReset)(ref, state.selectedValue, state.setSelectedValue);\n  return {\n    inputProps: (0, $4vDl6$mergeProps)(domProps, _objectSpread(_objectSpread({}, interactions), {}, {\n      type: \"radio\",\n      name: (0, $884aeceb3d67f00f$export$3b7b268d09480394).get(state),\n      tabIndex: tabIndex,\n      disabled: isDisabled,\n      checked: checked,\n      value: value,\n      onChange: onChange,\n      \"aria-describedby\": [props[\"aria-describedby\"], state.validationState === \"invalid\" ? (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).get(state) : null, (0, $884aeceb3d67f00f$export$8e8b214e06dd397d).get(state)].filter(Boolean).join(\" \") || undefined\n    })),\n    isDisabled: isDisabled,\n    isSelected: checked,\n    isPressed: isPressed\n  };\n}\nfunction $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {\n  var name = props.name,\n    validationState = props.validationState,\n    isReadOnly = props.isReadOnly,\n    isRequired = props.isRequired,\n    isDisabled = props.isDisabled,\n    _props$orientation = props.orientation,\n    orientation = _props$orientation === void 0 ? \"vertical\" : _props$orientation;\n  var _ref3 = (0, $4vDl6$useLocale)(),\n    direction = _ref3.direction;\n  var _ref4 = (0, $4vDl6$useField)(_objectSpread(_objectSpread({}, props), {}, {\n      labelElementType: \"span\"\n    })),\n    labelProps = _ref4.labelProps,\n    fieldProps = _ref4.fieldProps,\n    descriptionProps = _ref4.descriptionProps,\n    errorMessageProps = _ref4.errorMessageProps;\n  (0, $884aeceb3d67f00f$export$8e8b214e06dd397d).set(state, descriptionProps.id);\n  (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).set(state, errorMessageProps.id);\n  var domProps = (0, $4vDl6$filterDOMProps)(props, {\n    labelable: true\n  });\n  var _ref5 = (0, $4vDl6$useFocusWithin)({\n      onBlurWithin: function onBlurWithin() {\n        if (!state.selectedValue) state.setLastFocusedValue(null);\n      }\n    }),\n    focusWithinProps = _ref5.focusWithinProps;\n  var onKeyDown = function onKeyDown(e) {\n    var nextDir;\n    switch (e.key) {\n      case \"ArrowRight\":\n        if (direction === \"rtl\" && orientation !== \"vertical\") nextDir = \"prev\";else nextDir = \"next\";\n        break;\n      case \"ArrowLeft\":\n        if (direction === \"rtl\" && orientation !== \"vertical\") nextDir = \"next\";else nextDir = \"prev\";\n        break;\n      case \"ArrowDown\":\n        nextDir = \"next\";\n        break;\n      case \"ArrowUp\":\n        nextDir = \"prev\";\n        break;\n      default:\n        return;\n    }\n    e.preventDefault();\n    var walker = (0, $4vDl6$getFocusableTreeWalker)(e.currentTarget, {\n      from: e.target\n    });\n    var nextElem;\n    if (nextDir === \"next\") {\n      nextElem = walker.nextNode();\n      if (!nextElem) {\n        walker.currentNode = e.currentTarget;\n        nextElem = walker.firstChild();\n      }\n    } else {\n      nextElem = walker.previousNode();\n      if (!nextElem) {\n        walker.currentNode = e.currentTarget;\n        nextElem = walker.lastChild();\n      }\n    }\n    if (nextElem) {\n      nextElem.focus();\n      state.setSelectedValue(nextElem.value);\n    }\n  };\n  var groupName = (0, $4vDl6$useId)(name);\n  (0, $884aeceb3d67f00f$export$3b7b268d09480394).set(state, groupName);\n  return {\n    radioGroupProps: (0, $4vDl6$mergeProps)(domProps, _objectSpread(_objectSpread({\n      role: \"radiogroup\",\n      onKeyDown: onKeyDown,\n      \"aria-invalid\": validationState === \"invalid\" || undefined,\n      \"aria-errormessage\": props[\"aria-errormessage\"],\n      \"aria-readonly\": isReadOnly || undefined,\n      \"aria-required\": isRequired || undefined,\n      \"aria-disabled\": isDisabled || undefined,\n      \"aria-orientation\": orientation\n    }, fieldProps), focusWithinProps)),\n    labelProps: labelProps,\n    descriptionProps: descriptionProps,\n    errorMessageProps: errorMessageProps\n  };\n}\nexport { $0d5c49892c1215da$export$37b0961d2f4751e2 as useRadio, $430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup };","map":{"version":3,"sources":["packages/@react-aria/radio/src/useRadio.ts","packages/@react-aria/radio/src/utils.ts","packages/@react-aria/radio/src/useRadioGroup.ts"],"names":[],"mappings":";;;;;;;;ACcO,IAAM,yCAAA,GAAkB,IAAI,OAAA,CAAA,CAAA;AAC5B,IAAM,yCAAA,GAA2B,IAAI,OAAA,CAAA,CAAA;AACrC,IAAM,yCAAA,GAA4B,IAAI,OAAA,CAAA,CAAA;ADsBtC,SAAS,yCAAA,CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC,EAAA;EACtG,IACE,KAAA,GAIE,KAAA,CALA,KAAA;IAEF,QAAA,GAGE,KAAA,CAJG,QAAA;IAES,SAAA,GAEZ,KAAA,CAFF,YAAA;IACmB,cAAA,GACjB,KAAA,CADF,iBAAA;EAGF,IAAM,UAAA,GAAa,KAAA,CAAM,UAAA,IAAc,KAAA,CAAM,UAAA;EAE7C,IAAI,WAAA,GAAc,QAAA,IAAY,IAAA;EAC9B,IAAI,YAAA,GAAe,SAAA,IAAa,IAAA,IAAQ,cAAA,IAAkB,IAAA;EAC1D,IAAI,CAAC,WAAA,IAAe,CAAC,YAAA,EACnB,OAAA,CAAQ,IAAA,CAAK,kFAAA,CAAA;EAGf,IAAI,OAAA,GAAU,KAAA,CAAM,aAAA,KAAkB,KAAA;EAEtC,IAAI,QAAA,GAAW,SAAX,QAAA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MACpB;IACF,CAAA,MAAO;MACL,QAAA,GAAW,MAAA,CAAO,YAAA,CAAA,CAAA;MAClB,IAAI,CAAC,QAAA,EAAU;QACb,MAAA,CAAO,WAAA,GAAc,CAAA,CAAE,aAAA;QACvB,QAAA,GAAW,MAAA,CAAO,SAAA,CAAA,CAAA;MACpB;IACF;IACA,IAAI,QAAA,EAAU;MAEZ,QAAA,CAAS,KAAA,CAAA,CAAA;MACT,KAAA,CAAM,gBAAA,CAAiB,QAAA,CAAS,KAAA,CAAA;IAClC;EACF,CAAA;EAEA,IAAI,SAAA,GAAY,CAAA,CAAA,EAAA,YAAI,EAAE,IAAA,CAAA;EACtB,CAAA,CAAA,EAAA,yCAAc,EAAE,GAAA,CAAI,KAAA,EAAO,SAAA,CAAA;EAE3B,OAAO;IACL,eAAA,EAAiB,CAAA,CAAA,EAAA,iBAAS,EAAE,QAAA,EAAA,aAAA,CAAA,aAAA;MAE1B,IAAA,EAAM,YAAA;iBACN,SAAA;MACA,cAAA,EAAgB,eAAA,KAAoB,SAAA,IAAa,SAAA;MACjD,mBAAA,EAAqB,KAAK,CAAC,mBAAA,CAAoB;MAC/C,eAAA,EAAiB,UAAA,IAAc,SAAA;MAC/B,eAAA,EAAiB,UAAA,IAAc,SAAA;MAC/B,eAAA,EAAiB,UAAA,IAAc,SAAA;MAC/B,kBAAA,EAAoB;IAAA,GACjB,UAAU,GACV,gBAAgB,CACrB,CAAA;gBACA,UAAA;sBACA,gBAAA;uBACA;EACF,CAAA;AACF","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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\n  /** Props for the input element. */\n  inputProps: InputHTMLAttributes<HTMLInputElement>,\n  /** Whether the radio is disabled. */\n  isDisabled: boolean,\n  /** Whether the radio is currently selected. */\n  isSelected: boolean,\n  /** Whether the radio is in a pressed state. */\n  isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLInputElement>): RadioAria {\n  let {\n    value,\n    children,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledby\n  } = props;\n\n  const isDisabled = props.isDisabled || state.isDisabled;\n\n  let hasChildren = children != null;\n  let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n  if (!hasChildren && !hasAriaLabel) {\n    console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n  }\n\n  let checked = state.selectedValue === value;\n\n  let onChange = (e) => {\n    e.stopPropagation();\n    state.setSelectedValue(value);\n  };\n\n  let {pressProps, isPressed} = usePress({\n    isDisabled\n  });\n\n  let {focusableProps} = useFocusable(mergeProps(props, {\n    onFocus: () => state.setLastFocusedValue(value)\n  }), ref);\n  let interactions = mergeProps(pressProps, focusableProps);\n  let domProps = filterDOMProps(props, {labelable: true});\n  let tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n  if (isDisabled) {\n    tabIndex = undefined;\n  }\n\n  useFormReset(ref, state.selectedValue, state.setSelectedValue);\n\n  return {\n    inputProps: mergeProps(domProps, {\n      ...interactions,\n      type: 'radio',\n      name: radioGroupNames.get(state),\n      tabIndex,\n      disabled: isDisabled,\n      checked,\n      value,\n      onChange,\n      'aria-describedby': [\n        props['aria-describedby'],\n        state.validationState === 'invalid' ? radioGroupErrorMessageIds.get(state) : null,\n        radioGroupDescriptionIds.get(state)\n      ].filter(Boolean).join(' ') || undefined\n    }),\n    isDisabled,\n    isSelected: checked,\n    isPressed\n  };\n}\n","/*\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 {RadioGroupState} from '@react-stately/radio';\n\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\nexport const radioGroupDescriptionIds = new WeakMap<RadioGroupState, string>();\nexport const radioGroupErrorMessageIds = new WeakMap<RadioGroupState, string>();\n","/*\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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria {\n  /** Props for the radio group wrapper element. */\n  radioGroupProps: DOMAttributes,\n  /** Props for the radio group's visible label (if any). */\n  labelProps: DOMAttributes,\n  /** Props for the radio group description element, if any. */\n  descriptionProps: DOMAttributes,\n  /** Props for the radio group error message element, if any. */\n  errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n  let {\n    name,\n    validationState,\n    isReadOnly,\n    isRequired,\n    isDisabled,\n    orientation = 'vertical'\n  } = props;\n  let {direction} = useLocale();\n\n  let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n    ...props,\n    // Radio group is not an HTML input element so it\n    // shouldn't be labeled by a <label> element.\n    labelElementType: 'span'\n  });\n  radioGroupDescriptionIds.set(state, descriptionProps.id);\n  radioGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n  let domProps = filterDOMProps(props, {labelable: true});\n\n  // When the radio group loses focus, reset the focusable radio to null if\n  // there is no selection. This allows tabbing into the group from either\n  // direction to go to the first or last radio.\n  let {focusWithinProps} = useFocusWithin({\n    onBlurWithin() {\n      if (!state.selectedValue) {\n        state.setLastFocusedValue(null);\n      }\n    }\n  });\n\n  let onKeyDown = (e) => {\n    let nextDir;\n    switch (e.key) {\n      case 'ArrowRight':\n        if (direction === 'rtl' && orientation !== 'vertical') {\n          nextDir = 'prev';\n        } else {\n          nextDir = 'next';\n        }\n        break;\n      case 'ArrowLeft':\n        if (direction === 'rtl' && orientation !== 'vertical') {\n          nextDir = 'next';\n        } else {\n          nextDir = 'prev';\n        }\n        break;\n      case 'ArrowDown':\n        nextDir = 'next';\n        break;\n      case 'ArrowUp':\n        nextDir = 'prev';\n        break;\n      default:\n        return;\n    }\n    e.preventDefault();\n    let walker = getFocusableTreeWalker(e.currentTarget, {from: e.target});\n    let nextElem;\n    if (nextDir === 'next') {\n      nextElem = walker.nextNode();\n      if (!nextElem) {\n        walker.currentNode = e.currentTarget;\n        nextElem = walker.firstChild();\n      }\n    } else {\n      nextElem = walker.previousNode();\n      if (!nextElem) {\n        walker.currentNode = e.currentTarget;\n        nextElem = walker.lastChild();\n      }\n    }\n    if (nextElem) {\n      // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n      nextElem.focus();\n      state.setSelectedValue(nextElem.value);\n    }\n  };\n\n  let groupName = useId(name);\n  radioGroupNames.set(state, groupName);\n\n  return {\n    radioGroupProps: mergeProps(domProps, {\n      // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n      role: 'radiogroup',\n      onKeyDown,\n      'aria-invalid': validationState === 'invalid' || undefined,\n      'aria-errormessage': props['aria-errormessage'],\n      'aria-readonly': isReadOnly || undefined,\n      'aria-required': isRequired || undefined,\n      'aria-disabled': isDisabled || undefined,\n      'aria-orientation': orientation,\n      ...fieldProps,\n      ...focusWithinProps\n    }),\n    labelProps,\n    descriptionProps,\n    errorMessageProps\n  };\n}\n"]},"metadata":{},"sourceType":"module"}