Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/polite-points-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Add color schema
2 changes: 1 addition & 1 deletion bindings/devup-ui-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ mod tests {

assert_eq!(
get_css().unwrap(),
":root{--primary:#FFF;}\n:root[data-theme=dark]{--primary:#000;}\n"
":root{color-scheme:light;--primary:#FFF;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#000;}\n"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: bindings/devup-ui-wasm/src/lib.rs
expression: theme.to_css()
---
":root{--primary:#000;}\n:root[data-theme=dark]{--primary:#fff;}\n.typo-default{font-family:Arial;font-size:16px;font-weight:400;line-height:1.5;letter-spacing:0.5em}\n@media (min-width:480px){.typo-default{font-family:Arial;font-size:24px;font-weight:400;line-height:1.5;letter-spacing:0.5em}}\n@media (min-width:768px){.typo-default{font-family:Arial;font-size:24px;line-height:1.5;letter-spacing:0.5em}}"
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#fff;}\n.typo-default{font-family:Arial;font-size:16px;font-weight:400;line-height:1.5;letter-spacing:0.5em}\n@media (min-width:480px){.typo-default{font-family:Arial;font-size:24px;font-weight:400;line-height:1.5;letter-spacing:0.5em}}\n@media (min-width:768px){.typo-default{font-family:Arial;font-size:24px;line-height:1.5;letter-spacing:0.5em}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/theme.rs
expression: theme.to_css()
---
":root{--primary:#000;}\n:root[data-theme=dark]{--primary:#000;}\n"
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#000;}\n"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/theme.rs
expression: theme.to_css()
---
":root{--primary:#000;}\n:root[data-theme=b]{--primary:#000;}\n"
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=b]{color-scheme:dark;--primary:#000;}\n"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/theme.rs
expression: theme.to_css()
---
":root{--primary:#000;}\n:root[data-theme=a]{--primary:#000;}\n:root[data-theme=b]{--primary:#000;}\n:root[data-theme=c]{--primary:#000;}\n"
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=a]{color-scheme:dark;--primary:#000;}\n:root[data-theme=b]{color-scheme:dark;--primary:#000;}\n:root[data-theme=c]{color-scheme:dark;--primary:#000;}\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: libs/sheet/src/theme.rs
expression: theme.to_css()
---
":root{--primary:#000;}\n"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/theme.rs
expression: theme.to_css()
---
":root{--primary:#000;}\n:root[data-theme=dark]{--primary:#000;}\n"
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#000;}\n"
32 changes: 28 additions & 4 deletions libs/sheet/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,29 @@ impl Theme {
});
col
};
let single_theme = entries.len() <= 1;
for (theme_name, theme_properties) in entries {
if let Some(theme_key) = if *theme_name == *default_theme_key {
None
} else {
Some(theme_name)
} {
theme_declaration
.push_str(format!(":root[data-theme={}]{{", theme_key).as_str());
theme_declaration.push_str(
format!(":root[data-theme={}]{{{}", theme_key, "color-scheme:dark;")
.as_str(),
);
} else {
theme_declaration.push_str(":root{");
theme_declaration.push_str(
format!(
":root{{{}",
if single_theme {
""
} else {
"color-scheme:light;"
}
)
.as_str(),
);
}
for (prop, value) in theme_properties.0.iter() {
theme_declaration.push_str(format!("--{}:{};", prop, value).as_str());
Expand Down Expand Up @@ -278,7 +291,7 @@ mod tests {
let css = theme.to_css();
assert_eq!(
css,
":root{--primary:#000;}\n:root[data-theme=dark]{--primary:#fff;}\n.typo-default{font-family:Arial;font-size:16px;font-weight:400;line-height:1.5;letter-spacing:0.5}\n@media (min-width:480px){.typo-default{font-family:Arial;font-size:24px;font-weight:400;line-height:1.5;letter-spacing:0.5}.typo-default1{font-family:Arial;font-size:24px;font-weight:400;line-height:1.5;letter-spacing:0.5}}"
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#fff;}\n.typo-default{font-family:Arial;font-size:16px;font-weight:400;line-height:1.5;letter-spacing:0.5}\n@media (min-width:480px){.typo-default{font-family:Arial;font-size:24px;font-weight:400;line-height:1.5;letter-spacing:0.5}.typo-default1{font-family:Arial;font-size:24px;font-weight:400;line-height:1.5;letter-spacing:0.5}}"
);

assert_eq!(Theme::default().to_css(), "");
Expand Down Expand Up @@ -386,6 +399,17 @@ mod tests {
}),
);
assert_debug_snapshot!(theme.to_css());

let mut theme = Theme::default();
theme.add_color_theme(
"light",
ColorTheme({
let mut map = HashMap::new();
map.insert("primary".to_string(), "#000".to_string());
map
}),
);
assert_debug_snapshot!(theme.to_css());
}

#[test]
Expand Down