MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus-components / CopyButton

Function CopyButton

preview/src/main.rs:439–458  ·  view source on GitHub ↗
(#[props(extends=GlobalAttributes)] attributes: Vec<Attribute>)

Source from the content-addressed store, hash-verified

437
438#[component]
439fn CopyButton(#[props(extends=GlobalAttributes)] attributes: Vec<Attribute>) -> Element {
440 let mut copied = use_signal(|| false);
441
442 rsx! {
443 button {
444 class: "dx-copy-button",
445 r#type: "button",
446 aria_label: "Copy code",
447 "data-copied": copied,
448 "onclick": "const visiblePre = Array.from(this.parentNode.querySelectorAll('pre')).find((pre) => pre.offsetParent !== null); navigator.clipboard.writeText(visiblePre ? visiblePre.innerText : Array.from(this.parentNode.childNodes).filter((node) => node !== this).map((node) => node.textContent).join('').trim());",
449 onclick: move |_| copied.set(true),
450 ..attributes,
451 if copied() {
452 CheckIcon {}
453 } else {
454 CopyIcon {}
455 }
456 }
457 }
458}
459
460#[component]
461fn CopyIcon() -> Element {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected