{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { useControlledState as $cWY0e$useControlledState } from \"@react-stately/utils\";\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 $f47e43bfabc9ba47$exports = {};\n$parcel$export($f47e43bfabc9ba47$exports, \"useToggleState\", function () {\n  return $f47e43bfabc9ba47$export$8042c6c013fd5226;\n});\n\nfunction $f47e43bfabc9ba47$export$8042c6c013fd5226() {\n  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n  var isReadOnly = props.isReadOnly;\n\n  var _$cWY0e$useControlled = $cWY0e$useControlledState(props.isSelected, props.defaultSelected || false, props.onChange),\n      _$cWY0e$useControlled2 = _slicedToArray(_$cWY0e$useControlled, 2),\n      isSelected = _$cWY0e$useControlled2[0],\n      setSelected = _$cWY0e$useControlled2[1];\n\n  function updateSelected(value) {\n    if (!isReadOnly) setSelected(value);\n  }\n\n  function toggleState() {\n    if (!isReadOnly) setSelected(!isSelected);\n  }\n\n  return {\n    isSelected: isSelected,\n    setSelected: updateSelected,\n    toggle: toggleState\n  };\n}\n\nexport { $f47e43bfabc9ba47$export$8042c6c013fd5226 as useToggleState };","map":{"version":3,"sources":["packages/@react-stately/toggle/src/useToggleState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;SA6BgB,yC,GAAqD;AAAA,MAAtC,KAAsC,uEAAjB,EAAiB;AACnE,MAAK,UAAL,GAAmB,KAAnB,CAAK,UAAL;;AAIA,8BAAgC,yBAAkB,CAAC,KAAK,CAAC,UAAP,EAAmB,KAAK,CAAC,eAAN,IAAyB,KAA5C,EAAmD,KAAK,CAAC,QAAzD,CAAlD;AAAA;AAAA,MAAK,UAAL;AAAA,MAAiB,WAAjB;;WAES,c,CAAe,K,EAAO;AAC7B,QAAE,CAAG,UAAL,EACE,WAAW,CAAC,KAAD,CAAX;AAEH;;WAEQ,W,GAAc;AACrB,QAAE,CAAG,UAAL,EACE,WAAW,CAAA,CAAE,UAAF,CAAX;AAEH;;AAED,SAAO;gBACL,UADK;AAEL,IAAA,WAAW,EAAE,cAFR;AAGL,IAAA,MAAM,EAAE;AAHH,GAAP;AAKD","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"}