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 multiple class declarations in a single component #21

Open
chanceeakin opened this issue Jan 22, 2021 · 2 comments
Open

Support multiple class declarations in a single component #21

chanceeakin opened this issue Jan 22, 2021 · 2 comments

Comments

@chanceeakin
Copy link

Lukas,

Love the work you've done thus far with porting CSS in JS to CSS in Rust!

Noticed that there's a limitation of one class to one component (specifically with Yew). It'd be great if this lib could support multiple classes per file. Ideally, allowing css_in_rust::Style::create Vec<String> or the like in addition to only strings.

Would love to connect and help build out this library!

@vskh
Copy link

vskh commented Jan 24, 2021

Hi chanceeakin,

I am also user of this lib and was just passing by when saw your issue. I wonder if there is specific usecase that you have in mind for this?

Right now it is possible to add substyles right in definition of Style, they all will be wrapped into an autoprefixed root style (thus scoped) and can be handy to tweak inner parts of the component.

Here is how I use it:

let style = Style::create(
            "Component",
            r#"
                width: 100%;
                display: flex;
                flex-direction: row;
                justify-content: space-between;
                align-items: center;

                .main {
                    /* ... */
                }

                .side {
                    /* ... */
                }
            "#)
            .unwrap();

The view can look like this:

html! {
        <div class=self.style.clone()>
            <div class="side">{"left"}</div>
            <div class="main">{"center"}</div>
            <div class="side">{"right"}</div>
        </div>
    }

Resulting stylesheet would have classes like this:

.Component-4594200420215021072 {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.Component-4594200420215021072 .main  {
                    /* ... */
}
.Component-4594200420215021072 .side  {
                    /* ... */
}

Let me know if that would help in your case?

@chanceeakin
Copy link
Author

That would totally help. For some reason, I missed that in the documentation. Thank you, @vskh!

My suggestion would be a breaking change, but I wonder if allowing multiple components would allow logic similar to nested selectors: https://cssinjs.org/jss-plugin-nested?v=v10.5.1.

I can move this out of issues or close, as y'all or the maintainers would prefer. :)

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

No branches or pull requests

2 participants