Add --icon-size
property, use within c-button
#1586
Merged
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.
Overview
Addresses an issue where icons were inconsistently sized if included as the primary button content, as one might expect for an icon-only button.
Previously, button icon sizes were controlled via
font-size
on the icon container,c-button__extra
. When an icon was included as the primary content,c-button__content
, there was no suchfont-size
declaration, and so the icon would appear smaller by comparison.I considered adding some utility classes and/or icon modifiers to solve this problem, but I realized when futzing with the component that there were other potential issues with relying on
font-size
on a containing element. For example, it's impossible to reliably negate the gap between the__extra
and__content
elements since thefont-size
for the icon increases the computed size of that gap to a spot between two of our modular scale steps.Instead, I added an optional
--icon-size
property to thec-icon
component. This allows us to set the desired size of the icon onc-button
, which cascades to all elements below. It also means the computed impact of the icon's size is not effective until the icon itself, so any margins or other relative values on its container will be more consistent with adjacent elements.Along the way, I noticed that the
c-button__extra
styles were being unnecessarily output a second time within the context of WordPress buttons. I separated those styles into their own mixins to prevent this.(This PR originally included other changes to
c-button
to streamline its template code, but I realized partway in that the actual solution to the issue was a smaller subset of that, which I've separated into this PR.)Screenshots
Before
After
Testing
On the deploy preview…