import React, { FC, InputHTMLAttributes, Ref, useId, useContext } from 'react';
import classnames from 'classnames';
import { RadioGroupContext, RadioValueType } from './RadioGroup';
import { useEventCallback } from './hooks';
/**
*
*/
export type RadioProps = {
label?: string;
name?: string;
value?: RadioValueType;
inputRef?: Ref;
} & Omit, 'value'>;
/**
*
*/
export const Radio: FC = ({
id: id_,
className,
label,
name,
value,
inputRef,
onChange: onChange_,
children,
...props
}) => {
const {
name: grpName,
error,
errorId,
onValueChange,
} = useContext(RadioGroupContext);
const prefix = useId();
const id = id_ ?? `${prefix}-id`;
const onChange = useEventCallback(
(e: React.ChangeEvent) => {
onChange_?.(e);
if (value != null) {
onValueChange?.(value);
}
}
);
const radioClassNames = classnames(className, 'slds-radio');
return (
);
};