アニメコピー
1 行のテキストとコピーボタン。
使いどころ
- ゲームやキャンペーンページの招待コード、紹介リンク、ギフトコード
- 一度だけコピーするインストールコマンドや API キー
注意点
- 長いテキストは省略記号で切り、全文は title に入ります。コピーされるのは常に全文です
- クリップボードには安全なページ(https か localhost)が必要で、それ以外ではテキストを選択します
- 視差効果を減らす設定ではエフェクトを描かず、ラベルは変わります
エージェントに追加してもらう
インストールコマンド、使いどころ、props、デザインルールを一度にコピーできます。Claude Code、Cursor、Codex に貼り付けてください。
CLI でインストール
shadcn CLI を使います。ソースはプロジェクトにコピーされるので、すべての行があなたのものです。
$ npx shadcn@latest add https://sunui.synvize.com/r/anime-copy.json手動でインストール
- 1. 依存パッケージをインストールします。
$ npm install clsx tailwind-merge - 2.
cnヘルパーがなければlib/utils.tsに追加します。shadcn/ui を使っていない場合は、色のトークン用に sunui-theme.css も追加します(手順)。そのあとコンポーネントをコピーします。anime-copy.tsx"use client"; import { useEffect, useRef, useState } from "react"; import { at, later, onFrame, paletteOf, sfx, slash, Spring, ticks, type SfxLang } from "@/components/ui/anime-fx"; import { cn } from "@/lib/utils"; export type AnimeCopyProps = { /** What is shown and copied */ text: string; /** The button's label */ label?: string; /** The button's label after copying */ copiedLabel?: string; /** The button's label when the clipboard refused and the text was selected instead */ selectedLabel?: string; /** Called after the text is on the clipboard */ onCopy?: (text: string) => void; /** Back to ready this many milliseconds after copying */ resetAfter?: number; /** Lettering language; defaults to <html lang> */ lang?: SfxLang; /** Show the sound-effect word on the cut */ lettering?: boolean; className?: string; }; const SHELL = "border-[3px] border-foreground bg-card text-foreground shadow-[4px_5px_0_color-mix(in_oklch,var(--sunui-spot,var(--primary))_38%,var(--card))]"; async function write(text: string) { try { await navigator.clipboard.writeText(text); return true; } catch { return false; } } /** * A line of text with a copy button: an install command, an invite code, a referral link. Hover or focus the button and two * wedges point at it; click and one stroke cleaves across the whole bar, the bar recoils, the button inverts for a frame and a * click word lands; the button settles on a check. If the clipboard refuses, the text is selected so the person can copy it. */ export function AnimeCopy({ text, label = "Copy", copiedLabel = "Copied", selectedLabel = "Selected", onCopy, resetAfter = 1800, lang, lettering = true, className }: AnimeCopyProps) { const bar = useRef<HTMLDivElement>(null); const code = useRef<HTMLElement>(null); const btn = useRef<HTMLButtonElement>(null); const [state, setState] = useState<"ready" | "copied" | "selected">("ready"); const [inverted, setInverted] = useState(false); const st = useRef({ x: new Spring(0, 700, 16), off: null as null | (() => void), seq: 0, aimed: false }); useEffect(() => { const s = st.current; return () => { s.off?.(); s.off = null; }; }, []); // Anticipation: two wedges point at the button, once per hover or focus const aim = () => { const el = btn.current; const s = st.current; if (!el || s.aimed || state !== "ready") return; s.aimed = true; const P = paletteOf(el); const c = at(el, 0.5, 1); ticks(P, c.x, c.y + 18, { dir: -Math.PI / 2, n: 2, r: 4, len: 12, fan: 0.9, life: 0.38 }); }; // Recoil: the bar is knocked along the cut and springs back const recoil = () => { const s = st.current; s.x.v = -260; if (s.off) return; s.off = onFrame((dt) => { const x = s.x.step(dt); if (bar.current) bar.current.style.transform = s.x.still ? "" : `translate(${x.toFixed(2)}px, ${(x * 0.35).toFixed(2)}px)`; if (s.x.still) { s.off?.(); s.off = null; } }); }; const copy = async () => { const el = bar.current; const b = btn.current; const s = st.current; if (!el || !b) return; const ok = await write(text); const n = ++s.seq; if (!ok) { // The clipboard refused (an insecure page, a denied permission): select the text instead const range = document.createRange(); if (code.current) range.selectNodeContents(code.current); const sel = window.getSelection(); sel?.removeAllRanges(); sel?.addRange(range); setState("selected"); } else { setState("copied"); onCopy?.(text); const P = paletteOf(el); const r = el.getBoundingClientRect(); // The cleave: a stroke across the whole bar, rising left to right, a little past both ends slash(P, r.left + scrollX - 48, r.top + scrollY + r.height * 1.05, r.right + scrollX + 48, r.top + scrollY - r.height * 0.05, { width: 12, life: 0.36 }); recoil(); setInverted(true); later(180, () => n === s.seq && setInverted(false)); const c = at(b, 0.5, 0); if (lettering) sfx(P, "click", c.x - 4, c.y - 28, { size: 44, lang, rot: -0.1, life: 0.75 }); ticks(P, c.x + 26, c.y - 4, { dir: -0.7, n: 2, r: 4, len: 13 }); } window.setTimeout(() => { if (n !== s.seq) return; setState("ready"); s.aimed = false; }, resetAfter); }; const shown = state === "copied" ? copiedLabel : state === "selected" ? selectedLabel : label; return ( <div ref={bar} className={cn("flex w-full max-w-md items-center gap-3 rounded-[14px] py-2 pr-2 pl-4 will-change-transform", SHELL, className)}> <code ref={code} className="min-w-0 flex-1 truncate font-mono text-[14px] font-semibold" title={text}> {text} </code> <button ref={btn} type="button" onClick={copy} onPointerEnter={aim} onFocus={aim} onPointerLeave={() => state === "ready" && (st.current.aimed = false)} className={cn( "inline-flex shrink-0 items-center gap-1.5 rounded-[10px] border-[2.5px] border-foreground bg-card px-3.5 py-1.5 text-[14px] leading-none font-extrabold italic select-none touch-manipulation", "outline-none focus-visible:ring-[3px] focus-visible:ring-[var(--sunui-spot,var(--primary))] focus-visible:ring-offset-2 focus-visible:ring-offset-background", state === "copied" && "border-[var(--sunui-spot,var(--primary))]", inverted && "bg-foreground text-background", )} > <svg viewBox="0 0 24 18" aria-hidden className="h-[13px] overflow-visible transition-[width] duration-200" style={{ width: state === "copied" ? 16 : 0 }}> <path d="M3 9.5l6 6L21 2.5" fill="none" stroke="var(--sunui-success, currentColor)" strokeWidth={4} strokeLinecap="round" strokeLinejoin="round" pathLength={1} strokeDasharray={1} strokeDashoffset={state === "copied" ? 0 : 1} style={{ transition: "stroke-dashoffset 240ms cubic-bezier(.2,.8,.2,1)" }} /> </svg> {shown} </button> <span role="status" aria-live="polite" className="sr-only"> {state === "ready" ? "" : shown} </span> </div> ); }
似ているブロック
- Pro
- Pro



