BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ericts-ui/copy-button

Copy Button

ericts-ui/copy-button
FreeComponent

A shadcn Button-based clipboard control with animated copy and success states.

Live preview

live · rendered by the registry
Rendered by ericts-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://ui.ericts.com/r/copy-button.json

Source

registry/base/ui/copy-button.tsxui.ericts.com/r/copy-button.json
1"use client";
2
3import * as React from "react";
4import { AnimatePresence, motion, useReducedMotion } from "motion/react";
5import { Check, Copy } from "lucide-react";
6
7import { Button } from "@/components/ui/button";
8
9const variants = {
10 hidden: { opacity: 0, scale: 0.5 },
11 visible: { opacity: 1, scale: 1 },
12};
13
14type ButtonProps = React.ComponentPropsWithoutRef<typeof Button>;
15type ButtonClickEvent = Parameters<NonNullable<ButtonProps["onClick"]>>[0];
16
17export type CopyButtonProps = Omit<
18 ButtonProps,
19 "children" | "value" | "onCopy"
20> & {
21 /** Text written to the clipboard when the button is pressed. */
22 value: string;
23 /** How long, in ms, the copied state is shown before reverting. */
24 timeout?: number;
25 /** Called with the copied value after a successful write. */
26 onCopy?: (value: string) => void;
27};
28
29export function CopyButton({
30 value,
31 timeout = 1000,
32 onCopy,
33 onClick,
34 className,
35 variant = "outline",
36 size = "icon",
37 type = "button",
38 "aria-label": ariaLabel = "Copy to clipboard",
39 ...props
40}: CopyButtonProps) {
41 const [copied, setCopied] = React.useState(false);
42 const shouldReduceMotion = useReducedMotion();
43 const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
44
45 React.useEffect(() => {
46 return () => {
47 if (timer.current) clearTimeout(timer.current);
48 };
49 }, []);
50
51 const handleCopy = React.useCallback(
52 async (event: ButtonClickEvent) => {
53 onClick?.(event);
54
55 if (event.defaultPrevented) return;
56
57 try {
58 await navigator.clipboard.writeText(value);
59 } catch {
60 // Clipboard access can be denied (insecure context, no permission) —
61 // bail out without flipping into the copied state.
62 return;
63 }
64
65 onCopy?.(value);
66 setCopied(true);
67
68 if (timer.current) clearTimeout(timer.current);
69 timer.current = setTimeout(() => setCopied(false), timeout);
70 },
71 [onClick, onCopy, timeout, value],
72 );
73
74 // An icon swap is a tiny state change, so keep it snappy: ease-out, well
75 // under 150ms. Motion is removed entirely under prefers-reduced-motion.
76 const transition = shouldReduceMotion
77 ? { duration: 0 }
78 : ({ duration: 0.13, ease: [0.215, 0.61, 0.355, 1] } as const);
79
80 return (
81 <Button
82 type={type}
83 variant={variant}
84 size={size}
85 aria-label={ariaLabel}
86 data-copied={copied}
87 onClick={handleCopy}
88 className={className}
89 {...props}
90 >
91// … truncated

What it pulls in

npm packages

  • motion
  • lucide-react

Other registry items

  • button

Files it writes

  • registry/base/ui/copy-button.tsx

Facts

Registry
ericts-ui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-09
Last confirmed
today

Go to the source

Docs on ericts-ui ui.ericts.com EricTsai83/ericts-ui on GitHub Raw registry item This item as JSON

More from ericts-ui

All 33 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Adaptive Draweradaptive-drawerericts-uiComponentsFree2 deps
Check Animationcheck-animationericts-uiComponentsFreeno deps · 2 files
Context Cursorcontext-cursorericts-uiComponentsFree1 dep
Expandable Dialogexpandable-modalericts-uiComponentsFree1 dep
Expandable Tabsexpandable-tabsericts-uiComponentsFree1 dep
Expandable Toolbarexpandable-toolbarericts-uiComponentsFree1 dep
Expanding Panelexpanding-panelericts-uiComponentsFree2 deps
Expanding Segmented Tabsexpanding-segmented-tabsericts-uiComponentsFree1 dep
BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex