@react-aria/radio 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,127 @@
1
+ import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.mjs";
2
+ import {filterDOMProps as $czmJy$filterDOMProps, useId as $czmJy$useId, mergeProps as $czmJy$mergeProps} from "@react-aria/utils";
3
+ import {getFocusableTreeWalker as $czmJy$getFocusableTreeWalker} from "@react-aria/focus";
4
+ import {useField as $czmJy$useField} from "@react-aria/label";
5
+ import {useFocusWithin as $czmJy$useFocusWithin} from "@react-aria/interactions";
6
+ import {useLocale as $czmJy$useLocale} from "@react-aria/i18n";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
25
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = 'vertical', validationBehavior: validationBehavior = 'aria' } = props;
26
+ let { direction: direction } = (0, $czmJy$useLocale)();
27
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
28
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $czmJy$useField)({
29
+ ...props,
30
+ // Radio group is not an HTML input element so it
31
+ // shouldn't be labeled by a <label> element.
32
+ labelElementType: 'span',
33
+ isInvalid: state.isInvalid,
34
+ errorMessage: props.errorMessage || validationErrors
35
+ });
36
+ let domProps = (0, $czmJy$filterDOMProps)(props, {
37
+ labelable: true
38
+ });
39
+ // When the radio group loses focus, reset the focusable radio to null if
40
+ // there is no selection. This allows tabbing into the group from either
41
+ // direction to go to the first or last radio.
42
+ let { focusWithinProps: focusWithinProps } = (0, $czmJy$useFocusWithin)({
43
+ onBlurWithin (e) {
44
+ var _props_onBlur;
45
+ (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
46
+ if (!state.selectedValue) state.setLastFocusedValue(null);
47
+ },
48
+ onFocusWithin: props.onFocus,
49
+ onFocusWithinChange: props.onFocusChange
50
+ });
51
+ let onKeyDown = (e)=>{
52
+ let nextDir;
53
+ switch(e.key){
54
+ case 'ArrowRight':
55
+ if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'prev';
56
+ else nextDir = 'next';
57
+ break;
58
+ case 'ArrowLeft':
59
+ if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'next';
60
+ else nextDir = 'prev';
61
+ break;
62
+ case 'ArrowDown':
63
+ nextDir = 'next';
64
+ break;
65
+ case 'ArrowUp':
66
+ nextDir = 'prev';
67
+ break;
68
+ default:
69
+ return;
70
+ }
71
+ e.preventDefault();
72
+ let walker = (0, $czmJy$getFocusableTreeWalker)(e.currentTarget, {
73
+ from: e.target
74
+ });
75
+ let nextElem;
76
+ if (nextDir === 'next') {
77
+ nextElem = walker.nextNode();
78
+ if (!nextElem) {
79
+ walker.currentNode = e.currentTarget;
80
+ nextElem = walker.firstChild();
81
+ }
82
+ } else {
83
+ nextElem = walker.previousNode();
84
+ if (!nextElem) {
85
+ walker.currentNode = e.currentTarget;
86
+ nextElem = walker.lastChild();
87
+ }
88
+ }
89
+ if (nextElem) {
90
+ // Call focus on nextElem so that keyboard navigation scrolls the radio into view
91
+ nextElem.focus();
92
+ state.setSelectedValue(nextElem.value);
93
+ }
94
+ };
95
+ let groupName = (0, $czmJy$useId)(name);
96
+ (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
97
+ name: groupName,
98
+ descriptionId: descriptionProps.id,
99
+ errorMessageId: errorMessageProps.id,
100
+ validationBehavior: validationBehavior
101
+ });
102
+ return {
103
+ radioGroupProps: (0, $czmJy$mergeProps)(domProps, {
104
+ // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
105
+ role: 'radiogroup',
106
+ onKeyDown: onKeyDown,
107
+ 'aria-invalid': state.isInvalid || undefined,
108
+ 'aria-errormessage': props['aria-errormessage'],
109
+ 'aria-readonly': isReadOnly || undefined,
110
+ 'aria-required': isRequired || undefined,
111
+ 'aria-disabled': isDisabled || undefined,
112
+ 'aria-orientation': orientation,
113
+ ...fieldProps,
114
+ ...focusWithinProps
115
+ }),
116
+ labelProps: labelProps,
117
+ descriptionProps: descriptionProps,
118
+ errorMessageProps: errorMessageProps,
119
+ isInvalid: isInvalid,
120
+ validationErrors: validationErrors,
121
+ validationDetails: validationDetails
122
+ };
123
+ }
124
+
125
+
126
+ export {$430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
127
+ //# sourceMappingURL=useRadioGroup.module.js.map
@@ -0,0 +1,127 @@
1
+ import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.module.js";
2
+ import {filterDOMProps as $czmJy$filterDOMProps, useId as $czmJy$useId, mergeProps as $czmJy$mergeProps} from "@react-aria/utils";
3
+ import {getFocusableTreeWalker as $czmJy$getFocusableTreeWalker} from "@react-aria/focus";
4
+ import {useField as $czmJy$useField} from "@react-aria/label";
5
+ import {useFocusWithin as $czmJy$useFocusWithin} from "@react-aria/interactions";
6
+ import {useLocale as $czmJy$useLocale} from "@react-aria/i18n";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
25
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = 'vertical', validationBehavior: validationBehavior = 'aria' } = props;
26
+ let { direction: direction } = (0, $czmJy$useLocale)();
27
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
28
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $czmJy$useField)({
29
+ ...props,
30
+ // Radio group is not an HTML input element so it
31
+ // shouldn't be labeled by a <label> element.
32
+ labelElementType: 'span',
33
+ isInvalid: state.isInvalid,
34
+ errorMessage: props.errorMessage || validationErrors
35
+ });
36
+ let domProps = (0, $czmJy$filterDOMProps)(props, {
37
+ labelable: true
38
+ });
39
+ // When the radio group loses focus, reset the focusable radio to null if
40
+ // there is no selection. This allows tabbing into the group from either
41
+ // direction to go to the first or last radio.
42
+ let { focusWithinProps: focusWithinProps } = (0, $czmJy$useFocusWithin)({
43
+ onBlurWithin (e) {
44
+ var _props_onBlur;
45
+ (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
46
+ if (!state.selectedValue) state.setLastFocusedValue(null);
47
+ },
48
+ onFocusWithin: props.onFocus,
49
+ onFocusWithinChange: props.onFocusChange
50
+ });
51
+ let onKeyDown = (e)=>{
52
+ let nextDir;
53
+ switch(e.key){
54
+ case 'ArrowRight':
55
+ if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'prev';
56
+ else nextDir = 'next';
57
+ break;
58
+ case 'ArrowLeft':
59
+ if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'next';
60
+ else nextDir = 'prev';
61
+ break;
62
+ case 'ArrowDown':
63
+ nextDir = 'next';
64
+ break;
65
+ case 'ArrowUp':
66
+ nextDir = 'prev';
67
+ break;
68
+ default:
69
+ return;
70
+ }
71
+ e.preventDefault();
72
+ let walker = (0, $czmJy$getFocusableTreeWalker)(e.currentTarget, {
73
+ from: e.target
74
+ });
75
+ let nextElem;
76
+ if (nextDir === 'next') {
77
+ nextElem = walker.nextNode();
78
+ if (!nextElem) {
79
+ walker.currentNode = e.currentTarget;
80
+ nextElem = walker.firstChild();
81
+ }
82
+ } else {
83
+ nextElem = walker.previousNode();
84
+ if (!nextElem) {
85
+ walker.currentNode = e.currentTarget;
86
+ nextElem = walker.lastChild();
87
+ }
88
+ }
89
+ if (nextElem) {
90
+ // Call focus on nextElem so that keyboard navigation scrolls the radio into view
91
+ nextElem.focus();
92
+ state.setSelectedValue(nextElem.value);
93
+ }
94
+ };
95
+ let groupName = (0, $czmJy$useId)(name);
96
+ (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
97
+ name: groupName,
98
+ descriptionId: descriptionProps.id,
99
+ errorMessageId: errorMessageProps.id,
100
+ validationBehavior: validationBehavior
101
+ });
102
+ return {
103
+ radioGroupProps: (0, $czmJy$mergeProps)(domProps, {
104
+ // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
105
+ role: 'radiogroup',
106
+ onKeyDown: onKeyDown,
107
+ 'aria-invalid': state.isInvalid || undefined,
108
+ 'aria-errormessage': props['aria-errormessage'],
109
+ 'aria-readonly': isReadOnly || undefined,
110
+ 'aria-required': isRequired || undefined,
111
+ 'aria-disabled': isDisabled || undefined,
112
+ 'aria-orientation': orientation,
113
+ ...fieldProps,
114
+ ...focusWithinProps
115
+ }),
116
+ labelProps: labelProps,
117
+ descriptionProps: descriptionProps,
118
+ errorMessageProps: errorMessageProps,
119
+ isInvalid: isInvalid,
120
+ validationErrors: validationErrors,
121
+ validationDetails: validationDetails
122
+ };
123
+ }
124
+
125
+
126
+ export {$430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
127
+ //# sourceMappingURL=useRadioGroup.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,SAAS,0CAAc,KAA0B,EAAE,KAAsB;IAC9E,IAAI,QACF,IAAI,cACJ,UAAU,cACV,UAAU,cACV,UAAU,eACV,cAAc,gCACd,qBAAqB,QACtB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAE1B,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,MAAM,iBAAiB;IAC9E,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;QACR,iDAAiD;QACjD,6CAA6C;QAC7C,kBAAkB;QAClB,WAAW,MAAM,SAAS;QAC1B,cAAc,MAAM,YAAY,IAAI;IACtC;IAEA,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,yEAAyE;IACzE,wEAAwE;IACxE,8CAA8C;IAC9C,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QACtC,cAAa,CAAC;gBACZ;aAAA,gBAAA,MAAM,MAAM,cAAZ,oCAAA,mBAAA,OAAe;YACf,IAAI,CAAC,MAAM,aAAa,EACtB,MAAM,mBAAmB,CAAC;QAE9B;QACA,eAAe,MAAM,OAAO;QAC5B,qBAAqB,MAAM,aAAa;IAC1C;IAEA,IAAI,YAAY,CAAC;QACf,IAAI;QACJ,OAAQ,EAAE,GAAG;YACX,KAAK;gBACH,IAAI,cAAc,SAAS,gBAAgB,YACzC,UAAU;qBAEV,UAAU;gBAEZ;YACF,KAAK;gBACH,IAAI,cAAc,SAAS,gBAAgB,YACzC,UAAU;qBAEV,UAAU;gBAEZ;YACF,KAAK;gBACH,UAAU;gBACV;YACF,KAAK;gBACH,UAAU;gBACV;YACF;gBACE;QACJ;QACA,EAAE,cAAc;QAChB,IAAI,SAAS,CAAA,GAAA,6BAAqB,EAAE,EAAE,aAAa,EAAE;YAAC,MAAM,EAAE,MAAM;QAAA;QACpE,IAAI;QACJ,IAAI,YAAY,QAAQ;YACtB,WAAW,OAAO,QAAQ;YAC1B,IAAI,CAAC,UAAU;gBACb,OAAO,WAAW,GAAG,EAAE,aAAa;gBACpC,WAAW,OAAO,UAAU;YAC9B;QACF,OAAO;YACL,WAAW,OAAO,YAAY;YAC9B,IAAI,CAAC,UAAU;gBACb,OAAO,WAAW,GAAG,EAAE,aAAa;gBACpC,WAAW,OAAO,SAAS;YAC7B;QACF;QACA,IAAI,UAAU;YACZ,iFAAiF;YACjF,SAAS,KAAK;YACd,MAAM,gBAAgB,CAAC,SAAS,KAAK;QACvC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,YAAI,EAAE;IACtB,CAAA,GAAA,yCAAa,EAAE,GAAG,CAAC,OAAO;QACxB,MAAM;QACN,eAAe,iBAAiB,EAAE;QAClC,gBAAgB,kBAAkB,EAAE;4BACpC;IACF;IAEA,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,MAAM,SAAS,IAAI;YACnC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,oBAAoB;YACpB,GAAG,UAAU;YACb,GAAG,gBAAgB;QACrB;oBACA;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/radio/src/useRadioGroup.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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria extends ValidationResult {\n /** Props for the radio group wrapper element. */\n radioGroupProps: DOMAttributes,\n /** Props for the radio group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the radio group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the radio group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical',\n validationBehavior = 'aria'\n } = props;\n let {direction} = useLocale();\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid: state.isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin(e) {\n props.onBlur?.(e);\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n },\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {from: e.target});\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupData.set(state, {\n name: groupName,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': state.isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroup.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, "radioGroupData", () => $eeb149278aae5c67$export$37b65e5b5444d35c);
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 $eeb149278aae5c67$export$37b65e5b5444d35c = new WeakMap();
18
+
19
+
20
+ //# sourceMappingURL=utils.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI","sources":["packages/@react-aria/radio/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 {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n descriptionId: string | undefined,\n errorMessageId: string | undefined,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData = new WeakMap<RadioGroupState, RadioGroupData>();\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 $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
12
+
13
+
14
+ export {$884aeceb3d67f00f$export$37b65e5b5444d35c as radioGroupData};
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 $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
12
+
13
+
14
+ export {$884aeceb3d67f00f$export$37b65e5b5444d35c as radioGroupData};
15
+ //# sourceMappingURL=utils.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI","sources":["packages/@react-aria/radio/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 {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n descriptionId: string | undefined,\n errorMessageId: string | undefined,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData = new WeakMap<RadioGroupState, RadioGroupData>();\n"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@react-aria/radio",
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/focus": "^3.0.0-nightly-641446f65-240905",
26
+ "@react-aria/form": "^3.0.0-nightly-641446f65-240905",
27
+ "@react-aria/i18n": "^3.0.0-nightly-641446f65-240905",
28
+ "@react-aria/interactions": "^3.0.0-nightly-641446f65-240905",
29
+ "@react-aria/label": "^3.0.0-nightly-641446f65-240905",
30
+ "@react-aria/utils": "^3.0.0-nightly-641446f65-240905",
31
+ "@react-stately/radio": "^3.0.0-nightly-641446f65-240905",
32
+ "@react-types/radio": "^3.0.0-nightly-641446f65-240905",
33
+ "@react-types/shared": "^3.0.0-nightly-641446f65-240905",
34
+ "@swc/helpers": "^0.5.0"
35
+ },
36
+ "peerDependencies": {
37
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "stableVersion": "3.10.7"
43
+ }
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 {useRadio} from './useRadio';
13
+ export {useRadioGroup} from './useRadioGroup';
14
+ export type {AriaRadioGroupProps, AriaRadioProps} from '@react-types/radio';
15
+ export type {Orientation} from '@react-types/shared';
16
+ export type {RadioAria} from './useRadio';
17
+ export type {RadioGroupAria} from './useRadioGroup';
@@ -0,0 +1,121 @@
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 {AriaRadioProps} from '@react-types/radio';
14
+ import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
15
+ import {InputHTMLAttributes, LabelHTMLAttributes} from 'react';
16
+ import {radioGroupData} from './utils';
17
+ import {RadioGroupState} from '@react-stately/radio';
18
+ import {RefObject} from '@react-types/shared';
19
+ import {useFocusable} from '@react-aria/focus';
20
+ import {useFormValidation} from '@react-aria/form';
21
+ import {usePress} from '@react-aria/interactions';
22
+
23
+ export interface RadioAria {
24
+ /** Props for the label wrapper element. */
25
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>,
26
+ /** Props for the input element. */
27
+ inputProps: InputHTMLAttributes<HTMLInputElement>,
28
+ /** Whether the radio is disabled. */
29
+ isDisabled: boolean,
30
+ /** Whether the radio is currently selected. */
31
+ isSelected: boolean,
32
+ /** Whether the radio is in a pressed state. */
33
+ isPressed: boolean
34
+ }
35
+
36
+ /**
37
+ * Provides the behavior and accessibility implementation for an individual
38
+ * radio button in a radio group.
39
+ * @param props - Props for the radio.
40
+ * @param state - State for the radio group, as returned by `useRadioGroupState`.
41
+ * @param ref - Ref to the HTML input element.
42
+ */
43
+ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLInputElement | null>): RadioAria {
44
+ let {
45
+ value,
46
+ children,
47
+ 'aria-label': ariaLabel,
48
+ 'aria-labelledby': ariaLabelledby
49
+ } = props;
50
+
51
+ const isDisabled = props.isDisabled || state.isDisabled;
52
+
53
+ let hasChildren = children != null;
54
+ let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
55
+ if (!hasChildren && !hasAriaLabel) {
56
+ console.warn('If you do not provide children, you must specify an aria-label for accessibility');
57
+ }
58
+
59
+ let checked = state.selectedValue === value;
60
+
61
+ let onChange = (e) => {
62
+ e.stopPropagation();
63
+ state.setSelectedValue(value);
64
+ };
65
+
66
+ let {pressProps, isPressed} = usePress({
67
+ isDisabled
68
+ });
69
+
70
+ // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.
71
+ let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({
72
+ isDisabled,
73
+ onPress() {
74
+ state.setSelectedValue(value);
75
+ }
76
+ });
77
+
78
+ let {focusableProps} = useFocusable(mergeProps(props, {
79
+ onFocus: () => state.setLastFocusedValue(value)
80
+ }), ref);
81
+ let interactions = mergeProps(pressProps, focusableProps);
82
+ let domProps = filterDOMProps(props, {labelable: true});
83
+ let tabIndex: number | undefined = -1;
84
+ if (state.selectedValue != null) {
85
+ if (state.selectedValue === value) {
86
+ tabIndex = 0;
87
+ }
88
+ } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {
89
+ tabIndex = 0;
90
+ }
91
+ if (isDisabled) {
92
+ tabIndex = undefined;
93
+ }
94
+
95
+ let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;
96
+ useFormReset(ref, state.selectedValue, state.setSelectedValue);
97
+ useFormValidation({validationBehavior}, state, ref);
98
+
99
+ return {
100
+ labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),
101
+ inputProps: mergeProps(domProps, {
102
+ ...interactions,
103
+ type: 'radio',
104
+ name,
105
+ tabIndex,
106
+ disabled: isDisabled,
107
+ required: state.isRequired && validationBehavior === 'native',
108
+ checked,
109
+ value,
110
+ onChange,
111
+ 'aria-describedby': [
112
+ props['aria-describedby'],
113
+ state.isInvalid ? errorMessageId : null,
114
+ descriptionId
115
+ ].filter(Boolean).join(' ') || undefined
116
+ }),
117
+ isDisabled,
118
+ isSelected: checked,
119
+ isPressed: isPressed || isLabelPressed
120
+ };
121
+ }