@react-stately/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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @react-stately/radio
2
+
3
+ This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
@@ -0,0 +1,17 @@
1
+ import {useRadioGroupState as $a54cdc5c1942b639$export$bca9d026f8e704eb} from "./useRadioGroupState.mjs";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$a54cdc5c1942b639$export$bca9d026f8e704eb as useRadioGroupState};
17
+ //# sourceMappingURL=module.js.map
package/dist/main.js ADDED
@@ -0,0 +1,22 @@
1
+ var $307db30b5687e2e8$exports = require("./useRadioGroupState.main.js");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "useRadioGroupState", () => $307db30b5687e2e8$exports.useRadioGroupState);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/radio/src/index.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\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js ADDED
@@ -0,0 +1,17 @@
1
+ import {useRadioGroupState as $a54cdc5c1942b639$export$bca9d026f8e704eb} from "./useRadioGroupState.module.js";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$a54cdc5c1942b639$export$bca9d026f8e704eb as useRadioGroupState};
17
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/radio/src/index.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\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,40 @@
1
+ import { FormValidationState } from "@react-stately/form";
2
+ import { RadioGroupProps } from "@react-types/radio";
3
+ import { ValidationState } from "@react-types/shared";
4
+ export interface RadioGroupState extends FormValidationState {
5
+ /**
6
+ * The name for the group, used for native form submission.
7
+ * @deprecated
8
+ * @private
9
+ */
10
+ readonly name: string;
11
+ /** Whether the radio group is disabled. */
12
+ readonly isDisabled: boolean;
13
+ /** Whether the radio group is read only. */
14
+ readonly isReadOnly: boolean;
15
+ /** Whether the radio group is required. */
16
+ readonly isRequired: boolean;
17
+ /**
18
+ * Whether the radio group is valid or invalid.
19
+ * @deprecated Use `isInvalid` instead.
20
+ */
21
+ readonly validationState: ValidationState | null;
22
+ /** Whether the radio group is invalid. */
23
+ readonly isInvalid: boolean;
24
+ /** The currently selected value. */
25
+ readonly selectedValue: string | null;
26
+ /** Sets the selected value. */
27
+ setSelectedValue(value: string | null): void;
28
+ /** The value of the last focused radio. */
29
+ readonly lastFocusedValue: string | null;
30
+ /** Sets the last focused value. */
31
+ setLastFocusedValue(value: string | null): void;
32
+ }
33
+ /**
34
+ * Provides state management for a radio group component. Provides a name for the group,
35
+ * and manages selection and focus state.
36
+ */
37
+ export function useRadioGroupState(props: RadioGroupProps): RadioGroupState;
38
+ export type { RadioGroupProps } from '@react-types/radio';
39
+
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAkBA,gCAAiC,SAAQ,mBAAmB;IAC1D;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IAEjD,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,oCAAoC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC,+BAA+B;IAC/B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE7C,2CAA2C;IAC3C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzC,mCAAmC;IACnC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;CAChD;AAKD;;;GAGG;AACH,mCAAmC,KAAK,EAAE,eAAe,GAAG,eAAe,CAiC1E;ACnFD,YAAY,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC","sources":["packages/@react-stately/radio/src/packages/@react-stately/radio/src/useRadioGroupState.ts","packages/@react-stately/radio/src/packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/index.ts"],"sourcesContent":[null,null,"/*\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\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,61 @@
1
+ var $cVa5U$reactstatelyform = require("@react-stately/form");
2
+ var $cVa5U$reactstatelyutils = require("@react-stately/utils");
3
+ var $cVa5U$react = require("react");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useRadioGroupState", () => $307db30b5687e2e8$export$bca9d026f8e704eb);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ let $307db30b5687e2e8$var$instance = Math.round(Math.random() * 10000000000);
25
+ let $307db30b5687e2e8$var$i = 0;
26
+ function $307db30b5687e2e8$export$bca9d026f8e704eb(props) {
27
+ // Preserved here for backward compatibility. React Aria now generates the name instead of stately.
28
+ let name = (0, $cVa5U$react.useMemo)(()=>props.name || `radio-group-${$307db30b5687e2e8$var$instance}-${++$307db30b5687e2e8$var$i}`, [
29
+ props.name
30
+ ]);
31
+ var _props_defaultValue;
32
+ let [selectedValue, setSelected] = (0, $cVa5U$reactstatelyutils.useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
33
+ let [lastFocusedValue, setLastFocusedValue] = (0, $cVa5U$react.useState)(null);
34
+ let validation = (0, $cVa5U$reactstatelyform.useFormValidationState)({
35
+ ...props,
36
+ value: selectedValue
37
+ });
38
+ let setSelectedValue = (value)=>{
39
+ if (!props.isReadOnly && !props.isDisabled) {
40
+ setSelected(value);
41
+ validation.commitValidation();
42
+ }
43
+ };
44
+ let isInvalid = validation.displayValidation.isInvalid;
45
+ return {
46
+ ...validation,
47
+ name: name,
48
+ selectedValue: selectedValue,
49
+ setSelectedValue: setSelectedValue,
50
+ lastFocusedValue: lastFocusedValue,
51
+ setLastFocusedValue: setLastFocusedValue,
52
+ isDisabled: props.isDisabled || false,
53
+ isReadOnly: props.isReadOnly || false,
54
+ isRequired: props.isRequired || false,
55
+ validationState: props.validationState || (isInvalid ? 'invalid' : null),
56
+ isInvalid: isInvalid
57
+ };
58
+ }
59
+
60
+
61
+ //# sourceMappingURL=useRadioGroupState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA+CD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,wBAAE,CAAC,EAAE;QAAC,MAAM,IAAI;KAAC;QAClB;IAAnE,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,KAAK,EAAE,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,8CAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;0BACf;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/@react-stately/radio/src/useRadioGroupState.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 {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.main.js.map"}
@@ -0,0 +1,56 @@
1
+ import {useFormValidationState as $l55kx$useFormValidationState} from "@react-stately/form";
2
+ import {useControlledState as $l55kx$useControlledState} from "@react-stately/utils";
3
+ import {useMemo as $l55kx$useMemo, useState as $l55kx$useState} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ let $a54cdc5c1942b639$var$instance = Math.round(Math.random() * 10000000000);
19
+ let $a54cdc5c1942b639$var$i = 0;
20
+ function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
21
+ // Preserved here for backward compatibility. React Aria now generates the name instead of stately.
22
+ let name = (0, $l55kx$useMemo)(()=>props.name || `radio-group-${$a54cdc5c1942b639$var$instance}-${++$a54cdc5c1942b639$var$i}`, [
23
+ props.name
24
+ ]);
25
+ var _props_defaultValue;
26
+ let [selectedValue, setSelected] = (0, $l55kx$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
27
+ let [lastFocusedValue, setLastFocusedValue] = (0, $l55kx$useState)(null);
28
+ let validation = (0, $l55kx$useFormValidationState)({
29
+ ...props,
30
+ value: selectedValue
31
+ });
32
+ let setSelectedValue = (value)=>{
33
+ if (!props.isReadOnly && !props.isDisabled) {
34
+ setSelected(value);
35
+ validation.commitValidation();
36
+ }
37
+ };
38
+ let isInvalid = validation.displayValidation.isInvalid;
39
+ return {
40
+ ...validation,
41
+ name: name,
42
+ selectedValue: selectedValue,
43
+ setSelectedValue: setSelectedValue,
44
+ lastFocusedValue: lastFocusedValue,
45
+ setLastFocusedValue: setLastFocusedValue,
46
+ isDisabled: props.isDisabled || false,
47
+ isReadOnly: props.isReadOnly || false,
48
+ isRequired: props.isRequired || false,
49
+ validationState: props.validationState || (isInvalid ? 'invalid' : null),
50
+ isInvalid: isInvalid
51
+ };
52
+ }
53
+
54
+
55
+ export {$a54cdc5c1942b639$export$bca9d026f8e704eb as useRadioGroupState};
56
+ //# sourceMappingURL=useRadioGroupState.module.js.map
@@ -0,0 +1,56 @@
1
+ import {useFormValidationState as $l55kx$useFormValidationState} from "@react-stately/form";
2
+ import {useControlledState as $l55kx$useControlledState} from "@react-stately/utils";
3
+ import {useMemo as $l55kx$useMemo, useState as $l55kx$useState} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ let $a54cdc5c1942b639$var$instance = Math.round(Math.random() * 10000000000);
19
+ let $a54cdc5c1942b639$var$i = 0;
20
+ function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
21
+ // Preserved here for backward compatibility. React Aria now generates the name instead of stately.
22
+ let name = (0, $l55kx$useMemo)(()=>props.name || `radio-group-${$a54cdc5c1942b639$var$instance}-${++$a54cdc5c1942b639$var$i}`, [
23
+ props.name
24
+ ]);
25
+ var _props_defaultValue;
26
+ let [selectedValue, setSelected] = (0, $l55kx$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
27
+ let [lastFocusedValue, setLastFocusedValue] = (0, $l55kx$useState)(null);
28
+ let validation = (0, $l55kx$useFormValidationState)({
29
+ ...props,
30
+ value: selectedValue
31
+ });
32
+ let setSelectedValue = (value)=>{
33
+ if (!props.isReadOnly && !props.isDisabled) {
34
+ setSelected(value);
35
+ validation.commitValidation();
36
+ }
37
+ };
38
+ let isInvalid = validation.displayValidation.isInvalid;
39
+ return {
40
+ ...validation,
41
+ name: name,
42
+ selectedValue: selectedValue,
43
+ setSelectedValue: setSelectedValue,
44
+ lastFocusedValue: lastFocusedValue,
45
+ setLastFocusedValue: setLastFocusedValue,
46
+ isDisabled: props.isDisabled || false,
47
+ isReadOnly: props.isReadOnly || false,
48
+ isRequired: props.isRequired || false,
49
+ validationState: props.validationState || (isInvalid ? 'invalid' : null),
50
+ isInvalid: isInvalid
51
+ };
52
+ }
53
+
54
+
55
+ export {$a54cdc5c1942b639$export$bca9d026f8e704eb as useRadioGroupState};
56
+ //# sourceMappingURL=useRadioGroupState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA+CD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,wBAAE,CAAC,EAAE;QAAC,MAAM,IAAI;KAAC;QAClB;IAAnE,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,KAAK,EAAE,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,6BAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;0BACf;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF","sources":["packages/@react-stately/radio/src/useRadioGroupState.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 {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroupState.module.js.map"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@react-stately/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-stately/form": "^3.0.0-nightly-641446f65-240905",
26
+ "@react-stately/utils": "^3.0.0-nightly-641446f65-240905",
27
+ "@react-types/radio": "^3.0.0-nightly-641446f65-240905",
28
+ "@react-types/shared": "^3.0.0-nightly-641446f65-240905",
29
+ "@swc/helpers": "^0.5.0"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "stableVersion": "3.10.7"
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
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
+ export {useRadioGroupState} from './useRadioGroupState';
14
+
15
+ export type {RadioGroupProps} from '@react-types/radio';
16
+ export type {RadioGroupState} from './useRadioGroupState';
@@ -0,0 +1,98 @@
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 {FormValidationState, useFormValidationState} from '@react-stately/form';
14
+ import {RadioGroupProps} from '@react-types/radio';
15
+ import {useControlledState} from '@react-stately/utils';
16
+ import {useMemo, useState} from 'react';
17
+ import {ValidationState} from '@react-types/shared';
18
+
19
+ export interface RadioGroupState extends FormValidationState {
20
+ /**
21
+ * The name for the group, used for native form submission.
22
+ * @deprecated
23
+ * @private
24
+ */
25
+ readonly name: string,
26
+
27
+ /** Whether the radio group is disabled. */
28
+ readonly isDisabled: boolean,
29
+
30
+ /** Whether the radio group is read only. */
31
+ readonly isReadOnly: boolean,
32
+
33
+ /** Whether the radio group is required. */
34
+ readonly isRequired: boolean,
35
+
36
+ /**
37
+ * Whether the radio group is valid or invalid.
38
+ * @deprecated Use `isInvalid` instead.
39
+ */
40
+ readonly validationState: ValidationState | null,
41
+
42
+ /** Whether the radio group is invalid. */
43
+ readonly isInvalid: boolean,
44
+
45
+ /** The currently selected value. */
46
+ readonly selectedValue: string | null,
47
+
48
+ /** Sets the selected value. */
49
+ setSelectedValue(value: string | null): void,
50
+
51
+ /** The value of the last focused radio. */
52
+ readonly lastFocusedValue: string | null,
53
+
54
+ /** Sets the last focused value. */
55
+ setLastFocusedValue(value: string | null): void
56
+ }
57
+
58
+ let instance = Math.round(Math.random() * 10000000000);
59
+ let i = 0;
60
+
61
+ /**
62
+ * Provides state management for a radio group component. Provides a name for the group,
63
+ * and manages selection and focus state.
64
+ */
65
+ export function useRadioGroupState(props: RadioGroupProps): RadioGroupState {
66
+ // Preserved here for backward compatibility. React Aria now generates the name instead of stately.
67
+ let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);
68
+ let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);
69
+ let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);
70
+
71
+ let validation = useFormValidationState({
72
+ ...props,
73
+ value: selectedValue
74
+ });
75
+
76
+ let setSelectedValue = (value) => {
77
+ if (!props.isReadOnly && !props.isDisabled) {
78
+ setSelected(value);
79
+ validation.commitValidation();
80
+ }
81
+ };
82
+
83
+ let isInvalid = validation.displayValidation.isInvalid;
84
+
85
+ return {
86
+ ...validation,
87
+ name,
88
+ selectedValue: selectedValue,
89
+ setSelectedValue,
90
+ lastFocusedValue,
91
+ setLastFocusedValue,
92
+ isDisabled: props.isDisabled || false,
93
+ isReadOnly: props.isReadOnly || false,
94
+ isRequired: props.isRequired || false,
95
+ validationState: props.validationState || (isInvalid ? 'invalid' : null),
96
+ isInvalid
97
+ };
98
+ }