35 lines
903 B
TypeScript
35 lines
903 B
TypeScript
import { Check, Minus } from 'lucide-react'
|
|
import { cx } from './cx'
|
|
|
|
export function Checkbox({
|
|
checked,
|
|
indeterminate = false,
|
|
onChange,
|
|
label,
|
|
}: {
|
|
checked: boolean
|
|
indeterminate?: boolean
|
|
onChange: (next: boolean) => void
|
|
label: string
|
|
}) {
|
|
const on = checked || indeterminate
|
|
return (
|
|
<button
|
|
type="button"
|
|
role="checkbox"
|
|
aria-checked={indeterminate ? 'mixed' : checked}
|
|
aria-label={label}
|
|
onClick={e => {
|
|
e.stopPropagation()
|
|
onChange(!checked)
|
|
}}
|
|
className={cx(
|
|
'inline-grid place-items-center w-4 h-4 rounded-[5px] cursor-pointer',
|
|
on ? 'bg-accent text-white' : 'bg-surface shadow-[inset_0_0_0_1.5px_var(--color-faint)]',
|
|
)}
|
|
>
|
|
{indeterminate ? <Minus size={12} strokeWidth={3} aria-hidden /> : checked ? <Check size={12} strokeWidth={3} aria-hidden /> : null}
|
|
</button>
|
|
)
|
|
}
|