'use client'; import { Icon } from '../../icons'; import { type FC, type KeyboardEventHandler, type ReactNode, useCallback, useEffect, useId, useRef } from 'react'; import styles from './Checkbox.module.css'; import type { RefProp } from '../../lib/react'; export interface CheckboxProps extends RefProp { checked?: boolean, defaultChecked?: boolean, formValue?: string, indeterminate?: boolean, onChange?: (checked: boolean) => void, name?: string, children: ReactNode, disabled?: boolean, } export const Checkbox: FC = ({ ref, checked, defaultChecked, formValue, indeterminate = false, onChange, name, disabled, children }) => { const inputRef = useRef(null); const id = useId(); useEffect(() => { if(inputRef.current) { inputRef.current.indeterminate = indeterminate; } }, [indeterminate]); const labelOnKeyDown: KeyboardEventHandler = useCallback((e) => { if(e.key === 'Enter' || e.key === ' ') { inputRef.current?.click(); e.preventDefault(); } }, []); return ( ); };