diff --git a/.idea/leptos-use.iml b/.idea/leptos-use.iml index b9141b0..c55e122 100644 --- a/.idea/leptos-use.iml +++ b/.idea/leptos-use.iml @@ -16,6 +16,7 @@ + @@ -28,6 +29,7 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 346e1c6..997602c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.1.7 + +#### New Function +- `use_element_size` + ## 0.1.6 - Fixed documentation so all feature are documented diff --git a/Cargo.toml b/Cargo.toml index fa2cd4a..c260d7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos-use" -version = "0.1.6" +version = "0.1.7" edition = "2021" authors = ["Marc-Stefan Cassola"] categories = ["gui", "web-programming"] @@ -10,6 +10,7 @@ keywords = ["leptos", "utilities"] license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/Synphonyte/leptos-use" +homepage = "https://leptos-use.rs" [dependencies] @@ -24,6 +25,7 @@ version = "0.3.63" features = [ "CssStyleDeclaration", "DomRectReadOnly", + "Element", "MouseEvent", "Navigator", "ResizeObserver", diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index e4ce538..a00a283 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -7,6 +7,7 @@ # Elements +- [use_element_size](elements/use_element_size.md) - [use_resize_observer](elements/use_resize_observer.md) # Browser diff --git a/docs/book/src/elements/use_element_size.md b/docs/book/src/elements/use_element_size.md new file mode 100644 index 0000000..b59e781 --- /dev/null +++ b/docs/book/src/elements/use_element_size.md @@ -0,0 +1,3 @@ +# use_element_size + + diff --git a/examples/use_element_size/.cargo/config.toml b/examples/use_element_size/.cargo/config.toml new file mode 100644 index 0000000..8467175 --- /dev/null +++ b/examples/use_element_size/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["--cfg=web_sys_unstable_apis"] diff --git a/examples/use_element_size/Cargo.toml b/examples/use_element_size/Cargo.toml new file mode 100644 index 0000000..e249885 --- /dev/null +++ b/examples/use_element_size/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "use_element_size" +version = "0.1.0" +edition = "2021" + +[dependencies] +leptos = "0.3" +console_error_panic_hook = "0.1" +console_log = "1" +log = "0.4" +leptos-use = { path = "../..", features = ["docs"] } +web-sys = "0.3" + +[dev-dependencies] +wasm-bindgen = "0.2" +wasm-bindgen-test = "0.3.0" diff --git a/examples/use_element_size/README.md b/examples/use_element_size/README.md new file mode 100644 index 0000000..9f63d84 --- /dev/null +++ b/examples/use_element_size/README.md @@ -0,0 +1,23 @@ +A simple example for `use_element_size`. + +If you don't have it installed already, install [Trunk](https://trunkrs.dev/) and [Tailwind](https://tailwindcss.com/docs/installation) +as well as the nightly toolchain for Rust and the wasm32-unknown-unknown target: + +```bash +cargo install trunk +npm install -D tailwindcss @tailwindcss/forms +rustup toolchain install nightly +rustup target add wasm32-unknown-unknown +``` + +Then, open two terminals. In the first one, run: + +``` +npx tailwindcss -i ./input.css -o ./style/output.css --watch +``` + +In the second one, run: + +```bash +trunk serve --open +``` \ No newline at end of file diff --git a/examples/use_element_size/Trunk.toml b/examples/use_element_size/Trunk.toml new file mode 100644 index 0000000..3e4be08 --- /dev/null +++ b/examples/use_element_size/Trunk.toml @@ -0,0 +1,2 @@ +[build] +public_url = "/demo/" \ No newline at end of file diff --git a/examples/use_element_size/index.html b/examples/use_element_size/index.html new file mode 100644 index 0000000..ae249a6 --- /dev/null +++ b/examples/use_element_size/index.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/use_element_size/input.css b/examples/use_element_size/input.css new file mode 100644 index 0000000..bd6213e --- /dev/null +++ b/examples/use_element_size/input.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/examples/use_element_size/rust-toolchain.toml b/examples/use_element_size/rust-toolchain.toml new file mode 100644 index 0000000..271800c --- /dev/null +++ b/examples/use_element_size/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" \ No newline at end of file diff --git a/examples/use_element_size/src/main.rs b/examples/use_element_size/src/main.rs new file mode 100644 index 0000000..14a18dc --- /dev/null +++ b/examples/use_element_size/src/main.rs @@ -0,0 +1,31 @@ +use leptos::*; +use leptos_use::docs::{demo_or_body, Note}; +use leptos_use::{use_element_size, UseElementSizeReturn}; + +#[component] +fn Demo(cx: Scope) -> impl IntoView { + let el = create_node_ref(cx); + + let UseElementSizeReturn { width, height } = use_element_size(cx, el); + + let text = move || format!("width: {}\nheight: {}", width.get(), height.get()); + + view! { cx, + "Resize the box to see changes" +