Add fontVariantNumeric utilities - #2305
Merged
Merged
Conversation
adamwathan
force-pushed
the
font-variant-numeric
branch
from
September 3, 2020 18:16
911a95f to
8ea81df
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR adds a new set of utilities for the
font-variant-numericproperty:normal-numsfont-variant-numerictonormalordinalordinalfeatureslashed-zeroslashed-zerofeaturelining-numslining-numsfeatureoldstyle-numsoldstyle-numsfeatureproportional-numsproportional-numsfeaturetabular-numstabular-numsfeaturediagonal-fractionsdiagonal-fractionsfeaturestacked-fractionsstacked-fractionsfeatureThe exciting thing about how these are implemented is that they are composable in your HTML, so you can enable multiple
font-variant-numericfeatures by adding multiple classes:The
normal-numsclass can be used to reset things, usually used at a particular breakpoint:By default, only
responsivevariants are enabled for this new core plugin.Design details
This was pretty challenging to implement and only works thanks to a magical tip from @davidkpiano. Here's what the CSS looks like:
The general idea here is that we build the actual
font-variant-numericproperty value out of CSS custom properties, and we use this incredible hack of setting a custom property to an empty comment to make it possible to provide a no-op default value for every "slot" in the final property value.I've had to use
/*!*/rather than/**/because most CSS minifiers will strip comments that don't start with a!.Any properties that are incompatible with each other are assigned to the same CSS custom property, so the slots we are filling look like this:
...where every slot on its own is optional.
So magical.