mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-23 00:59:22 -05:00
added use_favicon
This commit is contained in:
parent
4cabc25ec5
commit
06815b1ca9
23 changed files with 785 additions and 3 deletions
2
.idea/leptos-use.iml
generated
2
.idea/leptos-use.iml
generated
|
@ -20,6 +20,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/examples/watch_debounced/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/examples/watch_pausable/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/examples/watch_throttled/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/examples/use_favicon/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/examples/use_media_query/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/examples/use_storage/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/use_event_listener/target" />
|
||||
|
@ -38,6 +39,7 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/examples/watch_debounced/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/watch_pausable/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/watch_throttled/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/use_favicon/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/use_media_query/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/use_storage/target" />
|
||||
</content>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#### Braking Changes
|
||||
- `watch` doesn't accept `immediate` as a direct argument anymore. This is only provided by the option variant.
|
||||
- `watch` has now variant `watch_with_options` which allows for debouncing and throttling.
|
||||
|
||||
#### New Functions
|
||||
- `use_storage`
|
||||
|
@ -17,10 +18,11 @@
|
|||
- `use_media_query`
|
||||
- `use_preferred_dark`
|
||||
- `use_preferred_contrast`
|
||||
- `use_favicon`
|
||||
|
||||
#### Other Changes
|
||||
|
||||
- `watch` has now variant `watch_with_options` which allows for debouncing and throttling.
|
||||
- Function count badge in readme
|
||||
|
||||
## 0.1.8/9
|
||||
|
||||
|
|
|
@ -31,9 +31,11 @@ features = [
|
|||
"CustomEventInit",
|
||||
"DomRectReadOnly",
|
||||
"Element",
|
||||
"HtmlLinkElement",
|
||||
"MediaQueryList",
|
||||
"MouseEvent",
|
||||
"Navigator",
|
||||
"NodeList",
|
||||
"ResizeObserver",
|
||||
"ResizeObserverBoxOptions",
|
||||
"ResizeObserverEntry",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<p align="center">
|
||||
<a href="https://crates.io/crates/leptos-use"><img src="https://img.shields.io/crates/v/leptos-use.svg?label=&color=%232C1275" alt="Crates.io"/></a>
|
||||
<a href="https://leptos-use.rs"><img src="https://img.shields.io/badge/-docs%20%26%20demos-%239A233F" alt="Docs & Demos"></a>
|
||||
<a href="https://leptos-use.rs"><img src="https://img.shields.io/badge/-22%20functions-%23EF3939" alt="23 Functions" /></a>
|
||||
<a href="https://leptos-use.rs"><img src="https://img.shields.io/badge/-23%20functions-%23EF3939" alt="23 Functions" /></a>
|
||||
</p>
|
||||
|
||||
<br/>
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
# Browser
|
||||
|
||||
- [use_event_listener](browser/use_event_listener.md)
|
||||
- [use_favicon](browser/use_favicon.md)
|
||||
- [use_media_query](browser/use_media_query.md)
|
||||
- [use_preferred_contrast](browser/use_preferred_contrast.md)
|
||||
- [use_preferred_dark](browser/use_preferred_dark.md)
|
||||
|
|
3
docs/book/src/browser/use_favicon.md
Normal file
3
docs/book/src/browser/use_favicon.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# use_favicon
|
||||
|
||||
<!-- cmdrun python3 ../extract_doc_comment.py use_favicon -->
|
|
@ -21,7 +21,7 @@ def main():
|
|||
original_text
|
||||
)
|
||||
|
||||
if sys.argv[1] == "--check":
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "--check":
|
||||
if original_text != text:
|
||||
print("[Failed] README.md doesn't have the correct function count badge", file=sys.stderr)
|
||||
print(" * Run `python3 docs/generate_count_badge.py` to fix", file=sys.stderr)
|
||||
|
|
16
examples/use_favicon/Cargo.toml
Normal file
16
examples/use_favicon/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "use_favicon"
|
||||
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"
|
23
examples/use_favicon/README.md
Normal file
23
examples/use_favicon/README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
A simple example for `use_favicon`.
|
||||
|
||||
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
examples/use_favicon/Trunk.toml
Normal file
2
examples/use_favicon/Trunk.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[build]
|
||||
public_url = "/demo/"
|
27
examples/use_favicon/img/favicon-blue.svg
Normal file
27
examples/use_favicon/img/favicon-blue.svg
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<style>
|
||||
path.black {
|
||||
fill: #1e1838;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
path.black {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<path d="M16.114,22.343c-1.714,-0 -3.2,-0.914 -3.885,-2.514c-0.458,-1.029 -0.572,-2.172 -0.229,-3.315c0.343,-1.143 1.143,-1.943 2.171,-2.514c0.572,-0.343 1.258,-0.457 1.829,-0.457c1.714,-0 3.2,0.914 3.886,2.514c1.028,2.172 0.114,4.8 -2.057,5.829c-0.458,0.228 -1.029,0.457 -1.715,0.457Z"
|
||||
style="fill:#0018F5;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,15.943c0.572,-0 1.486,0.343 1.829,1.143c0.343,0.685 0.228,1.257 0.114,1.6c-0.114,0.343 -0.343,0.8 -1.028,1.143c-0.229,0.114 -0.572,0.228 -0.915,0.228c-0.571,0 -1.485,-0.343 -1.828,-1.143c-0.457,-1.028 -0.115,-2.285 0.914,-2.743c0.343,-0.228 0.571,-0.228 0.914,-0.228Zm0,-4.572c-0.914,0 -1.943,0.229 -2.857,0.686c-3.314,1.486 -4.686,5.486 -3.086,8.8c1.143,2.4 3.543,3.772 5.943,3.772c0.915,-0 1.943,-0.229 2.857,-0.686c3.315,-1.6 4.686,-5.6 3.086,-8.8c-1.143,-2.4 -3.428,-3.772 -5.943,-3.772Z"
|
||||
style="fill:#0018F5;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,6.114c-0.8,0 -1.485,-0.457 -1.828,-1.143c-0.457,-1.028 -0,-2.171 0.914,-2.628c0.229,-0.114 0.571,-0.229 0.914,-0.229c0.8,0 1.486,0.457 1.829,1.143c0.457,1.029 0.114,2.172 -0.914,2.629c-0.343,0.114 -0.572,0.228 -0.915,0.228Z"
|
||||
style="fill:#0018F5;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,3.829c0,-0 0.229,-0 0.229,0.114c0.114,0.114 -0,0.343 -0.114,0.343l-0.115,-0c0,-0 -0.228,-0 -0.228,-0.115c-0.115,-0.114 -0,-0.342 0.114,-0.342l0.114,-0Zm0,-3.429c-0.571,-0 -1.143,0.114 -1.6,0.343c-1.828,0.914 -2.628,3.086 -1.714,5.028c0.686,1.372 1.943,2.058 3.314,2.058c0.572,-0 1.143,-0.115 1.6,-0.343c1.829,-0.915 2.629,-3.086 1.715,-4.915c-0.572,-1.371 -1.943,-2.171 -3.315,-2.171Z"
|
||||
style="fill:#0018F5;fill-rule:nonzero;"/>
|
||||
<path class="black"
|
||||
d="M27.314,10.914c0,-0.114 -0.114,-0.343 -0.343,-0.571c0,-0.114 -0.114,-0.229 -0.114,-0.229c-0.457,-0.8 -1.143,-1.943 -1.143,-1.943l-2.514,1.486l1.486,2.629c1.943,3.657 2.057,7.657 0.571,10.857c-1.6,3.428 -5.028,5.371 -9.143,5.371c-4.228,0 -7.543,-1.943 -9.143,-5.371c-1.6,-3.2 -1.371,-7.2 0.572,-10.857l1.6,-2.629l-2.743,-1.486c-0,0 -0.686,1.029 -1.143,1.943c-0.114,0 -0.228,0.115 -0.228,0.229c-0.115,0.228 -0.229,0.457 -0.343,0.571c-2.286,4.572 -2.515,9.486 -0.457,13.715c2.171,4.457 6.4,6.971 11.771,6.971c5.257,0 9.6,-2.514 11.771,-6.971c2.058,-4.229 1.829,-9.258 -0.457,-13.715Z"
|
||||
style="fill-rule:nonzero;"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
27
examples/use_favicon/img/favicon-green.svg
Normal file
27
examples/use_favicon/img/favicon-green.svg
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<style>
|
||||
path.black {
|
||||
fill: #1e1838;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
path.black {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<path d="M16.114,22.343c-1.714,-0 -3.2,-0.914 -3.885,-2.514c-0.458,-1.029 -0.572,-2.172 -0.229,-3.315c0.343,-1.143 1.143,-1.943 2.171,-2.514c0.572,-0.343 1.258,-0.457 1.829,-0.457c1.714,-0 3.2,0.914 3.886,2.514c1.028,2.172 0.114,4.8 -2.057,5.829c-0.458,0.228 -1.029,0.457 -1.715,0.457Z"
|
||||
style="fill:#25F55E;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,15.943c0.572,-0 1.486,0.343 1.829,1.143c0.343,0.685 0.228,1.257 0.114,1.6c-0.114,0.343 -0.343,0.8 -1.028,1.143c-0.229,0.114 -0.572,0.228 -0.915,0.228c-0.571,0 -1.485,-0.343 -1.828,-1.143c-0.457,-1.028 -0.115,-2.285 0.914,-2.743c0.343,-0.228 0.571,-0.228 0.914,-0.228Zm0,-4.572c-0.914,0 -1.943,0.229 -2.857,0.686c-3.314,1.486 -4.686,5.486 -3.086,8.8c1.143,2.4 3.543,3.772 5.943,3.772c0.915,-0 1.943,-0.229 2.857,-0.686c3.315,-1.6 4.686,-5.6 3.086,-8.8c-1.143,-2.4 -3.428,-3.772 -5.943,-3.772Z"
|
||||
style="fill:#25F55E;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,6.114c-0.8,0 -1.485,-0.457 -1.828,-1.143c-0.457,-1.028 -0,-2.171 0.914,-2.628c0.229,-0.114 0.571,-0.229 0.914,-0.229c0.8,0 1.486,0.457 1.829,1.143c0.457,1.029 0.114,2.172 -0.914,2.629c-0.343,0.114 -0.572,0.228 -0.915,0.228Z"
|
||||
style="fill:#25F55E;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,3.829c0,-0 0.229,-0 0.229,0.114c0.114,0.114 -0,0.343 -0.114,0.343l-0.115,-0c0,-0 -0.228,-0 -0.228,-0.115c-0.115,-0.114 -0,-0.342 0.114,-0.342l0.114,-0Zm0,-3.429c-0.571,-0 -1.143,0.114 -1.6,0.343c-1.828,0.914 -2.628,3.086 -1.714,5.028c0.686,1.372 1.943,2.058 3.314,2.058c0.572,-0 1.143,-0.115 1.6,-0.343c1.829,-0.915 2.629,-3.086 1.715,-4.915c-0.572,-1.371 -1.943,-2.171 -3.315,-2.171Z"
|
||||
style="fill:#25F55E;fill-rule:nonzero;"/>
|
||||
<path class="black"
|
||||
d="M27.314,10.914c0,-0.114 -0.114,-0.343 -0.343,-0.571c0,-0.114 -0.114,-0.229 -0.114,-0.229c-0.457,-0.8 -1.143,-1.943 -1.143,-1.943l-2.514,1.486l1.486,2.629c1.943,3.657 2.057,7.657 0.571,10.857c-1.6,3.428 -5.028,5.371 -9.143,5.371c-4.228,0 -7.543,-1.943 -9.143,-5.371c-1.6,-3.2 -1.371,-7.2 0.572,-10.857l1.6,-2.629l-2.743,-1.486c-0,0 -0.686,1.029 -1.143,1.943c-0.114,0 -0.228,0.115 -0.228,0.229c-0.115,0.228 -0.229,0.457 -0.343,0.571c-2.286,4.572 -2.515,9.486 -0.457,13.715c2.171,4.457 6.4,6.971 11.771,6.971c5.257,0 9.6,-2.514 11.771,-6.971c2.058,-4.229 1.829,-9.258 -0.457,-13.715Z"
|
||||
style="fill-rule:nonzero;"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
BIN
examples/use_favicon/img/favicon-leptos.ico
Normal file
BIN
examples/use_favicon/img/favicon-leptos.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
27
examples/use_favicon/img/favicon-orange.svg
Normal file
27
examples/use_favicon/img/favicon-orange.svg
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<style>
|
||||
path.black {
|
||||
fill: #1e1838;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
path.black {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<path d="M16.114,22.343c-1.714,-0 -3.2,-0.914 -3.885,-2.514c-0.458,-1.029 -0.572,-2.172 -0.229,-3.315c0.343,-1.143 1.143,-1.943 2.171,-2.514c0.572,-0.343 1.258,-0.457 1.829,-0.457c1.714,-0 3.2,0.914 3.886,2.514c1.028,2.172 0.114,4.8 -2.057,5.829c-0.458,0.228 -1.029,0.457 -1.715,0.457Z"
|
||||
style="fill:#F5C725;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,15.943c0.572,-0 1.486,0.343 1.829,1.143c0.343,0.685 0.228,1.257 0.114,1.6c-0.114,0.343 -0.343,0.8 -1.028,1.143c-0.229,0.114 -0.572,0.228 -0.915,0.228c-0.571,0 -1.485,-0.343 -1.828,-1.143c-0.457,-1.028 -0.115,-2.285 0.914,-2.743c0.343,-0.228 0.571,-0.228 0.914,-0.228Zm0,-4.572c-0.914,0 -1.943,0.229 -2.857,0.686c-3.314,1.486 -4.686,5.486 -3.086,8.8c1.143,2.4 3.543,3.772 5.943,3.772c0.915,-0 1.943,-0.229 2.857,-0.686c3.315,-1.6 4.686,-5.6 3.086,-8.8c-1.143,-2.4 -3.428,-3.772 -5.943,-3.772Z"
|
||||
style="fill:#F5C725;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,6.114c-0.8,0 -1.485,-0.457 -1.828,-1.143c-0.457,-1.028 -0,-2.171 0.914,-2.628c0.229,-0.114 0.571,-0.229 0.914,-0.229c0.8,0 1.486,0.457 1.829,1.143c0.457,1.029 0.114,2.172 -0.914,2.629c-0.343,0.114 -0.572,0.228 -0.915,0.228Z"
|
||||
style="fill:#F5C725;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,3.829c0,-0 0.229,-0 0.229,0.114c0.114,0.114 -0,0.343 -0.114,0.343l-0.115,-0c0,-0 -0.228,-0 -0.228,-0.115c-0.115,-0.114 -0,-0.342 0.114,-0.342l0.114,-0Zm0,-3.429c-0.571,-0 -1.143,0.114 -1.6,0.343c-1.828,0.914 -2.628,3.086 -1.714,5.028c0.686,1.372 1.943,2.058 3.314,2.058c0.572,-0 1.143,-0.115 1.6,-0.343c1.829,-0.915 2.629,-3.086 1.715,-4.915c-0.572,-1.371 -1.943,-2.171 -3.315,-2.171Z"
|
||||
style="fill:#F5C725;fill-rule:nonzero;"/>
|
||||
<path class="black"
|
||||
d="M27.314,10.914c0,-0.114 -0.114,-0.343 -0.343,-0.571c0,-0.114 -0.114,-0.229 -0.114,-0.229c-0.457,-0.8 -1.143,-1.943 -1.143,-1.943l-2.514,1.486l1.486,2.629c1.943,3.657 2.057,7.657 0.571,10.857c-1.6,3.428 -5.028,5.371 -9.143,5.371c-4.228,0 -7.543,-1.943 -9.143,-5.371c-1.6,-3.2 -1.371,-7.2 0.572,-10.857l1.6,-2.629l-2.743,-1.486c-0,0 -0.686,1.029 -1.143,1.943c-0.114,0 -0.228,0.115 -0.228,0.229c-0.115,0.228 -0.229,0.457 -0.343,0.571c-2.286,4.572 -2.515,9.486 -0.457,13.715c2.171,4.457 6.4,6.971 11.771,6.971c5.257,0 9.6,-2.514 11.771,-6.971c2.058,-4.229 1.829,-9.258 -0.457,-13.715Z"
|
||||
style="fill-rule:nonzero;"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
27
examples/use_favicon/img/favicon-red.svg
Normal file
27
examples/use_favicon/img/favicon-red.svg
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<style>
|
||||
path.black {
|
||||
fill: #1e1838;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
path.black {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<path d="M16.114,22.343c-1.714,-0 -3.2,-0.914 -3.885,-2.514c-0.458,-1.029 -0.572,-2.172 -0.229,-3.315c0.343,-1.143 1.143,-1.943 2.171,-2.514c0.572,-0.343 1.258,-0.457 1.829,-0.457c1.714,-0 3.2,0.914 3.886,2.514c1.028,2.172 0.114,4.8 -2.057,5.829c-0.458,0.228 -1.029,0.457 -1.715,0.457Z"
|
||||
style="fill:#e1393a;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,15.943c0.572,-0 1.486,0.343 1.829,1.143c0.343,0.685 0.228,1.257 0.114,1.6c-0.114,0.343 -0.343,0.8 -1.028,1.143c-0.229,0.114 -0.572,0.228 -0.915,0.228c-0.571,0 -1.485,-0.343 -1.828,-1.143c-0.457,-1.028 -0.115,-2.285 0.914,-2.743c0.343,-0.228 0.571,-0.228 0.914,-0.228Zm0,-4.572c-0.914,0 -1.943,0.229 -2.857,0.686c-3.314,1.486 -4.686,5.486 -3.086,8.8c1.143,2.4 3.543,3.772 5.943,3.772c0.915,-0 1.943,-0.229 2.857,-0.686c3.315,-1.6 4.686,-5.6 3.086,-8.8c-1.143,-2.4 -3.428,-3.772 -5.943,-3.772Z"
|
||||
style="fill:#e1393a;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,6.114c-0.8,0 -1.485,-0.457 -1.828,-1.143c-0.457,-1.028 -0,-2.171 0.914,-2.628c0.229,-0.114 0.571,-0.229 0.914,-0.229c0.8,0 1.486,0.457 1.829,1.143c0.457,1.029 0.114,2.172 -0.914,2.629c-0.343,0.114 -0.572,0.228 -0.915,0.228Z"
|
||||
style="fill:#e1393a;fill-rule:nonzero;"/>
|
||||
<path d="M16.114,3.829c0,-0 0.229,-0 0.229,0.114c0.114,0.114 -0,0.343 -0.114,0.343l-0.115,-0c0,-0 -0.228,-0 -0.228,-0.115c-0.115,-0.114 -0,-0.342 0.114,-0.342l0.114,-0Zm0,-3.429c-0.571,-0 -1.143,0.114 -1.6,0.343c-1.828,0.914 -2.628,3.086 -1.714,5.028c0.686,1.372 1.943,2.058 3.314,2.058c0.572,-0 1.143,-0.115 1.6,-0.343c1.829,-0.915 2.629,-3.086 1.715,-4.915c-0.572,-1.371 -1.943,-2.171 -3.315,-2.171Z"
|
||||
style="fill:#e1393a;fill-rule:nonzero;"/>
|
||||
<path class="black"
|
||||
d="M27.314,10.914c0,-0.114 -0.114,-0.343 -0.343,-0.571c0,-0.114 -0.114,-0.229 -0.114,-0.229c-0.457,-0.8 -1.143,-1.943 -1.143,-1.943l-2.514,1.486l1.486,2.629c1.943,3.657 2.057,7.657 0.571,10.857c-1.6,3.428 -5.028,5.371 -9.143,5.371c-4.228,0 -7.543,-1.943 -9.143,-5.371c-1.6,-3.2 -1.371,-7.2 0.572,-10.857l1.6,-2.629l-2.743,-1.486c-0,0 -0.686,1.029 -1.143,1.943c-0.114,0 -0.228,0.115 -0.228,0.229c-0.115,0.228 -0.229,0.457 -0.343,0.571c-2.286,4.572 -2.515,9.486 -0.457,13.715c2.171,4.457 6.4,6.971 11.771,6.971c5.257,0 9.6,-2.514 11.771,-6.971c2.058,-4.229 1.829,-9.258 -0.457,-13.715Z"
|
||||
style="fill-rule:nonzero;"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
8
examples/use_favicon/index.html
Normal file
8
examples/use_favicon/index.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link data-trunk rel="css" href="style/output.css">
|
||||
<link data-trunk rel="copy-dir" href="img">
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
3
examples/use_favicon/input.css
Normal file
3
examples/use_favicon/input.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
2
examples/use_favicon/rust-toolchain.toml
Normal file
2
examples/use_favicon/rust-toolchain.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[toolchain]
|
||||
channel = "nightly"
|
63
examples/use_favicon/src/main.rs
Normal file
63
examples/use_favicon/src/main.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use leptos::*;
|
||||
use leptos_use::docs::demo_or_body;
|
||||
use leptos_use::{use_favicon_with_options, UseFaviconOptions};
|
||||
|
||||
#[component]
|
||||
fn Demo(cx: Scope) -> impl IntoView {
|
||||
let (_, set_icon) = use_favicon_with_options(
|
||||
cx,
|
||||
UseFaviconOptions::default().base_url("use_favicon/demo/img/"),
|
||||
);
|
||||
|
||||
let classes = "border border-solid border-b-4 rounded p-2 block border-gray-500/50 bg-[--bg] active:translate-y-1 active:border-b".to_string();
|
||||
let img_classes = "block".to_string();
|
||||
|
||||
view! { cx,
|
||||
<p>"Click on an icon to change the favicon"</p>
|
||||
<p class="flex gap-2">
|
||||
<a class=classes.clone() href="#" on:click=move |e| {
|
||||
e.prevent_default();
|
||||
set_icon(Some("favicon-leptos.ico".into()));
|
||||
}>
|
||||
<img class=img_classes.clone() width="32" src="use_favicon/demo/img/favicon-leptos.ico" alt="favicon-red" />
|
||||
</a>
|
||||
|
||||
<a class=classes.clone() href="#" on:click=move |e| {
|
||||
e.prevent_default();
|
||||
set_icon(Some("favicon-red.svg".into()));
|
||||
}>
|
||||
<img class=img_classes.clone() width="32" src="use_favicon/demo/img/favicon-red.svg" alt="favicon-red" />
|
||||
</a>
|
||||
|
||||
<a class=classes.clone() href="#" on:click=move |e| {
|
||||
e.prevent_default();
|
||||
set_icon(Some("favicon-green.svg".into()));
|
||||
}>
|
||||
<img class=img_classes.clone() width="32" src="use_favicon/demo/img/favicon-green.svg" alt="favicon-green" />
|
||||
</a>
|
||||
|
||||
<a class=classes.clone() href="#" on:click=move |e| {
|
||||
e.prevent_default();
|
||||
set_icon(Some("favicon-blue.svg".into()));
|
||||
}>
|
||||
<img class=img_classes.clone() width="32" src="use_favicon/demo/img/favicon-blue.svg" alt="favicon-blue" />
|
||||
</a>
|
||||
|
||||
<a class=classes.clone() href="#" on:click=move |e| {
|
||||
e.prevent_default();
|
||||
set_icon(Some("favicon-orange.svg".into()));
|
||||
}>
|
||||
<img class=img_classes width="32" src="use_favicon/demo/img/favicon-orange.svg" alt="favicon-orange" />
|
||||
</a>
|
||||
</p>
|
||||
}
|
||||
}
|
||||
|
||||
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 /> }
|
||||
})
|
||||
}
|
403
examples/use_favicon/style/output.css
Normal file
403
examples/use_favicon/style/output.css
Normal file
|
@ -0,0 +1,403 @@
|
|||
[type='text'],[type='email'],[type='url'],[type='password'],[type='number'],[type='date'],[type='datetime-local'],[type='month'],[type='search'],[type='tel'],[type='time'],[type='week'],[multiple],textarea,select {
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
background-color: #fff;
|
||||
border-color: #6b7280;
|
||||
border-width: 1px;
|
||||
border-radius: 0px;
|
||||
padding-top: 0.5rem;
|
||||
padding-right: 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
padding-left: 0.75rem;
|
||||
font-size: 1rem;
|
||||
line-height: 1.5rem;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
}
|
||||
|
||||
[type='text']:focus, [type='email']:focus, [type='url']:focus, [type='password']:focus, [type='number']:focus, [type='date']:focus, [type='datetime-local']:focus, [type='month']:focus, [type='search']:focus, [type='tel']:focus, [type='time']:focus, [type='week']:focus, [multiple]:focus, textarea:focus, select:focus {
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 2px;
|
||||
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
|
||||
--tw-ring-offset-width: 0px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-color: #2563eb;
|
||||
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
||||
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
||||
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||
border-color: #2563eb;
|
||||
}
|
||||
|
||||
input::-moz-placeholder, textarea::-moz-placeholder {
|
||||
color: #6b7280;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
input::placeholder,textarea::placeholder {
|
||||
color: #6b7280;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
::-webkit-datetime-edit-fields-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
::-webkit-date-and-time-value {
|
||||
min-height: 1.5em;
|
||||
}
|
||||
|
||||
::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
select {
|
||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
|
||||
background-position: right 0.5rem center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 1.5em 1.5em;
|
||||
padding-right: 2.5rem;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact;
|
||||
}
|
||||
|
||||
[multiple] {
|
||||
background-image: initial;
|
||||
background-position: initial;
|
||||
background-repeat: unset;
|
||||
background-size: initial;
|
||||
padding-right: 0.75rem;
|
||||
-webkit-print-color-adjust: unset;
|
||||
print-color-adjust: unset;
|
||||
}
|
||||
|
||||
[type='checkbox'],[type='radio'] {
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
padding: 0;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
background-origin: border-box;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
flex-shrink: 0;
|
||||
height: 1rem;
|
||||
width: 1rem;
|
||||
color: #2563eb;
|
||||
background-color: #fff;
|
||||
border-color: #6b7280;
|
||||
border-width: 1px;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
}
|
||||
|
||||
[type='checkbox'] {
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
[type='radio'] {
|
||||
border-radius: 100%;
|
||||
}
|
||||
|
||||
[type='checkbox']:focus,[type='radio']:focus {
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 2px;
|
||||
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
|
||||
--tw-ring-offset-width: 2px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-color: #2563eb;
|
||||
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
||||
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
||||
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||
}
|
||||
|
||||
[type='checkbox']:checked,[type='radio']:checked {
|
||||
border-color: transparent;
|
||||
background-color: currentColor;
|
||||
background-size: 100% 100%;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
[type='checkbox']:checked {
|
||||
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
|
||||
}
|
||||
|
||||
[type='radio']:checked {
|
||||
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e");
|
||||
}
|
||||
|
||||
[type='checkbox']:checked:hover,[type='checkbox']:checked:focus,[type='radio']:checked:hover,[type='radio']:checked:focus {
|
||||
border-color: transparent;
|
||||
background-color: currentColor;
|
||||
}
|
||||
|
||||
[type='checkbox']:indeterminate {
|
||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");
|
||||
border-color: transparent;
|
||||
background-color: currentColor;
|
||||
background-size: 100% 100%;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
[type='checkbox']:indeterminate:hover,[type='checkbox']:indeterminate:focus {
|
||||
border-color: transparent;
|
||||
background-color: currentColor;
|
||||
}
|
||||
|
||||
[type='file'] {
|
||||
background: unset;
|
||||
border-color: inherit;
|
||||
border-width: 0;
|
||||
border-radius: 0;
|
||||
padding: 0;
|
||||
font-size: unset;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
[type='file']:focus {
|
||||
outline: 1px solid ButtonText;
|
||||
outline: 1px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
*, ::before, ::after {
|
||||
--tw-border-spacing-x: 0;
|
||||
--tw-border-spacing-y: 0;
|
||||
--tw-translate-x: 0;
|
||||
--tw-translate-y: 0;
|
||||
--tw-rotate: 0;
|
||||
--tw-skew-x: 0;
|
||||
--tw-skew-y: 0;
|
||||
--tw-scale-x: 1;
|
||||
--tw-scale-y: 1;
|
||||
--tw-pan-x: ;
|
||||
--tw-pan-y: ;
|
||||
--tw-pinch-zoom: ;
|
||||
--tw-scroll-snap-strictness: proximity;
|
||||
--tw-gradient-from-position: ;
|
||||
--tw-gradient-via-position: ;
|
||||
--tw-gradient-to-position: ;
|
||||
--tw-ordinal: ;
|
||||
--tw-slashed-zero: ;
|
||||
--tw-numeric-figure: ;
|
||||
--tw-numeric-spacing: ;
|
||||
--tw-numeric-fraction: ;
|
||||
--tw-ring-inset: ;
|
||||
--tw-ring-offset-width: 0px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-color: rgb(59 130 246 / 0.5);
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
--tw-shadow-colored: 0 0 #0000;
|
||||
--tw-blur: ;
|
||||
--tw-brightness: ;
|
||||
--tw-contrast: ;
|
||||
--tw-grayscale: ;
|
||||
--tw-hue-rotate: ;
|
||||
--tw-invert: ;
|
||||
--tw-saturate: ;
|
||||
--tw-sepia: ;
|
||||
--tw-drop-shadow: ;
|
||||
--tw-backdrop-blur: ;
|
||||
--tw-backdrop-brightness: ;
|
||||
--tw-backdrop-contrast: ;
|
||||
--tw-backdrop-grayscale: ;
|
||||
--tw-backdrop-hue-rotate: ;
|
||||
--tw-backdrop-invert: ;
|
||||
--tw-backdrop-opacity: ;
|
||||
--tw-backdrop-saturate: ;
|
||||
--tw-backdrop-sepia: ;
|
||||
}
|
||||
|
||||
::backdrop {
|
||||
--tw-border-spacing-x: 0;
|
||||
--tw-border-spacing-y: 0;
|
||||
--tw-translate-x: 0;
|
||||
--tw-translate-y: 0;
|
||||
--tw-rotate: 0;
|
||||
--tw-skew-x: 0;
|
||||
--tw-skew-y: 0;
|
||||
--tw-scale-x: 1;
|
||||
--tw-scale-y: 1;
|
||||
--tw-pan-x: ;
|
||||
--tw-pan-y: ;
|
||||
--tw-pinch-zoom: ;
|
||||
--tw-scroll-snap-strictness: proximity;
|
||||
--tw-gradient-from-position: ;
|
||||
--tw-gradient-via-position: ;
|
||||
--tw-gradient-to-position: ;
|
||||
--tw-ordinal: ;
|
||||
--tw-slashed-zero: ;
|
||||
--tw-numeric-figure: ;
|
||||
--tw-numeric-spacing: ;
|
||||
--tw-numeric-fraction: ;
|
||||
--tw-ring-inset: ;
|
||||
--tw-ring-offset-width: 0px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-color: rgb(59 130 246 / 0.5);
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
--tw-shadow-colored: 0 0 #0000;
|
||||
--tw-blur: ;
|
||||
--tw-brightness: ;
|
||||
--tw-contrast: ;
|
||||
--tw-grayscale: ;
|
||||
--tw-hue-rotate: ;
|
||||
--tw-invert: ;
|
||||
--tw-saturate: ;
|
||||
--tw-sepia: ;
|
||||
--tw-drop-shadow: ;
|
||||
--tw-backdrop-blur: ;
|
||||
--tw-backdrop-brightness: ;
|
||||
--tw-backdrop-contrast: ;
|
||||
--tw-backdrop-grayscale: ;
|
||||
--tw-backdrop-hue-rotate: ;
|
||||
--tw-backdrop-invert: ;
|
||||
--tw-backdrop-opacity: ;
|
||||
--tw-backdrop-saturate: ;
|
||||
--tw-backdrop-sepia: ;
|
||||
}
|
||||
|
||||
.m-2 {
|
||||
margin: 0.5rem;
|
||||
}
|
||||
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.inline-block {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.gap-2 {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.rounded {
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.border {
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
.border-b {
|
||||
border-bottom-width: 1px;
|
||||
}
|
||||
|
||||
.border-b-2 {
|
||||
border-bottom-width: 2px;
|
||||
}
|
||||
|
||||
.border-b-4 {
|
||||
border-bottom-width: 4px;
|
||||
}
|
||||
|
||||
.border-solid {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.border-black {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(0 0 0 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-\[\] {
|
||||
border-color: ;
|
||||
}
|
||||
|
||||
.border-\[--\] {
|
||||
border-color: var(--);
|
||||
}
|
||||
|
||||
.border-\[--theme-popup-border\] {
|
||||
border-color: var(--theme-popup-border);
|
||||
}
|
||||
|
||||
.border-gray-500 {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(107 114 128 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-gray-600 {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(75 85 99 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-red-600 {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(220 38 38 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-gray-500\/50 {
|
||||
border-color: rgb(107 114 128 / 0.5);
|
||||
}
|
||||
|
||||
.bg-\[--theme-popup-border\] {
|
||||
background-color: var(--theme-popup-border);
|
||||
}
|
||||
|
||||
.bg-\[--bg\] {
|
||||
background-color: var(--bg);
|
||||
}
|
||||
|
||||
.bg-white {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.p-2 {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.text-\[--brand-color\] {
|
||||
color: var(--brand-color);
|
||||
}
|
||||
|
||||
.text-green-600 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(22 163 74 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.opacity-75 {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.hover\:bg-\[\]:hover {
|
||||
background-color: ;
|
||||
}
|
||||
|
||||
.hover\:bg-\[--bg\]:hover {
|
||||
background-color: var(--bg);
|
||||
}
|
||||
|
||||
.hover\:bg-\[--bg\&\]:hover {
|
||||
background-color: var(--bg&);
|
||||
}
|
||||
|
||||
.active\:translate-y-1:active {
|
||||
--tw-translate-y: 0.25rem;
|
||||
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
||||
}
|
||||
|
||||
.active\:border-b:active {
|
||||
border-bottom-width: 1px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.dark\:text-green-500 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(34 197 94 / var(--tw-text-opacity));
|
||||
}
|
||||
}
|
15
examples/use_favicon/tailwind.config.js
Normal file
15
examples/use_favicon/tailwind.config.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: {
|
||||
files: ["*.html", "./src/**/*.rs", "../../src/docs/**/*.rs"],
|
||||
},
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
corePlugins: {
|
||||
preflight: false,
|
||||
},
|
||||
plugins: [
|
||||
require('@tailwindcss/forms'),
|
||||
],
|
||||
}
|
|
@ -12,6 +12,7 @@ mod use_debounce_fn;
|
|||
#[cfg(web_sys_unstable_apis)]
|
||||
mod use_element_size;
|
||||
mod use_event_listener;
|
||||
mod use_favicon;
|
||||
mod use_media_query;
|
||||
mod use_mouse;
|
||||
mod use_preferred_contrast;
|
||||
|
@ -31,6 +32,7 @@ pub use use_debounce_fn::*;
|
|||
#[cfg(web_sys_unstable_apis)]
|
||||
pub use use_element_size::*;
|
||||
pub use use_event_listener::*;
|
||||
pub use use_favicon::*;
|
||||
pub use use_media_query::*;
|
||||
pub use use_mouse::*;
|
||||
pub use use_preferred_contrast::*;
|
||||
|
|
127
src/use_favicon.rs
Normal file
127
src/use_favicon.rs
Normal file
|
@ -0,0 +1,127 @@
|
|||
use crate::watch;
|
||||
use default_struct_builder::DefaultBuilder;
|
||||
use leptos::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
/// Reactive favicon.
|
||||
///
|
||||
/// ## Demo
|
||||
///
|
||||
/// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/use_favicon)
|
||||
///
|
||||
/// ## Usage
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos::*;
|
||||
/// # use leptos_use::use_favicon;
|
||||
/// #
|
||||
/// # #[component]
|
||||
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||||
/// #
|
||||
/// let (icon, set_icon) = use_favicon(cx);
|
||||
///
|
||||
/// set_icon(Some("dark.png".to_string())); // change current icon
|
||||
/// #
|
||||
/// # view! { cx, }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// ## Passing a Source Signal
|
||||
///
|
||||
/// You can pass a `Signal` to [`use_favicon_with_options`]. Change from the source signal will be
|
||||
/// reflected in your favicon automatically.
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos::*;
|
||||
/// # use leptos_use::{use_favicon_with_options, UseFaviconOptions, use_preferred_dark};
|
||||
/// #
|
||||
/// # #[component]
|
||||
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||||
/// #
|
||||
/// let is_dark = use_preferred_dark(cx);
|
||||
///
|
||||
/// let (icon, _) = use_favicon_with_options(
|
||||
/// cx,
|
||||
/// UseFaviconOptions::default().new_icon(
|
||||
/// Signal::derive(cx, move || {
|
||||
/// Some((if is_dark() { "dark.png" } else { "light.png" }).to_string())
|
||||
/// }),
|
||||
/// )
|
||||
/// );
|
||||
/// #
|
||||
/// # view! { cx, }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
pub fn use_favicon(cx: Scope) -> (ReadSignal<Option<String>>, WriteSignal<Option<String>>) {
|
||||
use_favicon_with_options(cx, UseFaviconOptions::default())
|
||||
}
|
||||
|
||||
/// Version of [`use_favicon`] that accepts a `UseFaviconOptions`. See [`use_favicon`] for more details.
|
||||
pub fn use_favicon_with_options(
|
||||
cx: Scope,
|
||||
options: UseFaviconOptions,
|
||||
) -> (ReadSignal<Option<String>>, WriteSignal<Option<String>>) {
|
||||
let UseFaviconOptions {
|
||||
new_icon,
|
||||
base_url,
|
||||
rel,
|
||||
} = options;
|
||||
|
||||
let link_selector = format!("link[rel*=\"{rel}\"]");
|
||||
|
||||
let (favicon, set_favicon) = create_signal(cx, new_icon.get_untracked());
|
||||
|
||||
if matches!(&new_icon, MaybeSignal::Dynamic(_)) {
|
||||
create_effect(cx, move |_| set_favicon(new_icon.get()));
|
||||
}
|
||||
|
||||
let apply_icon = move |icon: &String| {
|
||||
if let Some(head) = document().head() {
|
||||
if let Ok(links) = head.query_selector_all(&link_selector) {
|
||||
let href = format!("{base_url}{icon}");
|
||||
|
||||
for i in 0..links.length() {
|
||||
let node = links.get(i).expect("checked length");
|
||||
let link: web_sys::HtmlLinkElement = node.unchecked_into();
|
||||
link.set_href(&href);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let _ = watch(cx, favicon, move |new_icon, prev_icon, _| {
|
||||
if Some(new_icon) != prev_icon {
|
||||
if let Some(new_icon) = new_icon {
|
||||
apply_icon(new_icon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
(favicon, set_favicon)
|
||||
}
|
||||
|
||||
/// Options for [`use_favicon_with_options`].
|
||||
#[derive(DefaultBuilder)]
|
||||
pub struct UseFaviconOptions {
|
||||
/// New input favicon. Can be a `Signal` in which case updates will change the favicon. Defaults to None.
|
||||
#[builder(into)]
|
||||
new_icon: MaybeSignal<Option<String>>,
|
||||
|
||||
/// Base URL of the favicon. Defaults to "".
|
||||
#[builder(into)]
|
||||
base_url: String,
|
||||
/// Rel attribute of the <link> tag. Defaults to "icon".
|
||||
#[builder(into)]
|
||||
rel: String,
|
||||
}
|
||||
|
||||
impl Default for UseFaviconOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
new_icon: Default::default(),
|
||||
base_url: "".to_string(),
|
||||
rel: "icon".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue