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-buttonnpx oxyn add composerrsx! {
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.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add copy-buttonuse 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
rsx! {
CopyButton {
value: "npx oxyn add composer",
on_copy: move |text: String| clipboard.write(text),
}
}Examples
Outline
Bordered with a label.
npx oxyn add composerCode
rsx! {
CopyButton {
value: "npx oxyn add composer",
on_copy: move |text: String| clipboard.write(text),
}
}Icon
Icon only.
npx oxyn add composerCode
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 composerCode
rsx! {
CopyButton {
value: "npx oxyn add composer",
variant: "solid",
on_copy: move |text: String| clipboard.write(text),
}
}Failed
The failure state.
npx oxyn add composerCode
rsx! {
CopyButton {
value: "npx oxyn add composer",
on_copy: move |text: String| clipboard.write(text),
}
}API reference
CopyButton
| Prop | Type | Default | Description |
|---|---|---|---|
valuerequired | String | — | Text to copy. |
label | String | "Copy" | Idle label. |
icon_only | bool | Default::default() | Icon only. |
variant | String | "outline" | `outline` · `plain` · `solid`. |
size | String | "md" | `sm` · `md`. |
disabled | bool | Default::default() | Disabled. |
fail | bool | Default::default() | Simulate a failed copy. |
on_copy | EventHandler<String> | — | Copy pressed (value). |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| EnterorSpace | Copy |
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
| Transition | Duration | Easing | Reduced motion |
|---|---|---|---|
| Out | 100 ms | linear | instant |
| In | 160 ms (60 ms delay) | linear | instant |
| Check draw | 260 ms | ease.out | none |
| Hold | 1500 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
CopyButtonfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
CopyButtonElinoxyn_gpui. - Props to set first:
value. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.