import cn from "@utils/classnames.ts";
import { type ReactNode } from "react";
import { FormError } from "../index.ts";
import LabelTooltip from "./LabelTooltip.tsx";
interface CheckboxOption {
name: string;
label: string;
description?: string;
}
interface InputCheckboxListProps {
label: string;
options: CheckboxOption[];
value: string[];
onChange: (value: string[]) => void;
error?: string;
required?: boolean;
className?: string;
id?: string;
tooltip?: string | ReactNode;
}
export default function InputCheckboxList({
label,
options,
value,
onChange,
error,
required,
className = "",
id,
tooltip = "",
}: InputCheckboxListProps) {
const handleCheckboxChange = (optionName: string, checked: boolean) => {
if (checked) {
onChange([...value, optionName]);
} else {
onChange(value.filter((name) => name !== optionName));
}
};
return (
{label}
{required && (
*
)}
{tooltip !== "" && {tooltip}>} />}
{options.map((option) => {
const checkboxId = `${id || "checkbox-list"}-${option.name}`;
const isChecked = value.includes(option.name);
return (
);
})}
{error &&
{error}}
);
}