informed
Version:
A lightweight framework and utility for building powerful forms in React applications
39 lines (36 loc) • 1.43 kB
JavaScript
import { objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React from 'react';
import { RadioGroupContext } from '../../Context.js';
import { useField } from '../../hooks/useField.js';
import { Radio } from './Radio.js';
var RadioGroup = function RadioGroup(props) {
var _useField = useField(props),
fieldApi = _useField.fieldApi,
fieldState = _useField.fieldState,
userProps = _useField.userProps;
var groupContext = _objectSpread2({
radioGroupApi: fieldApi,
radioGroupState: fieldState
}, props);
var label = userProps.label,
id = userProps.id,
options = userProps.options,
children = userProps.children;
var showError = fieldState.showError,
error = fieldState.error;
return /*#__PURE__*/React.createElement(RadioGroupContext.Provider, {
value: groupContext
}, /*#__PURE__*/React.createElement("fieldset", {
"aria-describedby": "".concat(id, "-error")
}, label ? /*#__PURE__*/React.createElement("legend", null, label) : null, options ? options.map(function (option) {
return /*#__PURE__*/React.createElement("label", {
key: option.value
}, option.label, " ", /*#__PURE__*/React.createElement(Radio, {
value: option.value
}));
}) : children, showError ? /*#__PURE__*/React.createElement("small", {
role: "alert",
id: "".concat(id, "-error")
}, error) : null));
};
export { RadioGroup };