{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { useMemo, useState } from \"react\";\nimport { useControlledState } from \"@react-stately/utils\";\nvar $eaf77ba5e143129c6bb329a6e66020d3$var$instance = Math.round(Math.random() * 10000000000);\nvar $eaf77ba5e143129c6bb329a6e66020d3$var$i = 0;\nexport function useRadioGroupState(props) {\n  var name = useMemo(function () {\n    return props.name || \"radio-group-\" + $eaf77ba5e143129c6bb329a6e66020d3$var$instance + \"-\" + ++$eaf77ba5e143129c6bb329a6e66020d3$var$i;\n  }, [props.name]);\n  var _useControlledState = useControlledState(props.value, props.defaultValue, props.onChange),\n    _useControlledState2 = _slicedToArray(_useControlledState, 2),\n    selectedValue = _useControlledState2[0],\n    setSelected = _useControlledState2[1];\n  var _useState = useState(null),\n    _useState2 = _slicedToArray(_useState, 2),\n    lastFocusedValue = _useState2[0],\n    setLastFocusedValue = _useState2[1];\n  var setSelectedValue = function setSelectedValue(value) {\n    if (!props.isReadOnly) {\n      setSelected(value);\n    }\n  };\n  return {\n    name: name,\n    selectedValue: selectedValue,\n    setSelectedValue: setSelectedValue,\n    lastFocusedValue: lastFocusedValue,\n    setLastFocusedValue: setLastFocusedValue\n  };\n}","map":{"version":3,"sources":["packages/@react-stately/radio/src/useRadioGroupState.ts"],"names":["instance","Math","round","random","i","useRadioGroupState","props","name","useMemo","selectedValue","setSelected","useControlledState","value","defaultValue","onChange","lastFocusedValue","setLastFocusedValue","useState","setSelectedValue","isReadOnly"],"mappings":";;;AAqCA,IAAIA,8CAAQ,GAAGC,IAAI,CAACC,KAALD,CAAWA,IAAI,CAACE,MAALF,CAAAA,CAAAA,GAAgB,WAA3BA,CAAf;AACA,IAAIG,uCAAC,GAAG,CAAR;OAMO,SAASC,kBAAT,CAA4BC,KAA5B,EAAsE;EAE3E,IAAIC,IAAI,GAAGC,OAAO,CAAC;IAAA,OAAMF,KAAK,CAACC,IAAND,IAAAA,cAAAA,GAA6BN,8CAA7BM,GAAAA,GAAAA,GAAyC,EAAEF,uCAAlD;EAAA,GAAuD,CAACE,KAAK,CAACC,IAAP,CAAvD,CAAlB;EACA,IAAA,mBAAA,GAAmCI,kBAAkB,CAACL,KAAK,CAACM,KAAP,EAAcN,KAAK,CAACO,YAApB,EAAkCP,KAAK,CAACQ,QAAxC,CAArD;IAAA,oBAAA,GAAA,cAAA,CAAA,mBAAA;IAAKL,aAAD,GAAA,oBAAA;IAAgBC,WAAhB,GAAA,oBAAA;EACJ,IAAA,SAAA,GAA8CO,QAAQ,CAAC,IAAD,CAAtD;IAAA,UAAA,GAAA,cAAA,CAAA,SAAA;IAAKF,gBAAD,GAAA,UAAA;IAAmBC,mBAAnB,GAAA,UAAA;EAEJ,IAAIE,gBAAgB,GAAIN,SAApBM,gBAAgB,CAAIN,KAAD,EAAW;IAChC,IAAI,CAACN,KAAK,CAACa,UAAX,EAAuB;MACrBT,WAAW,CAACE,KAAD,CAAXF;IACD;EACF,CAJD;EAMA,OAAO;IACLH,IADK,EACLA,IADK;IAELE,aAFK,EAELA,aAFK;IAGLS,gBAHK,EAGLA,gBAHK;IAILH,gBAJK,EAILA,gBAJK;IAKLC,mBAAAA,EAAAA;EALK,CAAP;AAOD","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 {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupState {\n  /**\n   * The name for the group, used for native form submission.\n   * @deprecated\n   * @private\n   */\n  readonly name: string,\n\n  /** The currently selected value. */\n  readonly selectedValue: string | null,\n\n  /** Sets the selected value. */\n  setSelectedValue(value: string): void,\n\n  /** The value of the last focused radio. */\n  readonly lastFocusedValue: string | null,\n\n  /** Sets the last focused value. */\n  setLastFocusedValue(value: string): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState  {\n  // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n  let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n  let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue, props.onChange);\n  let [lastFocusedValue, setLastFocusedValue] = useState(null);\n\n  let setSelectedValue = (value) => {\n    if (!props.isReadOnly) {\n      setSelected(value);\n    }\n  };\n\n  return {\n    name,\n    selectedValue,\n    setSelectedValue,\n    lastFocusedValue,\n    setLastFocusedValue\n  };\n}\n"]},"metadata":{},"sourceType":"module"}