leptos-use/examples/use_element_size/src/main.rs

35 lines
925 B
Rust
Raw Normal View History

2023-07-03 16:10:58 +01:00
use leptos::html::Textarea;
2024-05-07 12:41:44 +01:00
use leptos::prelude::*;
2023-06-05 00:02:13 +01:00
use leptos_use::docs::{demo_or_body, Note};
use leptos_use::{use_element_size, UseElementSizeReturn};
#[component]
2023-07-27 18:06:36 +01:00
fn Demo() -> impl IntoView {
let el = NodeRef::<Textarea>::new();
2023-06-05 00:02:13 +01:00
2023-07-27 18:06:36 +01:00
let UseElementSizeReturn { width, height } = use_element_size(el);
2023-06-05 00:02:13 +01:00
let text = move || format!("width: {}\nheight: {}", width.get(), height.get());
2023-07-27 19:48:21 +01:00
view! {
<Note class="mb-2">"Resize the box to see changes"</Note>
2023-06-05 00:02:13 +01:00
<textarea
node_ref=el
readonly
class="resize rounded-md p-4 w-[200px] h-[100px] text-2xl leading-10"
prop:value=text
2023-07-27 19:48:21 +01:00
></textarea>
2023-06-05 00:02:13 +01:00
}
}
fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
let unmount_handle = leptos::mount::mount_to(demo_or_body(), || {
2023-07-27 19:48:21 +01:00
view! { <Demo/> }
});
unmount_handle.forget();
2023-06-05 00:02:13 +01:00
}