Updated
Chain Copy
Customize
Icon and label
Soft
Medium
Success colour
Reset after1.6s
Radius12px
Installation
npx shadcn@latest add https://uibrik.com/r/chain-copy.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/chain-copy/chain-copy.tsx"use client"; import { AnimatePresence, motion, useReducedMotion } 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; const VARIANTS = { soft: "bg-muted hover:bg-neutral-200/70 dark:hover:bg-neutral-800", ghost: "bg-transparent hover:bg-muted", solid: "bg-foreground text-background hover:bg-foreground/90", } as const; // How long the chain hangs apart before it links back up. const BREAK_MS = 260;
Adds the files to
components/uibrik/chain-copy and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/chain-copy.Usage
import { ChainCopy } from "@/components/uibrik/chain-copy/chain-copy";<ChainCopy label="Copy link" copiedLabel="Copied" text="https://example.com/invite/8f3k2" display="label" variant="soft" size="md" successColor="#16a34a" resetAfter={1.6} radius={12} onCopy={(text) => {}}/>Where to use Chain Copy
Share links
The chain breaking and relinking says a link was taken, not just any text.
Pairs with Share Menu and Popover
Invite links
Team invites and referral links get a copy action people notice.
Pairs with Invite Members
Docs anchors
Heading permalinks copy with a small, satisfying beat.
Props
ChainCopy- label
- Type string
- "Copy link"
- Button text.
- copiedLabel
- Type string
- "Copied"
- text
- Type string
- "https://example.com/invite/8f3k2"
- Text written to the clipboard. Leave out to copy the page URL.
- display
- Type "label" | "icon"
- "label"
- Show the label, or the icon alone.
- variant
- Type "soft" | "ghost" | "solid"
- "soft"
- Button look.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- successColor
- Type string
- "#16a34a"
- Colour of the relinked chain and label.
- resetAfter
- Type number
- 1.6
- How long Copied stays.
- radius
- Type number
- 12
- Corner radius.
- onCopy
- Type (text: string) => void
- –
- Called after a successful copy.
- className
- Type string
- –
- Classes for the button.