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 opt-in customization features #127

Closed

Conversation

nderscore
Copy link
Contributor

The changes here originally started out as a fork that was catered specifically to NativeWind v3.x, which is planning to introduce a new CVA/stitches-eseque variants API.

Recently, I updated my fork to be configurable by specifying additional settings to Prettier, so that it could be used to support other non-standard Tailwind use cases. Now that the changes have been made more generic, I think it makes sense to propose moving them upstream.


This PR adds three new Prettier config options, which enable users to expand on and customize where the plugin searches for Tailwind classes.

  • tailwindJSXProps - allows customizing which JSX props the plugin searches
  • tailwindFunctionCalls - enables searching for tailwind classes in certain function calls by name
  • tailwindTaggedTemplates - enables searching for tailwind classes in certain tagged template expressions by function name

They are all optional to use and backwards-compatible with existing usage. Usage examples can be found in the diff of the README and unit tests.

This approach could also be expanded upon to support other custom tailwind/tailwind-ish use cases, such as sorting tailwind classes in object properties or variable declarations.

@joelrojo
Copy link

joelrojo commented Mar 4, 2023

This feature would be awesome! Thanks for this @nderscore

@nderscore nderscore force-pushed the upstream-customization branch 2 times, most recently from d613b6a to 9dac940 Compare March 4, 2023 18:54
@balAdamT
Copy link

I am also excited for this feature!

@filippofilip95
Copy link

filippofilip95 commented Apr 25, 2023

Looking forward to these features :)

@thecrypticace thecrypticace self-assigned this May 4, 2023
@reinink
Copy link
Member

reinink commented May 9, 2023

Hey, thanks for this PR! We've had internal discussions for quite some time now about adding these kinds of customizations to our Prettier plugin, but it just hasn't materialized to date. This PR was a great step in the right direction and inspired us to try and take another crack at it.

In principle we really like what you've done here, but since we wanted to tweak the proposed API slightly, we created a new PR (#155) based on this one and have included you as a co-author. This gives us the ability to properly document these new customization options in the PR description.

You can see that PR for more details, but here is the TLDR:

  • We've renamed tailwindJSXProps to tailwindAttributes, just to make it more generalized so it can be used for non-React projects.
  • We've merged tailwindFunctionCalls and tailwindTaggedTemplates into a single new tailwindFunctions option, since tagged template literals are essentially functions under the hood.
  • We've removed regular expression support, at least for now. We wanted to start simple with these customization options, and can always revisit this in the future.

Thanks again for your work here! 🙏

@reinink reinink closed this May 9, 2023
@thecrypticace
Copy link
Contributor

Hey, we've just merged #155 which provides a way for you to specify additional attributes, functions, and tagged template literals that should be sorted by the plugin. It's available via our insiders build and will be released in the next version of the plugin. We would like to get some feedback on this feature before we release it, so please give it a try and let us know what you think!

To test the new features you can install the insiders build like so:

npm install prettier-plugin-tailwindcss@insiders

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

Successfully merging this pull request may close these issues.

None yet

6 participants