feat: add util to write tw classes inside strings #761
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
More often than not, there are times when you may want to write Tailwind CSS classes within TypeScript strings. For example:
When doing so, you lose intellisense in VSCode through TailwindCSS extension. To overcome this problem, the extension team created a setting to allow for custom class name completion contexts.
I thought it would be nice if this library helped the DX of TailwindCSS classes by providing a util function that when paired with the correct VSCode setting, it would automatically generate suggestions.
Approach
We can provide the following auto-imported function under the flag
addTwUtil
:We can also add in the documentation that users should add the following configuration in VSCode:
With these modifications, users of this module will now be able to write TailwindCSS classes like this:
Here's a small video showcasing the use case:
Screen.Recording.2023-11-15.at.10.23.33.mov
I feel like this could improve a lot the DX when using Tailwind CSS classes. I'm not sure if this is something you are willing to add to this module since it's very coupled to VSCode development and it requires modification of VSCode settings to work (that's why I set
addTwUtil
to befalse
by default).