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

Add intellisense when using classnames plugin #197

Closed
davea38 opened this issue Oct 1, 2020 · 8 comments
Closed

Add intellisense when using classnames plugin #197

davea38 opened this issue Oct 1, 2020 · 8 comments

Comments

@davea38
Copy link

davea38 commented Oct 1, 2020

I write a lot of react code and use the https://github.com/JedWatson/classnames plugin for conditional CSS rendering.

Any chance you could enable this plugin to detect the classNames function?

import classNames from 'classnames';

<div className={classNames([
   'flex flex-col',
   ...
])} />
@0az
Copy link

0az commented Oct 1, 2020

I have my own minimalist version of this (const kn = (...classes) => classes.filter(e => !!e).flat().map(e => e + '').join(' ')), which works in enough cases for a copy/paste snippet in every project.

No idea what the low level parsing looks like, but detecting the class={}/class="" for Preact JSX or className={} for React JSX would probably suffice to support my use case as well: just enable the relevant completions inside every string in all such contexts.

@bradlc
Copy link
Contributor

bradlc commented Oct 8, 2020

Hey @davea38! Any strings inside the class(Name) attribute should already trigger the completions:

image

Is this not working for you?

@kristiandupont
Copy link

@bradlc that's great if you call classNames inline. However, I frequently call it before the return statement. I too would love either a sophisticated detection of the classnames package or maybe something similar to what Headwind does.

@davea38
Copy link
Author

davea38 commented Oct 12, 2020

Thanks for your reply @bradlc! As @kristiandupont points out, the majority of the time I am using classNames before a JSX return in a plain javascript function. It's less of a problem as I become more familiar with Tailwind, but my brain has a finite limit for the amount of 'stuff' it can hold... :)

Apologies that my example didn't actually cover the USE case that I wanted!

@eddyw
Copy link

eddyw commented Nov 19, 2020

Screen Shot 2020-11-19 at 20 42 14

You sort of can 😝. However, as soon as you format JS adding spaces between `=` char, it'll stop intellisense and the color decorations will disappear.

This "works" because of this:

const match = findLast(/(?:\b|:)class(?:Name)?=['"`{]/gi, str)

It'd be great if the RegExp allowed matching className( ) with parens. Then you could always do:

import { clsx as className } from './my-classNames-lib'

const styles = className({ white: 'text-white' }, 'bg-green-400')

@eddyw
Copy link

eddyw commented Nov 19, 2020

Since it's just a regular expression, you can use JS comments to make it match class={ } like this:
Screen Shot 2020-11-19 at 20 50 03
Anyways, it'd great if there was a better and official solution.

@bradlc
Copy link
Contributor

bradlc commented Nov 30, 2020

Please see tailwindlabs/tailwindcss#7553, in particular my recent comment

@bradlc bradlc closed this as completed Nov 30, 2020
@davea38
Copy link
Author

davea38 commented Nov 30, 2020

@bradlc - thank you! Will try this feature out in the latest version :)

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

No branches or pull requests

5 participants