@react-aria/checkbox 3.16.4 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +0,0 @@
1
- import {checkboxGroupData as $1ae600c947479353$export$ec98120685d4f57d} from "./utils.mjs";
2
- import {filterDOMProps as $gtLuF$filterDOMProps, mergeProps as $gtLuF$mergeProps} from "@react-aria/utils";
3
- import {useField as $gtLuF$useField} from "@react-aria/label";
4
- import {useFocusWithin as $gtLuF$useFocusWithin} from "@react-aria/interactions";
5
-
6
- /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */
17
-
18
-
19
-
20
- function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
21
- let { isDisabled: isDisabled, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
22
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
23
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $gtLuF$useField)({
24
- ...props,
25
- // Checkbox group is not an HTML input element so it
26
- // shouldn't be labeled by a <label> element.
27
- labelElementType: 'span',
28
- isInvalid: isInvalid,
29
- errorMessage: props.errorMessage || validationErrors
30
- });
31
- (0, $1ae600c947479353$export$ec98120685d4f57d).set(state, {
32
- name: name,
33
- form: form,
34
- descriptionId: descriptionProps.id,
35
- errorMessageId: errorMessageProps.id,
36
- validationBehavior: validationBehavior
37
- });
38
- let domProps = (0, $gtLuF$filterDOMProps)(props, {
39
- labelable: true
40
- });
41
- let { focusWithinProps: focusWithinProps } = (0, $gtLuF$useFocusWithin)({
42
- onBlurWithin: props.onBlur,
43
- onFocusWithin: props.onFocus,
44
- onFocusWithinChange: props.onFocusChange
45
- });
46
- return {
47
- groupProps: (0, $gtLuF$mergeProps)(domProps, {
48
- role: 'group',
49
- 'aria-disabled': isDisabled || undefined,
50
- ...fieldProps,
51
- ...focusWithinProps
52
- }),
53
- labelProps: labelProps,
54
- descriptionProps: descriptionProps,
55
- errorMessageProps: errorMessageProps,
56
- isInvalid: isInvalid,
57
- validationErrors: validationErrors,
58
- validationDetails: validationDetails
59
- };
60
- }
61
-
62
-
63
- export {$1e9fce0cfacc738b$export$49ff6f28c54f1cbe as useCheckboxGroup};
64
- //# sourceMappingURL=useCheckboxGroup.module.js.map
@@ -1,64 +0,0 @@
1
- import {checkboxGroupData as $1ae600c947479353$export$ec98120685d4f57d} from "./utils.module.js";
2
- import {filterDOMProps as $gtLuF$filterDOMProps, mergeProps as $gtLuF$mergeProps} from "@react-aria/utils";
3
- import {useField as $gtLuF$useField} from "@react-aria/label";
4
- import {useFocusWithin as $gtLuF$useFocusWithin} from "@react-aria/interactions";
5
-
6
- /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */
17
-
18
-
19
-
20
- function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
21
- let { isDisabled: isDisabled, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
22
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
23
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $gtLuF$useField)({
24
- ...props,
25
- // Checkbox group is not an HTML input element so it
26
- // shouldn't be labeled by a <label> element.
27
- labelElementType: 'span',
28
- isInvalid: isInvalid,
29
- errorMessage: props.errorMessage || validationErrors
30
- });
31
- (0, $1ae600c947479353$export$ec98120685d4f57d).set(state, {
32
- name: name,
33
- form: form,
34
- descriptionId: descriptionProps.id,
35
- errorMessageId: errorMessageProps.id,
36
- validationBehavior: validationBehavior
37
- });
38
- let domProps = (0, $gtLuF$filterDOMProps)(props, {
39
- labelable: true
40
- });
41
- let { focusWithinProps: focusWithinProps } = (0, $gtLuF$useFocusWithin)({
42
- onBlurWithin: props.onBlur,
43
- onFocusWithin: props.onFocus,
44
- onFocusWithinChange: props.onFocusChange
45
- });
46
- return {
47
- groupProps: (0, $gtLuF$mergeProps)(domProps, {
48
- role: 'group',
49
- 'aria-disabled': isDisabled || undefined,
50
- ...fieldProps,
51
- ...focusWithinProps
52
- }),
53
- labelProps: labelProps,
54
- descriptionProps: descriptionProps,
55
- errorMessageProps: errorMessageProps,
56
- isInvalid: isInvalid,
57
- validationErrors: validationErrors,
58
- validationDetails: validationDetails
59
- };
60
- }
61
-
62
-
63
- export {$1e9fce0cfacc738b$export$49ff6f28c54f1cbe as useCheckboxGroup};
64
- //# sourceMappingURL=useCheckboxGroup.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA2BM,SAAS,0CAAiB,KAA6B,EAAE,KAAyB;IACvF,IAAI,cAAC,UAAU,QAAE,IAAI,QAAE,IAAI,sBAAE,qBAAqB,QAAO,GAAG;IAC5D,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,MAAM,iBAAiB;IAE9E,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;QACR,oDAAoD;QACpD,6CAA6C;QAC7C,kBAAkB;mBAClB;QACA,cAAc,MAAM,YAAY,IAAI;IACtC;IAEA,CAAA,GAAA,yCAAgB,EAAE,GAAG,CAAC,OAAO;cAC3B;cACA;QACA,eAAe,iBAAiB,EAAE;QAClC,gBAAgB,kBAAkB,EAAE;4BACpC;IACF;IAEA,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QACtC,cAAc,MAAM,MAAM;QAC1B,eAAe,MAAM,OAAO;QAC5B,qBAAqB,MAAM,aAAa;IAC1C;IAEA,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC/B,MAAM;YACN,iBAAiB,cAAc;YAC/B,GAAG,UAAU;YACb,GAAG,gBAAgB;QACrB;oBACA;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/checkbox/src/useCheckboxGroup.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 {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\n\nexport interface CheckboxGroupAria extends ValidationResult {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\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, form, validationBehavior = 'aria'} = props;\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\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 isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n checkboxGroupData.set(state, {\n name,\n form,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin: props.onBlur,\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\n });\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useCheckboxGroup.module.js.map"}
@@ -1,93 +0,0 @@
1
- var $468c774d7db917b7$exports = require("./useCheckbox.main.js");
2
- var $64fc3370e682155f$exports = require("./utils.main.js");
3
- var $2Rh3D$reactstatelyform = require("@react-stately/form");
4
- var $2Rh3D$react = require("react");
5
- var $2Rh3D$reactstatelytoggle = require("@react-stately/toggle");
6
-
7
-
8
- function $parcel$export(e, n, v, s) {
9
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
- }
11
-
12
- $parcel$export(module.exports, "useCheckboxGroupItem", () => $07e03121d6ac83c8$export$353b32fc6898d37d);
13
- /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */
24
-
25
-
26
-
27
-
28
- function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
29
- const toggleState = (0, $2Rh3D$reactstatelytoggle.useToggleState)({
30
- isReadOnly: props.isReadOnly || state.isReadOnly,
31
- isSelected: state.isSelected(props.value),
32
- defaultSelected: state.defaultValue.includes(props.value),
33
- onChange (isSelected) {
34
- if (isSelected) state.addValue(props.value);
35
- else state.removeValue(props.value);
36
- if (props.onChange) props.onChange(isSelected);
37
- }
38
- });
39
- let { name: name, form: form, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $64fc3370e682155f$exports.checkboxGroupData).get(state);
40
- var _props_validationBehavior;
41
- validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
42
- // Local validation for this checkbox.
43
- let { realtimeValidation: realtimeValidation } = (0, $2Rh3D$reactstatelyform.useFormValidationState)({
44
- ...props,
45
- value: toggleState.isSelected,
46
- // Server validation is handled at the group level.
47
- name: undefined,
48
- validationBehavior: 'aria'
49
- });
50
- // Update the checkbox group state when realtime validation changes.
51
- let nativeValidation = (0, $2Rh3D$react.useRef)((0, $2Rh3D$reactstatelyform.DEFAULT_VALIDATION_RESULT));
52
- let updateValidation = ()=>{
53
- state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
54
- };
55
- (0, $2Rh3D$react.useEffect)(updateValidation);
56
- // Combine group and checkbox level validation.
57
- let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
58
- let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
59
- var _props_isRequired;
60
- let res = (0, $468c774d7db917b7$exports.useCheckbox)({
61
- ...props,
62
- isReadOnly: props.isReadOnly || state.isReadOnly,
63
- isDisabled: props.isDisabled || state.isDisabled,
64
- name: props.name || name,
65
- form: props.form || form,
66
- isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
67
- validationBehavior: validationBehavior,
68
- [(0, $2Rh3D$reactstatelyform.privateValidationStateProp)]: {
69
- realtimeValidation: combinedRealtimeValidation,
70
- displayValidation: displayValidation,
71
- resetValidation: state.resetValidation,
72
- commitValidation: state.commitValidation,
73
- updateValidation (v) {
74
- nativeValidation.current = v;
75
- updateValidation();
76
- }
77
- }
78
- }, toggleState, inputRef);
79
- return {
80
- ...res,
81
- inputProps: {
82
- ...res.inputProps,
83
- 'aria-describedby': [
84
- props['aria-describedby'],
85
- state.isInvalid ? errorMessageId : null,
86
- descriptionId
87
- ].filter(Boolean).join(' ') || undefined
88
- }
89
- };
90
- }
91
-
92
-
93
- //# sourceMappingURL=useCheckboxGroupItem.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAA4C;IAC7I,MAAM,cAAc,CAAA,GAAA,wCAAa,EAAE;QACjC,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,CAAC,MAAM,KAAK;QACxC,iBAAiB,MAAM,YAAY,CAAC,QAAQ,CAAC,MAAM,KAAK;QACxD,UAAS,UAAU;YACjB,IAAI,YACF,MAAM,QAAQ,CAAC,MAAM,KAAK;iBAE1B,MAAM,WAAW,CAAC,MAAM,KAAK;YAG/B,IAAI,MAAM,QAAQ,EAChB,MAAM,QAAQ,CAAC;QAEnB;IACF;IAEA,IAAI,QAAC,IAAI,QAAE,IAAI,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,2CAAgB,EAAE,GAAG,CAAC;QACvE;IAArB,qBAAqB,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B;IAEjD,sCAAsC;IACtC,IAAI,sBAAC,kBAAkB,EAAC,GAAG,CAAA,GAAA,8CAAqB,EAAE;QAChD,GAAG,KAAK;QACR,OAAO,YAAY,UAAU;QAC7B,mDAAmD;QACnD,MAAM;QACN,oBAAoB;IACtB;IAEA,oEAAoE;IACpE,IAAI,mBAAmB,CAAA,GAAA,mBAAK,EAAE,CAAA,GAAA,iDAAwB;IACtD,IAAI,mBAAmB;QACrB,MAAM,UAAU,CAAC,MAAM,KAAK,EAAE,mBAAmB,SAAS,GAAG,qBAAqB,iBAAiB,OAAO;IAC5G;IAEA,CAAA,GAAA,sBAAQ,EAAE;IAEV,+CAA+C;IAC/C,IAAI,6BAA6B,MAAM,kBAAkB,CAAC,SAAS,GAAG,MAAM,kBAAkB,GAAG;IACjG,IAAI,oBAAoB,uBAAuB,WAAW,MAAM,iBAAiB,GAAG;QAQtE;IANd,IAAI,MAAM,CAAA,GAAA,qCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,MAAM,MAAM,IAAI,IAAI;QACpB,MAAM,MAAM,IAAI,IAAI;QACpB,YAAY,CAAA,oBAAA,MAAM,UAAU,cAAhB,+BAAA,oBAAoB,MAAM,UAAU;4BAChD;QACA,CAAC,CAAA,GAAA,kDAAyB,EAAE,EAAE;YAC5B,oBAAoB;+BACpB;YACA,iBAAiB,MAAM,eAAe;YACtC,kBAAkB,MAAM,gBAAgB;YACxC,kBAAiB,CAAmB;gBAClC,iBAAiB,OAAO,GAAG;gBAC3B;YACF;QACF;IACF,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;IACF;AACF","sources":["packages/@react-aria/checkbox/src/useCheckboxGroupItem.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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, ValidationResult} from '@react-types/shared';\nimport {useEffect, useRef} 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 | null>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n defaultSelected: state.defaultValue.includes(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 {name, form, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;\n validationBehavior = props.validationBehavior ?? validationBehavior;\n\n // Local validation for this checkbox.\n let {realtimeValidation} = useFormValidationState({\n ...props,\n value: toggleState.isSelected,\n // Server validation is handled at the group level.\n name: undefined,\n validationBehavior: 'aria'\n });\n\n // Update the checkbox group state when realtime validation changes.\n let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let updateValidation = () => {\n state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);\n };\n\n useEffect(updateValidation);\n\n // Combine group and checkbox level validation.\n let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;\n let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || name,\n form: props.form || form,\n isRequired: props.isRequired ?? state.isRequired,\n validationBehavior,\n [privateValidationStateProp]: {\n realtimeValidation: combinedRealtimeValidation,\n displayValidation,\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation,\n updateValidation(v: ValidationResult) {\n nativeValidation.current = v;\n updateValidation();\n }\n }\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useCheckboxGroupItem.main.js.map"}
@@ -1,88 +0,0 @@
1
- import {useCheckbox as $406796ff087fe49b$export$e375f10ce42261c5} from "./useCheckbox.mjs";
2
- import {checkboxGroupData as $1ae600c947479353$export$ec98120685d4f57d} from "./utils.mjs";
3
- import {useFormValidationState as $6clEo$useFormValidationState, DEFAULT_VALIDATION_RESULT as $6clEo$DEFAULT_VALIDATION_RESULT, privateValidationStateProp as $6clEo$privateValidationStateProp} from "@react-stately/form";
4
- import {useRef as $6clEo$useRef, useEffect as $6clEo$useEffect} from "react";
5
- import {useToggleState as $6clEo$useToggleState} from "@react-stately/toggle";
6
-
7
- /*
8
- * Copyright 2020 Adobe. All rights reserved.
9
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License. You may obtain a copy
11
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software distributed under
14
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- * OF ANY KIND, either express or implied. See the License for the specific language
16
- * governing permissions and limitations under the License.
17
- */
18
-
19
-
20
-
21
-
22
- function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
23
- const toggleState = (0, $6clEo$useToggleState)({
24
- isReadOnly: props.isReadOnly || state.isReadOnly,
25
- isSelected: state.isSelected(props.value),
26
- defaultSelected: state.defaultValue.includes(props.value),
27
- onChange (isSelected) {
28
- if (isSelected) state.addValue(props.value);
29
- else state.removeValue(props.value);
30
- if (props.onChange) props.onChange(isSelected);
31
- }
32
- });
33
- let { name: name, form: form, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
34
- var _props_validationBehavior;
35
- validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
36
- // Local validation for this checkbox.
37
- let { realtimeValidation: realtimeValidation } = (0, $6clEo$useFormValidationState)({
38
- ...props,
39
- value: toggleState.isSelected,
40
- // Server validation is handled at the group level.
41
- name: undefined,
42
- validationBehavior: 'aria'
43
- });
44
- // Update the checkbox group state when realtime validation changes.
45
- let nativeValidation = (0, $6clEo$useRef)((0, $6clEo$DEFAULT_VALIDATION_RESULT));
46
- let updateValidation = ()=>{
47
- state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
48
- };
49
- (0, $6clEo$useEffect)(updateValidation);
50
- // Combine group and checkbox level validation.
51
- let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
52
- let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
53
- var _props_isRequired;
54
- let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
55
- ...props,
56
- isReadOnly: props.isReadOnly || state.isReadOnly,
57
- isDisabled: props.isDisabled || state.isDisabled,
58
- name: props.name || name,
59
- form: props.form || form,
60
- isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
61
- validationBehavior: validationBehavior,
62
- [(0, $6clEo$privateValidationStateProp)]: {
63
- realtimeValidation: combinedRealtimeValidation,
64
- displayValidation: displayValidation,
65
- resetValidation: state.resetValidation,
66
- commitValidation: state.commitValidation,
67
- updateValidation (v) {
68
- nativeValidation.current = v;
69
- updateValidation();
70
- }
71
- }
72
- }, toggleState, inputRef);
73
- return {
74
- ...res,
75
- inputProps: {
76
- ...res.inputProps,
77
- 'aria-describedby': [
78
- props['aria-describedby'],
79
- state.isInvalid ? errorMessageId : null,
80
- descriptionId
81
- ].filter(Boolean).join(' ') || undefined
82
- }
83
- };
84
- }
85
-
86
-
87
- export {$fba3e38d5ca8983f$export$353b32fc6898d37d as useCheckboxGroupItem};
88
- //# sourceMappingURL=useCheckboxGroupItem.module.js.map
@@ -1,88 +0,0 @@
1
- import {useCheckbox as $406796ff087fe49b$export$e375f10ce42261c5} from "./useCheckbox.module.js";
2
- import {checkboxGroupData as $1ae600c947479353$export$ec98120685d4f57d} from "./utils.module.js";
3
- import {useFormValidationState as $6clEo$useFormValidationState, DEFAULT_VALIDATION_RESULT as $6clEo$DEFAULT_VALIDATION_RESULT, privateValidationStateProp as $6clEo$privateValidationStateProp} from "@react-stately/form";
4
- import {useRef as $6clEo$useRef, useEffect as $6clEo$useEffect} from "react";
5
- import {useToggleState as $6clEo$useToggleState} from "@react-stately/toggle";
6
-
7
- /*
8
- * Copyright 2020 Adobe. All rights reserved.
9
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License. You may obtain a copy
11
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software distributed under
14
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- * OF ANY KIND, either express or implied. See the License for the specific language
16
- * governing permissions and limitations under the License.
17
- */
18
-
19
-
20
-
21
-
22
- function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
23
- const toggleState = (0, $6clEo$useToggleState)({
24
- isReadOnly: props.isReadOnly || state.isReadOnly,
25
- isSelected: state.isSelected(props.value),
26
- defaultSelected: state.defaultValue.includes(props.value),
27
- onChange (isSelected) {
28
- if (isSelected) state.addValue(props.value);
29
- else state.removeValue(props.value);
30
- if (props.onChange) props.onChange(isSelected);
31
- }
32
- });
33
- let { name: name, form: form, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
34
- var _props_validationBehavior;
35
- validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
36
- // Local validation for this checkbox.
37
- let { realtimeValidation: realtimeValidation } = (0, $6clEo$useFormValidationState)({
38
- ...props,
39
- value: toggleState.isSelected,
40
- // Server validation is handled at the group level.
41
- name: undefined,
42
- validationBehavior: 'aria'
43
- });
44
- // Update the checkbox group state when realtime validation changes.
45
- let nativeValidation = (0, $6clEo$useRef)((0, $6clEo$DEFAULT_VALIDATION_RESULT));
46
- let updateValidation = ()=>{
47
- state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
48
- };
49
- (0, $6clEo$useEffect)(updateValidation);
50
- // Combine group and checkbox level validation.
51
- let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
52
- let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
53
- var _props_isRequired;
54
- let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
55
- ...props,
56
- isReadOnly: props.isReadOnly || state.isReadOnly,
57
- isDisabled: props.isDisabled || state.isDisabled,
58
- name: props.name || name,
59
- form: props.form || form,
60
- isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
61
- validationBehavior: validationBehavior,
62
- [(0, $6clEo$privateValidationStateProp)]: {
63
- realtimeValidation: combinedRealtimeValidation,
64
- displayValidation: displayValidation,
65
- resetValidation: state.resetValidation,
66
- commitValidation: state.commitValidation,
67
- updateValidation (v) {
68
- nativeValidation.current = v;
69
- updateValidation();
70
- }
71
- }
72
- }, toggleState, inputRef);
73
- return {
74
- ...res,
75
- inputProps: {
76
- ...res.inputProps,
77
- 'aria-describedby': [
78
- props['aria-describedby'],
79
- state.isInvalid ? errorMessageId : null,
80
- descriptionId
81
- ].filter(Boolean).join(' ') || undefined
82
- }
83
- };
84
- }
85
-
86
-
87
- export {$fba3e38d5ca8983f$export$353b32fc6898d37d as useCheckboxGroupItem};
88
- //# sourceMappingURL=useCheckboxGroupItem.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAA4C;IAC7I,MAAM,cAAc,CAAA,GAAA,qBAAa,EAAE;QACjC,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,CAAC,MAAM,KAAK;QACxC,iBAAiB,MAAM,YAAY,CAAC,QAAQ,CAAC,MAAM,KAAK;QACxD,UAAS,UAAU;YACjB,IAAI,YACF,MAAM,QAAQ,CAAC,MAAM,KAAK;iBAE1B,MAAM,WAAW,CAAC,MAAM,KAAK;YAG/B,IAAI,MAAM,QAAQ,EAChB,MAAM,QAAQ,CAAC;QAEnB;IACF;IAEA,IAAI,QAAC,IAAI,QAAE,IAAI,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,yCAAgB,EAAE,GAAG,CAAC;QACvE;IAArB,qBAAqB,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B;IAEjD,sCAAsC;IACtC,IAAI,sBAAC,kBAAkB,EAAC,GAAG,CAAA,GAAA,6BAAqB,EAAE;QAChD,GAAG,KAAK;QACR,OAAO,YAAY,UAAU;QAC7B,mDAAmD;QACnD,MAAM;QACN,oBAAoB;IACtB;IAEA,oEAAoE;IACpE,IAAI,mBAAmB,CAAA,GAAA,aAAK,EAAE,CAAA,GAAA,gCAAwB;IACtD,IAAI,mBAAmB;QACrB,MAAM,UAAU,CAAC,MAAM,KAAK,EAAE,mBAAmB,SAAS,GAAG,qBAAqB,iBAAiB,OAAO;IAC5G;IAEA,CAAA,GAAA,gBAAQ,EAAE;IAEV,+CAA+C;IAC/C,IAAI,6BAA6B,MAAM,kBAAkB,CAAC,SAAS,GAAG,MAAM,kBAAkB,GAAG;IACjG,IAAI,oBAAoB,uBAAuB,WAAW,MAAM,iBAAiB,GAAG;QAQtE;IANd,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,MAAM,MAAM,IAAI,IAAI;QACpB,MAAM,MAAM,IAAI,IAAI;QACpB,YAAY,CAAA,oBAAA,MAAM,UAAU,cAAhB,+BAAA,oBAAoB,MAAM,UAAU;4BAChD;QACA,CAAC,CAAA,GAAA,iCAAyB,EAAE,EAAE;YAC5B,oBAAoB;+BACpB;YACA,iBAAiB,MAAM,eAAe;YACtC,kBAAkB,MAAM,gBAAgB;YACxC,kBAAiB,CAAmB;gBAClC,iBAAiB,OAAO,GAAG;gBAC3B;YACF;QACF;IACF,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;IACF;AACF","sources":["packages/@react-aria/checkbox/src/useCheckboxGroupItem.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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, ValidationResult} from '@react-types/shared';\nimport {useEffect, useRef} 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 | null>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n defaultSelected: state.defaultValue.includes(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 {name, form, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;\n validationBehavior = props.validationBehavior ?? validationBehavior;\n\n // Local validation for this checkbox.\n let {realtimeValidation} = useFormValidationState({\n ...props,\n value: toggleState.isSelected,\n // Server validation is handled at the group level.\n name: undefined,\n validationBehavior: 'aria'\n });\n\n // Update the checkbox group state when realtime validation changes.\n let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let updateValidation = () => {\n state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);\n };\n\n useEffect(updateValidation);\n\n // Combine group and checkbox level validation.\n let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;\n let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || name,\n form: props.form || form,\n isRequired: props.isRequired ?? state.isRequired,\n validationBehavior,\n [privateValidationStateProp]: {\n realtimeValidation: combinedRealtimeValidation,\n displayValidation,\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation,\n updateValidation(v: ValidationResult) {\n nativeValidation.current = v;\n updateValidation();\n }\n }\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useCheckboxGroupItem.module.js.map"}
@@ -1,20 +0,0 @@
1
-
2
- function $parcel$export(e, n, v, s) {
3
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
- }
5
-
6
- $parcel$export(module.exports, "checkboxGroupData", () => $64fc3370e682155f$export$ec98120685d4f57d);
7
- /*
8
- * Copyright 2020 Adobe. All rights reserved.
9
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License. You may obtain a copy
11
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software distributed under
14
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- * OF ANY KIND, either express or implied. See the License for the specific language
16
- * governing permissions and limitations under the License.
17
- */ const $64fc3370e682155f$export$ec98120685d4f57d = new WeakMap();
18
-
19
-
20
- //# sourceMappingURL=utils.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAYM,MAAM,4CAAoE,IAAI","sources":["packages/@react-aria/checkbox/src/utils.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 {CheckboxGroupState} from '@react-stately/checkbox';\n\ninterface CheckboxGroupData {\n name?: string,\n form?: string,\n descriptionId?: string,\n errorMessageId?: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData: WeakMap<CheckboxGroupState, CheckboxGroupData> = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\n"],"names":[],"version":3,"file":"utils.main.js.map"}
package/dist/utils.mjs DELETED
@@ -1,15 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */ const $1ae600c947479353$export$ec98120685d4f57d = new WeakMap();
12
-
13
-
14
- export {$1ae600c947479353$export$ec98120685d4f57d as checkboxGroupData};
15
- //# sourceMappingURL=utils.module.js.map
@@ -1,15 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */ const $1ae600c947479353$export$ec98120685d4f57d = new WeakMap();
12
-
13
-
14
- export {$1ae600c947479353$export$ec98120685d4f57d as checkboxGroupData};
15
- //# sourceMappingURL=utils.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAYM,MAAM,4CAAoE,IAAI","sources":["packages/@react-aria/checkbox/src/utils.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 {CheckboxGroupState} from '@react-stately/checkbox';\n\ninterface CheckboxGroupData {\n name?: string,\n form?: string,\n descriptionId?: string,\n errorMessageId?: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData: WeakMap<CheckboxGroupState, CheckboxGroupData> = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\n"],"names":[],"version":3,"file":"utils.module.js.map"}
@@ -1,104 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {AriaCheckboxProps} from '@react-types/checkbox';
14
- import {InputHTMLAttributes, LabelHTMLAttributes, useEffect, useMemo} from 'react';
15
- import {mergeProps} from '@react-aria/utils';
16
- import {privateValidationStateProp, useFormValidationState} from '@react-stately/form';
17
- import {RefObject, ValidationResult} from '@react-types/shared';
18
- import {ToggleState} from '@react-stately/toggle';
19
- import {useFormValidation} from '@react-aria/form';
20
- import {usePress} from '@react-aria/interactions';
21
- import {useToggle} from '@react-aria/toggle';
22
-
23
- export interface CheckboxAria extends ValidationResult {
24
- /** Props for the label wrapper element. */
25
- labelProps: LabelHTMLAttributes<HTMLLabelElement>,
26
- /** Props for the input element. */
27
- inputProps: InputHTMLAttributes<HTMLInputElement>,
28
- /** Whether the checkbox is selected. */
29
- isSelected: boolean,
30
- /** Whether the checkbox is in a pressed state. */
31
- isPressed: boolean,
32
- /** Whether the checkbox is disabled. */
33
- isDisabled: boolean,
34
- /** Whether the checkbox is read only. */
35
- isReadOnly: boolean
36
- }
37
-
38
- /**
39
- * Provides the behavior and accessibility implementation for a checkbox component.
40
- * Checkboxes allow users to select multiple items from a list of individual items, or
41
- * to mark one individual item as selected.
42
- * @param props - Props for the checkbox.
43
- * @param state - State for the checkbox, as returned by `useToggleState`.
44
- * @param inputRef - A ref for the HTML input element.
45
- */
46
- export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement | null>): CheckboxAria {
47
- // Create validation state here because it doesn't make sense to add to general useToggleState.
48
- let validationState = useFormValidationState({...props, value: state.isSelected});
49
- let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;
50
- let {labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({
51
- ...props,
52
- isInvalid
53
- }, state, inputRef);
54
-
55
- useFormValidation(props, validationState, inputRef);
56
-
57
- let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;
58
- useEffect(() => {
59
- // indeterminate is a property, but it can only be set via javascript
60
- // https://css-tricks.com/indeterminate-checkboxes/
61
- if (inputRef.current) {
62
- inputRef.current.indeterminate = !!isIndeterminate;
63
- }
64
- });
65
-
66
- // Reset validation state on label press for checkbox with a hidden input.
67
- let {pressProps} = usePress({
68
- isDisabled: isDisabled || isReadOnly,
69
- onPress() {
70
- // @ts-expect-error
71
- let {[privateValidationStateProp]: groupValidationState} = props;
72
-
73
- let {commitValidation} = groupValidationState
74
- ? groupValidationState
75
- : validationState;
76
-
77
- commitValidation();
78
- }
79
- });
80
-
81
- return {
82
- labelProps: mergeProps(
83
- labelProps,
84
- pressProps,
85
- useMemo(() => ({
86
- // Prevent label from being focused when mouse down on it.
87
- // Note, this does not prevent the input from being focused in the `click` event.
88
- onMouseDown: e => e.preventDefault()
89
- }), [])),
90
- inputProps: {
91
- ...inputProps,
92
- checked: isSelected,
93
- 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,
94
- required: isRequired && validationBehavior === 'native'
95
- },
96
- isSelected,
97
- isPressed,
98
- isDisabled,
99
- isReadOnly,
100
- isInvalid,
101
- validationErrors,
102
- validationDetails
103
- };
104
- }