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

Help with formatting in JavaScript files #80

Closed
Alonski opened this issue Jul 2, 2020 · 4 comments
Closed

Help with formatting in JavaScript files #80

Alonski opened this issue Jul 2, 2020 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Alonski
Copy link

Alonski commented Jul 2, 2020

Is your feature request related to a problem? Please describe.
Hello, I am trying to set up Headwind for use in Javascript files.

I have getters where I use a switch-case to choose the classNames for a component in Ember.
Headwind works in templates but I can't seem to get it to work in Javascript.

This is my code:

  get buttonClass() {
        const classNames = "border-0 rounded-sm min-w-24 min-h-8"; // Want this to be headwinded
        switch (this.variant) {
            case "primary":
                return `${classNames} button-primary`;
            default:
                return "";
        }
    }

I tried setting this regex but it might be wrong :)

  "headwind.classRegex": {
        "javascript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
    }
@heybourn
Copy link
Owner

heybourn commented Jul 8, 2020

I'm pretty horrible with REGEX so couldn't help you here - maybe @praveenperera has some ideas?

@heybourn heybourn added the help wanted Extra attention is needed label Jul 8, 2020
@praveenperera
Copy link
Contributor

praveenperera commented Jul 9, 2020

@Alonski here is the regex that works: https://regex101.com/r/ewrRFX/1

Try:

-       "javascript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"

+       "javascript": "(?:\\bclassNames?\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"

It will watch one both className = ... and classNames = ...

@Alonski
Copy link
Author

Alonski commented Aug 4, 2020

@praveenperera Sorry for the late followup.
So I tried what you suggested and Headwind still isn't sorting the classes :)

@petertriho
Copy link
Contributor

Fixed in #109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants