Skip to content

Commit

Permalink
feat(tab): Improved mixins (#4675)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickrodee committed May 3, 2019
1 parent 7cc0832 commit 252009f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/mdc-tab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Mixin | Description
`mdc-tab-active-states-color($color)` | Customizes the color of the active tab's states.
`mdc-tab-parent-positioning` | Sets the positioning of the MDCTab's parent element so that `MDCTab.computeDimensions()` reports the same values in all browsers.
`mdc-tab-fixed-width($width)` | Sets the fixed width of the tab. The tab will never be smaller than the given width.
`mdc-tab-horizontal-padding($padding)` | Sets the horizontal padding of the tab.

## `MDCTab` Properties and Methods

Expand Down
4 changes: 4 additions & 0 deletions packages/mdc-tab/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

// Public mixins

@mixin mdc-tab-horizontal-padding($padding) {
padding: 0 $padding;
}

@mixin mdc-tab-text-label-color($color) {
.mdc-tab__text-label {
@include mdc-theme-prop(color, $color);
Expand Down
5 changes: 5 additions & 0 deletions packages/mdc-tab/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
$mdc-tab-icon-size: 24px !default;
$mdc-tab-height: 48px !default;
$mdc-tab-stacked-height: 72px !default;
$mdc-tab-horizontal-padding: 24px !default;
$mdc-tab-text-label-opacity: .6 !default;
$mdc-tab-icon-opacity: .54 !default;
$mdc-tab-text-label-color-default: rgba(mdc-theme-prop-value(on-surface), $mdc-tab-text-label-opacity) !default;
$mdc-tab-icon-color-default: rgba(mdc-theme-prop-value(on-surface), $mdc-tab-icon-opacity) !default;
$mdc-tab-text-label-color-active: mdc-theme-prop-value(primary);
$mdc-tab-icon-color-active: mdc-theme-prop-value(primary);
15 changes: 6 additions & 9 deletions packages/mdc-tab/mdc-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
// postcss-bem-linter: define tab

.mdc-tab {
@include mdc-tab-text-label-color(on-surface);
@include mdc-tab-icon-color(on-surface);
@include mdc-tab-text-label-color($mdc-tab-text-label-color-default);
@include mdc-tab-icon-color($mdc-tab-icon-color-default);
@include mdc-tab-indicator-surface;
@include mdc-typography(button);
@include mdc-tab-horizontal-padding($mdc-tab-horizontal-padding);

display: flex;
flex: 1 0 auto;
Expand All @@ -43,7 +44,6 @@
height: $mdc-tab-height;
// Explicitly setting margin to 0 is to override safari default margin for button elements.
margin: 0;
padding: 0 24px;
border: none;
outline: none;
background: none;
Expand Down Expand Up @@ -89,13 +89,12 @@

.mdc-tab__text-label,
.mdc-tab__icon {
transition: 150ms color linear, 150ms opacity linear;
transition: 150ms color linear;
z-index: 2;
}

.mdc-tab__text-label {
display: inline-block;
opacity: $mdc-tab-text-label-opacity;
// Setting line-height here overrides the line-height from the typography
// mixin above. The line-height needs to be overridden so that the spacing
// between the text label and the icon as well as the text label and the
Expand All @@ -106,7 +105,6 @@
.mdc-tab__icon {
width: $mdc-tab-icon-size;
height: $mdc-tab-icon-size;
opacity: $mdc-tab-icon-opacity;
font-size: $mdc-tab-icon-size;
}

Expand All @@ -129,13 +127,12 @@
}

.mdc-tab--active {
@include mdc-tab-text-label-color(primary);
@include mdc-tab-icon-color(primary);
@include mdc-tab-text-label-color($mdc-tab-text-label-color-active);
@include mdc-tab-icon-color($mdc-tab-icon-color-active);

.mdc-tab__text-label,
.mdc-tab__icon {
transition-delay: 100ms;
opacity: 1;
}
}

Expand Down

0 comments on commit 252009f

Please sign in to comment.