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AAM,CAAC,CAAA,gBAAiB,kBAAkB;iBAElE,SAAS,eAAe,MAAM,CAAC;QAEnC;QACA,YAAW,KAAK,EAAE,CAAC;YACjB,IAAI,IAAI,IAAI,IAAI,cAAc,OAAO;YACrC,IAAI,EAAE,SAAS,EACb,EAAE,GAAG,CAAC,OAAO;iBAEb,EAAE,MAAM,CAAC;YAGX,cAAc,OAAO,GAAG;YACxB,WAAW,gBAAgB,CAAC,CAAA,GAAA,yCAAc,KAAK,EAAE,MAAM;QACzD;QACA,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;oBACA;IACF;IAEA,OAAO;AACT","sources":["packages/react-stately/src/checkbox/useCheckboxGroupState.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 {\n FormValidationState,\n mergeValidation,\n useFormValidationState\n} from '../form/useFormValidationState';\nimport {\n HelpTextProps,\n InputBase,\n InputDOMProps,\n LabelableProps,\n Validation,\n ValidationResult,\n ValidationState,\n ValueBase\n} from '@react-types/shared';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useRef, useState} from 'react';\n\nexport interface CheckboxGroupProps\n extends\n ValueBase<string[]>,\n Pick<InputDOMProps, 'name'>,\n InputBase,\n LabelableProps,\n HelpTextProps,\n Validation<string[]> {}\n\nexport interface CheckboxGroupState extends FormValidationState {\n /** Current selected values. */\n readonly value: readonly string[];\n /** Default selected values. */\n readonly defaultValue: 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 /**\n * The current validation state of the checkbox group.\n *\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null;\n\n /** Whether the checkbox group is invalid. */\n readonly isInvalid: boolean;\n\n /**\n * Whether the checkboxes in the group are required.\n * This changes to false once at least one item is selected.\n */\n readonly isRequired: 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 /** Sets whether one of the checkboxes is invalid. */\n setInvalid(value: string, validation: ValidationResult): 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(\n props.value,\n props.defaultValue || [],\n props.onChange\n );\n let [initialValues] = useState(selectedValues);\n let isRequired = !!props.isRequired && selectedValues.length === 0;\n\n let invalidValues = useRef(new Map<string, ValidationResult>());\n let validation = useFormValidationState({\n ...props,\n value: selectedValues\n });\n\n let isInvalid = validation.displayValidation.isInvalid;\n const state: CheckboxGroupState = {\n ...validation,\n value: selectedValues,\n defaultValue: props.defaultValue ?? initialValues,\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 setValue(selectedValues => {\n if (!selectedValues.includes(value)) {\n return selectedValues.concat(value);\n }\n return selectedValues;\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 setInvalid(value, v) {\n let s = new Map(invalidValues.current);\n if (v.isInvalid) {\n s.set(value, v);\n } else {\n s.delete(value);\n }\n\n invalidValues.current = s;\n validation.updateValidation(mergeValidation(...s.values()));\n },\n validationState: props.validationState ?? (isInvalid ? 'invalid' : null),\n isInvalid,\n isRequired\n };\n\n return state;\n}\n"],"names":[],"version":3,"file":"useCheckboxGroupState.mjs.map"}