69 lines
3.1 KiB
JavaScript
69 lines
3.1 KiB
JavaScript
import {useFormValidationState as $fQ2SF$useFormValidationState} from "@react-stately/form";
|
|
import {useControlledState as $fQ2SF$useControlledState} from "@react-stately/utils";
|
|
import {useMemo as $fQ2SF$useMemo, useState as $fQ2SF$useState} from "react";
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/ /*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
let $a54cdc5c1942b639$var$instance = Math.round(Math.random() * 10000000000);
|
|
let $a54cdc5c1942b639$var$i = 0;
|
|
function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
|
|
// Preserved here for backward compatibility. React Aria now generates the name instead of stately.
|
|
let name = (0, $fQ2SF$useMemo)(()=>props.name || `radio-group-${$a54cdc5c1942b639$var$instance}-${++$a54cdc5c1942b639$var$i}`, [
|
|
props.name
|
|
]);
|
|
var _props_defaultValue;
|
|
let [selectedValue, setSelected] = (0, $fQ2SF$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
|
|
let [lastFocusedValue, setLastFocusedValue] = (0, $fQ2SF$useState)(null);
|
|
let validation = (0, $fQ2SF$useFormValidationState)({
|
|
...props,
|
|
value: selectedValue
|
|
});
|
|
let setSelectedValue = (value)=>{
|
|
if (!props.isReadOnly && !props.isDisabled) {
|
|
setSelected(value);
|
|
validation.commitValidation();
|
|
}
|
|
};
|
|
let isInvalid = validation.displayValidation.isInvalid;
|
|
return {
|
|
...validation,
|
|
name: name,
|
|
selectedValue: selectedValue,
|
|
setSelectedValue: setSelectedValue,
|
|
lastFocusedValue: lastFocusedValue,
|
|
setLastFocusedValue: setLastFocusedValue,
|
|
isDisabled: props.isDisabled || false,
|
|
isReadOnly: props.isReadOnly || false,
|
|
isRequired: props.isRequired || false,
|
|
validationState: props.validationState || (isInvalid ? "invalid" : null),
|
|
isInvalid: isInvalid
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
export {$a54cdc5c1942b639$export$bca9d026f8e704eb as useRadioGroupState};
|
|
//# sourceMappingURL=module.js.map
|