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

[JSX] Support for css modules and packages like clsx or classnames #82

Open
MaelWeb opened this issue Jul 20, 2020 · 2 comments
Open

[JSX] Support for css modules and packages like clsx or classnames #82

MaelWeb opened this issue Jul 20, 2020 · 2 comments

Comments

@MaelWeb
Copy link

MaelWeb commented Jul 20, 2020

This works very well in the JSX file. But there are still some small regrets. When I use classnames() in JSX, it doesn't work. Is it possible to enable this in JSX?

e.g.

// tese.less
.test {
    color: '#000';
}
//  test.jsx
import ClassNames from "classnames";

export default function test() {
     return (<div className={ ClassNames('test') } /> )
}
@pranaygp
Copy link
Owner

there are too many possible things to consider when support CSS-in-JS

"classnames" is only one way.

there's also CSS Modules which is getting a lot of traction now (https://github.com/css-modules/css-modules)

also, consider the clsx package, or even just the fact that className can be anything apart from a string.

We can definitely try to support some of the simpler cases, like classnames("string literal") or clsx("literal-1", "literal-2"). For now, I'm going to leave this as an exercise for anyone who'd like to contribute such features. We can tackle this for one use-case at a time, for one CSS-in-JS package/solution at a time

@pranaygp pranaygp changed the title JSX classnames() Support [JSX] Support for css modules and packages like clsx or classnames Jul 27, 2020
@pranaygp pranaygp pinned this issue Jul 27, 2020
@pasquale95
Copy link

pasquale95 commented Aug 9, 2023

Hi, thanks for your extension!
One thing I noticed and that can be improved is the following. If we work with .jsx or .tsx files, the extension resolves the css class if specified without curly brackets, but it doesn't if the curly brackets are there. For instance:

<div className="container" /> // <- resolved
<div className={"container"} /> // <- not resolved

Do you think you can improve also this little aspect? It would be great!

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

No branches or pull requests

3 participants