{"ast":null,"code":"import { usePress } from \"@react-aria/interactions\";\nimport { useFocusable } from \"@react-aria/focus\";\nimport { filterDOMProps, mergeProps } from \"@react-aria/utils\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nexport function useToggle(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\n  if (!hasChildren && !hasAriaLabel) {\n    console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n  }\n\n  var _usePress = usePress({\n    isDisabled: isDisabled\n  }),\n      pressProps = _usePress.pressProps;\n\n  var _useFocusable = useFocusable(props, ref),\n      focusableProps = _useFocusable.focusableProps;\n\n  var interactions = mergeProps(pressProps, focusableProps);\n  var domProps = filterDOMProps(props, {\n    labelable: true\n  });\n  return {\n    inputProps: mergeProps(domProps, _babelRuntimeHelpersEsmExtends({\n      'aria-invalid': validationState === 'invalid' || undefined,\n      'aria-errormessage': props['aria-errormessage'],\n      'aria-controls': props['aria-controls'],\n      onChange: onChange,\n      disabled: isDisabled,\n      required: isRequired,\n      readOnly: isReadOnly,\n      value: value,\n      name: name,\n      type: 'checkbox'\n    }, interactions))\n  };\n}","map":{"version":3,"sources":["packages/@react-aria/toggle/src/useToggle.ts"],"names":["isDisabled","validationState","onChange","e","state","hasChildren","children","hasAriaLabel","ariaLabel","ariaLabelledby","console","pressProps","usePress","focusableProps","useFocusable","interactions","mergeProps","domProps","filterDOMProps","labelable","inputProps","props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AGC,UAAU,CAAA,UAAA,EAA7B,cAA6B,CAA7B;AACA,MAAIC,QAAQ,GAAGC,cAAc,CAAA,KAAA,EAAQ;AAACC,IAAAA,SAAS,EAAE;AAAZ,GAAR,CAA7B;AAEA,SAAO;AACLC,IAAAA,UAAU,EAAEJ,UAAU,CAAA,QAAA,EAAA,8BAAA,CAAA;AACpB,sBAAgBf,eAAe,KAAfA,SAAAA,IADI,SAAA;AAEpB,2BAAqBoB,KAAK,CAFN,mBAEM,CAFN;AAGpB,uBAAiBA,KAAK,CAHF,eAGE,CAHF;AAIpBnB,MAAAA,QAJoB,EAIpBA,QAJoB;AAKpBoB,MAAAA,QAAQ,EALY,UAAA;AAMpBC,MAAAA,QAAQ,EANY,UAAA;AAOpBC,MAAAA,QAAQ,EAPY,UAAA;AAQpBC,MAAAA,KARoB,EAQpBA,KARoB;AASpBC,MAAAA,IAToB,EASpBA,IAToB;AAUpBC,MAAAA,IAAI,EAAE;AAVc,KAAA,EAAA,YAAA,CAAA;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      onChange,\n      disabled: isDisabled,\n      required: isRequired,\n      readOnly: isReadOnly,\n      value,\n      name,\n      type: 'checkbox',\n      ...interactions\n    })\n  };\n}\n"]},"metadata":{},"sourceType":"module"}