MCPcopy Create free account
hub / github.com/acking-you/static_flow / copy_button

Function copy_button

crates/frontend/src/components/copy_button.rs:36–64  ·  view source on GitHub ↗
(props: &CopyButtonProps)

Source from the content-addressed store, hash-verified

34 pub class: Classes,
35 /// Tooltip / accessible label.
36 #[prop_or(AttrValue::Static("复制"))]
37 pub title: AttrValue,
38}
39
40/// Inline copy button that flips to a checkmark for ~1.2s after copying.
41#[function_component(CopyButton)]
42pub fn copy_button(props: &CopyButtonProps) -> Html {
43 let copied = use_state(|| false);
44 let onclick = {
45 let text = props.text.clone();
46 let copied = copied.clone();
47 Callback::from(move |_: MouseEvent| {
48 sf_copy_text(&text);
49 copied.set(true);
50 let copied = copied.clone();
51 gloo_timers::callback::Timeout::new(1200, move || copied.set(false)).forget();
52 })
53 };
54 let icon = if *copied { "fa-check" } else { "fa-copy" };
55 html! {
56 <button
57 type="button"
58 class={classes!(
59 "btn-copy-inline",
60 props.class.clone(),
61 copied.then_some("btn-copy-inline--done")
62 )}
63 onclick={onclick}
64 title={props.title.clone()}
65 aria-label={props.title.clone()}
66 >
67 <i class={classes!("fas", icon)} aria-hidden="true"></i>

Callers

nothing calls this directly

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected