'use client'; import React, { forwardRef, useState } from 'react'; export interface CheckboxProps extends React.InputHTMLAttributes { label?: string; className?: string; } export const Checkbox = forwardRef( ({ label, className = '', onChange, ...props }, ref) => { // Keep track of focus state for styling const [isFocused, setIsFocused] = useState(false); // Handle click on the custom checkbox const handleClick = () => { if (props.disabled) return; // Create a synthetic event to pass to the onChange handler const syntheticEvent = { target: { name: props.name, checked: !props.checked, type: 'checkbox' } } as React.ChangeEvent; // Call the onChange handler with the synthetic event if (onChange) { onChange(syntheticEvent); } }; return (
setIsFocused(true)} onBlur={() => setIsFocused(false)} onChange={onChange} {...props} />
{props.checked && ( )}
{label && ( )}
); } ); Checkbox.displayName = 'Checkbox';