{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { useControlledState as $6Znrd$useControlledState } from \"@react-stately/utils\";\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 $bc37996ff2234e7b$exports = {};\n$parcel$export($bc37996ff2234e7b$exports, \"useCheckboxGroupState\", function () {\n  return $bc37996ff2234e7b$export$daff6da51032a415;\n});\n\nfunction $bc37996ff2234e7b$export$daff6da51032a415() {\n  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n  var _$6Znrd$useControlled = $6Znrd$useControlledState(props.value, props.defaultValue || [], props.onChange),\n      _$6Znrd$useControlled2 = _slicedToArray(_$6Znrd$useControlled, 2),\n      selectedValues = _$6Znrd$useControlled2[0],\n      _setValue = _$6Znrd$useControlled2[1];\n\n  var state = {\n    value: selectedValues,\n    setValue: function setValue(value) {\n      if (props.isReadOnly || props.isDisabled) return;\n\n      _setValue(value);\n    },\n    isDisabled: props.isDisabled || false,\n    isReadOnly: props.isReadOnly || false,\n    isSelected: function isSelected(value) {\n      return selectedValues.includes(value);\n    },\n    addValue: function addValue(value) {\n      if (props.isReadOnly || props.isDisabled) return;\n      if (!selectedValues.includes(value)) _setValue(selectedValues.concat(value));\n    },\n    removeValue: function removeValue(value) {\n      if (props.isReadOnly || props.isDisabled) return;\n      if (selectedValues.includes(value)) _setValue(selectedValues.filter(function (existingValue) {\n        return existingValue !== value;\n      }));\n    },\n    toggleValue: function toggleValue(value) {\n      if (props.isReadOnly || props.isDisabled) return;\n      if (selectedValues.includes(value)) _setValue(selectedValues.filter(function (existingValue) {\n        return existingValue !== value;\n      }));else _setValue(selectedValues.concat(value));\n    }\n  };\n  return state;\n}\n\nexport { $bc37996ff2234e7b$export$daff6da51032a415 as useCheckboxGroupState };","map":{"version":3,"sources":["packages/@react-stately/checkbox/src/useCheckboxGroupState.ts"],"names":[],"m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b;AACjB,UAAI,KAAK,CAAC,UAAN,IAAoB,KAAK,CAAC,UAA9B,EACE;AAEF,UAAI,cAAc,CAAC,QAAf,CAAwB,KAAxB,CAAJ,EACE,SAAQ,CAAC,cAAc,CAAC,MAAf,CAAqB,UAAC,aAAD;AAAA,eAAkB,aAAa,KAAK,KAApC;AAAA,OAArB,CAAD,CAAR,CADF,KAGE,SAAQ,CAAC,cAAc,CAAC,MAAf,CAAsB,KAAtB,CAAD,CAAR;AAEH;AAvC+B,GAAlC;AA0CA,SAAO,KAAP;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 {CheckboxGroupProps} from '@react-types/checkbox';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface CheckboxGroupState {\n  /** Current selected values. */\n  readonly value: readonly string[],\n\n  /** Whether the checkbox group is disabled. */\n  readonly isDisabled: boolean,\n\n  /** Whether the checkbox group is read only. */\n  readonly isReadOnly: boolean,\n\n  /** Returns whether the given value is selected. */\n  isSelected(value: string): boolean,\n\n  /** Sets the selected values. */\n  setValue(value: string[]): void,\n\n  /** Adds a value to the set of selected values. */\n  addValue(value: string): void,\n\n  /** Removes a value from the set of selected values. */\n  removeValue(value: string): void,\n\n  /** Toggles a value in the set of selected values. */\n  toggleValue(value: string): void\n}\n\n/**\n * Provides state management for a checkbox group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useCheckboxGroupState(props: CheckboxGroupProps = {}): CheckboxGroupState {\n  let [selectedValues, setValue] = useControlledState(props.value, props.defaultValue || [], props.onChange);\n\n  const state: CheckboxGroupState = {\n    value: selectedValues,\n    setValue(value) {\n      if (props.isReadOnly || props.isDisabled) {\n        return;\n      }\n\n      setValue(value);\n    },\n    isDisabled: props.isDisabled || false,\n    isReadOnly: props.isReadOnly || false,\n    isSelected(value) {\n      return selectedValues.includes(value);\n    },\n    addValue(value) {\n      if (props.isReadOnly || props.isDisabled) {\n        return;\n      }\n      if (!selectedValues.includes(value)) {\n        setValue(selectedValues.concat(value));\n      }\n    },\n    removeValue(value) {\n      if (props.isReadOnly || props.isDisabled) {\n        return;\n      }\n      if (selectedValues.includes(value)) {\n        setValue(selectedValues.filter(existingValue => existingValue !== value));\n      }\n    },\n    toggleValue(value) {\n      if (props.isReadOnly || props.isDisabled) {\n        return;\n      }\n      if (selectedValues.includes(value)) {\n        setValue(selectedValues.filter(existingValue => existingValue !== value));\n      } else {\n        setValue(selectedValues.concat(value));\n      }\n    }\n  };\n\n  return state;\n}\n"]},"metadata":{},"sourceType":"module"}