@react-aria/checkbox 3.0.0-nightly-641446f65-240905

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.
@@ -0,0 +1,91 @@
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
+ onChange (isSelected) {
33
+ if (isSelected) state.addValue(props.value);
34
+ else state.removeValue(props.value);
35
+ if (props.onChange) props.onChange(isSelected);
36
+ }
37
+ });
38
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $64fc3370e682155f$exports.checkboxGroupData).get(state);
39
+ var _props_validationBehavior;
40
+ validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
41
+ // Local validation for this checkbox.
42
+ let { realtimeValidation: realtimeValidation } = (0, $2Rh3D$reactstatelyform.useFormValidationState)({
43
+ ...props,
44
+ value: toggleState.isSelected,
45
+ // Server validation is handled at the group level.
46
+ name: undefined,
47
+ validationBehavior: 'aria'
48
+ });
49
+ // Update the checkbox group state when realtime validation changes.
50
+ let nativeValidation = (0, $2Rh3D$react.useRef)((0, $2Rh3D$reactstatelyform.DEFAULT_VALIDATION_RESULT));
51
+ let updateValidation = ()=>{
52
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
53
+ };
54
+ (0, $2Rh3D$react.useEffect)(updateValidation);
55
+ // Combine group and checkbox level validation.
56
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
57
+ let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
58
+ var _props_isRequired;
59
+ let res = (0, $468c774d7db917b7$exports.useCheckbox)({
60
+ ...props,
61
+ isReadOnly: props.isReadOnly || state.isReadOnly,
62
+ isDisabled: props.isDisabled || state.isDisabled,
63
+ name: props.name || name,
64
+ isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
65
+ validationBehavior: validationBehavior,
66
+ [(0, $2Rh3D$reactstatelyform.privateValidationStateProp)]: {
67
+ realtimeValidation: combinedRealtimeValidation,
68
+ displayValidation: displayValidation,
69
+ resetValidation: state.resetValidation,
70
+ commitValidation: state.commitValidation,
71
+ updateValidation (v) {
72
+ nativeValidation.current = v;
73
+ updateValidation();
74
+ }
75
+ }
76
+ }, toggleState, inputRef);
77
+ return {
78
+ ...res,
79
+ inputProps: {
80
+ ...res.inputProps,
81
+ 'aria-describedby': [
82
+ props['aria-describedby'],
83
+ state.isInvalid ? errorMessageId : null,
84
+ descriptionId
85
+ ].filter(Boolean).join(' ') || undefined
86
+ }
87
+ };
88
+ }
89
+
90
+
91
+ //# sourceMappingURL=useCheckboxGroupItem.main.js.map
@@ -0,0 +1 @@
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,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,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,2CAAgB,EAAE,GAAG,CAAC;QACjE;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;QAOtE;IALd,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,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 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, 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 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"}
@@ -0,0 +1,86 @@
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
+ onChange (isSelected) {
27
+ if (isSelected) state.addValue(props.value);
28
+ else state.removeValue(props.value);
29
+ if (props.onChange) props.onChange(isSelected);
30
+ }
31
+ });
32
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
33
+ var _props_validationBehavior;
34
+ validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
35
+ // Local validation for this checkbox.
36
+ let { realtimeValidation: realtimeValidation } = (0, $6clEo$useFormValidationState)({
37
+ ...props,
38
+ value: toggleState.isSelected,
39
+ // Server validation is handled at the group level.
40
+ name: undefined,
41
+ validationBehavior: 'aria'
42
+ });
43
+ // Update the checkbox group state when realtime validation changes.
44
+ let nativeValidation = (0, $6clEo$useRef)((0, $6clEo$DEFAULT_VALIDATION_RESULT));
45
+ let updateValidation = ()=>{
46
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
47
+ };
48
+ (0, $6clEo$useEffect)(updateValidation);
49
+ // Combine group and checkbox level validation.
50
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
51
+ let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
52
+ var _props_isRequired;
53
+ let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
54
+ ...props,
55
+ isReadOnly: props.isReadOnly || state.isReadOnly,
56
+ isDisabled: props.isDisabled || state.isDisabled,
57
+ name: props.name || name,
58
+ isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
59
+ validationBehavior: validationBehavior,
60
+ [(0, $6clEo$privateValidationStateProp)]: {
61
+ realtimeValidation: combinedRealtimeValidation,
62
+ displayValidation: displayValidation,
63
+ resetValidation: state.resetValidation,
64
+ commitValidation: state.commitValidation,
65
+ updateValidation (v) {
66
+ nativeValidation.current = v;
67
+ updateValidation();
68
+ }
69
+ }
70
+ }, toggleState, inputRef);
71
+ return {
72
+ ...res,
73
+ inputProps: {
74
+ ...res.inputProps,
75
+ 'aria-describedby': [
76
+ props['aria-describedby'],
77
+ state.isInvalid ? errorMessageId : null,
78
+ descriptionId
79
+ ].filter(Boolean).join(' ') || undefined
80
+ }
81
+ };
82
+ }
83
+
84
+
85
+ export {$fba3e38d5ca8983f$export$353b32fc6898d37d as useCheckboxGroupItem};
86
+ //# sourceMappingURL=useCheckboxGroupItem.module.js.map
@@ -0,0 +1,86 @@
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
+ onChange (isSelected) {
27
+ if (isSelected) state.addValue(props.value);
28
+ else state.removeValue(props.value);
29
+ if (props.onChange) props.onChange(isSelected);
30
+ }
31
+ });
32
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
33
+ var _props_validationBehavior;
34
+ validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
35
+ // Local validation for this checkbox.
36
+ let { realtimeValidation: realtimeValidation } = (0, $6clEo$useFormValidationState)({
37
+ ...props,
38
+ value: toggleState.isSelected,
39
+ // Server validation is handled at the group level.
40
+ name: undefined,
41
+ validationBehavior: 'aria'
42
+ });
43
+ // Update the checkbox group state when realtime validation changes.
44
+ let nativeValidation = (0, $6clEo$useRef)((0, $6clEo$DEFAULT_VALIDATION_RESULT));
45
+ let updateValidation = ()=>{
46
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
47
+ };
48
+ (0, $6clEo$useEffect)(updateValidation);
49
+ // Combine group and checkbox level validation.
50
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
51
+ let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
52
+ var _props_isRequired;
53
+ let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
54
+ ...props,
55
+ isReadOnly: props.isReadOnly || state.isReadOnly,
56
+ isDisabled: props.isDisabled || state.isDisabled,
57
+ name: props.name || name,
58
+ isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
59
+ validationBehavior: validationBehavior,
60
+ [(0, $6clEo$privateValidationStateProp)]: {
61
+ realtimeValidation: combinedRealtimeValidation,
62
+ displayValidation: displayValidation,
63
+ resetValidation: state.resetValidation,
64
+ commitValidation: state.commitValidation,
65
+ updateValidation (v) {
66
+ nativeValidation.current = v;
67
+ updateValidation();
68
+ }
69
+ }
70
+ }, toggleState, inputRef);
71
+ return {
72
+ ...res,
73
+ inputProps: {
74
+ ...res.inputProps,
75
+ 'aria-describedby': [
76
+ props['aria-describedby'],
77
+ state.isInvalid ? errorMessageId : null,
78
+ descriptionId
79
+ ].filter(Boolean).join(' ') || undefined
80
+ }
81
+ };
82
+ }
83
+
84
+
85
+ export {$fba3e38d5ca8983f$export$353b32fc6898d37d as useCheckboxGroupItem};
86
+ //# sourceMappingURL=useCheckboxGroupItem.module.js.map
@@ -0,0 +1 @@
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,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,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,yCAAgB,EAAE,GAAG,CAAC;QACjE;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;QAOtE;IALd,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,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 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, 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 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"}
@@ -0,0 +1,20 @@
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
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAoB,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 descriptionId?: string,\n errorMessageId?: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\n"],"names":[],"version":3,"file":"utils.main.js.map"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAoB,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 descriptionId?: string,\n errorMessageId?: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\n"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@react-aria/checkbox",
3
+ "version": "3.0.0-nightly-641446f65-240905",
4
+ "description": "Spectrum UI components in React",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/main.js",
7
+ "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
13
+ "types": "dist/types.d.ts",
14
+ "source": "src/index.ts",
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "sideEffects": false,
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/adobe/react-spectrum"
23
+ },
24
+ "dependencies": {
25
+ "@react-aria/form": "^3.0.0-nightly-641446f65-240905",
26
+ "@react-aria/interactions": "^3.0.0-nightly-641446f65-240905",
27
+ "@react-aria/label": "^3.0.0-nightly-641446f65-240905",
28
+ "@react-aria/toggle": "^3.0.0-nightly-641446f65-240905",
29
+ "@react-aria/utils": "^3.0.0-nightly-641446f65-240905",
30
+ "@react-stately/checkbox": "^3.0.0-nightly-641446f65-240905",
31
+ "@react-stately/form": "^3.0.0-nightly-641446f65-240905",
32
+ "@react-stately/toggle": "^3.0.0-nightly-641446f65-240905",
33
+ "@react-types/checkbox": "^3.0.0-nightly-641446f65-240905",
34
+ "@react-types/shared": "^3.0.0-nightly-641446f65-240905",
35
+ "@swc/helpers": "^0.5.0"
36
+ },
37
+ "peerDependencies": {
38
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "stableVersion": "3.14.6"
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
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
+ export type {CheckboxAria} from './useCheckbox';
13
+ export {useCheckbox} from './useCheckbox';
14
+ export {useCheckboxGroup} from './useCheckboxGroup';
15
+ export {useCheckboxGroupItem} from './useCheckboxGroupItem';
16
+ export type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';
17
+ export type {CheckboxGroupAria} from './useCheckboxGroup';
@@ -0,0 +1,80 @@
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} from 'react';
15
+ import {RefObject, ValidationResult} from '@react-types/shared';
16
+ import {ToggleState} from '@react-stately/toggle';
17
+ import {useFormValidation} from '@react-aria/form';
18
+ import {useFormValidationState} from '@react-stately/form';
19
+ import {useToggle} from '@react-aria/toggle';
20
+
21
+ export interface CheckboxAria extends ValidationResult {
22
+ /** Props for the label wrapper element. */
23
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>,
24
+ /** Props for the input element. */
25
+ inputProps: InputHTMLAttributes<HTMLInputElement>,
26
+ /** Whether the checkbox is selected. */
27
+ isSelected: boolean,
28
+ /** Whether the checkbox is in a pressed state. */
29
+ isPressed: boolean,
30
+ /** Whether the checkbox is disabled. */
31
+ isDisabled: boolean,
32
+ /** Whether the checkbox is read only. */
33
+ isReadOnly: boolean
34
+ }
35
+
36
+ /**
37
+ * Provides the behavior and accessibility implementation for a checkbox component.
38
+ * Checkboxes allow users to select multiple items from a list of individual items, or
39
+ * to mark one individual item as selected.
40
+ * @param props - Props for the checkbox.
41
+ * @param state - State for the checkbox, as returned by `useToggleState`.
42
+ * @param inputRef - A ref for the HTML input element.
43
+ */
44
+ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement | null>): CheckboxAria {
45
+ // Create validation state here because it doesn't make sense to add to general useToggleState.
46
+ let validationState = useFormValidationState({...props, value: state.isSelected});
47
+ let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;
48
+ let {labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({
49
+ ...props,
50
+ isInvalid
51
+ }, state, inputRef);
52
+
53
+ useFormValidation(props, validationState, inputRef);
54
+
55
+ let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;
56
+ useEffect(() => {
57
+ // indeterminate is a property, but it can only be set via javascript
58
+ // https://css-tricks.com/indeterminate-checkboxes/
59
+ if (inputRef.current) {
60
+ inputRef.current.indeterminate = !!isIndeterminate;
61
+ }
62
+ });
63
+
64
+ return {
65
+ labelProps,
66
+ inputProps: {
67
+ ...inputProps,
68
+ checked: isSelected,
69
+ 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,
70
+ required: isRequired && validationBehavior === 'native'
71
+ },
72
+ isSelected,
73
+ isPressed,
74
+ isDisabled,
75
+ isReadOnly,
76
+ isInvalid,
77
+ validationErrors,
78
+ validationDetails
79
+ };
80
+ }
@@ -0,0 +1,80 @@
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 {AriaCheckboxGroupProps} from '@react-types/checkbox';
14
+ import {checkboxGroupData} from './utils';
15
+ import {CheckboxGroupState} from '@react-stately/checkbox';
16
+ import {DOMAttributes, ValidationResult} from '@react-types/shared';
17
+ import {filterDOMProps, mergeProps} from '@react-aria/utils';
18
+ import {useField} from '@react-aria/label';
19
+ import {useFocusWithin} from '@react-aria/interactions';
20
+
21
+ export interface CheckboxGroupAria extends ValidationResult {
22
+ /** Props for the checkbox group wrapper element. */
23
+ groupProps: DOMAttributes,
24
+ /** Props for the checkbox group's visible label (if any). */
25
+ labelProps: DOMAttributes,
26
+ /** Props for the checkbox group description element, if any. */
27
+ descriptionProps: DOMAttributes,
28
+ /** Props for the checkbox group error message element, if any. */
29
+ errorMessageProps: DOMAttributes
30
+ }
31
+
32
+ /**
33
+ * Provides the behavior and accessibility implementation for a checkbox group component.
34
+ * Checkbox groups allow users to select multiple items from a list of options.
35
+ * @param props - Props for the checkbox group.
36
+ * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.
37
+ */
38
+ export function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {
39
+ let {isDisabled, name, validationBehavior = 'aria'} = props;
40
+ let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
41
+
42
+ let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
43
+ ...props,
44
+ // Checkbox group is not an HTML input element so it
45
+ // shouldn't be labeled by a <label> element.
46
+ labelElementType: 'span',
47
+ isInvalid,
48
+ errorMessage: props.errorMessage || validationErrors
49
+ });
50
+
51
+ checkboxGroupData.set(state, {
52
+ name,
53
+ descriptionId: descriptionProps.id,
54
+ errorMessageId: errorMessageProps.id,
55
+ validationBehavior
56
+ });
57
+
58
+ let domProps = filterDOMProps(props, {labelable: true});
59
+
60
+ let {focusWithinProps} = useFocusWithin({
61
+ onBlurWithin: props.onBlur,
62
+ onFocusWithin: props.onFocus,
63
+ onFocusWithinChange: props.onFocusChange
64
+ });
65
+
66
+ return {
67
+ groupProps: mergeProps(domProps, {
68
+ role: 'group',
69
+ 'aria-disabled': isDisabled || undefined,
70
+ ...fieldProps,
71
+ ...focusWithinProps
72
+ }),
73
+ labelProps,
74
+ descriptionProps,
75
+ errorMessageProps,
76
+ isInvalid,
77
+ validationErrors,
78
+ validationDetails
79
+ };
80
+ }