@trellixio/roaster-coffee
Version:
Beans' product component library
24 lines (23 loc) • 1 kB
JavaScript
import * as React from 'react';
import { classNames, useUid, useUncontrolled } from '@/utils';
import { RadioGroupProvider } from './RadioGroup.context';
export 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 (React.createElement(RadioGroupProvider, { value: {
value: internalValue,
onChange: handleChange,
name: groupName,
} },
React.createElement("p", null, title),
React.createElement("div", { ref: ref, className: classNames('option-list radio', { 'items-group': orientation === 'horizontal' }, className) }, children)));
});