[0.2] Rework rounded
utilities to radius
, add ability to target corners
#196
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 is targeting the branch #188 is based on and should be merged against that branch first if we think this is a good idea.
This PR changes the name of the
rounded
utility toradius
, removes the default no-modifierrounded
utility altogether, and removes the ability to round the sides of an element (rounded-t-sm
), adding the ability to round specific corners instead (radius-tl-sm radius-tr-sm
).Changing
rounded
toradius
The name
rounded
is a bit unusual compared to our other utilities. On its own it's kind of nice, "this element is rounded", but when combined with modifiers it starts to feel awkward:In particular,
rounded-none
felt really odd.Other utilities use a more active/declarative tense which feels a little more natural with modifiers. For example, we use
tracking-wide
nottracked-wide
, andshadow-md
notshadowed-md
.Switching to just
round
felt wrong because "round" sounds like you're making something a circle, not just rounding it slightly.Switching to
radius-md
feels more consistent withtracking-wide
andshadow-md
, where it's like we're saying "The radius of this element is medium sized."radius-none
also feels miles better thanrounded-none
.It's also closer to the CSS property name which, although not a primary goal when we choose names, always ends up being a plus if we like a name better for other justifiable reasons and it also happens to be closer to the CSS property name.
Downsides
rounded
utility in favor ofradius-md
. I considered keeping a defaultradius
utility, but it feels weird, liketracking
would feel without a modifier.Targeting corners
instead ofin addition to sidesCurrently we support rounding the sides of an element, like so:
...which would round the top-left and top-right corners.
As part of reworking some of this border radius stuff, this PR
replaces the ability to target sides withadds the ability to target corners.So the above code
wouldcould be rewritten like:Motivations for this:
Currently it's very unintuitive to round a single corner. You have to round the entire element, then disable rounding on the two opposing sides. This is how you round just the bottom left corner for example:
This is really weird.
Switching toSupporting cornersinstead ofin addition to sides lets you be very explicit and direct about what you are trying to do:The existing radius side utilities have two declarations each; one for each corner they are targeting:This is the reason for issue 1. We are trading fine grained control for a bit of convenience, and nowadays I think I'm convinced that it's better to make this a simpler and more direct abstraction on top of the individual CSS properties.Forget this point :)
Downsides
Again big breaking change.
The
tl
,tr
,bl
,br
abbreviations are going to take some getting used to; I think they are pretty unintuitive but don't have a better alternative.You now need two classes to round both corners on one side of an element:This is without a doubt harder to read and grok than:It's only worse when combined with a bunch of other utilities too.No longer relevant; keeping both.
Q: Should we support targeting both sides and corners?Part of me really wants to support targeting corners as well as sides, since it's much more common to style two adjacent corners than one individual corner.~~The issue is it adds 100 more classes to the output, and 20 new classes every time you add a new radius size. This results in about ~1kb of extra file size (minified and gzipped) for the default configuration, which is not insignificant since the whole file is about ~29kb to begin with.~~
It would also be the only time in the framework that we provide "shortcut" classes like that for things you could already do with existing classes.Actually we already do this sort of thing forpl
andpr
withpx
, and in a few other places 🤔So my questions are:
tr
-style abbreviations so ugly that it's worth it?I should've made this two separate PRs and discussions but it's too late now 🙊