Skip to content

Commit 8cf991d

Browse files
authored
Merge pull request #26 from dev-five-git/add-special-properties
Add some properties to special properties
2 parents b58f203 + fd1f519 commit 8cf991d

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

.changeset/dirty-wolves-destroy.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+
Add placeholder, maxLength, minLength to special properties

libs/extractor/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ mod tests {
168168
}
169169
)
170170
.unwrap());
171+
172+
reset_class_map();
173+
assert_debug_snapshot!(extract(
174+
"test.tsx",
175+
r#"import {Input} from '@devup-ui/core'
176+
<Input placeholder="a" maxLength="b" minLength="c" />
177+
"#,
178+
ExtractOption {
179+
package: "@devup-ui/core".to_string(),
180+
css_file: None
181+
}
182+
)
183+
.unwrap());
171184
}
172185
#[test]
173186
#[serial]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import {Input} from '@devup-ui/core'\n <Input placeholder=\"a\" maxLength=\"b\" minLength=\"c\" />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [],
7+
code: "<input placeholder=\"a\" maxLength=\"b\" minLength=\"c\" />;\n",
8+
}

libs/extractor/src/utils.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use once_cell::sync::Lazy;
2+
use std::collections::HashSet;
3+
14
/// Convert a value to a pixel value
25
pub fn convert_value(value: &str) -> String {
36
let value = value.to_string();
@@ -8,18 +11,31 @@ pub fn convert_value(value: &str) -> String {
811
value
912
}
1013

14+
static SPECIAL_PROPERTIES: Lazy<HashSet<&str>> = Lazy::new(|| {
15+
let mut set = HashSet::<&str>::new();
16+
for prop in [
17+
"style",
18+
"className",
19+
"role",
20+
"ref",
21+
"key",
22+
"alt",
23+
"src",
24+
"children",
25+
"placeholder",
26+
"maxLength",
27+
"minLength",
28+
] {
29+
set.insert(prop);
30+
}
31+
set
32+
});
33+
1134
pub fn is_special_property(name: &str) -> bool {
12-
name == "style"
13-
|| name == "className"
14-
|| name.starts_with("on")
35+
name.starts_with("on")
1536
|| name.starts_with("data-")
1637
|| name.starts_with("aria-")
17-
|| name == "role"
18-
|| name == "ref"
19-
|| name == "key"
20-
|| name == "alt"
21-
|| name == "src"
22-
|| name == "children"
38+
|| SPECIAL_PROPERTIES.contains(name)
2339
}
2440

2541
#[cfg(test)]

0 commit comments

Comments
 (0)