BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/shadcn-htmx/copy-button

Copy Button

shadcn-htmx/copy-button
FreeComponent

A native <button> that writes an associated string (snippet, API key, URL) to the clipboard with the Async Clipboard API, then flips to a transient aria-live "Copied" state. Progressive-enhancement fallback for non-secure contexts. Ships in five flavours: Hono JSX (TypeScript), Jinja2 macro, Go html/template, Phoenix function component, and a raw HTML snippet. Follows the WAI-ARIA APG button pattern.

Live preview

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

Install it

npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/copy-button.json

Source

registry/ui/copy-button.tsxshadcn-htmx.productdevbook.com/r/copy-button.json · first 6 KB
1/** @jsxImportSource hono/jsx */
2import { cn, type ClassValue } from "@/registry/lib/cn"
3
4// Copy Button — shadcn-htmx, htmx v4 + Tailwind v4.
5//
6// Click-to-copy button: writes an associated string (a snippet, an API key, a
7// URL) to the system clipboard, then flips to a transient "Copied" state and
8// announces it through a visually-hidden aria-live region. The docs site's own
9// code-block is a consumer.
10//
11// Built on the Async Clipboard API. navigator.clipboard.writeText(text)
12// returns a Promise that resolves once the system clipboard has been updated;
13// it works only in a secure context (HTTPS / localhost) and from a window that
14// has focus:
15// repos/mdn/files/en-us/web/api/clipboard/writetext/index.md
16// The shared behaviour in site.js follows web.dev's progressive-enhancement
17// recipe — use the async API when present, otherwise fall back to a throwaway
18// <textarea> + document.execCommand('copy'):
19// repos/web.dev/src/site/content/en/patterns/clipboard/copy-text/index.md
20//
21// Accessibility:
22// - A native <button> gives us role=button + Space/Enter activation for free
23// (APG button pattern: repos/aria-practices/content/patterns/button/).
24// - The transition is announced through an EMPTY element carrying
25// aria-live="polite": site.js writes "Copied" into it on success. MDN: the
26// aria-live attribute is set on an empty element that is then populated, so
27// AT announces the change without moving focus —
28// repos/mdn/files/en-us/web/accessibility/aria/reference/attributes/aria-live/index.md
29// - This is NOT a toggle: aria-pressed is wrong here (the label/state is
30// transient feedback, not a sticky on/off), so we use aria-live instead.
31//
32// All hx-*, data-* and aria-* attributes are forwarded onto the <button> via
33// {...rest}, so the button can also trigger an htmx request if you want one.
34
35export type CopyButtonVariant = "outline" | "ghost" | "secondary"
36export type CopyButtonSize = "default" | "sm" | "icon"
37
38const base =
39 "inline-flex shrink-0 items-center justify-center gap-1.5 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none " +
40 "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 " +
41 "disabled:pointer-events-none disabled:opacity-50 " +
42 "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5 " +
43 // Transient success state. site.js sets data-copied="true" for a beat, then
44// … truncated

Facts

Registry
shadcn-htmx
Type
registry:ui
Access
Free
Files written
0
Licence
MIT
In the index
at or before 2026-08-13
Last confirmed
yesterday

Go to the source

Docs on shadcn-htmx shadcn-htmx.productdevbook.com productdevbook/shadcn-htmx on GitHub Raw registry item This item as JSON

More from shadcn-htmx

All 83 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Accordionaccordionshadcn-htmxComponentsFreeno deps
Active Searchactive-searchshadcn-htmxComponentsFreeno deps
Alertalertshadcn-htmxComponentsFreeno deps
Alert Dialogalert-dialogshadcn-htmxComponentsFreeno deps
Aspect Ratioaspect-ratioshadcn-htmxComponentsFreeno deps
Auto Gridauto-gridshadcn-htmxComponentsFreeno deps
Autocompleteautocompleteshadcn-htmxComponentsFreeno deps
Autosize Textareaautosize-textareashadcn-htmxComponentsFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

KitGrade

SaaS starter kits, scored from measured facts

kitgrade.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

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

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

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

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

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

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex