Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use_device_pixel_ratio #61

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] -

### New Functions 🚀

- `use_device_pixel_ratio` (thanks to @mondeja)

## [0.9.0] - 2023-12-06

### New Functions 🚀
Expand Down
1 change: 1 addition & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# Sensors

- [on_click_outside](sensors/on_click_outside.md)
- [use_device_pixel_ratio](sensors/use_device_pixel_ratio.md)
- [use_element_hover](sensors/use_element_hover.md)
- [use_geolocation](sensors/use_geolocation.md)
- [use_idle](sensors/use_idle.md)
Expand Down
3 changes: 3 additions & 0 deletions docs/book/src/sensors/use_device_pixel_ratio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# use_device_pixel_ratio

<!-- cmdrun python3 ../extract_doc_comment.py use_device_pixel_ratio -->
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"use_css_var",
"use_cycle_list",
"use_debounce_fn",
"use_device_pixel_ratio",
"use_display_media",
"use_document_visibility",
"use_draggable",
Expand Down
16 changes: 16 additions & 0 deletions examples/use_device_pixel_ratio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "use_device_pixel_ratio"
version = "0.1.0"
edition = "2021"

[dependencies]
leptos = { version = "0.5", features = ["nightly", "csr"] }
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"
23 changes: 23 additions & 0 deletions examples/use_device_pixel_ratio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
A simple example for `use_device_pixel_ratio`.

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
```
2 changes: 2 additions & 0 deletions examples/use_device_pixel_ratio/Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
public_url = "/demo/"
7 changes: 7 additions & 0 deletions examples/use_device_pixel_ratio/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<link data-trunk rel="css" href="style/output.css">
</head>
<body></body>
</html>
3 changes: 3 additions & 0 deletions examples/use_device_pixel_ratio/input.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
2 changes: 2 additions & 0 deletions examples/use_device_pixel_ratio/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
24 changes: 24 additions & 0 deletions examples/use_device_pixel_ratio/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use leptos::*;
use leptos_use::docs::demo_or_body;
use leptos_use::use_device_pixel_ratio;

#[component]
fn Demo() -> impl IntoView {
let pixel_ratio = use_device_pixel_ratio();

view! {
<pre>{move || format!("pixelRatio: {}", pixel_ratio())}</pre>
<p>
"Zoom in and out (or move the window to a screen with a different scaling factor) to see the value changes."
</p>
}
}

fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();

mount_to(demo_or_body(), || {
view! { <Demo/> }
})
}
Loading
Loading