gajus / babel-plugin-react-css-modules

Transforms styleName to className using compile time CSS module resolution.
Other
2.05k stars 162 forks source link

Generate unique class name in css file if it referenced in JSX #284

Open yudium opened 4 years ago

yudium commented 4 years ago

I want to request a feature. Rather than having to use styleName on every element we can put it only on parent element and use existing global class. So JSX syntax will more simpler to look.

For example when I use bootstrap:

<div styleName="container">
    <div className="card" styleName="card">
        <div className="card-header" styleName="card-header">Title Here</div>
        <div className="card-body" styleName="card-body">Body Here</div>
    </div>
</div>

Will much simpler to look if we put styleName only on parent element:

<div styleName="container">
    <div className="card">
        <div className="card-header">Title Here</div>
        <div className="card-body">Body Here</div>
    </div>
</div>

so SCSS:

.container {  <-- generate only this to be a unique class Name
    margin: 0;
    .card {
        font-size: 14px;
        .card-header {
             background: #ddd;
        }
        .card-body {
             background: #f8f8f8;
        }
    }
}