"use client"; import React, { useCallback } from "react"; import { CheckboxProps } from "./types"; import { Button } from "@shared/components/button"; import { cx } from "@shared/utils"; export const Checkbox: React.FC = ({ state, checked = false, onChange, className, label, labelClassName, containerClassName, name, value, id, disabled = false, required = false, error = false, "data-cy": dataCy, renderInfoIcon, ...rest }) => { const isDisabled = disabled || state === "disabled"; const isFocused = state === "focus"; const inputId = id || name; const checkboxClasses = cx( "flex items-center justify-center w-6 h-6 rounded-[4px] outline-offset-2", isFocused && "outline", className ); const handleInputChange = useCallback( (e: React.ChangeEvent) => { if (!isDisabled) { if (onChange) { // Check if onChange expects a boolean parameter (new signature) if (onChange.length === 1) { (onChange as (isChecked: boolean) => void)(e.target.checked); } else { // Old signature - just call without parameters (onChange as () => void)(); } } } }, [isDisabled, onChange] ); const renderIcon = () => { if (checked) { return ( ); } return ( ); }; const checkboxElement = (
{label && ( )} {renderInfoIcon && ( )}
); return checkboxElement; }; Checkbox.displayName = "Checkbox"; export type { CheckboxProps };