Skip to content

Commit d3e194e

Browse files
authored
Merge pull request #119 from dev-five-git/color-schema
Add color schema
2 parents 29f24cd + 6db4317 commit d3e194e

9 files changed

+44
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Add color schema

bindings/devup-ui-wasm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ mod tests {
235235

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

bindings/devup-ui-wasm/src/snapshots/devup_ui_wasm__tests__deserialize_theme.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: bindings/devup-ui-wasm/src/lib.rs
33
expression: theme.to_css()
44
---
5-
":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}}"
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.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}}"

libs/sheet/src/snapshots/sheet__theme__tests__to_css_from_theme-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: libs/sheet/src/theme.rs
33
expression: theme.to_css()
44
---
5-
":root{--primary:#000;}\n:root[data-theme=dark]{--primary:#000;}\n"
5+
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#000;}\n"

libs/sheet/src/snapshots/sheet__theme__tests__to_css_from_theme-3.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: libs/sheet/src/theme.rs
33
expression: theme.to_css()
44
---
5-
":root{--primary:#000;}\n:root[data-theme=b]{--primary:#000;}\n"
5+
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=b]{color-scheme:dark;--primary:#000;}\n"

libs/sheet/src/snapshots/sheet__theme__tests__to_css_from_theme-4.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: libs/sheet/src/theme.rs
33
expression: theme.to_css()
44
---
5-
":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"
5+
":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"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: libs/sheet/src/theme.rs
3+
expression: theme.to_css()
4+
---
5+
":root{--primary:#000;}\n"

libs/sheet/src/snapshots/sheet__theme__tests__to_css_from_theme.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: libs/sheet/src/theme.rs
33
expression: theme.to_css()
44
---
5-
":root{--primary:#000;}\n:root[data-theme=dark]{--primary:#000;}\n"
5+
":root{color-scheme:light;--primary:#000;}\n:root[data-theme=dark]{color-scheme:dark;--primary:#000;}\n"

libs/sheet/src/theme.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,29 @@ impl Theme {
152152
});
153153
col
154154
};
155+
let single_theme = entries.len() <= 1;
155156
for (theme_name, theme_properties) in entries {
156157
if let Some(theme_key) = if *theme_name == *default_theme_key {
157158
None
158159
} else {
159160
Some(theme_name)
160161
} {
161-
theme_declaration
162-
.push_str(format!(":root[data-theme={}]{{", theme_key).as_str());
162+
theme_declaration.push_str(
163+
format!(":root[data-theme={}]{{{}", theme_key, "color-scheme:dark;")
164+
.as_str(),
165+
);
163166
} else {
164-
theme_declaration.push_str(":root{");
167+
theme_declaration.push_str(
168+
format!(
169+
":root{{{}",
170+
if single_theme {
171+
""
172+
} else {
173+
"color-scheme:light;"
174+
}
175+
)
176+
.as_str(),
177+
);
165178
}
166179
for (prop, value) in theme_properties.0.iter() {
167180
theme_declaration.push_str(format!("--{}:{};", prop, value).as_str());
@@ -278,7 +291,7 @@ mod tests {
278291
let css = theme.to_css();
279292
assert_eq!(
280293
css,
281-
":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}}"
294+
":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}}"
282295
);
283296

284297
assert_eq!(Theme::default().to_css(), "");
@@ -386,6 +399,17 @@ mod tests {
386399
}),
387400
);
388401
assert_debug_snapshot!(theme.to_css());
402+
403+
let mut theme = Theme::default();
404+
theme.add_color_theme(
405+
"light",
406+
ColorTheme({
407+
let mut map = HashMap::new();
408+
map.insert("primary".to_string(), "#000".to_string());
409+
map
410+
}),
411+
);
412+
assert_debug_snapshot!(theme.to_css());
389413
}
390414

391415
#[test]

0 commit comments

Comments
 (0)