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Ae,EAAE,MAAM,WAAW;IAE1D,OAAO;QACL,YAAY,CAAA,GAAA,yCAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,yCAAS,EAAE,UAAU;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,cAAc;sBAC/B;YACA,UAAU;YACV,GAAI,SAAS,OAAO,CAAC,IAAI;uBAAC;YAAK,CAAC;kBAChC;kBACA;YACA,MAAM;YACN,GAAG,YAAY;QACjB;QACA,YAAY,MAAM,UAAU;QAC5B,WAAW,aAAa;oBACxB;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF","sources":["packages/react-aria/src/toggle/useToggle.ts"],"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 {AriaLabelingProps, AriaValidationProps, FocusableDOMProps, InputDOMProps, PressEvents, RefObject} from '@react-types/shared';\nimport {ChangeEventHandler, InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {mergeProps} from '../utils/mergeProps';\nimport {ToggleProps, ToggleState} from 'react-stately/useToggleState';\nimport {useFocusable} from '../interactions/useFocusable';\nimport {useFormReset} from '../utils/useFormReset';\nimport {usePress} from '../interactions/usePress';\n\nexport interface AriaToggleProps extends ToggleProps, FocusableDOMProps, AriaLabelingProps, AriaValidationProps, InputDOMProps, PressEvents {\n  /**\n   * Identifies the element (or elements) whose contents or presence are controlled by the current element.\n   */\n  'aria-controls'?: string\n}\n\nexport interface ToggleAria {\n  /** Props to be spread on the label element. */\n  labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n  /** Props to be spread on the input element. */\n  inputProps: InputHTMLAttributes<HTMLInputElement>,\n  /** Whether the toggle is selected. */\n  isSelected: boolean,\n  /** Whether the toggle is in a pressed state. */\n  isPressed: boolean,\n  /** Whether the toggle is disabled. */\n  isDisabled: boolean,\n  /** Whether the toggle is read only. */\n  isReadOnly: boolean,\n  /** Whether the toggle is invalid. */\n  isInvalid: boolean\n}\n\n/**\n * Handles interactions for toggle elements, e.g. Checkboxes and Switches.\n */\nexport function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria {\n  let {\n    isDisabled = false,\n    isReadOnly = false,\n    value,\n    name,\n    form,\n    children,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledby,\n    validationState = 'valid',\n    isInvalid,\n    onPressStart,\n    onPressEnd,\n    onPressChange,\n    onPress,\n    onPressUp,\n    onClick\n  } = props;\n\n  let onChange: ChangeEventHandler<HTMLInputElement> = (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(getEventTarget(e).checked);\n  };\n\n  let hasChildren = children != null;\n  let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n  if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') {\n    console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n  }\n\n  // Handle press state for keyboard interactions and cases where labelProps is not used.\n  let {pressProps, isPressed} = usePress({\n    onPressStart,\n    onPressEnd,\n    onPressChange,\n    onPress,\n    onPressUp,\n    onClick,\n    isDisabled\n  });\n\n  // Handle press state on the label.\n  let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n    onPressStart,\n    onPressEnd,\n    onPressChange,\n    onPressUp,\n    onClick,\n    onPress(e) {\n      onPress?.(e);\n      state.toggle();\n      ref.current?.focus();\n    },\n    isDisabled: isDisabled || isReadOnly\n  });\n\n  let {focusableProps} = useFocusable(props, ref);\n  let interactions = mergeProps(pressProps, focusableProps);\n  let domProps = filterDOMProps(props, {labelable: true});\n\n  useFormReset(ref, state.defaultSelected, state.setSelected);\n\n  return {\n    labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n    inputProps: mergeProps(domProps, {\n      'aria-invalid': isInvalid || validationState === 'invalid' || undefined,\n      'aria-errormessage': props['aria-errormessage'],\n      'aria-controls': props['aria-controls'],\n      'aria-readonly': isReadOnly || undefined,\n      onChange,\n      disabled: isDisabled,\n      ...(value == null ? {} : {value}),\n      name,\n      form,\n      type: 'checkbox',\n      ...interactions\n    }),\n    isSelected: state.isSelected,\n    isPressed: isPressed || isLabelPressed,\n    isDisabled,\n    isReadOnly,\n    isInvalid: isInvalid || validationState === 'invalid'\n  };\n}\n"],"names":[],"version":3,"file":"useToggle.mjs.map"}