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

Add placeholder, maxLength, minLength to special properties
13 changes: 13 additions & 0 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ mod tests {
}
)
.unwrap());

reset_class_map();
assert_debug_snapshot!(extract(
"test.tsx",
r#"import {Input} from '@devup-ui/core'
<Input placeholder="a" maxLength="b" minLength="c" />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap());
}
#[test]
#[serial]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: libs/extractor/src/lib.rs
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()"
---
ExtractOutput {
styles: [],
code: "<input placeholder=\"a\" maxLength=\"b\" minLength=\"c\" />;\n",
}
34 changes: 25 additions & 9 deletions libs/extractor/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use once_cell::sync::Lazy;
use std::collections::HashSet;

/// Convert a value to a pixel value
pub fn convert_value(value: &str) -> String {
let value = value.to_string();
Expand All @@ -8,18 +11,31 @@ pub fn convert_value(value: &str) -> String {
value
}

static SPECIAL_PROPERTIES: Lazy<HashSet<&str>> = Lazy::new(|| {
let mut set = HashSet::<&str>::new();
for prop in [
"style",
"className",
"role",
"ref",
"key",
"alt",
"src",
"children",
"placeholder",
"maxLength",
"minLength",
] {
set.insert(prop);
}
set
});

pub fn is_special_property(name: &str) -> bool {
name == "style"
|| name == "className"
|| name.starts_with("on")
name.starts_with("on")
|| name.starts_with("data-")
|| name.starts_with("aria-")
|| name == "role"
|| name == "ref"
|| name == "key"
|| name == "alt"
|| name == "src"
|| name == "children"
|| SPECIAL_PROPERTIES.contains(name)
}

#[cfg(test)]
Expand Down
Loading