Skip to content

Commit

Permalink
Revamp Color Theme and Docs/Features (#38)
Browse files Browse the repository at this point in the history
* feat: debounce

* fix: fmt

* revision: debounce

* fix: clippy

* revision: docs, compile errors

* revision: debounce

* fix: fmt

* revision: use clone

* revision: remove clone

* revision: formatting

* revision: manually partialeq

* progress: stuff

Saving progress as there is a tornado-capable storm coming

* revision: docs, clippy, etc

* fix: example, features

* remove: old code

* revision: listening

* fix: doc reference

* revision: add partialeq

* revision: change target cfgs

* update: dioxus-signals

* fix: window_size

* fix: readme typo

* fix: signal life
  • Loading branch information
DogeDark committed Jun 16, 2024
1 parent d49812f commit 2fbad1b
Show file tree
Hide file tree
Showing 30 changed files with 377 additions and 236 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sudo apt-get install xorg-dev
You can add `dioxus-sdk` to your application by adding it to your dependencies.
```toml
[dependencies]
dioxus-sdk= { version = "0.5", features = [] }
dioxus-sdk = { version = "0.5", features = [] }
```

## License
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Examples

### [`color_scheme`](./color_scheme/)
Learn how to use `use_preferred_color_scheme`.
### [`system_theme`](./system_theme/)
Learn how to use `use_system_theme`.

### [`geolocation`](./geolocation/)
Learn how to use the `geolocation` abstraction.
Expand Down
14 changes: 0 additions & 14 deletions examples/color_scheme/Cargo.toml

This file was deleted.

42 changes: 0 additions & 42 deletions examples/color_scheme/Dioxus.toml

This file was deleted.

26 changes: 0 additions & 26 deletions examples/color_scheme/src/main.rs

This file was deleted.

1 change: 0 additions & 1 deletion examples/storage/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dioxus::prelude::*;
use dioxus_router::prelude::*;
use dioxus_sdk::storage::*;

fn main() {
Expand Down
12 changes: 12 additions & 0 deletions examples/system_theme/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "color_scheme"
version = "0.1.0"
edition = "2021"

[dependencies]
dioxus-sdk = { workspace = true, features = ["system_theme"] }
dioxus = { workspace = true }

[features]
web = ["dioxus/web"]
desktop = ["dioxus/desktop"]
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions examples/system_theme/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use dioxus::prelude::*;
use dioxus_sdk::theme::use_system_theme;

fn main() {
launch(App);
}

#[component]
fn App() -> Element {
let theme = use_system_theme();

let theme_text = match theme() {
Ok(theme) => rsx! { h3 { "Your system theme is {theme}." } },
Err(err) => rsx! { h3 {"Error getting system theme: {err:?}" } },
};

rsx!(
div {
style: "text-align: center;",
h1 { "🌗 Dioxus 🚀" }
{theme_text}
}

Other {}
)
}

#[component]
fn Other() -> Element {
let theme = use_system_theme();

let theme_text = match theme() {
Ok(theme) => rsx! { h3 { "Your system theme x2 is {theme}." } },
Err(err) => rsx! { h3 {"Error getting system theme: {err:?}" } },
};

rsx!(
div {
style: "text-align: center;",
{theme_text}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
dioxus-sdk = { workspace = true, features = ["use_window_size"] }
dioxus-sdk = { workspace = true, features = ["window_size"] }
dioxus = { workspace = true }

[features]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use dioxus::prelude::*;
use dioxus_sdk::utils::window::{get_window_size, use_window_size};

fn main() {
launch(app);
launch(App);
}

fn app() -> Element {
#[component]
fn App() -> Element {
let initial_size = use_signal(get_window_size);
let window_size = use_window_size();

rsx!(
div { style: "text-align: center;",
div {
style: "text-align: center;",
h1 { "↕️ Window Size Utilities ↔️" }
h3 { "Initial Size" }
p { "Width: {initial_size().width}" }
Expand Down
35 changes: 23 additions & 12 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ geolocation = [
"web-sys/PositionOptions",
"dep:wasm-bindgen",
]
color_scheme = [
system_theme = [
# Shared
"dep:futures",

# Desktop (not linux)
"dep:dioxus-desktop",

# Wasm
"web-sys/Window",
"web-sys/MediaQueryList",
"dep:wasm-bindgen",
"dep:wasm-bindgen-futures",
]
use_window_size = [
window_size = [
# Shared
"dep:futures-util",

Expand Down Expand Up @@ -70,6 +76,7 @@ storage = [
"dep:tokio",
"tokio/sync",
"dep:yazi",
"web-sys/Storage",
"web-sys/StorageEvent",
"dep:serde",
"dep:futures-util",
Expand All @@ -94,21 +101,24 @@ timing = [

# CI testing
wasm-testing = [
"color_scheme",
"system_theme",
"geolocation",
"channel",
"use_window_size",
"window_size",
"timing",
"i18n",
"storage",
]
desktop-testing = [
"system_theme",
"clipboard",
"notifications",
"geolocation",
"channel",
"use_window_size",
"window_size",
"i18n",
"timing",
"storage",
]


Expand All @@ -131,7 +141,7 @@ notify-rust = { version = "4.8.0", optional = true }
uuid = { version = "1.3.2", optional = true }
async-broadcast = { version = "0.5.1", optional = true }

# Used by: geolocation, storage
# Used by: geolocation, storage, timing, window_size, system_theme
futures = { version = "0.3.28", features = ["std"], optional = true }
futures-util = { version = "0.3.28", optional = true }

Expand All @@ -144,7 +154,7 @@ unic-langid = { version = "0.9.1", features = ["serde"], optional = true }
rustc-hash = { version = "1.1.0", optional = true }
postcard = { version = "1.0.2", features = ["use-std"], optional = true }
once_cell = { version = "1.17.0", optional = true }
dioxus-signals = { version = "0.5.0-alpha.2", features = [
dioxus-signals = { version = "0.5.1", features = [
"serialize",
], optional = true }

Expand All @@ -170,7 +180,7 @@ windows = { version = "0.48.0", optional = true }

[target.'cfg(target_family = "wasm")'.dependencies]

# Used by: color_scheme, geolocation, use_window_size
# Used by: color_scheme, geolocation, window_size
web-sys = { version = "0.3.60", optional = true }
wasm-bindgen = { version = "0.2.87", optional = true }
wasm-bindgen-futures = { version = "0.4.35", optional = true }
Expand All @@ -184,18 +194,19 @@ uuid = { version = "1.3.2", features = ["js"] }
# Used by: timing
gloo-timers = { version = "0.3.0", optional = true, features = ["futures"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(target_family = "wasm"))'.dependencies]

# Used by: storage
directories = { version = "4.0.1", optional = true }

# Used by: use_window_size
# Used by: window_size, system_theme
dioxus-desktop = { workspace = true, optional = true }

# # # # #
# Docs. #
# # # # #

[package.metadata.docs.rs]
default-target = "x86_64-pc-windows-msvc"
targets = ["x86_64-pc-windows-msvc", "wasm32-unknown-unknown"]
no-default-features = true
features = ["desktop-testing"]
features = ["desktop-testing", "wasm-testing"]
2 changes: 2 additions & 0 deletions sdk/src/clipboard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Interact with the clipboard.

cfg_if::cfg_if! {
if #[cfg(not(target_family = "wasm"))] {
mod use_clipboard;
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/clipboard/use_clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl UseClipboard {
///
/// # Examples
///
/// ```ignore
/// ```rust,ignore
/// use dioxus_sdk::clipboard::use_clipboard;
///
/// // Get a handle to the clipboard
Expand Down
8 changes: 0 additions & 8 deletions sdk/src/color_scheme/mod.rs

This file was deleted.

Loading

0 comments on commit 2fbad1b

Please sign in to comment.