Skip to content
Back

Copy button

Copy a value with immediate confirmation: icon and label crossfade to Copied, the check draws in, and it resets after a moment.

oxyn add copy-button
MCP
npx oxyn add composer
Dioxus
rsx! {
    CopyButton {
        value: "npx oxyn add composer",
        on_copy: move |text: String| clipboard.write(text),
    }
}

Rendered from Rust at build time · goes live when visible

When to use

  • Copy a command, a code block, an answer or an ID with instant confirmation.

When not to use

  • Code with a filename header, light highlighting, copy, wrap and Show all, line numbers, highlighted lines, diffs and a streaming caret: use Code block instead.
  • Feedback on a reply: use Response feedback instead.
  • An action label that swaps to its next state while keeping its place: use Action states instead.

Installation

Copy button is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add copy-button
Rust
use crate::oxyn::{CopyButton, PRIMITIVES_CSS};

Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{CopyButton, PRIMITIVES_CSS};

Usage

Dioxus · rust
rsx! {
    CopyButton {
        value: "npx oxyn add composer",
        on_copy: move |text: String| clipboard.write(text),
    }
}

Examples

Outline

Bordered with a label.

npx oxyn add composer
Code
rsx! {
    CopyButton {
        value: "npx oxyn add composer",
        on_copy: move |text: String| clipboard.write(text),
    }
}

Icon

Icon only.

npx oxyn add composer
Code
rsx! {
    CopyButton {
        value: "npx oxyn add composer",
        icon_only: true,
        variant: "plain",
        on_copy: move |text: String| clipboard.write(text),
    }
}

Solid

Solid (Oxyn plus).

npx oxyn add composer
Code
rsx! {
    CopyButton {
        value: "npx oxyn add composer",
        variant: "solid",
        on_copy: move |text: String| clipboard.write(text),
    }
}

Failed

The failure state.

npx oxyn add composer
Code
rsx! {
    CopyButton {
        value: "npx oxyn add composer",
        on_copy: move |text: String| clipboard.write(text),
    }
}

API reference

CopyButton

PropTypeDefaultDescription
valuerequiredString—Text to copy.
labelString"Copy"Idle label.
icon_onlyboolDefault::default()Icon only.
variantString"outline"`outline` · `plain` · `solid`.
sizeString"md"`sm` · `md`.
disabledboolDefault::default()Disabled.
failboolDefault::default()Simulate a failed copy.
on_copyEventHandler<String>—Copy pressed (value).

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
EnterorSpaceCopy

Accessibility

  • Named by label even when icon-only.
  • A polite status announces “Copy: Copied” or “Could not copy”.
From the spec

Native button named by label; polite status announces the result.

Motion & interaction

The old icon and word fade out in ~100 ms while the new ones fade in over ~160 ms; the check draws its stroke. The label cell reserves its widest word so the button never changes width.

Timing
TransitionDurationEasingReduced motion
Out100 mslinearinstant
In160 ms (60 ms delay)linearinstant
Check draw260 msease.outnone
Hold1500 ms—same

Responsive behaviour

  • The label cell reserves its widest state so nothing shifts.
Edge cases (spec)

The host writes the clipboard (on_copy; the site handles data-copy). Disabled stays idle.

Notes for AI

  • Import CopyButton from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: CopyButtonEl in oxyn_gpui.
  • Props to set first: value.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI