Anime Copy
A line of text with a copy button for install commands, invite codes and referral links.
When to use it
- Invite codes, referral links and gift codes on game or campaign pages
- Install commands or API keys that people copy once
Watch out
- Long text is truncated with an ellipsis and shown in full in the title; the full text is what gets copied
- The clipboard needs a secure page (https or localhost); elsewhere it falls back to selecting the text
- With reduced motion no effect is drawn and the label still changes
Let your agent add it
One copy holds the install command, when to use it, the props and the design rules. Paste it into Claude Code, Cursor or Codex.
Install with the CLI
Uses the shadcn CLI. The source is copied into your project, so you own every line.
$ npx shadcn@latest add https://sunui.synvize.com/r/anime-copy.jsonOr install manually
- 1. Install the dependencies.
$ npm install clsx tailwind-merge - 2. Add a
cnhelper atlib/utils.tsif you do not have one. Not using shadcn/ui? Also add sunui-theme.css for the colour tokens (how). Then copy the component.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> ); }
Similar blocks
- Pro
- Pro



