Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(button): Add padding mixin, adjust icon margin #2420

Merged
merged 10 commits into from
Mar 22, 2018
13 changes: 7 additions & 6 deletions packages/mdc-button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ container color to the given color, and updates the Button's ink and ripple colo

Mixin | Description
--- | ---
`mdc-button-container-fill-color` | Sets the container color to the given color.
`mdc-button-icon-color` | Sets the icon color to the given color.
`mdc-button-ink-color` | Sets the ink color to the given color. This affects both text and icon, unless `mdc-button-icon-color` is also used.
`mdc-button-stroke-color` | Sets the stroke color to the given color.
`mdc-button-corner-radius` | Sets the corner radius to the given number (defaults to 2px).
`mdc-button-stroke-width` | Sets the stroke width to the given number (defaults to 2px).
`mdc-button-container-fill-color($color)` | Sets the container color to the given color.
`mdc-button-icon-color($color)` | Sets the icon color to the given color.
`mdc-button-ink-color($color)` | Sets the ink color to the given color. This affects both text and icon, unless `mdc-button-icon-color` is also used.
`mdc-button-corner-radius($corner-radius)` | Sets the corner radius to the given number (defaults to 2px).
`mdc-button-horizontal-padding($padding)` | Sets horizontal padding to the given number.
`mdc-button-stroke-color($color)` | Sets the stroke color to the given color.
`mdc-button-stroke-width($width, $padding)` | Sets the stroke width to the given number (defaults to 2px) and adjusts padding accordingly. `$padding` is only required in cases where `mdc-button-horizontal-padding` is also included with a custom value.

The ripple effect for the Button component is styled using [MDC Ripple](../mdc-ripple) mixins.

Expand Down
21 changes: 16 additions & 5 deletions packages/mdc-button/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@
border-radius: $corner-radius;
}

@mixin mdc-button-stroke-width($stroke-width) {
@mixin mdc-button-horizontal-padding($padding) {
padding-right: $padding;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strictly speaking we should be adding /* @NoFlip */ on these. At the same time, I understand the argument about them being the same. Lets hope that never changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah, I didn't think about it here since I know we handle @noflip within our RTL stuff now, and these styles are equal and not RTL-dependent. If these ever did change to being asymmetrical, we'd absolutely want to add @noflip (probably automatically via use of mdc-rtl mixins).

I think if we wanted to take that strict of a stance about @noflip we'd have several instances across the repo where left and right are equal that we're not flagging right now.

padding-left: $padding;
}

@mixin mdc-button-stroke-width($stroke-width, $padding: $mdc-button-contained-horizontal-padding) {
// Note: Adjust padding to maintain consistent width with non-stroked buttons
$padding-value: max($mdc-button-horizontal-padding - $stroke-width, 0);
$padding-value: max($padding - $stroke-width, 0);

padding-right: $padding-value;
padding-left: $padding-value;
Expand All @@ -88,13 +93,13 @@
@include mdc-typography(button);
@include mdc-ripple-surface;
@include mdc-ripple-radius-bounded;
@include mdc-button-horizontal-padding($mdc-button-horizontal-padding);

display: inline-block;
position: relative;
box-sizing: border-box;
min-width: 64px;
height: $mdc-button-height;
padding: 0 $mdc-button-horizontal-padding;
border: none;
outline: none;
text-align: center;
Expand Down Expand Up @@ -138,14 +143,18 @@
}

@mixin mdc-button__icon-svg_ {
@include mdc-rtl-reflexive-box(margin, right, 8px);

margin-top: -2px;
fill: currentColor;
vertical-align: middle;
}

@mixin mdc-button__icon-contained_ {
@include mdc-rtl-reflexive-property(margin, -4px, 8px);
}

@mixin mdc-button--stroked_() {
@include mdc-button-horizontal-padding($mdc-button-contained-horizontal-padding);

border-style: solid;

&:disabled {
Expand All @@ -154,6 +163,8 @@
}

@mixin mdc-button--filled_() {
@include mdc-button-horizontal-padding($mdc-button-contained-horizontal-padding);

&:disabled {
@include mdc-theme-prop(background-color, rgba(black, .12));
@include mdc-theme-prop(color, text-disabled-on-light);
Expand Down
3 changes: 2 additions & 1 deletion packages/mdc-button/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
//

$mdc-button-height: 36px;
$mdc-button-horizontal-padding: 16px;
$mdc-button-horizontal-padding: 8px;
$mdc-button-contained-horizontal-padding: 16px;
$mdc-dense-button-height: 32px;
9 changes: 9 additions & 0 deletions packages/mdc-button/mdc-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
}
}

.mdc-button--raised,
.mdc-button--unelevated,
.mdc-button--stroked {
.mdc-button__icon {
// Icons inside contained buttons have different styles due to increased button padding
@include mdc-button__icon-contained_;
}
}

.mdc-button--raised,
.mdc-button--unelevated {
@include mdc-button--filled_;
Expand Down