From 27053ac4b1d7fc638229f203e12ee49074bb4afa Mon Sep 17 00:00:00 2001 From: toyota-corolla0 Date: Thu, 22 Feb 2024 00:28:38 -0600 Subject: [PATCH] feat: copyable_text component --- .cargo/config.toml | 2 ++ Cargo.toml | 2 +- src/components/copyable_text.rs | 54 +++++++++++++++++++++++++++++++++ src/components/mod.rs | 2 ++ src/components/receive_ln.rs | 7 +++-- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 src/components/copyable_text.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..252e482 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["--cfg=web_sys_unstable_apis"] \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 9181d73..837bd17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ tokio = { version = "1.28.2", features = [ "rt", "sync", "time" ] } tokio-stream = "0.1.14" wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4.37" -web-sys = { version = "0.3.65", features = [ "Navigator", "Window", "ServiceWorkerContainer" ] } +web-sys = { version = "0.3.65", features = [ "Navigator", "Window", "ServiceWorkerContainer", "HtmlTextAreaElement" ] } gloo-storage = "0.3.0" rand = "0.8.5" diff --git a/src/components/copyable_text.rs b/src/components/copyable_text.rs new file mode 100644 index 0000000..091fe97 --- /dev/null +++ b/src/components/copyable_text.rs @@ -0,0 +1,54 @@ +use leptos::*; +use leptos_use::{use_clipboard, UseClipboardReturn}; +use web_sys::HtmlTextAreaElement; + +#[component] +pub fn CopyableText( + #[prop(into)] text: Signal, + #[prop(default = 4)] rows: usize, + #[prop(into, optional)] class: String, +) -> impl IntoView { + let UseClipboardReturn { + is_supported, + text: _, + copied, + copy, + } = use_clipboard(); + + view! { +
+ + + + +
+ } +} diff --git a/src/components/mod.rs b/src/components/mod.rs index fa341b7..383e938 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,6 +1,7 @@ pub mod alerts; pub mod app; pub mod balance; +pub mod copyable_text; pub mod footer; pub mod joined; pub mod ln_receive_form; @@ -20,6 +21,7 @@ pub mod wallet_selector; pub use alerts::*; pub use app::*; pub use balance::*; +pub use copyable_text::*; pub use footer::*; pub use joined::*; pub use loader_icon::*; diff --git a/src/components/receive_ln.rs b/src/components/receive_ln.rs index c103b8a..75b7846 100644 --- a/src/components/receive_ln.rs +++ b/src/components/receive_ln.rs @@ -1,6 +1,6 @@ use leptos::*; -use super::{ErrorBlock, SuccessBlock}; +use super::{CopyableText, ErrorBlock, SuccessBlock}; use crate::components::ln_receive_form::LnReceiveForm; use crate::components::loader_icon::LoaderIcon; use crate::components::qrcode::QrCode; @@ -67,7 +67,10 @@ pub fn ReceiveLn() -> impl IntoView { None => empty_view().into_view(), } }} - {&invoice} +