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/modern-sites-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Fix media query issue
1 change: 1 addition & 0 deletions libs/css/src/style_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ mod tests {
#[case("&:selected", 4)]
#[case("&:disabled", 5)]
#[case("&:not-exist", 99)]
#[case("&:not-exist, &:hover", 0)]
#[case(":root[data-theme=dark] &:hover", 0)]
#[case(":root[data-theme=dark] &:focus-visible", 1)]
#[case(":root[data-theme=dark] &:focus", 2)]
Expand Down
19 changes: 10 additions & 9 deletions libs/extractor/src/css_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ pub fn css_to_style<'a>(
let sel = input[..start].trim().to_string();
if sel.starts_with("@media") {
Some(StyleSelector::Media {
query: sel.replace(" ", "")["@media".len()..].to_string(),
query: sel.replace(" ", "").replace("and(", "and (")["@media".len()..]
.to_string(),
selector: None,
})
} else {
Expand Down Expand Up @@ -268,11 +269,11 @@ mod tests {
}",
vec![
("border", "1px solid #000", Some(StyleSelector::Media {
query: "(min-width:768px)and(max-width:1024px)".to_string(),
query: "(min-width:768px)and (max-width:1024px)".to_string(),
selector: None,
})),
("color", "#FFF", Some(StyleSelector::Media {
query: "(min-width:768px)and(max-width:1024px)".to_string(),
query: "(min-width:768px)and (max-width:1024px)".to_string(),
selector: None,
})),
("border", "1px solid #000", Some(StyleSelector::Media {
Expand Down Expand Up @@ -338,19 +339,19 @@ mod tests {
}",
vec![
("border", "1px solid #FFF", Some(StyleSelector::Media {
query: "(max-width:768px)and(min-width:480px)".to_string(),
query: "(max-width:768px)and (min-width:480px)".to_string(),
selector: None,
})),
("color", "#FFF", Some(StyleSelector::Media {
query: "(max-width:768px)and(min-width:480px)".to_string(),
query: "(max-width:768px)and (min-width:480px)".to_string(),
selector: None,
})),
("border", "1px solid #000", Some(StyleSelector::Media {
query: "(max-width:768px)and(min-width:480px)".to_string(),
query: "(max-width:768px)and (min-width:480px)".to_string(),
selector: Some("&:hover".to_string()),
})),
("color", "#000", Some(StyleSelector::Media {
query: "(max-width:768px)and(min-width:480px)".to_string(),
query: "(max-width:768px)and (min-width:480px)".to_string(),
selector: Some("&:hover".to_string()),
})),
("border", "1px solid #FFF", Some(StyleSelector::Media {
Expand Down Expand Up @@ -392,11 +393,11 @@ mod tests {
selector: None,
})),
("border", "1px solid #000", Some(StyleSelector::Media {
query: "(max-width:768px)and(min-width:480px)".to_string(),
query: "(max-width:768px)and (min-width:480px)".to_string(),
selector: None,
})),
("color", "#000", Some(StyleSelector::Media {
query: "(max-width:768px)and(min-width:480px)".to_string(),
query: "(max-width:768px)and (min-width:480px)".to_string(),
selector: None,
})),
]
Expand Down
20 changes: 13 additions & 7 deletions libs/sheet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl ExtractStyle for StyleSheetProperty {
merge_selector(&self.class_name, self.selector.as_ref()),
multi
.into_iter()
.map(|prop| format!("{}:{};", prop, convert_theme_variable_value(&self.value)))
.map(|prop| format!("{}:{}", prop, convert_theme_variable_value(&self.value)))
.collect::<Vec<String>>()
.join("")
.join(";")
),
}
}
Expand Down Expand Up @@ -368,7 +368,7 @@ impl StyleSheet {
.join("");
css.push_str(
if let Some(break_point) = break_point {
format!("\n@media (min-width:{break_point}px){{{inner_css}}}")
format!("@media(min-width:{break_point}px){{{inner_css}}}")
} else {
inner_css
}
Expand All @@ -384,7 +384,7 @@ impl StyleSheet {
.join("");
css.push_str(
if let Some(break_point) = break_point {
format!("\n@media (min-width:{break_point}px){{{inner_css}}}")
format!("@media(min-width:{break_point}px){{{inner_css}}}")
} else {
inner_css
}
Expand All @@ -399,11 +399,17 @@ impl StyleSheet {
.join("");
css.push_str(
if let Some(break_point) = break_point {
format!("@media(min-width:{break_point}px)and {media}{{{inner_css}}}")
} else {
format!(
"\n@media (min-width:{break_point}px) and {media}{{{inner_css}}}"
"@media{}{{{}}}",
if media.starts_with("(") {
media.clone()
} else {
format!(" {media}")
},
inner_css.as_str()
)
} else {
format!("\n@media {}{{{}}}", media, inner_css.as_str())
}
.as_str(),
);
Expand Down
2 changes: 1 addition & 1 deletion libs/sheet/src/snapshots/sheet__tests__create_css-3.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:768px){.test{margin-left:40px;margin-right:40px;}.test{margin-top:40px;margin-bottom:40px;}}"
"@media(min-width:768px){.test{margin-left:40px;margin-right:40px}.test{margin-top:40px;margin-bottom:40px}}"
2 changes: 1 addition & 1 deletion libs/sheet/src/snapshots/sheet__tests__create_css.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{margin-left:40px;margin-right:40px;}}"
"@media(min-width:480px){.test{margin-left:40px;margin-right:40px}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{background:some}.test{background-color:red}}"
"@media(min-width:480px){.test{background:some}.test{background-color:red}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{background-color:red}}\n@media (min-width:480px){.test{background:some}}"
"@media(min-width:480px){.test{background-color:red}}@media(min-width:480px){.test{background:some}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){div{background-color:red}}"
"@media(min-width:480px){div{background-color:red}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){div{background-color:red}}\n@media (min-width:768px){div{background-color:blue}}"
"@media(min-width:480px){div{background-color:red}}@media(min-width:768px){div{background-color:blue}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){div{background-color:blue}}div{background-color:red}"
"@media(min-width:480px){div{background-color:blue}}div{background-color:red}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
".test{display:flex}.test{display:none}\n@media (min-width:768px){.test{display:flex}}"
".test{display:flex}.test{display:none}@media(min-width:768px){.test{display:flex}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{background-color:some}}\n@media (min-width:480px){.test:hover{background-color:red}}"
"@media(min-width:480px){.test{background-color:some}}@media(min-width:480px){.test:hover{background-color:red}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{background-color:red}.test:hover{background-color:some}}"
"@media(min-width:480px){.test{background-color:red}.test:hover{background-color:some}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{background:some}.test{background-color:red}}"
"@media(min-width:480px){.test{background:some}.test{background-color:red}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){.test{background-color:some}.test:hover{background-color:red}}"
"@media(min-width:480px){.test{background-color:some}.test:hover{background-color:red}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
".test{margin-top:40px;margin-bottom:40px;}\n@media print{.test{margin-left:40px;margin-right:40px;}}"
".test{margin-top:40px;margin-bottom:40px}@media print{.test{margin-left:40px;margin-right:40px}}"
2 changes: 1 addition & 1 deletion libs/sheet/src/snapshots/sheet__tests__print_selector.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media print{.test{margin-left:40px;margin-right:40px;}.test{margin-top:40px;margin-bottom:40px;}}\n@media (min-width:480px) and print{.test{margin-left:40px;margin-right:40px;}.test{margin-top:40px;margin-bottom:40px;}}"
"@media print{.test{margin-left:40px;margin-right:40px}.test{margin-top:40px;margin-bottom:40px}}@media(min-width:480px)and print{.test{margin-left:40px;margin-right:40px}.test{margin-top:40px;margin-bottom:40px}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:480px){*[role=group]:hover .test{margin-left:40px;margin-right:40px;}}\n@media (min-width:768px){*[role=group]:hover .test{margin-left:50px;margin-right:50px;}}"
"@media(min-width:480px){*[role=group]:hover .test{margin-left:40px;margin-right:40px}}@media(min-width:768px){*[role=group]:hover .test{margin-left:50px;margin-right:50px}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
".test{margin-left:40px;margin-right:40px;}\n@media (min-width:480px){.test{margin-left:40px;margin-right:40px;}.test{margin-left:44px;margin-right:44px;}}\n@media (min-width:480px){.test{margin-left:50px;margin-right:50px;}}.test{margin-left:70px;margin-right:70px;}\n@media (min-width:480px){.test{margin-left:60px;margin-right:60px;}}"
".test{margin-left:40px;margin-right:40px}@media(min-width:480px){.test{margin-left:40px;margin-right:40px}.test{margin-left:44px;margin-right:44px}}@media(min-width:480px){.test{margin-left:50px;margin-right:50px}}.test{margin-left:70px;margin-right:70px}@media(min-width:480px){.test{margin-left:60px;margin-right:60px}}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
".test{margin-left:41px;margin-right:41px;}.test{margin-left:42px;margin-right:42px;}:root[data-theme=light] .test{margin-left:50px;margin-right:50px;}:root[data-theme=light] .test{margin-left:51px;margin-right:51px;}"
".test{margin-left:41px;margin-right:41px}.test{margin-left:42px;margin-right:42px}:root[data-theme=light] .test{margin-left:50px;margin-right:50px}:root[data-theme=light] .test{margin-left:51px;margin-right:51px}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
":root[data-theme=light] .test:hover{margin-left:50px;margin-right:50px;}:root[data-theme=light] .test:active{margin-left:50px;margin-right:50px;}"
":root[data-theme=light] .test:hover{margin-left:50px;margin-right:50px}:root[data-theme=light] .test:active{margin-left:50px;margin-right:50px}"
2 changes: 1 addition & 1 deletion libs/sheet/src/snapshots/sheet__tests__theme_selector.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
":root[data-theme=dark] .test{margin-left:40px;margin-right:40px;}:root[data-theme=light] .test{margin-left:50px;margin-right:50px;}:root[data-theme=dark] .test{margin-top:40px;margin-bottom:40px;}"
":root[data-theme=dark] .test{margin-left:40px;margin-right:40px}:root[data-theme=light] .test{margin-left:50px;margin-right:50px}:root[data-theme=dark] .test{margin-top:40px;margin-bottom:40px}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: libs/sheet/src/lib.rs
expression: sheet.create_css()
---
"\n@media (min-width:1280px){.test{margin-left:40px;margin-right:40px;}}"
"@media(min-width:1280px){.test{margin-left:40px;margin-right:40px}}"