Skip to content

Commit eecfdac

Browse files
Add IntoAttributeValue implementation for Style (#20)
* Add IntoAttributeValue impl / Add test * Fix cargo fmt * Cleanup --------- Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
1 parent 241b099 commit eecfdac

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/leptos-style/src/style.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
};
55

66
use indexmap::IndexMap;
7-
use leptos::tachys::html::style::IntoStyle;
7+
use leptos::{attr::IntoAttributeValue, tachys::html::style::IntoStyle};
88

99
fn style_map_to_string(map: &IndexMap<String, Option<String>>) -> String {
1010
map.iter()
@@ -181,6 +181,14 @@ impl<const N: usize> From<[(String, String); N]> for Style {
181181
}
182182
}
183183

184+
impl IntoAttributeValue for Style {
185+
type Output = String;
186+
187+
fn into_attribute_value(self) -> Self::Output {
188+
self.to_string()
189+
}
190+
}
191+
184192
impl IntoStyle for Style {
185193
type AsyncOutput = Self;
186194
type State = (leptos::tachys::renderer::types::Element, Self);
@@ -332,4 +340,17 @@ mod tests {
332340
Style::from([("color", None::<String>)]).with_defaults([("color", None::<String>)]),
333341
);
334342
}
343+
344+
#[test]
345+
fn test_into_attribute_value() {
346+
assert_eq!(
347+
Style::from("color: red; background-color: blue;").into_attribute_value(),
348+
"color: red; background-color: blue;"
349+
);
350+
351+
assert_eq!(
352+
Style::from([("color", "red"), ("background-color", "blue")]).into_attribute_value(),
353+
"color: red; background-color: blue;"
354+
);
355+
}
335356
}

0 commit comments

Comments
 (0)