import "./index.scss"; import clsx from "clsx"; import { forwardRef, type HTMLAttributes, useEffect, useId, useRef } from "react"; function Mark(props: HTMLAttributes) { return ( ); } export type CheckboxProps = React.RefAttributes & Omit, "value"> & { className?: string; id?: string; /** * Label for the checkbox. */ label?: React.ReactNode; /** * Tooltip text for the checkbox. */ title?: string; value?: boolean; /** * Reverses the checkbox layout, placing the label before the checkbox. */ reverse?: boolean; }; export const Checkbox = forwardRef(function Checkbox( { className, disabled = false, id, onChange = () => null, label, title, reverse, value, ...other }: CheckboxProps, ref: React.ForwardedRef, ) { let inputId = useId(); inputId = id ?? inputId; let inputIdRef = `#${inputId}`; let input = useRef(null); // oxlint-disable-next-line react-hooks/exhaustive-deps -- Ref object useEffect(() => { if (typeof ref === "function") { ref(input.current); } else if (ref) { ref.current = input.current; } }, []); function handleClick() { let elem = input.current; if (elem) { elem.focus(); elem.click(); } } function handleInputChanged(evt: any) { if (!disabled) { onChange(evt); } } function handleKeyDown(evt: any) { if (evt.nativeEvent) { let { nativeEvent } = evt; if (nativeEvent.key === " ") { nativeEvent.preventDefault(); input.current?.click(); } } } return (
); });