// // 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. // // Selector '.mdc-*' should only be used in this project. // stylelint-disable selector-class-pattern @use 'sass:math'; @use '@material/density/functions' as density-functions; @use '@material/feature-targeting/feature-targeting'; @use '@material/ripple/ripple'; @use '@material/ripple/ripple-theme'; @use '@material/rtl/mixins' as rtl; @use '@material/theme/theme'; @use './variables'; @mixin core-styles($query: feature-targeting.all()) { @include without-ripple($query); @include ripple($query); } @mixin without-ripple($query: feature-targeting.all()) { $feat-structure: feature-targeting.create-target($query, structure); // postcss-bem-linter: define icon-button .mdc-icon-button { @include base_($query: $query); @include density(0, $query: $query); } .mdc-icon-button__icon { @include feature-targeting.targets($feat-structure) { display: inline-block; } // stylelint-disable-next-line plugin/selector-bem-pattern &.mdc-icon-button__icon--on { @include feature-targeting.targets($feat-structure) { display: none; } } } .mdc-icon-button--on { .mdc-icon-button__icon { @include feature-targeting.targets($feat-structure) { display: none; } // stylelint-disable-next-line plugin/selector-bem-pattern &.mdc-icon-button__icon--on { @include feature-targeting.targets($feat-structure) { display: inline-block; } } } } // postcss-bem-linter: end } @mixin ripple($query: feature-targeting.all()) { @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE .mdc-icon-button { @include ripple.surface($query: $query); @include ripple.radius-unbounded($query: $query); @include ripple-theme.states($query: $query); } } /// /// Sets the density scale for icon button. /// /// @param {Number | String} $density-scale - Density scale value for component. /// Supported density scale values range from `-5` to `0`, with `0` being the default. /// @mixin density($density-scale, $query: feature-targeting.all()) { $size: density-functions.prop-value( $density-config: variables.$density-config, $density-scale: $density-scale, $property-name: size, ); @include size($size, $query: $query); } /// /// Sets the size of the icon-button. /// /// @param {Number} $size - Size value for icon-button. /// Size will set the width, height, and padding for the overall component. /// @mixin size($size, $query: feature-targeting.all()) { $feat-structure: feature-targeting.create-target($query, structure); @include feature-targeting.targets($feat-structure) { width: $size; height: $size; padding: ($size - variables.$icon-size) / 2; } } /// /// Sets the width, height and padding of icon button. Also changes the size of /// the icon itself based on button size. /// /// @param {Number} $width - Width value for icon-button. /// @param {Number} $height - Height value for icon-button. (default: $width) /// @param {Number} $padding - Padding value for icon-button. (default: max($width, $height) / 2) /// @deprecated /// This mixin provides too much of low level customization. /// Please use mdc-icon-button-size instead. /// @mixin icon-size( $width, $height: $width, $padding: math.max($width, $height) / 2, $query: feature-targeting.all() ) { $feat-structure: feature-targeting.create-target($query, structure); @include feature-targeting.targets($feat-structure) { width: $width + $padding * 2; height: $height + $padding * 2; padding: $padding; font-size: math.max($width, $height); } // stylelint-disable-next-line selector-max-type svg, img { @include feature-targeting.targets($feat-structure) { width: $width; height: $height; } } } /// /// Sets the font color and the ripple color to the provided color value. /// @param {Color} $color - The desired font and ripple color. /// @mixin ink-color($color, $query: feature-targeting.all()) { @include ink-color_($color, $query: $query); @include ripple-theme.states($color, $query: $query); } /// /// Flips icon only in RTL context. /// @mixin flip-icon-in-rtl($query: feature-targeting.all()) { $feat-structure: feature-targeting.create-target($query, structure); .mdc-button__icon { @include rtl.rtl { @include feature-targeting.targets($feat-structure) { /* @noflip */ transform: rotate(180deg); } } } } /// /// Sets the font color to the provided color value for a disabled icon button. /// @param {Color} $color - The desired font color. /// @mixin disabled-ink-color($color, $query: feature-targeting.all()) { @include if-disabled_ { @include ink-color_($color, $query: $query); } } @mixin base_($query: feature-targeting.all()) { $feat-structure: feature-targeting.create-target($query, structure); @include feature-targeting.targets($feat-structure) { display: inline-block; position: relative; box-sizing: border-box; border: none; outline: none; background-color: transparent; fill: currentColor; color: inherit; font-size: variables.$icon-size; text-decoration: none; cursor: pointer; user-select: none; } // stylelint-disable-next-line selector-max-type svg, img { @include feature-targeting.targets($feat-structure) { width: variables.$icon-size; height: variables.$icon-size; } } @include disabled-ink-color(text-disabled-on-light, $query: $query); @include if-disabled_ { @include feature-targeting.targets($feat-structure) { cursor: default; pointer-events: none; } } } /// /// Sets the font color to the provided color value. This can be wrapped in /// a state qualifier such as `mdc-icon-button-if-disabled_`. /// @access private /// @mixin ink-color_($color, $query: feature-targeting.all()) { $feat-color: feature-targeting.create-target($query, color); @include feature-targeting.targets($feat-color) { @include theme.prop(color, $color); } } /// /// Helps style the icon button in its disabled state. /// @access private /// @mixin if-disabled_ { &:disabled { @content; } }