Skip to content

Commit

Permalink
Merge pull request #13 from palkerecsenyi/main
Browse files Browse the repository at this point in the history
Add role prop to icons
  • Loading branch information
finnbear authored Mar 13, 2024
2 parents 0189116 + 1b66984 commit 9a2e734
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() {

let width_regex = Regex::new(r##"[^-]width="[0-9a-z]*""##).unwrap();
let height_regex = Regex::new(r##"[^-]height="[0-9a-z]*""##).unwrap();
let role_regex = Regex::new(r##"[^-]role="[a-z]*""##).unwrap();
let class_regex = Regex::new(r##"class="[A-Za-z0-9-_ ]*""##).unwrap();
let text_regex = Regex::new(r##">(\s*[a-zA-Z.\-]+[a-zA-Z. \-]*)<"##).unwrap();
let title_regex = Regex::new(r##"<title>.+</title>"##).unwrap();
Expand Down Expand Up @@ -103,7 +104,10 @@ fn main() {
first_tag = width_regex.replace(&first_tag, "").into_owned();
}
if first_tag.contains(" height=") {
first_tag = height_regex.replace(&first_tag, "").into_owned()
first_tag = height_regex.replace(&first_tag, "").into_owned();
}
if first_tag.contains(" role=") {
first_tag = role_regex.replace(&first_tag, "").into_owned();
}

let remainder = title_regex.replace_all(&remainder, "").into_owned();
Expand All @@ -118,7 +122,7 @@ fn main() {
.into_owned();

let mut replacement = format!(
r#"xmlns="http://www.w3.org/2000/svg" data-license="{}" width={{width.clone()}} height={{height.clone()}} onclick={{onclick.clone()}} oncontextmenu={{oncontextmenu.clone()}} class={{class.clone()}} style={{style.clone()}}"#,
r#"xmlns="http://www.w3.org/2000/svg" data-license="{}" width={{width.clone()}} height={{height.clone()}} onclick={{onclick.clone()}} oncontextmenu={{oncontextmenu.clone()}} class={{class.clone()}} style={{style.clone()}} role={{role.clone()}}"#,
license
);

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub struct IconProps {
pub class: Classes,
/// For inline CSS.
#[prop_or(None)]
pub style: Option<AttrValue>,
pub style: Option<AttrValue>,
#[prop_or(None)]
pub role: Option<AttrValue>,
}

/// Renders a SVG icon. See [IconProps] for more information.
Expand Down Expand Up @@ -82,6 +84,7 @@ mod test {
oncontextmenu: None,
style: None,
title: None,
role: "presentation".into(),
});

let rendered = renderer.render().await;
Expand Down

0 comments on commit 9a2e734

Please sign in to comment.