{"ast":null,"code":"import { useToggleState } from \"@react-stately/toggle\";\nimport { useLabel } from \"@react-aria/label\";\nimport { filterDOMProps, mergeProps } from \"@react-aria/utils\";\nimport { useToggle } from \"@react-aria/toggle\";\nimport { useEffect } from \"react\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nexport function useCheckbox(props, state, inputRef) {\n  var _useToggle = useToggle(props, state, inputRef),\n      inputProps = _useToggle.inputProps;\n\n  var isSelected = state.isSelected;\n  var isIndeterminate = props.isIndeterminate;\n  useEffect(function () {\n    if (inputRef.current) {\n      inputRef.current.indeterminate = isIndeterminate;\n    }\n  });\n  return {\n    inputProps: _babelRuntimeHelpersEsmExtends({}, inputProps, {\n      checked: isSelected,\n      'aria-checked': isIndeterminate ? 'mixed' : isSelected\n    })\n  };\n}\nvar $c1125120fa765e2757aafb57a69ea88$export$checkboxGroupNames = new WeakMap();\nexport function useCheckboxGroup(props, state) {\n  var isDisabled = props.isDisabled,\n      name = props.name;\n\n  var _useLabel = useLabel(_babelRuntimeHelpersEsmExtends({}, props, {\n    labelElementType: 'span'\n  })),\n      labelProps = _useLabel.labelProps,\n      fieldProps = _useLabel.fieldProps;\n\n  var domProps = filterDOMProps(props, {\n    labelable: true\n  });\n  $c1125120fa765e2757aafb57a69ea88$export$checkboxGroupNames.set(state, name);\n  return {\n    groupProps: mergeProps(domProps, _babelRuntimeHelpersEsmExtends({\n      role: 'group',\n      'aria-disabled': isDisabled || undefined\n    }, fieldProps)),\n    labelProps: labelProps\n  };\n}\nexport function useCheckboxGroupItem(props, state, inputRef) {\n  var toggleState = useToggleState({\n    isReadOnly: props.isReadOnly || state.isReadOnly,\n    isSelected: state.isSelected(props.value),\n    onChange: function onChange(isSelected) {\n      if (isSelected) {\n        state.addValue(props.value);\n      } else {\n        state.removeValue(props.value);\n      }\n\n      if (props.onChange) {\n        props.onChange(isSelected);\n      }\n    }\n  });\n\n  var _useCheckbox = useCheckbox(_babelRuntimeHelpersEsmExtends({}, props, {\n    isReadOnly: props.isReadOnly || state.isReadOnly,\n    isDisabled: props.isDisabled || state.isDisabled,\n    name: props.name || $c1125120fa765e2757aafb57a69ea88$export$checkboxGroupNames.get(state)\n  }), toggleState, inputRef),\n      inputProps = _useCheckbox.inputProps;\n\n  return {\n    inputProps: inputProps\n  };\n}","map":{"version":3,"sources":["packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"names":["inputProps","useToggle","isSelected","isIndeterminate","useEffect","inputRef","checked","checkboxGroupNames","name","fieldProps","useLabel","labelElementType","domProps","filterDOMProps","labelable","groupProps","mergeProps","role","isDisabled","undefined","labelProps","toggleState","useToggleState","isReadOnly","props","state","onChange"],"mappings":";;;;;;OA8BO,SAAA,WAAA,CAAA,KAAA,EAAA,KAAA,EAAA,QAAA,EAAwH;AAAA,mBAC1GC,SAAS,CAAA,KAAA,EAAA,KAAA,EAA5B,QAA4B,CADiG;AAAA,MACxHD,UADwH,cACxHA,UADwH;;AAAA,MAExHE,UAFwH,GAE7H,KAF6H,CAExHA,UAFwH;AAAA,MAIxHC,eAJwH,GAI7H,KAJ6H,CAIxHA,eAJwH;AAK7HC,EAAAA,SAAS,CAAC,YAAM;AAGd,QAAIC,QAAQ,CAAZ,OAAA,EAAsB;AACpBA,MAAAA,QAAQ,CAARA,OAAAA,CAAAA,aAAAA,GAAAA,eAAAA;AACD;AALHD,GAAS,CAATA;AAQA,SAAO;AACLJ,IAAAA,UAAU,EAAA,8BAAA,CAAA,EAAA,EAAA,UAAA,EAAA;AAERM,MAAAA,OAAO,EAFC,UAAA;AAGR,sBAAgBH,eAAe,GAAA,OAAA,GAAaD;AAHpC,KAAA;AADL,GAAP;AAOD;ACpCM,IAAMK,0DAAkB,GAAG,IAA3B,OAA2B,EAA3B;OCkBA,SAAA,gBAAA,CAAA,KAAA,EAAA,KAAA,E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UAAAA;AACD;AACF;AAbgC,GAAD,CAAlC;;AADsJ,qBAiBnI,WAAA,CAAA,8BAAA,CAAA,EAAA,EAAA,KAAA,EAAA;AAEjBD,IAAAA,UAAU,EAAEC,KAAK,CAALA,UAAAA,IAAoBC,KAAK,CAFpB,UAAA;AAGjBP,IAAAA,UAAU,EAAEM,KAAK,CAALA,UAAAA,IAAoBC,KAAK,CAHpB,UAAA;AAIjBjB,IAAAA,IAAI,EAAEgB,KAAK,CAALA,IAAAA,IAAc,0DAAA,CAAA,GAAA,CAAA,KAAA;AAJH,GAAA,CAAA,EAAA,WAAA,EAAnB,QAAmB,CAjBmI;AAAA,MAiBjJxB,UAjBiJ,gBAiBjJA,UAjBiJ;;AAwBtJ,SAAO;AAACA,IAAAA,UAAAA,EAAAA;AAAD,GAAP;AACD","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 {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n  /** Props for the input element. */\n  inputProps: InputHTMLAttributes<HTMLInputElement>\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>): CheckboxAria {\n  let {inputProps} = useToggle(props, state, inputRef);\n  let {isSelected} = state;\n\n  let {isIndeterminate} = 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  return {\n    inputProps: {\n      ...inputProps,\n      checked: isSelected,\n      'aria-checked': isIndeterminate ? 'mixed' : isSelected\n    }\n  };\n}\n","/*\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 {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\n","/*\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 {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\nimport {useLabel} from '@react-aria/label';\n\ninterface CheckboxGroupAria {\n  /** Props for the checkbox group wrapper element. */\n  groupProps: HTMLAttributes<HTMLElement>,\n  /** Props for the checkbox group's visible label (if any). */\n  labelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n  let {isDisabled, name} = props;\n\n  let {labelProps, fieldProps} = useLabel({\n    ...props,\n    // Checkbox group is not an HTML input element so it\n    // shouldn't be labeled by a <label> element.\n    labelElementType: 'span'\n  });\n\n  let domProps = filterDOMProps(props, {labelable: true});\n\n  // Pass name prop from group to all items by attaching to the state.\n  checkboxGroupNames.set(state, name);\n\n  return {\n    groupProps: mergeProps(domProps, {\n      role: 'group',\n      'aria-disabled': isDisabled || undefined,\n      ...fieldProps\n    }),\n    labelProps\n  };\n}\n","/*\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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n  const toggleState = useToggleState({\n    isReadOnly: props.isReadOnly || state.isReadOnly,\n    isSelected: state.isSelected(props.value),\n    onChange(isSelected) {\n      if (isSelected) {\n        state.addValue(props.value);\n      } else {\n        state.removeValue(props.value);\n      }\n\n      if (props.onChange) {\n        props.onChange(isSelected);\n      }\n    }\n  });\n\n  let {inputProps} = useCheckbox({\n    ...props,\n    isReadOnly: props.isReadOnly || state.isReadOnly,\n    isDisabled: props.isDisabled || state.isDisabled,\n    name: props.name || checkboxGroupNames.get(state)\n  }, toggleState, inputRef);\n\n  return {inputProps};\n}\n"]},"metadata":{},"sourceType":"module"}