{"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 $aVyw8$mergeProps, filterDOMProps as $aVyw8$filterDOMProps } from \"@react-aria/utils\";\nimport { useFocusable as $aVyw8$useFocusable } from \"@react-aria/focus\";\nimport { usePress as $aVyw8$usePress } from \"@react-aria/interactions\";\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 $6f01a055f297c6b8$exports = {};\n$parcel$export($6f01a055f297c6b8$exports, \"useToggle\", function () {\n  return $6f01a055f297c6b8$export$cbe85ee05b554577;\n});\n\nfunction $6f01a055f297c6b8$export$cbe85ee05b554577(props, state, ref) {\n  var _props$isDisabled = props.isDisabled,\n      isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,\n      isRequired = props.isRequired,\n      isReadOnly = props.isReadOnly,\n      value = props.value,\n      name = props.name,\n      children = props.children,\n      ariaLabel = props['aria-label'],\n      ariaLabelledby = props['aria-labelledby'],\n      _props$validationStat = props.validationState,\n      validationState = _props$validationStat === void 0 ? 'valid' : _props$validationStat;\n\n  var onChange = function onChange(e) {\n    e.stopPropagation();\n    state.setSelected(e.target.checked);\n  };\n\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\n  var _$aVyw8$usePress = $aVyw8$usePress({\n    isDisabled: isDisabled\n  }),\n      pressProps = _$aVyw8$usePress.pressProps;\n\n  var _$aVyw8$useFocusable = $aVyw8$useFocusable(props, ref),\n      focusableProps = _$aVyw8$useFocusable.focusableProps;\n\n  var interactions = $aVyw8$mergeProps(pressProps, focusableProps);\n  var domProps = $aVyw8$filterDOMProps(props, {\n    labelable: true\n  });\n  return {\n    inputProps: $aVyw8$mergeProps(domProps, _objectSpread({\n      'aria-invalid': validationState === 'invalid' || undefined,\n      'aria-errormessage': props['aria-errormessage'],\n      'aria-controls': props['aria-controls'],\n      'aria-readonly': isReadOnly || undefined,\n      'aria-required': isRequired || undefined,\n      onChange: onChange,\n      disabled: isDisabled,\n      value: value,\n      name: name,\n      type: 'checkbox'\n    }, interactions))\n  };\n}\n\nexport { $6f01a055f297c6b8$export$cbe85ee05b554577 as useToggle };","map":{"version":3,"sources":["packages/@react-aria/toggle/src/useToggle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;SA6BgB,yC,CAAU,K,EAAwB,K,EAAoB,G,EAAyC;AAC7G,0BAUI,KAVJ,CAAK,UAAL;AAAA,MACE,UADF,kCACe,KADf;AAAA,MAEE,UAFF,GAUI,KAVJ,CACoB,UADpB;AAAA,MAGE,UAHF,GAUI,KAVJ,CAEY,UAFZ;AAAA,MAIE,KAJF,GAUI,KAVJ,CAGY,KAHZ;AAAA,MAKE,IALF,GAUI,KAVJ,CAIO,IAJP;AAAA,MAME,QANF,GAUI,KAVJ,CAKM,QALN;AAAA,MAOgB,SAPhB,GAUI,KAVJ,CAOE,YAPF;AAAA,MAQqB,cARrB,GAUI,KAVJ,CAQE,iBARF;AAAA,8BAUI,KAVJ,CAQmC,eARnC;AAAA,MASE,eATF,sCASoB,OATpB;;AAYA,MAAI,QAAQ,GAAA,SAAR,QAAQ,CAAI,CAAJ,EAAU;AAGpB,IAAA,CAAC,CAAC,eAAF;AACA,IAAA,KAAK,CAAC,WAAN,CAAkB,CAAC,CAAC,MAAF,CAAS,OAA3B;AACD,GALD;;AAOA,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;;AAIF,yBAAmB,eAAQ,CAAC;gBAC1B;AAD0B,GAAD,CAA3B;AAAA,MAAK,UAAL,oBAAK,UAAL;;AAIA,6BAAuB,mBAAY,CAAC,KAAD,EAAQ,GAAR,CAAnC;AAAA,MAAK,cAAL,wBAAK,cAAL;;AACA,MAAI,YAAY,GAAG,iBAAU,CAAC,UAAD,EAAa,cAAb,CAA7B;AACA,MAAI,QAAQ,GAAG,qBAAc,CAAC,KAAD,EAAQ;AAAC,IAAA,SAAS,EAAE;AAAZ,GAAR,CAA7B;AAEA,SAAO;AACL,IAAA,UAAU,EAAE,iBAAU,CAAC,QAAD;AACpB,sBAAgB,eAAe,KAAK,SAApB,IAAiC,SAD7B;AAEpB,2BAAqB,KAAK,CAAC,mBAAD,CAFN;AAGpB,uBAAiB,KAAK,CAAC,eAAD,CAHF;AAIpB,uBAAiB,UAAU,IAAI,SAJX;AAKpB,uBAAiB,UAAU,IAAI,SALX;gBAMpB,QANoB;AAOpB,MAAA,QAAQ,EAAE,UAPU;aAQpB,KARoB;YASpB,IAToB;AAUpB,MAAA,IAAI,EAAE;AAVc,OAWjB,YAXiB;AADjB,GAAP;AAeD","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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n  /**\n   * Props to be spread on the input element.\n   */\n  inputProps: InputHTMLAttributes<HTMLInputElement>\n}\n\n/**\n * Handles interactions for toggle elements, e.g. Checkboxes and Switches.\n */\nexport function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLElement>): ToggleAria {\n  let {\n    isDisabled = false,\n    isRequired,\n    isReadOnly,\n    value,\n    name,\n    children,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledby,\n    validationState = 'valid'\n  } = props;\n\n  let onChange = (e) => {\n    // since we spread props on label, onChange will end up there as well as in here.\n    // so we have to stop propagation at the lowest level that we care about\n    e.stopPropagation();\n    state.setSelected(e.target.checked);\n  };\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  // This handles focusing the input on pointer down, which Safari does not do by default.\n  let {pressProps} = usePress({\n    isDisabled\n  });\n\n  let {focusableProps} = useFocusable(props, ref);\n  let interactions = mergeProps(pressProps, focusableProps);\n  let domProps = filterDOMProps(props, {labelable: true});\n\n  return {\n    inputProps: mergeProps(domProps, {\n      'aria-invalid': validationState === 'invalid' || undefined,\n      'aria-errormessage': props['aria-errormessage'],\n      'aria-controls': props['aria-controls'],\n      'aria-readonly': isReadOnly || undefined,\n      'aria-required': isRequired || undefined,\n      onChange,\n      disabled: isDisabled,\n      value,\n      name,\n      type: 'checkbox',\n      ...interactions\n    })\n  };\n}\n"]},"metadata":{},"sourceType":"module"}