SunUI
創始會員NT$2,490 終身更新,1月11日截止取得席位
免費動漫作畫點按

動漫勾選框

真的勾選框(表單與空白鍵都能用),勾選時像動畫的一個鏡頭:方框彈起、水晶碎片飛出、勾自己描出來、一縷煙滾開,網點擬聲字落在標籤後面。

適合使用的時機

  • 遊戲或動漫頁面的同意事項、設定與清單
  • 希望讓人感覺像下定決心的單一勾選

注意事項

  • 很多個勾選框快速勾選時擬聲字會疊在一起,清單短才用,或把 lettering 關掉
  • 開啟減少動態時一個特效都不畫,狀態照常改變,不看特效也能使用

交給你的 agent 安裝

一次複製就包含安裝指令、使用時機、props 與設計規則。貼進 Claude Code、Cursor 或 Codex 即可。

用 CLI 安裝

使用 shadcn CLI。原始碼會複製到你的專案裡,每一行都由你掌握。

$ npx shadcn@latest add https://sunui.synvize.com/r/anime-checkbox.json

或手動安裝

  1. 1. 安裝相依套件。
    $ npm install clsx tailwind-merge
  2. 2. 如果還沒有,在 lib/utils.ts 加上 cn 輔助函式。沒有用 shadcn/ui?再加上 sunui-theme.css 提供顏色變數(做法)。然後複製元件程式碼。
    anime-checkbox.tsx
    "use client";
    
    import { useRef, useState, type InputHTMLAttributes, type ReactNode } from "react";
    
    import { at, paletteOf, puff, sfx, shards, ticks, useSquash, wob, type SfxLang } from "@/components/ui/anime-fx";
    import { cn } from "@/lib/utils";
    
    export type AnimeCheckboxProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "children" | "onChange"> & {
      /** The label */
      children: ReactNode;
      checked?: boolean;
      defaultChecked?: boolean;
      onCheckedChange?: (checked: boolean) => void;
      /** Lettering language; defaults to <html lang> (Chinese pages get Chinese, others Japanese) */
      lang?: SfxLang;
      /** Show the sound-effect word when it is ticked */
      lettering?: boolean;
    };
    
    const SHELL = "border-[3px] border-foreground bg-card shadow-[3px_4px_0_color-mix(in_oklch,var(--sunui-spot,var(--primary))_38%,var(--card))]";
    
    /**
     * A real checkbox (it works in forms and with Space) that ticks like an anime cut: the box pops, crystal chips fly,
     * the tick draws itself, a wisp of smoke rolls off and a screentone word lands beside the label. Unticking only wobbles.
     */
    export function AnimeCheckbox({ children, checked, defaultChecked = false, onCheckedChange, lang, lettering = true, className, disabled, ...rest }: AnimeCheckboxProps) {
      const box = useRef<HTMLSpanElement>(null);
      const label = useRef<HTMLLabelElement>(null);
      const [own, setOwn] = useState(defaultChecked);
      const on = checked ?? own;
      const sq = useSquash(box, { low: 0.7, wide: 0.3 });
    
      const change = (next: boolean) => {
        if (checked === undefined) setOwn(next);
        onCheckedChange?.(next);
        const el = box.current;
        if (!el) return;
        const P = paletteOf(el);
        const c = at(el);
        if (!next) {
          wob(P, c.x + c.w / 2 + 4, c.y, { dir: 1, r: 8, life: 0.3 });
          return;
        }
        sq.pop.x = 1.25;
        sq.kick();
        shards(P, c.x, c.y - c.h / 2, { n: 7, speed: 170, size: 6, life: 0.7 });
        ticks(P, c.x + c.w / 2, c.y - c.h / 2, { dir: -0.8, n: 3, r: 6, len: 12 });
        puff(P, c.x - c.w / 2 - 2, c.y + c.h / 2, { size: 8, vx: -24, vy: -6, life: 0.6 });
        // The word lands past the end of the label, never on it
        const end = at(label.current ?? el, 1, 0);
        if (lettering) sfx(P, "skid", end.x + 52, end.y - 14, { size: 50, lang, rot: -0.08, life: 0.9 });
      };
    
      return (
        <label ref={label} className={cn("inline-flex cursor-pointer items-center gap-3 select-none has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-45", className)}>
          <input type="checkbox" className="peer sr-only" checked={on} disabled={disabled} onChange={(e) => change(e.target.checked)} {...rest} />
          <span
            ref={box}
            aria-hidden
            className={cn(
              "grid size-7 shrink-0 place-items-center rounded-[8px] will-change-transform",
              "peer-focus-visible:ring-[3px] peer-focus-visible:ring-[var(--sunui-spot,var(--primary))] peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-background",
              SHELL,
            )}
          >
            <svg viewBox="0 0 24 24" className="size-5 overflow-visible">
              <path
                d="M4 12.5l5.5 5.5L20 6"
                fill="none"
                stroke="currentColor"
                strokeWidth={3.6}
                strokeLinecap="round"
                strokeLinejoin="round"
                pathLength={1}
                strokeDasharray={1}
                strokeDashoffset={on ? 0 : 1}
                style={{ transition: "stroke-dashoffset 240ms cubic-bezier(.2,.8,.2,1)" }}
              />
            </svg>
          </span>
          <span className="text-[15px] font-bold">{children}</span>
        </label>
      );
    }