import React from "react"; // helpers import { cn } from "@/helpers/common.helper"; type RadioInputProps = { name?: string; label: string | React.ReactNode | undefined; wrapperClassName?: string; fieldClassName?: string; buttonClassName?: string; labelClassName?: string; ariaLabel?: string; options: { label: string | React.ReactNode; value: string; disabled?: boolean }[]; vertical?: boolean; selected: string; onChange: (value: string) => void; className?: string; }; export const RadioInput = ({ name = "radio-input", label: inputLabel, labelClassName: inputLabelClassName = "", wrapperClassName: inputWrapperClassName = "", fieldClassName: inputFieldClassName = "", buttonClassName: inputButtonClassName = "", options, vertical, selected, ariaLabel, onChange, className, }: RadioInputProps) => { const wrapperClass = vertical ? "flex flex-col gap-1" : "flex gap-2"; const setSelected = (value: string) => { onChange(value); }; let aria = ariaLabel ? ariaLabel.toLowerCase().replace(" ", "-") : ""; if (!aria && typeof inputLabel === "string") { aria = inputLabel.toLowerCase().replace(" ", "-"); } else { aria = "radio-input"; } return (
{inputLabel}
{options.map(({ value, label, disabled }, index) => (
!disabled && setSelected(value)} className={cn( "flex items-center gap-2", disabled ? `bg-custom-background-200 border-custom-border-200 cursor-not-allowed` : ``, inputFieldClassName )} >
))}
); }; export default RadioInput;