kanso/ui
Form

Checkbox

A control that toggles between checked, unchecked and indeterminate.

LiveRev. 01

You agree to our terms of service.

Installation

CLI

$ npx shadcn@latest add https://konsa.rohitxyz.me/r/checkbox.json

Manual

Install the dependencies

npm install radix-ui lucide-react

Copy the source into your project

components/ui/checkbox.tsx
"use client";

import * as React from "react";
import { Checkbox as CheckboxPrimitive } from "radix-ui";
import { CheckIcon, MinusIcon } from "lucide-react";

import { cn } from "@/lib/utils";

function Checkbox({
  className,
  ...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
  return (
    <CheckboxPrimitive.Root
      data-slot="checkbox"
      className={cn(
        "peer group size-4 shrink-0 rounded-[4px] border border-input bg-background shadow-xs transition-colors outline-none",
        "focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
        "data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
        "data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground",
        "aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50",
        className,
      )}
      {...props}
    >
      <CheckboxPrimitive.Indicator className="flex items-center justify-center text-current">
        <CheckIcon
          className="size-3 group-data-[state=indeterminate]:hidden"
          strokeWidth={3}
        />
        <MinusIcon
          className="hidden size-3 group-data-[state=indeterminate]:block"
          strokeWidth={3}
        />
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  );
}

export { Checkbox };

Update the import paths to match your project

The file imports cn from @/lib/utils. See installation.

Usage

import { Checkbox } from "@/components/ui/checkbox";
<Checkbox id="terms" />
<Label htmlFor="terms">Accept terms</Label>
Checkbox