@trellixio/roaster-coffee
Version:
Beans' product component library
58 lines (52 loc) • 1.62 kB
JavaScript
;
var React = require('react');
var index$2 = require('../../../utils/classNames/index.js');
var index$1 = require('../../../utils/useUncontrolled/index.js');
var index = require('../../../utils/useUid/index.js');
require('@floating-ui/react');
var RadioGroup_context = require('./RadioGroup.context.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const RadioGroup = React__namespace.forwardRef((props, ref) => {
const { onChange, name, value, defaultValue, className, children, title, orientation = "vertical" } = props;
const groupName = index.useUid(name);
const [internalValue, setInternalValue] = index$1.useUncontrolled({
value,
defaultValue,
finalValue: "",
onChange
});
const handleChange = (event) => {
setInternalValue(event.currentTarget.value);
};
return /* @__PURE__ */ React__namespace.createElement(
RadioGroup_context.RadioGroupProvider,
{
value: {
value: internalValue,
onChange: handleChange,
name: groupName
}
},
/* @__PURE__ */ React__namespace.createElement("p", null, title),
/* @__PURE__ */ React__namespace.createElement(
"div",
{
ref,
className: index$2.classNames("option-list radio", { "items-group": orientation === "horizontal" }, className)
},
children
)
);
});
exports.RadioGroup = RadioGroup;
//# sourceMappingURL=RadioGroup.js.map