@trellixio/roaster-coffee
Version:
Beans' product component library
43 lines (40 loc) • 1.28 kB
JavaScript
import * as React from 'react';
import { classNames } from '../../../utils/classNames/index.js';
import { useUncontrolled } from '../../../utils/useUncontrolled/index.js';
import { useUid } from '../../../utils/useUid/index.js';
import '@floating-ui/react';
import { RadioGroupProvider } from './RadioGroup.context.js';
const RadioGroup = React.forwardRef((props, ref) => {
const { onChange, name, value, defaultValue, className, children, title, orientation = "vertical" } = props;
const groupName = useUid(name);
const [internalValue, setInternalValue] = useUncontrolled({
value,
defaultValue,
finalValue: "",
onChange
});
const handleChange = (event) => {
setInternalValue(event.currentTarget.value);
};
return /* @__PURE__ */ React.createElement(
RadioGroupProvider,
{
value: {
value: internalValue,
onChange: handleChange,
name: groupName
}
},
/* @__PURE__ */ React.createElement("p", null, title),
/* @__PURE__ */ React.createElement(
"div",
{
ref,
className: classNames("option-list radio", { "items-group": orientation === "horizontal" }, className)
},
children
)
);
});
export { RadioGroup };
//# sourceMappingURL=RadioGroup.js.map