Skip to content

Commit 06e875a

Browse files
authored
Merge pull request #138 from dev-five-git/selectors-in-theme-selector
Fix dark selector issue
2 parents 2067655 + 28c57b7 commit 06e875a

File tree

6 files changed

+122
-35
lines changed

6 files changed

+122
-35
lines changed

.changeset/neat-kiwis-teach.md

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+
Fix dark selector issue

Cargo.lock

Lines changed: 29 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/extractor/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
oxc_parser = "0.50.0"
8-
oxc_syntax = "0.50.0"
9-
oxc_span = "0.50.0"
10-
oxc_allocator = "0.50.0"
11-
oxc_ast = "0.50.0"
12-
oxc_codegen = "0.50.0"
7+
oxc_parser = "0.51.0"
8+
oxc_syntax = "0.51.0"
9+
oxc_span = "0.51.0"
10+
oxc_allocator = "0.51.0"
11+
oxc_ast = "0.51.0"
12+
oxc_codegen = "0.51.0"
1313
css = { path = "../css" }
1414
once_cell = "1.20.3"
1515

libs/extractor/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,27 @@ import {Button} from '@devup/ui'
21682168
}
21692169
)
21702170
.unwrap());
2171+
println!("=================");
2172+
2173+
reset_class_map();
2174+
assert_debug_snapshot!(extract(
2175+
"test.js",
2176+
r#"import {Box} from '@devup-ui/core'
2177+
<Box _hover={{bg:"white"}} _themeDark={{
2178+
selectors: {
2179+
'& :is(svg,img)': {
2180+
boxSize: '100%',
2181+
filter: 'brightness(0) invert(1)',
2182+
},
2183+
},
2184+
}} />
2185+
"#,
2186+
ExtractOption {
2187+
package: "@devup-ui/core".to_string(),
2188+
css_file: None
2189+
}
2190+
)
2191+
.unwrap());
21712192
}
21722193

21732194
#[test]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.js\",\nr#\"import {Box} from '@devup-ui/core'\n <Box _hover={{bg:\"white\"}} _themeDark={{\n selectors: {\n '& :is(svg,img)': {\n boxSize: '100%',\n filter: 'brightness(0) invert(1)',\n },\n },\n }} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "white",
11+
level: 0,
12+
selector: Some(
13+
Selector(
14+
"&:hover",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "boxSize",
23+
value: "100%",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
":root[data-theme=dark] & :is(svg,img)",
28+
),
29+
),
30+
style_order: None,
31+
},
32+
),
33+
Static(
34+
ExtractStaticStyle {
35+
property: "filter",
36+
value: "brightness(0) invert(1)",
37+
level: 0,
38+
selector: Some(
39+
Selector(
40+
":root[data-theme=dark] & :is(svg,img)",
41+
),
42+
),
43+
style_order: None,
44+
},
45+
),
46+
],
47+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"d0 d1 d2\" />;\n",
48+
}

libs/extractor/src/style_extractor.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,19 @@ pub fn extract_style_from_expression<'a>(
269269
None,
270270
&mut o.value,
271271
level,
272-
Some(&name.as_str().into()),
272+
Some(
273+
&if let Some(selector) = selector {
274+
format!(
275+
"{}{}",
276+
selector.to_string().split("&").collect::<Vec<_>>()[0],
277+
name.as_str()
278+
)
279+
} else {
280+
name
281+
}
282+
.as_str()
283+
.into(),
284+
),
273285
) {
274286
props.append(&mut styles);
275287
}

0 commit comments

Comments
 (0)