A set of radio buttons for choosing one option. The Radio component extends Base UI's Radio, and RadioGroup extends Base UI's RadioGroup. It gives Radio.Indicator a default dot.
Here is the component implementation code that you can copy to your project. You'll need both the Radio and RadioGroup components:
// https://devie-ui.com/components/radio
// https://base-ui.com/react/components/radio
import { Radio as BaseRadio } from "@base-ui/react/radio";
import clsx from "clsx";
import styles from "./Radio.module.scss";
function Root({ className, ...props }: Radio.Root.Props) {
return <BaseRadio.Root className={clsx(styles.root, className)} {...props} />;
}
function Indicator({ className, children, ...props }: Radio.Indicator.Props) {
return (
<BaseRadio.Indicator
className={clsx(styles.indicator, className)}
{...props}
>
{children || <DefaultIndicatorDot />}
</BaseRadio.Indicator>
);
}
function DefaultIndicatorDot() {
return <div className={styles.dot} />;
}
const Radio = {
Root,
Indicator,
};
namespace Radio {
export namespace Root {
export type Props = Omit<BaseRadio.Root.Props, "className"> & {
className?: string;
};
export type State = BaseRadio.Root.State;
}
export namespace Indicator {
export type Props = Omit<BaseRadio.Indicator.Props, "className"> & {
className?: string;
};
}
}
export default Radio;Wrap Radio.Root elements in a RadioGroup and set defaultValue to the selected value. Put each Root in a label so its text selects it.
Set disabled on a Radio.Root to disable one option, or on the RadioGroup to disable all of them.