Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Add support for wildcard utility matching #176

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thecrypticace
Copy link
Collaborator

@thecrypticace thecrypticace commented Mar 28, 2021

This is a work in progress. I'd like to see if this is a reasonable approach or if there are better ideas.

My first thought was to turn candidates (conditionally) into RegExp objects and match the utilities against them. That would be pretty powerful. Unfortunately the idea that a candidate is a string is pretty pervasive and also core to how matchUtilities, modifiers, and what not all work. For them to be regular expressions we'd have to generate all the classes in the tailwind config up front in memory and then match against the generated list.

My second thought was to add support for wildcards in asValue() but that would require supporting multiple return values — which for a prototype would be a significant change across all plugins just to not break something.

So end the end I settled with giving plugins the ability to explicitly register wildcard support. When you call a plugin you can say matchWildcards({ px: ['0', '1', '2', '3', …], …}) and when it finds p-{*} when resolving matches it expands to p-1, p-2, p-3, p-4, etc…

Due to implementation it includes duplicate utilities if you do p-{*} and p-1 / p-2 / etc… I need to find a way to clean this up / fix it but I wanted to get the reactions to the general approach first.

I've added wildcard support to the padding plugin only in this draft.

We can now support class tokens like p-{*} to include all p- utilities classes automatically. This requires explicit plugin support because we don’t know what theme config goes with what plugin. Only the plugin does.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant