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

Simple style! tag doesn't work in either Functional or Class Component #3115

Closed
patientplatypus6 opened this issue Feb 5, 2023 · 3 comments
Labels

Comments

@patientplatypus6
Copy link

patientplatypus6 commented Feb 5, 2023

Here is the code (putting the style! component within the view function of the class component produces the same error). This example is taken from the example page here (https://docs.rs/yew-style-in-rs/latest/yew_style_in_rs/)

use yew::prelude::*;
use yew_style_in_rs::*;

#[function_component]
pub fn Mdpages() -> Html {
    style! {
        let css = css! {r#"
            border: solid green 1px;
            width: 100%;
            height: 150px;
            text-align: center;
            box-sizing: border-box;

            & > p {
                background: white;
            }
        "#};
    }
    html!{
            <div class={classes!(css)}>
                <p>{"compile time static css"}</p>
            </div>
    }
}

And here is the error -

error[E0277]: the trait bound `Classes: From<yew_style_in_rs::css::StyleId>` is not satisfied
  --> src/pages/mdpages.rs:22:34
   |
22 |             <div class={classes!(css)}>
   |                                  ^^^ the trait `From<yew_style_in_rs::css::StyleId>` is not implemented for `Classes`
   |
   = help: the following other types implement trait `From<T>`:
             <Classes as From<&'static str>>
             <Classes as From<&Option<T>>>
             <Classes as From<&String>>
             <Classes as From<&[T]>>
             <Classes as From<Cow<'static, str>>>
             <Classes as From<Option<T>>>
             <Classes as From<String>>
             <Classes as From<Vec<T>>>
   = note: required for `yew_style_in_rs::css::StyleId` to implement `Into<Classes>`
note: required by a bound in `Classes::push`
  --> /Users/peterweyand/.cargo/registry/src/github.com-1ecc6299db9ec823/yew-0.20.0/src/html/classes.rs:58:20
   |
58 |     pub fn push<T: Into<Self>>(&mut self, class: T) {
   |                    ^^^^^^^^^^ required by this bound in `Classes::push`

Some errors have detailed explanations: E0277, E0423.
For more information about an error, try `rustc --explain E0277`.
warning: `yew_page` (lib) generated 4 warnings
error: could not compile `yew_page` due to 2 previous errors; 4 warnings emitted
2023-02-05T03:08:40.774108Z ERROR ❌ error
error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: error during cargo build execution
    2: cargo call returned a bad status
2023-02-05T03:08:40.774976Z  INFO 📡 serving static assets at -> /
2023-02-05T03:08:40.775031Z  INFO 📡 server listening at http://127.0.0.1:8080

This is as simple an example as I can make and I don't know why the error is occurring. I've found a workaround by including a hashmap of styles that I can import inside class components, but it's a bit clunky. Here is my Cargo.toml - maybe that's the issue, but I've imported yew_style_in_rs -

[package]
name = "yew_page"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
route = "0.2.0"
yew = { version = "0.20.0", features = ["csr"] }
yew-router = "0.17.0"
reqwest = "0.11.14"
wasm-logger = "0.2.0"
log = "0.4.17"
gloo-net = "0.2.5"
wasm-bindgen-futures = "0.4.33"
wasm-bindgen = "0.2.83"
js-sys = "0.3.60"
yew-style-in-rs = "0.4.1"

[dependencies.web-sys]
version = "0.3"
features = [
  "Headers",
  "Request",
  "RequestInit",
  "RequestMode",
  "Response",
  "Window",
  'HtmlCanvasElement',
  'WebGlBuffer',
  'WebGlProgram',
  'WebGlRenderingContext',
  'WebGlShader',
  'WebGlUniformLocation',
]

[[bin]]
name = "yew_page"
required-features = ["yew/csr"]
@patientplatypus6
Copy link
Author

@futursolo
Copy link
Member

This is due to yew_styles_in_rs does not support Yew v0.20. yew_styles_in_rs needs to be upgraded to support Yew v0.20 or you need to use Yew v0.19 with yew_styles_in_rs.

@futursolo futursolo added question and removed bug labels Feb 6, 2023
@voidpumpkin
Copy link
Member

We cant do much so closing.
Please wait until yew_styles_in_rs updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants