Abraham

Checkbox

Forms 5

About

Here is Checkbox component

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Checkbox to your project and fits it to your theme.

Code

How Checkbox is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import { Checkbox } from "@ark-ui/react/checkbox";
import { CheckIcon, MinusIcon } from "lucide-react";
import { useState } from "react";

const features = [
  { label: "Dark mode", value: "dark-mode" },
  { label: "Notifications", value: "notifications" },
  { label: "Analytics", value: "analytics" },
];

export default function IndeterminateCheckbox() {
  const [selectedFeatures, setSelectedFeatures] = useState<string[]>([
    "dark-mode",
  ]);

  // Calculate parent state based on selected features
  const getParentState = () => {
    if (selectedFeatures.length === 0) return false;
    if (selectedFeatures.length === features.length) return true;
    return "indeterminate";
  };

  const handleParentChange = (checked: boolean) => {
    if (checked) {
      // Select all features
      setSelectedFeatures(features.map((f) => f.value));
    } else {
      // Deselect all features
      setSelectedFeatures([]);
    }
  };

  const parentState = getParentState();

  return (
    <div className="space-y-4">
      <Checkbox.Root
        checked={parentState}
        onCheckedChange={(details) =>
          handleParentChange(details.checked === true)
        }
        className="flex items-center gap-3 cursor-pointer"
      >
        <Checkbox.Control className="w-5 h-5 bg-white border-2 border-gray-300 rounded data-[state=checked]:bg-blue-500 data-[state=checked]:border-blue-500 data-[state=indeterminate]:bg-gray-100 data-[state=indeterminate]:border-gray-400 data-hover:border-gray-400 dark:bg-gray-900 dark:border-gray-600 dark:data-[state=checked]:bg-blue-500 dark:data-[state=checked]:border-blue-500 dark:data-[state=indeterminate]:bg-gray-700 dark:data-[state=indeterminate]:border-gray-500 dark:data-hover:border-gray-400 transition-all duration-200 flex items-center justify-center">
          <Checkbox.Indicator>
            <CheckIcon className="w-3.5 h-3.5 text-white" />
          </Checkbox.Indicator>
          <Checkbox.Indicator indeterminate>
            <MinusIcon className="w-3.5 h-3.5 text-gray-600 dark:text-gray-300" />
          </Checkbox.Indicator>
        </Checkbox.Control>
        <Checkbox.Label className="text-sm font-medium text-gray-900 dark:text-gray-100 cursor-pointer">
          Select all features
        </Checkbox.Label>
        <Checkbox.HiddenInput />
      </Checkbox.Root>

      <div className="ml-6">
        <Checkbox.Group
          value={selectedFeatures}
          onValueChange={(values) => setSelectedFeatures(values)}
          className="space-y-3"
        >
          {features.map((feature) => (
            <Checkbox.Root
              key={feature.value}
              value={feature.value}
              className="flex items-center gap-3 cursor-pointer"
            >
              <Checkbox.Control className="w-5 h-5 bg-white border-2 border-gray-300 rounded data-[state=checked]:bg-blue-500 data-[state=checked]:border-blue-500 data-hover:border-gray-400 dark:bg-gray-900 dark:border-gray-600 dark:data-[state=checked]:bg-blue-500 dark:data-[state=checked]:border-blue-500 dark:data-hover:border-gray-400 transition-all duration-200 flex items-center justify-center">
                <Checkbox.Indicator>
                  <CheckIcon className="w-3.5 h-3.5 text-white" />
                </Checkbox.Indicator>
              </Checkbox.Control>
              <Checkbox.Label className="text-sm text-gray-700 dark:text-gray-200 cursor-pointer">
                {feature.label}
              </Checkbox.Label>
              <Checkbox.HiddenInput />
            </Checkbox.Root>
          ))}
        </Checkbox.Group>
      </div>
    </div>
  );
}

Dependencies

More by Abraham

View all
  • Signature Pad

    Signature Pad

    106
  • Carousel

    Carousel

    81
  • timeline-animation

    timeline-animation

    65
  • Basic Toast

    Basic Toast

    56
  • Calendar

    Calendar

    54
  • QR Code

    QR Code

    51
  •  Menu

    Menu

    50
  • Steps

    Steps

    43

More in Forms

View all
  • Premium Auth

    Premium Auth

    500
  • Login 2

    Login 2

    7
  • Authentication Card

    Authentication Card

    47
  • Login 1

    Login 1

    52
  • Contact Card

    Contact Card

    1K
  • Login Form

    Login Form

    6
  • Form

    Form

    16
  • Book A Demo 3

    Book A Demo 3

    83