@trellixio/roaster-coffee
Version:
Beans' product component library
17 lines (16 loc) • 1.05 kB
JavaScript
import * as React from 'react';
import { classNames, useUid } from '@/utils';
import { RadioGroup } from './RadioGroup/RadioGroup';
import { useRadioGroupContext } from './RadioGroup/RadioGroup.context';
export const Radio = React.forwardRef((props, ref) => {
const { id, label, name, disabled, value, labelClassName, inputClassName, isRichSelector } = props;
const ctx = useRadioGroupContext();
const uid = useUid(id);
const checked = ctx.value === value;
return (React.createElement("label", { htmlFor: uid, className: classNames(labelClassName, { selector: isRichSelector, selected: checked }) },
React.createElement("input", { value: value, ref: ref, type: "radio", name: name !== null && name !== void 0 ? name : ctx.name, id: uid, checked: checked, disabled: disabled, onChange: ctx.onChange }),
React.createElement("span", { className: classNames('input-radio', inputClassName) }),
React.createElement("div", { className: "content" }, label)));
});
Radio.displayName = 'Radio';
Radio.Group = RadioGroup;