{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\n\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; }\n\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; }\n\nimport { mergeProps as $iHgPh$mergeProps, filterDOMProps as $iHgPh$filterDOMProps, useId as $iHgPh$useId } from \"@react-aria/utils\";\nimport { useFocusable as $iHgPh$useFocusable, getFocusableTreeWalker as $iHgPh$getFocusableTreeWalker } from \"@react-aria/focus\";\nimport { usePress as $iHgPh$usePress, useFocusWithin as $iHgPh$useFocusWithin } from \"@react-aria/interactions\";\nimport { useLabel as $iHgPh$useLabel } from \"@react-aria/label\";\nimport { useLocale as $iHgPh$useLocale } from \"@react-aria/i18n\";\n\nfunction $parcel$export(e, n, v, s) {\n  Object.defineProperty(e, n, {\n    get: v,\n    set: s,\n    enumerable: true,\n    configurable: true\n  });\n}\n\nvar $6657631d22f179ad$exports = {};\n$parcel$export($6657631d22f179ad$exports, \"useRadio\", function () {\n  return $6657631d22f179ad$export$37b0961d2f4751e2;\n});\nvar $bd4891a2aaf94c29$export$3b7b268d09480394 = new WeakMap();\n\nfunction $6657631d22f179ad$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\n  var onChange = function onChange(e) {\n    e.stopPropagation();\n    state.setSelectedValue(value);\n  };\n\n  var _$iHgPh$usePress = $iHgPh$usePress({\n    isDisabled: isDisabled\n  }),\n      pressProps = _$iHgPh$usePress.pressProps;\n\n  var _$iHgPh$useFocusable = $iHgPh$useFocusable($iHgPh$mergeProps(props, {\n    onFocus: function onFocus() {\n      return state.setLastFocusedValue(value);\n    }\n  }), ref),\n      focusableProps = _$iHgPh$useFocusable.focusableProps;\n\n  var interactions = $iHgPh$mergeProps(pressProps, focusableProps);\n  var domProps = $iHgPh$filterDOMProps(props, {\n    labelable: true\n  });\n  var tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n  if (isDisabled) tabIndex = undefined;\n  return {\n    inputProps: $iHgPh$mergeProps(domProps, _objectSpread(_objectSpread({}, interactions), {}, {\n      type: 'radio',\n      name: $bd4891a2aaf94c29$export$3b7b268d09480394.get(state),\n      tabIndex: tabIndex,\n      disabled: isDisabled,\n      checked: checked,\n      value: value,\n      onChange: onChange\n    }))\n  };\n}\n\nvar $c6603e85cbfc3c71$exports = {};\n$parcel$export($c6603e85cbfc3c71$exports, \"useRadioGroup\", function () {\n  return $c6603e85cbfc3c71$export$62b9571f283ff5c2;\n});\n\nfunction $c6603e85cbfc3c71$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\n  var _$iHgPh$useLocale = $iHgPh$useLocale(),\n      direction = _$iHgPh$useLocale.direction;\n\n  var _$iHgPh$useLabel = $iHgPh$useLabel(_objectSpread(_objectSpread({}, props), {}, {\n    labelElementType: 'span'\n  })),\n      labelProps = _$iHgPh$useLabel.labelProps,\n      fieldProps = _$iHgPh$useLabel.fieldProps;\n\n  var domProps = $iHgPh$filterDOMProps(props, {\n    labelable: true\n  });\n\n  var _$iHgPh$useFocusWithi = $iHgPh$useFocusWithin({\n    onBlurWithin: function onBlurWithin() {\n      if (!state.selectedValue) state.setLastFocusedValue(null);\n    }\n  }),\n      focusWithinProps = _$iHgPh$useFocusWithi.focusWithinProps;\n\n  var onKeyDown = function onKeyDown(e) {\n    var nextDir;\n\n    switch (e.key) {\n      case 'ArrowRight':\n        if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'prev';else nextDir = 'next';\n        break;\n\n      case 'ArrowLeft':\n        if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'next';else nextDir = 'prev';\n        break;\n\n      case 'ArrowDown':\n        nextDir = 'next';\n        break;\n\n      case 'ArrowUp':\n        nextDir = 'prev';\n        break;\n\n      default:\n        return;\n    }\n\n    e.preventDefault();\n    var walker = $iHgPh$getFocusableTreeWalker(e.currentTarget, {\n      from: e.target\n    });\n    var nextElem;\n\n    if (nextDir === 'next') {\n      nextElem = walker.nextNode();\n\n      if (!nextElem) {\n        walker.currentNode = e.currentTarget;\n        nextElem = walker.firstChild();\n      }\n    } else {\n      nextElem = walker.previousNode();\n\n      if (!nextElem) {\n        walker.currentNode = e.currentTarget;\n        nextElem = walker.lastChild();\n      }\n    }\n\n    if (nextElem) {\n      nextElem.focus();\n      state.setSelectedValue(nextElem.value);\n    }\n  };\n\n  var groupName = $iHgPh$useId(name);\n  $bd4891a2aaf94c29$export$3b7b268d09480394.set(state, groupName);\n  return {\n    radioGroupProps: $iHgPh$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  };\n}\n\nexport { $6657631d22f179ad$export$37b0961d2f4751e2 as useRadio, $c6603e85cbfc3c71$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,yCAAe,GAAG,IAAI,OAAJ,EAAxB;;SDkBS,yC,CAAS,K,EAAuB,K,EAAwB,G,EAAwC;AAC9G,MACE,KADF,GAKI,KALJ,CAAK,KAAL;AAAA,MAEE,QAFF,GAKI,KALJ,CACO,QADP;AAAA,MAGgB,SAHhB,GAKI,KALJ,CAGE,YAHF;AAAA,MAIqB,cAJrB,GAKI,KALJ,CAIE,iBAJF;AAOA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAN,IAAoB,KAAK,CAAC,UAA7C;AAEA,MAAI,WAAW,GAAG,QAAQ,IAAI,IAA9B;AACA,MAAI,YAAY,GAAG,SAAS,IAAI,IAAb,IAAqB,cAAc,IAAI,IAA1D;AACA,MAAE,CAAG,WAAH,IAAc,CAAK,YAArB,EACE,OAAO,CAAC,IAAR,CAAa,kFAAb;AAGF,MAAI,OAAO,GAAG,KAAK,CAAC,aAAN,KAAwB,KAAtC;;AAEA,MAAI,QAAQ,GAAA,SAAR,QAAQ,CAAI,CAAJ,EAAU;AACpB,IAAA,CAAC,CAAC,eAAF;AACA,IAAA,KAAK,CAAC,gBAAN,CAAuB,KAAvB;AACD,GAHD;;AAKA,yBAAmB,eAAQ,CAAC;gBAC1B;AAD0B,GAAD,CAA3B;AAAA,MAAK,UAAL,oBAAK,UAAL;;AAIA,6BAAuB,mBAAY,CAAC,iBAAU,CAAC,KAAD,EAAQ;AACpD,IAAA,OAAO,EAAA;AAAA,aAAQ,KAAK,CAAC,mBAAN,CAA0B,K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,CAAG,QAAL,EAAe;AACb,QAAA,MAAM,CAAC,WAAP,GAAqB,CAAC,CAAC,aAAvB;AACA,QAAA,QAAQ,GAAG,MAAM,CAAC,SAAP,EAAX;AACD;AACF;;AACD,QAAI,QAAJ,EAAc;AAEZ,MAAA,QAAQ,CAAC,KAAT;AACA,MAAA,KAAK,CAAC,gBAAN,CAAuB,QAAQ,CAAC,KAAhC;AACD;AACF,GA/CD;;AAiDA,MAAI,SAAS,GAAG,YAAK,CAAC,IAAD,CAArB;AACA,EAAA,yCAAe,CAAC,GAAhB,CAAoB,KAApB,EAA2B,SAA3B;AAEA,SAAO;AACL,IAAA,eAAe,EAAE,iBAAU,CAAC,QAAD;AAEzB,MAAA,IAAI,EAAE,YAFmB;iBAGzB,SAHyB;AAIzB,sBAAgB,eAAe,KAAK,SAApB,IAAiC,SAJxB;AAKzB,2BAAqB,KAAK,CAAC,mBAAD,CALD;AAMzB,uBAAiB,UAAU,IAAI,SANN;AAOzB,uBAAiB,UAAU,IAAI,SAPN;AAQzB,uBAAiB,UAAU,IAAI,SARN;AASzB,0BAAoB;AATK,OAUtB,UAVsB,GAWtB,gBAXsB,EADtB;gBAcL;AAdK,GAAP;AAgBD","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} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\ninterface RadioAria {\n  /** Props for the input element. */\n  inputProps: InputHTMLAttributes<HTMLElement>\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<HTMLElement>): 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} = 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  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    })\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>();\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 {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {HTMLAttributes} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLabel} from '@react-aria/label';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface RadioGroupAria {\n  /** Props for the radio group wrapper element. */\n  radioGroupProps: HTMLAttributes<HTMLElement>,\n  /** Props for the radio group's visible label (if any). */\n  labelProps: HTMLAttributes<HTMLElement>\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} = useLabel({\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\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  };\n}\n"]},"metadata":{},"sourceType":"module"}