{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { useControlledState as $bOkae$useControlledState } from \"@react-stately/utils\";\nfunction $3017fa7ffdddec74$export$8042c6c013fd5226() {\n  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n  var isReadOnly = props.isReadOnly;\n  var _ref = (0, $bOkae$useControlledState)(props.isSelected, props.defaultSelected || false, props.onChange),\n    _ref2 = _slicedToArray(_ref, 2),\n    isSelected = _ref2[0],\n    setSelected = _ref2[1];\n  function updateSelected(value) {\n    if (!isReadOnly) setSelected(value);\n  }\n  function toggleState() {\n    if (!isReadOnly) setSelected(!isSelected);\n  }\n  return {\n    isSelected: isSelected,\n    setSelected: updateSelected,\n    toggle: toggleState\n  };\n}\nexport { $3017fa7ffdddec74$export$8042c6c013fd5226 as useToggleState };","map":{"version":3,"sources":["packages/@react-stately/toggle/src/useToggleState.ts"],"names":[],"mappings":";;AA6BO,SAAS,yCAAA,CAAA,EAAqD;EAAA,IAAtC,KAAA,GAAA,SAAA,CAAA,MAAA,QAAA,SAAA,QAAA,SAAA,GAAA,SAAA,MAAqB,CAAC,CAAC;EACpD,IAAK,UAAA,GAAc,KAAA,CAAf,UAAA;EAIJ,IAAA,IAAA,GAAgC,CAAA,CAAA,EAAA,yBAAkB,EAAC,KAAA,CAAM,UAAU,EAAE,KAAA,CAAM,eAAe,IAAI,KAAK,EAAE,KAAA,CAAM,QAAQ,CAAA;IAAA,KAAA,GAAA,cAAA,CAAA,IAAA;IAA9G,UAAA,GAAA,KAAA;IAAY,WAAA,GAAA,KAAA;EAEjB,SAAS,cAAA,CAAe,KAAK,EAAE;IAC7B,IAAI,CAAC,UAAA,EACH,WAAA,CAAY,KAAA,CAAA;EAEhB;EAEA,SAAS,WAAA,CAAA,EAAc;IACrB,IAAI,CAAC,UAAA,EACH,WAAA,CAAY,CAAC,UAAA,CAAA;EAEjB;EAEA,OAAO;gBACL,UAAA;IACA,WAAA,EAAa,cAAA;IACb,MAAA,EAAQ;EACV,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 {ToggleProps} from '@react-types/checkbox';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface ToggleState {\n  /** Whether the toggle is selected. */\n  readonly isSelected: boolean,\n\n  /** Updates selection state. */\n  setSelected(isSelected: boolean): void,\n\n  /** Toggle the selection state. */\n  toggle(): void\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleProps = {}): ToggleState {\n  let {isReadOnly} = props;\n\n  // have to provide an empty function so useControlledState doesn't throw a fit\n  // can't use useControlledState's prop calling because we need the event object from the change\n  let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);\n\n  function updateSelected(value) {\n    if (!isReadOnly) {\n      setSelected(value);\n    }\n  }\n\n  function toggleState() {\n    if (!isReadOnly) {\n      setSelected(!isSelected);\n    }\n  }\n\n  return {\n    isSelected,\n    setSelected: updateSelected,\n    toggle: toggleState\n  };\n}\n"]},"metadata":{},"sourceType":"module"}