Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support style attribute #54

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Changes from 1 commit
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
66 changes: 46 additions & 20 deletions packages/lib/src/icon_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,56 @@ pub struct IconProps<T: IconShape + Clone + PartialEq + 'static> {
pub class: String,
/// An accessible, short-text description for the icon.
pub title: Option<String>,
/// The style of the `<svg>` element.
pub style: Option<String>,
}

/// Icon component which generates SVG elements
#[allow(non_snake_case)]
pub fn Icon<T: IconShape + Clone + PartialEq + 'static>(props: IconProps<T>) -> Element {
let (fill, stroke, stroke_width) = props.icon.fill_and_stroke(&props.fill);
rsx!(
svg {
class: "{props.class}",
height: "{props.height}",
width: "{props.width}",
view_box: "{props.icon.view_box()}",
xmlns: "{props.icon.xmlns()}",
fill,
stroke,
stroke_width,
stroke_linecap: "{props.icon.stroke_linecap()}",
stroke_linejoin: "{props.icon.stroke_linejoin()}",
if let Some(title_text) = props.title {
title {
"{title_text}"
}
},
{props.icon.child_elements()}
}
)
if let Some(style_text) = props.style {
rsx!(
svg {
class: "{props.class}",
style: "{style_text}",
height: "{props.height}",
width: "{props.width}",
view_box: "{props.icon.view_box()}",
xmlns: "{props.icon.xmlns()}",
fill,
stroke,
stroke_width,
stroke_linecap: "{props.icon.stroke_linecap()}",
stroke_linejoin: "{props.icon.stroke_linejoin()}",
if let Some(title_text) = props.title {
title {
"{title_text}"
}
},
{props.icon.child_elements()}
}
)
} else {
rsx!(
svg {
class: "{props.class}",
height: "{props.height}",
width: "{props.width}",
view_box: "{props.icon.view_box()}",
xmlns: "{props.icon.xmlns()}",
fill,
stroke,
stroke_width,
stroke_linecap: "{props.icon.stroke_linecap()}",
stroke_linejoin: "{props.icon.stroke_linejoin()}",
if let Some(title_text) = props.title {
title {
"{title_text}"
}
},
{props.icon.child_elements()}
}
)
}
wooden-worm marked this conversation as resolved.
Show resolved Hide resolved
}
Loading