make_styles!() { /* proc-macro */ }
Expand description
Introduces dynamic CSS code which can be injected.
ยงExample
#[derive(Clone)]
struct MyTheme {
pub primary_color: String,
pub header_color: String,
}
impl css_in_rs::Theme for MyTheme {
/* ... */
}
make_styles! {
(theme: MyTheme) -> MyClasses {
"*" {
padding: "0px",
},
text {
margin: "10px",
color: theme.primary_color,
},
header {
margin: "20px",
color: theme.header_color,
},
}
}
This essentially expands to
// Generated code; expanded form of the macro above
struct MyClasses {
pub text: String,
pub header: String,
}
impl ::css_in_rs::Classes for MyClasses {
/* ... */
}
You can inject this style into the DOM using a StyleProvider
(see
css-in-rs crate). It will hand you a MyClasses
instance with uniquely
generated classnames (usually something like css-17
).