39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import * as React from "react"
|
|
import { Check } from "lucide-react"
|
|
import { cn } from "@/lib/utils"
|
|
|
|
interface CheckboxProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
checked?: boolean
|
|
onCheckedChange?: (checked: boolean) => void
|
|
}
|
|
|
|
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
({ className, checked, onCheckedChange, ...props }, ref) => {
|
|
return (
|
|
<div className="relative flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
ref={ref}
|
|
checked={checked}
|
|
onChange={(e) => onCheckedChange?.(e.target.checked)}
|
|
className={cn(
|
|
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
"appearance-none checked:bg-primary checked:border-primary",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
<Check
|
|
className={cn(
|
|
"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 h-3 w-3 text-primary-foreground pointer-events-none",
|
|
checked ? "opacity-100" : "opacity-0"
|
|
)}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
Checkbox.displayName = "Checkbox"
|
|
|
|
export { Checkbox }
|