Skip to content
Blocks

Kanban Board

Editable tasks, drag and drop, and keyboard-accessible status changes.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/kanban-board.json

Use it

Scroll horizontally for long lines
"use client";
import {KanbanBoard} from '@/components/jez-ui/blocks/kanban-board';

export default function Example(){

return <><KanbanBoard/></>;
}

Props & types

Scroll horizontally for long lines
export type DemoTask = { id: string; title: string; status: string };

{ className?: string }

Source

View 5 source files

registry/blocks/kanban-board.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import {
  GripVertical,
  Plus,
  Circle,
  CircleDashed,
  CircleCheck,
  RotateCcw,
} from "lucide-react";
import { cn } from "../ui/utils";
import { useDemoState } from "./demo-state";
import { Input } from "../ui/input";
import { Button } from "../ui/button";
export type DemoTask = { id: string; title: string; status: string };
export const initialTasks: DemoTask[] = [
  { id: "1", title: "Explore homepage directions", status: "To do" },
  { id: "2", title: "Build the component preview", status: "In progress" },
  { id: "3", title: "Review keyboard navigation", status: "In progress" },
  { id: "4", title: "Write the project brief", status: "Done" },
];
const statuses = ["To do", "In progress", "Done"];
const statusIcons = [CircleDashed, Circle, CircleCheck];
export function KanbanBoard({ className }: { className?: string }) {
  const [tasks, setTasks, reset] = useDemoState("tasks", initialTasks);
  const [title, setTitle] = React.useState("");
  const [dragging, setDragging] = React.useState<string>();
  const [over, setOver] = React.useState<string>();
  const [announcement, setAnnouncement] = React.useState("");
  function move(id: string, status: string) {
    if (!statuses.includes(status) || !tasks.some((t) => t.id === id)) return;
    setTasks((t) => t.map((x) => (x.id === id ? { ...x, status } : x)));
    setAnnouncement(
      `${tasks.find((t) => t.id === id)?.title} moved to ${status}.`,
    );
    setDragging(undefined);
    setOver(undefined);
  }
  return (
    <section className={cn("grid gap-5", className)}>
      <form
        className="flex max-w-xl gap-2"
        onSubmit={(e) => {
          e.preventDefault();
          if (title.trim()) {
            setTasks((t) => [
              ...t,
              { id: crypto.randomUUID(), title: title.trim(), status: "To do" },
            ]);
            setTitle("");
          }
        }}
      >
        <Input
          aria-label="New task title"
          placeholder="What needs doing?"
          required
          value={title}
          onChange={(e) => setTitle(e.target.value)}
        />
        <Button type="submit">
          <Plus size={16} />
          Add task
        </Button>
      </form>
      <div className="grid gap-5 lg:grid-cols-3">
        {statuses.map((status, index) => {
          const Icon = statusIcons[index];
          const column = tasks.filter((t) => t.status === status);
          return (
            <section
              key={status}
              aria-label={status}
              onDragOver={(e) => {
                e.preventDefault();
                e.dataTransfer.dropEffect = "move";
                setOver(status);
              }}
              onDragLeave={(e) => {
                if (!e.currentTarget.contains(e.relatedTarget as Node))
                  setOver(undefined);
              }}
              onDrop={(e) => {
                e.preventDefault();
                move(e.dataTransfer.getData("text/plain"), status);
              }}
              className={cn(
                "min-h-72 rounded-xl border border-transparent bg-muted/35 p-3 transition-colors",
                over === status && "border-primary/40 bg-primary/5",
              )}
            >
              <h3 className="mb-4 flex items-center gap-2 px-1 py-1 text-sm font-medium">
                <Icon
                  size={16}
                  className={cn(
                    index === 1 ? "text-primary" : "text-muted-foreground",
                  )}
                />
                {status}
                <span className="ml-1 text-xs text-muted-foreground">
                  {column.length}
                </span>
              </h3>
              <div className="grid gap-2.5">
                {column.map((t) => (
                  <article
                    key={t.id}
                    className={cn(
                      "group rounded-lg border border-border bg-background p-3.5 shadow-xs transition-opacity",
                      dragging === t.id && "opacity-40",
                    )}
                  >
                    <div className="mb-3 flex items-center justify-between">
                      <span className="font-mono text-xs text-muted-foreground">
                        PRJ-
                        {t.id.length > 6
                          ? t.id.slice(0, 4).toUpperCase()
                          : String(Number(t.id) + 100)}
                      </span>
                      <button
                        type="button"
                        draggable
                        aria-label={`Drag ${t.title}`}
                        title="Drag to another column, or use the status menu below"
                        onDragStart={(e) => {
                          e.dataTransfer.setData("text/plain", t.id);
                          e.dataTransfer.effectAllowed = "move";
                          setDragging(t.id);
                        }}
                        onDragEnd={() => {
                          setDragging(undefined);
                          setOver(undefined);
                        }}
                        className="-m-1 cursor-grab rounded p-1 text-muted-foreground hover:bg-muted active:cursor-grabbing"
                      >
                        <GripVertical size={16} />
                      </button>
                    </div>
                    <input
                      aria-label={`Edit task ${t.title}`}
                      value={t.title}
                      onChange={(e) =>
                        setTasks((v) =>
                          v.map((x) =>
                            x.id === t.id ? { ...x, title: e.target.value } : x,
                          ),
                        )
                      }
                      className="mb-4 w-full min-w-0 rounded bg-transparent py-1 text-sm font-medium outline-none focus:ring-2 focus:ring-primary/30"
                    />
                    <div className="flex items-center justify-between gap-2 border-t border-border/50 pt-3">
                      <select
                        aria-label={`Status for ${t.title}`}
                        value={t.status}
                        onChange={(e) => move(t.id, e.target.value)}
                        className="max-w-full cursor-pointer rounded-md border-0 bg-muted/70 px-2 py-1 text-xs text-muted-foreground"
                      >
                        {statuses.map((s) => (
                          <option key={s}>{s}</option>
                        ))}
                      </select>
                      <span
                        className="grid size-6 place-items-center rounded-full border border-border bg-muted text-xs"
                        title="Alex Morgan"
                      >
                        AM
                      </span>
                    </div>
                  </article>
                ))}
                {!column.length && (
                  <div
                    className={cn(
                      "grid min-h-40 place-items-center rounded-lg border border-dashed border-border text-sm text-muted-foreground",
                      dragging && "border-primary/40",
                    )}
                  >
                    Drop a task here
                  </div>
                )}
              </div>
            </section>
          );
        })}
      </div>
      <div className="flex flex-wrap items-center justify-between gap-3">
        <p className="text-xs text-muted-foreground">
          Drag using the grip, or change a task’s status from its menu.
        </p>
        <Button size="sm" variant="ghost" onClick={reset}>
          <RotateCcw size={13} />
          Reset demo
        </Button>
      </div>
      <p role="status" className="sr-only">
        {announcement}
      </p>
    </section>
  );
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

registry/blocks/demo-state.ts

Scroll horizontally for long lines
"use client";
import { useState, useEffect, useCallback } from "react";
export function useDemoState<T>(key: string, initial: T) {
  const [state, setState] = useState(initial);
  const [loaded, setLoaded] = useState(false);
  useEffect(() => {
    try {
      const raw = localStorage.getItem("jez-demo:" + key);
      if (raw) setState(JSON.parse(raw));
    } catch {}
    setLoaded(true);
  }, [key]);
  useEffect(() => {
    if (loaded)
      try {
        localStorage.setItem("jez-demo:" + key, JSON.stringify(state));
      } catch {}
  }, [key, state, loaded]);
  const reset = useCallback(() => setState(initial), [initial]);
  return [state, setState, reset] as const;
}

registry/ui/input.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function Input({ className, ...props }: React.ComponentProps<"input">) {
  return (
    <input
      className={cn(
        "block h-10 w-full min-w-0 rounded-lg border border-border bg-background px-3 text-sm leading-normal shadow-[0_1px_2px_#00000004] transition-[border-color,box-shadow] placeholder:text-muted-foreground/75 hover:border-foreground/25 focus:border-primary focus:outline-none focus:ring-3 focus:ring-primary/10 aria-invalid:border-danger aria-invalid:ring-danger/10 disabled:cursor-not-allowed disabled:bg-muted/50 disabled:opacity-50",
        className,
      )}
      {...props}
    />
  );
}

registry/ui/button.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Slot } from "radix-ui";
import { LoaderCircle } from "lucide-react";
import { cn } from "./utils";
export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
  variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
  size?: "sm" | "md" | "lg";
  loading?: boolean;
  asChild?: boolean;
};
export function Button({
  variant = "primary",
  size = "md",
  loading,
  asChild,
  className,
  children,
  disabled,
  ...props
}: ButtonProps) {
  const Comp = asChild ? Slot.Root : "button";
  return (
    <Comp
      type={asChild ? undefined : "button"}
      disabled={asChild ? undefined : disabled || loading}
      aria-disabled={disabled || loading || undefined}
      aria-busy={loading || undefined}
      className={cn(
        "relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent text-sm font-medium leading-none transition-[background-color,border-color,box-shadow,transform] duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:scale-[.98] disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none [&_svg]:shrink-0",
        {
          "bg-primary text-primary-foreground shadow-[inset_0_1px_0_#ffffff26,0_1px_2px_#00000012] hover:bg-primary/90":
            variant === "primary",
          "border-border/60 bg-muted text-foreground hover:bg-muted/70":
            variant === "secondary",
          "border-border bg-background text-foreground shadow-sm hover:bg-muted/60":
            variant === "outline",
          "text-muted-foreground hover:bg-muted hover:text-foreground":
            variant === "ghost",
          "bg-danger text-danger-foreground hover:bg-danger/90":
            variant === "danger",
        },
        {
          "h-8 px-3 text-xs": size === "sm",
          "h-10 px-4": size === "md",
          "h-12 px-6": size === "lg",
        },
        className,
      )}
      {...props}
    >
      {asChild ? (
        children
      ) : (
        <>
          <span
            className={cn(
              "inline-flex min-w-0 flex-1 items-center justify-center gap-2",
              loading && "invisible",
            )}
          >
            {children}
          </span>
          {loading && (
            <LoaderCircle
              aria-hidden="true"
              className="absolute size-4 animate-spin motion-reduce:animate-none"
            />
          )}
        </>
      )}
    </Comp>
  );
}

Dependencies

lucide-react@0.577.0 · clsx@2.1.1 · tailwind-merge@3.5.0 · radix-ui@1.6.7

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →