import clsx from 'clsx'; import { CheckboxChecked, CheckboxNull } from '@/components/Icons'; import { CProps } from '@/components/props'; import { globals } from '@/utils/constants'; import { CheckboxProps } from './Checkbox'; export interface CheckboxTristateProps extends Omit { /** Current value - `null`, `true` or `false`. */ value: boolean | null; /** Callback to set the `value`. */ onChange?: (newValue: boolean | null) => void; } /** * Component that allows toggling among three states: `true`, `false`, and `null`. */ function CheckboxTristate({ disabled, label, title, titleHtml, hideTitle, className, value, onChange, ...restProps }: CheckboxTristateProps) { const cursor = disabled ? 'cursor-arrow' : onChange ? 'cursor-pointer' : ''; function handleClick(event: CProps.EventMouse): void { event.preventDefault(); event.stopPropagation(); if (disabled || !onChange) { return; } if (value === false) { onChange(null); } else if (value === null) { onChange(true); } else { onChange(false); } } return ( ); } export default CheckboxTristate;