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

Enable camelCase by default for CSS Modules #376

Closed
tribou opened this issue Aug 2, 2016 · 15 comments
Closed

Enable camelCase by default for CSS Modules #376

tribou opened this issue Aug 2, 2016 · 15 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects

Comments

@tribou
Copy link
Contributor

tribou commented Aug 2, 2016

I wanted to bring this up for discussion as I use camelCase by default with CSS modules since it lets me key in the class associations a bit faster.

/* CSS */
.my-class {
}
.my-other-class {
}

With:

// css-loader?modules&camelCase
import Cn from 'classnames'
import css from './MyComponent.module.css'
...
css.myClass
Cn(css.myClass, css.myOtherClass)

Without:

// css-loader?modules
import Cn from 'classnames'
import css from './MyComponent.module.css'
...
css['my-class']
Cn(css['my-class'], css['my-other-class'])

This may just be an opinion piece; but for me, it looks cleaner and can be typed faster.

@KyleAMathews
Copy link
Contributor

Yeah this makes a lot of sense. Actually I thought CSS Modules did camelCase by default :-)

I'll support this change. Anyone else with thoughts? @gatsbyjs/gatsby-core-maintainers

This would be a breaking change so wouldn't go in for a bit.

@MoOx
Copy link

MoOx commented Aug 2, 2016

Why don't you just define your css classes as .camelCase ?
This will make it harder for everyone to lookup for references...

@NogsMPLS
Copy link
Contributor

NogsMPLS commented Aug 2, 2016

CSS Modules doesn't enforce it, though it is recommended that you write your classnames in camelCase specifically because of this case.

though I'm not sure if I agree with mutating the class names like that.

If i write .my-class in CSS, but want myClass in JS, why not just type .myClass in CSS in the first place?

@tribou
Copy link
Contributor Author

tribou commented Aug 2, 2016

I have no excuse... Other than dasherized class/property names have been the standard with CSS for years and old habits die hard, I suppose. 😄

FYI, css-loader injects both versions of css.myClass and css['my-class'] into the resulting object when camelCase is enabled, so this actually wouldn't be a breaking change.

e.g.

// css =
{
  "my-class": "gobbledygook",
  myClass: "gobbledygook",
}

@KyleAMathews
Copy link
Contributor

Well if it's not a breaking change... I can't see the harm then.

@NogsMPLS
Copy link
Contributor

NogsMPLS commented Aug 2, 2016

Ah, well, as long as it doesn't get rid of my-class, but instead appends a myClass then yeah, I'm for it.

👍

@jakubrohleder
Copy link
Contributor

Same thoughts, adding this option seems reasonable. I didn't know about 👍

@KyleAMathews
Copy link
Contributor

@tribou still want to add a PR?

@stereobooster
Copy link

stereobooster commented Sep 20, 2016

I know gatsby uses Flow. But some more notes for potential restriction on css module names (if you use TypeScript) https://github.com/Quramy/typed-css-modules#remarks

@oliverbenns
Copy link
Contributor

I have to agree with the comments. Just start writing in camel case. If you're referencing in camel case when it's actually kebab, it's not exactly clear what you're referencing. I agree it takes a bit of getting used to, but it doesn't seem reasonable to add such functionality for the sake of old naming conventions.

@tribou
Copy link
Contributor Author

tribou commented Nov 5, 2016

It appears there's too much opposition on this one. Unless we get some more positive comments, I'll close this for now.

@tribou tribou closed this as completed Nov 5, 2016
@jquense
Copy link
Contributor

jquense commented Nov 5, 2016

adding a comment in support, we do have this option set for all our projects and I don't think anyone has ever been confused. case transformation accross languages is fairly common concept for programmers I think, especially js ones who often work with backends in other not node. I for one also refuse to write css classes in camelCase, I just can't bring myself to so that :P

@KyleAMathews
Copy link
Contributor

Yeah, I think this is quite reasonable to add. If someone would like to create a PR I'd be happy to merge it.

@KyleAMathews KyleAMathews reopened this Nov 7, 2016
@drexkdal
Copy link

Just want to point out that there is automatic conversion from kebab-case to camelCase other places in DOM land:

  • Attribute names (data-my-attr=dataset.myAttr)
  • CSS properties (background-color:style.backgroundColor)

@Chuloo
Copy link
Contributor

Chuloo commented Aug 3, 2018

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications we're clearing out old issues as many of them have already been resolved with the latest updates.

See a more recent update on this issue with #5458 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
No open projects
Development

No branches or pull requests

10 participants