myFavShrimp / turf

Macro based compile-time SCSS transpilation, CSS minification, and class name uniquification toolchain inspired by CSS modules.
MIT License
58 stars 3 forks source link

Set `ClassName` to pub #4

Closed xeho91 closed 1 year ago

xeho91 commented 1 year ago

What?

Allow reusability of the same CSS (hashed) across multiple UI components files.

How?

Add pub modifier to the struct ClassName

Why?

Example from my recent case:

I have the components:

Both of them share the same CSS. Instead of creating and duplicating the same CSS files for each of them, I can create just one, in a separate mod file, then "re-export" it, so both of those components (in separated files) can reuse the same CSS.

Example

// button/styles.rs
style_sheet!("/button/styles.scss");

pub static BUTTON_STYLE_SHEET: &str = STYLE_SHEET;
pub type ButtonClassName = ClassName;
// button/default.rs

use super::super::utils::{ButtonClassName, BUTTON_STYLE_SHEET};

pub static STYLE_SHEET: &str = BUTTON_STYLE_SHEET;

impl yew::Component for Button {
  // ...
}
// button/icon.rs

use super::super::utils::{ButtonClassName, BUTTON_STYLE_SHEET};

pub static STYLE_SHEET: &str = BUTTON_STYLE_SHEET;

impl yew::Component for ButtonIcon {
  // ...
}

This is best I could come up with possible solution to solve this case. Please let me know what do you think, or if you have a better solution for my case.

Thanks! ❤️

myFavShrimp commented 1 year ago

This change seems reasonable. Thank you for your contribution!