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

Commit

Permalink
feat: add feature targeting for styles to tab-related packages (#4838)
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and Matt Goo committed Jun 25, 2019
1 parent a676966 commit c7efc10
Show file tree
Hide file tree
Showing 13 changed files with 580 additions and 341 deletions.
62 changes: 38 additions & 24 deletions packages/mdc-tab-bar/_mixins.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
//
// Copyright 2018 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

@mixin mdc-tab-bar-width($width) {
width: $width;
@import "@material/feature-targeting/functions";
@import "@material/feature-targeting/mixins";

@mixin mdc-tab-bar-core-styles($query: mdc-feature-all()) {
// postcss-bem-linter: define tab-bar
.mdc-tab-bar {
@include mdc-tab-bar-width(100%, $query);
}
// postcss-bem-linter: end
}

@mixin mdc-tab-bar-width($width, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
width: $width;
}
}
9 changes: 1 addition & 8 deletions packages/mdc-tab-bar/mdc-tab-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,4 @@
*/

@import "./mixins";

// postcss-bem-linter: define tab-bar

.mdc-tab-bar {
@include mdc-tab-bar-width(100%);
}

// postcss-bem-linter: end
@include mdc-tab-bar-core-styles;
1 change: 1 addition & 0 deletions packages/mdc-tab-bar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@material/base": "^1.0.0",
"@material/elevation": "^1.1.0",
"@material/feature-targeting": "^0.44.1",
"@material/tab": "^2.3.0",
"@material/tab-scroller": "^2.3.0",
"tslib": "^1.9.3"
Expand Down
191 changes: 155 additions & 36 deletions packages/mdc-tab-indicator/_mixins.scss
Original file line number Diff line number Diff line change
@@ -1,60 +1,179 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
//
// Copyright 2018 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

@import "@material/animation/variables";
@import "@material/theme/mixins";
@import "@material/feature-targeting/functions";
@import "@material/feature-targeting/mixins";

@mixin mdc-tab-indicator-surface {
position: relative;
@mixin mdc-tab-indicator-core-styles($query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);
$feat-animation: mdc-feature-create-target($query, animation);

// postcss-bem-linter: define tab-indicator

.mdc-tab-indicator {
@include mdc-tab-indicator-base_($query);
}

.mdc-tab-indicator__content {
@include mdc-feature-targets($feat-structure) {
transform-origin: left;
opacity: 0;
}
}

.mdc-tab-indicator__content--underline {
@include mdc-feature-targets($feat-structure) {
align-self: flex-end;
box-sizing: border-box;
width: 100%;
border-top-style: solid;
}
}

.mdc-tab-indicator__content--icon {
@include mdc-feature-targets($feat-structure) {
align-self: center;
margin: 0 auto;
}
}

.mdc-tab-indicator--active .mdc-tab-indicator__content {
@include mdc-feature-targets($feat-structure) {
opacity: 1;
}
}

// Slide by default
.mdc-tab-indicator .mdc-tab-indicator__content {
@include mdc-feature-targets($feat-animation) {
transition: 250ms transform $mdc-animation-standard-curve-timing-function;
}
}

// --no-transition is applied in cases where styles need to be applied immediately to set up a transition
.mdc-tab-indicator--no-transition .mdc-tab-indicator__content {
@include mdc-feature-targets($feat-animation) {
transition: none;
}
}

.mdc-tab-indicator--fade .mdc-tab-indicator__content {
@include mdc-feature-targets($feat-animation) {
transition: 150ms opacity linear;
}
}

// postcss-bem-linter: ignore
.mdc-tab-indicator--active.mdc-tab-indicator--fade .mdc-tab-indicator__content {
@include mdc-feature-targets($feat-animation) {
transition-delay: 100ms;
}
}

// postcss-bem-linter: end
}

@mixin mdc-tab-indicator-underline-color($color) {
@mixin mdc-tab-indicator-surface($query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
position: relative;
}
}

@mixin mdc-tab-indicator-underline-color($color, $query: mdc-feature-all()) {
$feat-color: mdc-feature-create-target($query, color);

.mdc-tab-indicator__content--underline {
@include mdc-theme-prop(border-color, $color);
@include mdc-feature-targets($feat-color) {
@include mdc-theme-prop(border-color, $color);
}
}
}

@mixin mdc-tab-indicator-underline-height($height) {
@mixin mdc-tab-indicator-underline-height($height, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

.mdc-tab-indicator__content--underline {
border-top-width: $height;
@include mdc-feature-targets($feat-structure) {
border-top-width: $height;
}
}
}

@mixin mdc-tab-indicator-underline-top-corner-radius($radius) {
@mixin mdc-tab-indicator-underline-top-corner-radius($radius, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

.mdc-tab-indicator__content--underline {
border-top-left-radius: $radius;
border-top-right-radius: $radius;
@include mdc-feature-targets($feat-structure) {
border-top-left-radius: $radius;
border-top-right-radius: $radius;
}
}
}

@mixin mdc-tab-indicator-icon-color($color) {
@mixin mdc-tab-indicator-icon-color($color, $query: mdc-feature-all()) {
$feat-color: mdc-feature-create-target($query, color);

.mdc-tab-indicator__content--icon {
@include mdc-theme-prop(color, $color);
@include mdc-feature-targets($feat-color) {
@include mdc-theme-prop(color, $color);
}
}
}

@mixin mdc-tab-indicator-icon-height($height) {
@mixin mdc-tab-indicator-icon-height($height, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

.mdc-tab-indicator__content--icon {
height: $height;
font-size: $height;
@include mdc-feature-targets($feat-structure) {
height: $height;
font-size: $height;
}
}
}

//
// Private
//

@mixin mdc-tab-indicator-base_($query) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-tab-indicator-underline-color(primary, $query);
@include mdc-tab-indicator-icon-color(secondary, $query);
@include mdc-tab-indicator-underline-height(2px, $query);
@include mdc-tab-indicator-icon-height(34px, $query);

@include mdc-feature-targets($feat-structure) {
display: flex;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 1;
}
}
63 changes: 1 addition & 62 deletions packages/mdc-tab-indicator/mdc-tab-indicator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,5 @@
* THE SOFTWARE.
*/

@import "@material/animation/variables";
@import "./mixins";

// postcss-bem-linter: define tab-indicator

.mdc-tab-indicator {
@include mdc-tab-indicator-underline-color(primary);
@include mdc-tab-indicator-underline-height(2px);
@include mdc-tab-indicator-icon-color(secondary);
@include mdc-tab-indicator-icon-height(34px);

display: flex;
position: absolute;
top: 0;
left: 0;
justify-content: center;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 1;
}

.mdc-tab-indicator__content {
transform-origin: left;
opacity: 0;
}

.mdc-tab-indicator__content--underline {
align-self: flex-end;
box-sizing: border-box;
width: 100%;
border-top-style: solid;
}

.mdc-tab-indicator__content--icon {
align-self: center;
margin: 0 auto;
}

.mdc-tab-indicator--active .mdc-tab-indicator__content {
opacity: 1;
}

// Slide by default
.mdc-tab-indicator .mdc-tab-indicator__content {
transition: 250ms transform $mdc-animation-standard-curve-timing-function;
}

// --no-transition is applied in cases where styles need to be applied immediately to set up a transition
.mdc-tab-indicator--no-transition .mdc-tab-indicator__content {
transition: none;
}

.mdc-tab-indicator--fade .mdc-tab-indicator__content {
transition: 150ms opacity linear;
}

// postcss-bem-linter: ignore
.mdc-tab-indicator--active.mdc-tab-indicator--fade .mdc-tab-indicator__content {
transition-delay: 100ms;
}

// postcss-bem-linter: end
@include mdc-tab-indicator-core-styles;
1 change: 1 addition & 0 deletions packages/mdc-tab-indicator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@material/animation": "^1.0.0",
"@material/base": "^1.0.0",
"@material/feature-targeting": "^0.44.1",
"@material/theme": "^1.1.0",
"tslib": "^1.9.3"
},
Expand Down
Loading

0 comments on commit c7efc10

Please sign in to comment.