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,uBAAuB,UAAW;YAClE,UAAU,cAAc,uBAAuB;QACjD;oBACA;mBACA;oBACA;oBACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/react-aria/src/checkbox/useCheckbox.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 {AriaToggleProps, useToggle} from '../toggle/useToggle';\nimport {InputDOMProps, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes, LabelHTMLAttributes, useEffect, useMemo} from 'react';\nimport {mergeProps} from '../utils/mergeProps';\nimport {privateValidationStateProp, useFormValidationState} from 'react-stately/private/form/useFormValidationState';\nimport {ToggleProps, ToggleState} from 'react-stately/useToggleState';\nimport {useFormValidation} from '../form/useFormValidation';\nimport {usePress} from '../interactions/usePress';\n\nexport interface CheckboxProps extends ToggleProps {\n  /**\n   * Indeterminism is presentational only.\n   * The indeterminate visual representation remains regardless of user interaction.\n   */\n  isIndeterminate?: boolean\n}\n\nexport interface AriaCheckboxProps extends CheckboxProps, InputDOMProps, AriaToggleProps {}\n\nexport interface CheckboxAria extends ValidationResult {\n  /** Props for the label wrapper element. */\n  labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n  /** Props for the input element. */\n  inputProps: InputHTMLAttributes<HTMLInputElement>,\n  /** Whether the checkbox is selected. */\n  isSelected: boolean,\n  /** Whether the checkbox is in a pressed state. */\n  isPressed: boolean,\n  /** Whether the checkbox is disabled. */\n  isDisabled: boolean,\n  /** Whether the checkbox is read only. */\n  isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement | null>): CheckboxAria {\n  // Create validation state here because it doesn't make sense to add to general useToggleState.\n  let validationState = useFormValidationState({...props, value: state.isSelected});\n  let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n  let {labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({\n    ...props,\n    isInvalid\n  }, state, inputRef);\n\n  useFormValidation(props, validationState, inputRef);\n\n  let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;\n  useEffect(() => {\n    // indeterminate is a property, but it can only be set via javascript\n    // https://css-tricks.com/indeterminate-checkboxes/\n    if (inputRef.current) {\n      inputRef.current.indeterminate = !!isIndeterminate;\n    }\n  });\n\n  // Reset validation state on label press for checkbox with a hidden input.\n  let {pressProps} = usePress({\n    isDisabled: isDisabled || isReadOnly,\n    onPress() {\n      // @ts-expect-error\n      let {[privateValidationStateProp]: groupValidationState} = props;\n\n      let {commitValidation} = groupValidationState\n      ? groupValidationState\n      : validationState;\n\n      commitValidation();\n    }\n  });\n\n  return {\n    labelProps: mergeProps(\n      labelProps,\n      pressProps,\n      useMemo(() => ({\n        // Prevent label from being focused when mouse down on it.\n        // Note, this does not prevent the input from being focused in the `click` event.\n        onMouseDown: e => e.preventDefault()\n      }), [])),\n    inputProps: {\n      ...inputProps,\n      checked: isSelected,\n      'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n      required: isRequired && validationBehavior === 'native'\n    },\n    isSelected,\n    isPressed,\n    isDisabled,\n    isReadOnly,\n    isInvalid,\n    validationErrors,\n    validationDetails\n  };\n}\n"],"names":[],"version":3,"file":"useCheckbox.cjs.map"}