-
Notifications
You must be signed in to change notification settings - Fork 4
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
Use CSS Modules #362
Comments
Thanks for typing this up. I'm going to leave some thoughts here in separate comments. Also, we could consider using Github Discussions for things like this in the future (which I believe let you have threads off of comments). |
What does classnames/bind get us over treating the imported styles like normal classes (which they are)? Could write // component.tsx
-import classNames from 'classnames/bind';
import styles from './component.module.css';
-const cx = classNames.bind(styles);
function Component() {
- <div classNames={cx('some-class')} />
+ <div className={styles['some-class']} />
} |
I'm not super familiar with https://github.com/gajus/babel-plugin-react-css-modules. Having briefly glanced through its readme, seems like it adds a Less magic = More better. |
Also, I'd encourage the use of camel case class names. For example .someClass {
property: value;
} // component.tsx
import styles from './component.module.css';
function Component() {
return <div classNames={styles.someClass} />
} Slightly less typing. |
The main reason for not using camel case was to implement some form of BEM so we write our classes like this For the |
Regarding ternaries, I'm completely on board with using classnames. This totally makes sense className={cz(styles.foo, active && styles.active, enabled && styles.enabled)} What's not clear is whether |
Summarizing offline discussion outcomes:
Follow up question: Is this sufficient when considering pages in the app if we want to follow the same style there? |
I updated the issue, but wanted to call out that at least with interpolation camel case makes this much worse (option 4). This leaves options 1,2,3 - I still mostly like option 1, but am happy to go with option 3 if that's the team's preference. Thoughts? |
I also think any of options 1-3 could work fine 😛 some other things I thought of:
|
Option 3 looks clearer, more explicit, and more obivously correct to me. But that could just be personal preference. To answer one of your questions, Annie:
I don't believe it makes it harder (correct me if that's wrong). More that it's not clear (to me) that we get a lot of benefit from it. |
I don't think it would be an issue except in the case of collisions between global and local in a given JS/CSS module pair. |
The PR is merged, and it seems we've come to an agreement around Option 3. Thanks for reviewing everyone! |
Calling this one accepted 👍 |
Problem
CSS in JS hasn't been working great for us given our updated constraints:
Solution
Mostly back to where we started with CSS, but now that we don't need to consider using global css - we can use css modules, and in order to bind classnames to the styles we'll use
classnames/bind
.What does this look like?
Option 1: kebab-case +
classnames.bind
+ string interpolationOption 2: kebab-case +
classnames
+ string interpolationOption 3: camelCase +
classnames
+ conditionals #365Option 4: camelCase +
classnames
+ capitalized interpolation 🤢Additional Notes:
classnames
isn't very useful until there's a lot of conditionals, better to usestyles['some-class']
in this scenarioBenefits
Challenges and Mitigations
Compilation on App Side
Will need to ensure the css is compiled properly in the app side. This should only involve a suggested addition to a webpack config/storybook config/jest config for the dependent apps.
The text was updated successfully, but these errors were encountered: