-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Minor changes and added
use_preferred_color_scheme
example (#2)
* Updated dioxus, clean up code and added use_preferred_color_scheme example * add readmes
- Loading branch information
Showing
9 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
target | ||
dist | ||
/Cargo.lock | ||
/.cargo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Examples | ||
|
||
### [`color_scheme`](./color_scheme/) | ||
Learn how to use `use_preferred_color_scheme`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "color_scheme" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
dioxus-std = { path="../../" } | ||
dioxus = "0.3" | ||
dioxus-web = "0.3" | ||
|
||
log = "0.4.6" | ||
|
||
# WebAssembly Debug | ||
wasm-logger = "0.2.0" | ||
console_error_panic_hook = "0.1.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[application] | ||
|
||
# App (Project) Name | ||
name = "color_scheme" | ||
|
||
# Dioxus App Default Platform | ||
# desktop, web, mobile, ssr | ||
default_platform = "web" | ||
|
||
# `build` & `serve` dist path | ||
out_dir = "dist" | ||
|
||
# resource (public) file folder | ||
asset_dir = "public" | ||
|
||
[web.app] | ||
|
||
# HTML title tag content | ||
title = "dioxus | ⛺" | ||
|
||
[web.watcher] | ||
|
||
# when watcher trigger, regenerate the `index.html` | ||
reload_html = true | ||
|
||
# which files or dirs will be watcher monitoring | ||
watch_path = ["src", "public"] | ||
|
||
# include `assets` in web platform | ||
[web.resource] | ||
|
||
# CSS style file | ||
style = [] | ||
|
||
# Javascript code file | ||
script = [] | ||
|
||
[web.resource.dev] | ||
|
||
# Javascript code file | ||
# serve: [dev-server] only | ||
script = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# color_scheme | ||
|
||
Learn how to use `use_preferred_color_scheme`. | ||
|
||
Run: | ||
|
||
```dioxus serve``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use dioxus::prelude::*; | ||
use dioxus_std::hooks::use_preferred_color_scheme; | ||
|
||
fn main() { | ||
// init debug tool for WebAssembly | ||
wasm_logger::init(wasm_logger::Config::default()); | ||
console_error_panic_hook::set_once(); | ||
|
||
dioxus_web::launch(app); | ||
} | ||
|
||
fn app(cx: Scope) -> Element { | ||
let color_scheme = use_preferred_color_scheme(cx); | ||
|
||
render!( | ||
div { | ||
style: "text-align: center;", | ||
h1 { "🌗 Dioxus 🚀" } | ||
if let Ok(color_scheme) = color_scheme { | ||
rsx!( | ||
h3 { "You preferred color scheme is {color_scheme:?}." } | ||
) | ||
} else { | ||
rsx!( | ||
h3 { "There was an error when reading your preferred color scheme."} | ||
) | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters