Krizaka UI
Krizaka UI
Composants

Copy button

A button that copies a value, says “Copied” in a live region, and falls back to a selected field when the clipboard is unavailable.

Web · ✓Mobile · ✗ à construireBureau · ✓BêtaActions
import { CopyButton } from "@krizaka/ui/copy-button";

Web uniquement — React, depuis @krizaka/ui/copy-button. Bêta : son API peut encore changer à une version mineure.

  • Mobile · ✗ à construire. The native twins of PromoCodeField, MoneyInput and CopyButton are a follow-up of the coupons surfaces. issue #782

Pourquoi il est là. The coupons (@krizaka/coupons): the owner-link block of Yomizaka and the founder offer code of Akinaza — copy in one click, with a read-only field as the fallback (krizaka-ui#576, #783).

Quand l’utiliser

  • To copy a link, a code or an identifier: an owner link, a coupon, an API key.
  • Beside a value the person must paste elsewhere.

Quand ne pas l’utiliser

  • To copy a block of code with its file name and language.À la place : Code block
  • For an action that is not a copy.À la place : Button

Installation

Installer

npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Importer

import { CopyButton } from "@krizaka/ui/copy-button";

Exemples

With words

The label, then “Copied” for 1.8 s.

Icon only

A ghost button beside a code.

Props

A button that copies value. State: data-copied.

PropTypeDéfautDescription
copiedLabelrequisstring—What it says once copied, announced politely: "Copied".
fallbackLabelrequisstring—Said when the clipboard is unavailable, above the selected value: "Press Ctrl+C to copy".
labelrequisstring—The words of the button (and its accessible name), passed translated: "Copy link". Icon only: set iconOnly.
valuerequisstring—The text to copy.
announcestring—A message announced politely by assistive technology when it changes (“Saved”, “Upload failed”) — passed translated.
copiedIconReactNode—Replaces the check icon shown once copied.
iconReactNode—Replaces the copy icon (a @krizaka/icons one, say).
iconOnlyboolean—Shows only the icon (the label stays the accessible name).
indicatorbooleantrueShows the glyph while loading / with a status. false: you draw your own.
loadingboolean—Disables and signals the wait (aria-busy, data-loading) and shows the Krizaka loader glyph before the label; the button keeps its colour.
magneticboolean—@deprecated Since 3.31 (krizaka-ui#393): does nothing — a button never moves under the pointer. Removed in 4.0.
progressnumber | null—Between 0 and 1, while loading: the glyph's trace and a light fill across the button grow to the value (an upload, an export).
resetMsnumber1800How long "Copied" stays, in milliseconds (1800 by default).
shape"rounded" | "pill" | "cut"roundedrounded (an 8 px radius, the radius of a field) · pill. cut is deprecated (krizaka-ui#393: the chamfer is retired) — it draws rounded and warns in development; it will be removed in 4.0.
shimmerboolean—@deprecated Since 3.31 (krizaka-ui#393): does nothing — the hover is quiet. Removed in 4.0.
size"sm" | "lg" | "icon" | "md"mdsm · md · lg, or icon (a square).
status"success" | "error" | null—How the action ended: success draws a check, error a cross (and the button shakes its head once); a ring of the status colour opens around it. Clear it to return to rest.
variant"danger" | "primary" | "gradient" | "secondary" | "outline" | "ghost"secondaryThe look: primary (the accent), gradient (accent → accent-2), secondary (a raised surface), outline, ghost, danger.

Accessibilité

  • “Copied” is announced politely (role=status) and names the button while it shows.
  • Icon only: the label is the accessible name.
  • Without the Clipboard API a read-only field appears, selected: nothing fails silently.

Clavier

TouchesAction
Enter / SpaceCopies the value.

Bonnes pratiques

  • label says what is copied (“Copy link”), not just “Copy”.
  • Keep fallbackLabel short: it appears above the selected value when the clipboard is refused.
  • Pass a @krizaka/icons icon through icon to match the page.

Générée depuis le code de @krizaka/ui 3.67.1 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page