Updated
Copy Button
Customize
Icon + label
Soft
Medium
Reset after1.5s
Radius12px
Installation
npx shadcn@latest add https://uibrik.com/r/copy-button.jsonInstall the packages
npm install motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/copy-button/copy-button.tsx"use client"; import { AnimatePresence, motion } from "motion/react"; import { useEffect, useRef, useState } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, padX: 10, font: 13, icon: 16 }, md: { height: 40, padX: 13, font: 14, icon: 18 }, lg: { height: 48, padX: 16, font: 15, icon: 20 }, } as const; // Neutral looks shared by the library's quiet buttons. const VARIANTS = { soft: "bg-muted hover:bg-neutral-200/70 dark:hover:bg-neutral-800", ghost: "bg-transparent hover:bg-muted", outline: "bg-background shadow-[inset_0_0_0_1px_var(--border)] hover:bg-muted", } as const; export type CopyButtonProps = { /** Text written to the clipboard. */
Adds the files to
components/uibrik/copy-button and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/copy-button.Usage
import { CopyButton } from "@/components/uibrik/copy-button/copy-button";<CopyButton text="npm install motion" label="Copy" copiedLabel="Copied" display="label" variant="soft" size="md" tintSuccess={false} resetAfter={1.5} radius={12} onCopy={(text) => {}}/>Where to use Copy Button
Code snippets
Sheets sliding into a check confirm the copy without a toast covering the code.
Pairs with Code Block
API keys and invite links
A label that rolls to Copied gives a clear success state for one-off secrets and links.
Pairs with Settings Page
Coupon and referral codes
A clear confirmation helps shoppers trust the code is on their clipboard before checkout.
Props
CopyButton- text
- Type string
- "npm install motion"
- Text written to the clipboard.
- label
- Type string
- "Copy"
- Button text.
- copiedLabel
- Type string
- "Copied"
- Shown once the text is copied.
- display
- Type "label" | "icon"
- "label"
- Icon and label, or the icon alone (the label stays as its accessible name).
- variant
- Type "soft" | "ghost" | "outline"
- "soft"
- Filled, transparent until hovered, or outlined.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- tintSuccess
- Type boolean
- false
- Colour the copied state instead of keeping it neutral.
- successColor
- Type string
- "#16a34a"
- Colour of the copied state when tinted.
- resetAfter
- Type number
- 1.5
- How long Copied shows before reverting.
- radius
- Type number
- 12
- Corner radius.
- onCopy
- Type (text: string) => void
- –
- Called after a successful copy.
- className
- Type string
- –
- Classes for the button.