Add "prefix" and "important" options to config #183
Closed
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.
This could've been two separate PRs but it's really just the consolidation of #99 and #100 but moved into the config file instead of being made available as at-rules.
This PR adds support for a new
optionskey in the config file, with two options so far:Prefix
The prefix option causes all of Tailwind's utilities to be generated with the given prefix.
This is (shockingly) more complex than it sounds, so there's a few rules worth understanding.
The prefix is added to the beginning of the utility name, not the full class name.
This means that if you set a prefix of
tw-, you'll get utilities that look like this:...not like this:
This may seem counter-intuitive at first, keep reading.
Your own classes that Tailwind touches with features like
@responsivedo not adopt this prefix.For example, this custom class wrapped in
@responsive:...will generate this code:
...not this code:
This is the reason for putting the prefix at the beginning of the utility name, not the class name.
If we put the prefix at the beginning of the full class, your own custom utilities would have no prefix, and the responsive prefixes would look different:
This inconsistency was ugly enough that it felt like putting the prefix before just the utility portion was the right move, because the only other option was prefixing your own custom utilities too, and that didn't feel right either.
Important
Important is simpler; it just makes all of Tailwind's utilities
!important.It doesn't make any of your own custom utilities that use Tailwind features important though; if you want that behavior, simply mark them as
!importantyourself:One important special case here is the
.containerclass. Using theimportantoption does not make the.containerclass important.This is because that class isn't really a utility; it's more of a component. It already gets special treatment in the codebase in that it doesn't get responsive variations generated (
.md:container,.lg:container, etc.).Since it's more of a component, it makes sense that it's styles should be overridable if needed, even though I don't know why you'd ever do that.
The End.
If you have opinions about all the prefix positioning crap I am open to hearing them, we argued about it for a while and this seemed like the best solution.