2023-07-03 16:10:58 +01:00
|
|
|
use leptos::html::Textarea;
|
2023-05-31 05:56:32 +01:00
|
|
|
use leptos::*;
|
2023-06-02 13:38:01 +01:00
|
|
|
use leptos_use::docs::{demo_or_body, Note};
|
|
|
|
use leptos_use::use_resize_observer;
|
2023-05-31 05:56:32 +01:00
|
|
|
|
|
|
|
#[component]
|
|
|
|
fn Demo(cx: Scope) -> impl IntoView {
|
2023-07-03 16:10:58 +01:00
|
|
|
let el = create_node_ref::<Textarea>(cx);
|
2023-05-31 05:56:32 +01:00
|
|
|
let (text, set_text) = create_signal(cx, "".to_string());
|
|
|
|
|
2023-06-02 13:38:01 +01:00
|
|
|
use_resize_observer(cx, el, move |entries, _| {
|
2023-05-31 05:56:32 +01:00
|
|
|
let rect = entries[0].content_rect();
|
2023-06-21 13:09:00 +02:00
|
|
|
set_text.set(format!(
|
2023-05-31 05:56:32 +01:00
|
|
|
"width: {:.0}\nheight: {:.0}",
|
|
|
|
rect.width(),
|
|
|
|
rect.height()
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
|
|
|
view! { cx,
|
|
|
|
<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"
|
2023-06-21 13:09:00 +02:00
|
|
|
prop:value=move || text.get()
|
2023-06-05 00:02:13 +01:00
|
|
|
/>
|
2023-05-31 05:56:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
_ = console_log::init_with_level(log::Level::Debug);
|
|
|
|
console_error_panic_hook::set_once();
|
|
|
|
|
|
|
|
mount_to(demo_or_body(), |cx| {
|
|
|
|
view! { cx, <Demo /> }
|
|
|
|
})
|
|
|
|
}
|