futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
371 stars 22 forks source link

str not converted into StyleSource implicitly #132

Closed 6-eyes closed 1 year ago

6-eyes commented 1 year ago

I am trying out stylist for the first time. As per the tutorials, i should be able to convert &str into the required type, but it produces the error given as:

the trait `From<&str>` is not implemented for `StyleSource`

The error. image

Following is my code.

use stylist::{yew::styled_component, Style};

#[styled_component(App)]
pub fn app() -> Html {    
    let style_str = "background-color: red;";
    let stylesheet = Style::new(style_str).unwrap();
    html! {
            <div class={stylesheet}>
                <h1>{"Hello World using stylesheet!"}</h1>
                <p>{"some more text..."}</p>
            </div>
    }
}  
WorldSEnder commented 1 year ago

Consider the css! macro available in a styled_component or the use_style! hook available in any function component.

Creating a style from a runtime string requires enabling the parser feature and is most of the time not what you want.