| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- //
- // Copyright 2020 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 --
- // Internal styling for Tooltip MDC component.
- @use 'sass:map';
- @use 'sass:meta';
- @use '@material/elevation/elevation-theme';
- @use '@material/feature-targeting/feature-targeting';
- @use '@material/rtl/rtl';
- @use '@material/shape/mixins' as shape-mixins;
- @use '@material/button/button-text-theme';
- @use '@material/theme/theme';
- @use '@material/theme/theme-color';
- @use '@material/theme/keys';
- @use '@material/typography/typography';
- @use '@material/tokens/resolvers';
- $fill-color: surface;
- $text-color: on-surface;
- $divider-color: rgba(theme-color.prop-value(on-surface), 0.12);
- $graphic-background-color: primary;
- $graphic-color: surface;
- $graphic-shape-radius: 50%;
- $primary-action-text-color: primary;
- $secondary-action-text-color: primary;
- $mobile-breakpoint: 480px;
- $z-index: 1;
- $custom-property-prefix: 'banner';
- $light-theme: (
- action-focus-state-layer-color: theme-color.$primary,
- action-focus-state-layer-opacity: 0.12,
- action-focus-label-text-color: null,
- action-hover-state-layer-color: theme-color.$primary,
- action-hover-state-layer-opacity: 0.04,
- action-hover-label-text-color: null,
- action-label-text-color: theme-color.$primary,
- // TODO(b/197004146): Support action label typography.
- action-label-text-font: null,
- action-label-text-size: null,
- action-label-text-tracking: null,
- action-label-text-weight: null,
- action-pressed-state-layer-color: theme-color.$primary,
- action-pressed-state-layer-opacity: 0.1,
- action-pressed-label-text-color: null,
- container-color: theme-color.$surface,
- container-elevation: null,
- container-shadow-color: null,
- container-shape: 0,
- divider-color: $divider-color,
- divider-height: 1px,
- supporting-text-color: theme-color.$on-surface,
- supporting-text-font: typography.get-font(body2),
- supporting-text-line-height: typography.get-line-height(body2),
- supporting-text-size: typography.get-size(body2),
- supporting-text-tracking: typography.get-tracking(body2),
- supporting-text-weight: typography.get-weight(body2),
- with-image-image-shape: $graphic-shape-radius,
- with-image-image-size: 40px,
- );
- @mixin theme($theme, $resolvers: resolvers.$material) {
- // TODO(b/251881053): Replace with `validate-theme`.
- @include theme.validate-theme-styles($light-theme, $theme);
- $theme: _resolve-theme($theme, $resolvers);
- @include keys.declare-custom-properties(
- $theme,
- $prefix: $custom-property-prefix
- );
- }
- @function _resolve-theme($theme, $resolvers) {
- @return map.merge(
- $theme,
- _resolve-theme-elevation(
- $theme,
- map.get($resolvers, elevation),
- container-elevation
- )
- );
- }
- @function _resolve-theme-elevation($theme, $resolver, $keys...) {
- @if $resolver == null {
- @return $theme;
- }
- @each $key in $keys {
- // Resolve the value for each state key.
- $resolved-value: meta.call(
- $resolver,
- $elevation: map.get($theme, $key),
- $shadow-color: map.get($theme, container-shadow-color)
- );
- // Update the theme with the resolved value.
- $theme: map.set($theme, $key, $resolved-value);
- }
- @return $theme;
- }
- @mixin theme-styles(
- $theme,
- $resolver: resolvers.$material,
- $query: feature-targeting.all()
- ) {
- @include theme.validate-theme-styles($light-theme, $theme);
- $theme: keys.create-theme-properties(
- $theme,
- $prefix: $custom-property-prefix
- );
- @include text-color(map.get($theme, supporting-text-color), $query: $query);
- @include _supporting-text-typography(
- (
- font: map.get($theme, supporting-text-font),
- size: map.get($theme, supporting-text-size),
- tracking: map.get($theme, supporting-text-tracking),
- weight: map.get($theme, supporting-text-weight),
- line-height: map.get($theme, supporting-text-line-height),
- ),
- $query: $query
- );
- @include graphic-shape-radius(
- map.get($theme, with-image-image-shape),
- $query: $query
- );
- @include _graphic-size(
- map.get($theme, with-image-image-size),
- $query: $query
- );
- @include fill-color(map.get($theme, container-color), $query: $query);
- @include divider-color(map.get($theme, divider-color), $query: $query);
- @include _divider-height(map.get($theme, divider-height), $query: $query);
- @include _banner-shape(map.get($theme, container-shape), $query: $query);
- @include _banner-elevation(
- $resolver,
- map.get($theme, container-elevation),
- map.get($theme, container-shadow-color),
- $query
- );
- .mdc-button {
- @include button-text-theme.theme-styles(
- (
- focus-label-text-color: map.get($theme, action-focus-label-text-color),
- focus-state-layer-color: map.get($theme, action-focus-state-layer-color),
- focus-state-layer-opacity:
- map.get($theme, action-focus-state-layer-opacity),
- hover-label-text-color: map.get($theme, action-hover-label-text-color),
- hover-state-layer-color: map.get($theme, action-hover-state-layer-color),
- hover-state-layer-opacity:
- map.get($theme, action-hover-state-layer-opacity),
- label-text-color: map.get($theme, action-label-text-color),
- label-text-font: map.get($theme, action-label-text-font),
- label-text-size: map.get($theme, action-label-text-size),
- label-text-tracking: map.get($theme, action-label-text-tracking),
- label-text-weight: map.get($theme, action-label-text-weight),
- pressed-label-text-color:
- map.get($theme, action-pressed-label-text-color),
- pressed-state-layer-color:
- map.get($theme, action-pressed-state-layer-color),
- pressed-state-layer-opacity:
- map.get($theme, action-pressed-state-layer-opacity),
- ),
- $query: $query
- );
- }
- }
- ///
- /// Customizes fill color.
- /// @param {Color | String} $color Either a valid color value or a key from
- /// `$theme-theme-color.property-values`.
- ///
- @mixin fill-color($color, $query: feature-targeting.all()) {
- $feat-color: feature-targeting.create-target($query, color);
- @include feature-targeting.targets($feat-color) {
- @include theme.property(background-color, $color);
- }
- .mdc-banner__fixed {
- @include feature-targeting.targets($feat-color) {
- @include theme.property(background-color, $color);
- }
- }
- }
- ///
- /// Customizes text color.
- /// @param {Color | String} $color Either a valid color value or a key from
- /// `$theme-theme-color.property-values`.
- ///
- @mixin text-color($color, $query: feature-targeting.all()) {
- $feat-color: feature-targeting.create-target($query, color);
- .mdc-banner__text {
- @include feature-targeting.targets($feat-color) {
- @include theme.property(color, $color);
- }
- }
- }
- ///
- /// Customizes divider color.
- /// @param {Color | String} $color Either a valid color value or a key from
- /// `$theme-theme-color.property-values`.
- ///
- @mixin divider-color($color, $query: feature-targeting.all()) {
- $feat-color: feature-targeting.create-target($query, color);
- @include feature-targeting.targets($feat-color) {
- @include theme.property(border-bottom-color, $color);
- }
- .mdc-banner__fixed {
- @include feature-targeting.targets($feat-color) {
- @include theme.property(border-bottom-color, $color);
- }
- }
- }
- @mixin _divider-height($height, $query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- @include feature-targeting.targets($feat-structure) {
- @include theme.property(border-bottom-width, $height);
- }
- .mdc-banner__fixed {
- @include feature-targeting.targets($feat-structure) {
- @include theme.property(border-bottom-width, $height);
- }
- }
- }
- ///
- /// Customizes the graphic color.
- /// @param {Color | String} $color Either a valid color value or a key from
- /// `$theme-theme-color.property-values`.
- ///
- @mixin graphic-color($color, $query: feature-targeting.all()) {
- $feat-color: feature-targeting.create-target($query, color);
- .mdc-banner__graphic {
- @include feature-targeting.targets($feat-color) {
- @include theme.property(color, $color);
- }
- }
- }
- ///
- /// Customizes the graphic background color.
- /// @param {Color | String} $color Either a valid color value or a key from
- /// `$theme-theme-color.property-values`.
- ///
- @mixin graphic-background-color($color, $query: feature-targeting.all()) {
- $feat-color: feature-targeting.create-target($query, color);
- .mdc-banner__graphic {
- @include feature-targeting.targets($feat-color) {
- @include theme.property(background-color, $color);
- }
- }
- }
- ///
- /// Customizes the graphic shape radius.
- /// @param {Number} $shape-radius Shape radius in length or percentage.
- ///
- @mixin graphic-shape-radius($shape-radius, $query: feature-targeting.all()) {
- .mdc-banner__graphic {
- @include shape-mixins.radius($shape-radius, $query: $query);
- }
- }
- ///
- /// Sets the min-width for the banner content.
- /// @param {Number} $min-width Minimum width value in `px`.
- /// @param {Number} $mobile-breakpoint Mobile breakpoint value in `px`.
- ///
- @mixin min-width(
- $min-width,
- $mobile-breakpoint: $mobile-breakpoint,
- $query: feature-targeting.all()
- ) {
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-banner__content,
- .mdc-banner__fixed {
- @include feature-targeting.targets($feat-structure) {
- min-width: $min-width;
- // The first media query ensures that banners are always 100% width on
- // mobile devices, as required by the spec. The second media query
- // prevents banners from being wider than the viewport for large min-width
- // values.
- @media (max-width: $mobile-breakpoint), (max-width: $min-width) {
- min-width: 100%;
- }
- }
- }
- }
- ///
- /// Sets the max-width for the banner content.
- /// @param {Number} $max-width Maximum width value in `px`.
- ///
- @mixin max-width($max-width, $query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-banner__content {
- @include feature-targeting.targets($feat-structure) {
- max-width: $max-width;
- }
- }
- }
- ///
- /// Sets the banner content to centered instead of leading.
- ///
- @mixin position-centered($query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-banner__content {
- @include feature-targeting.targets($feat-structure) {
- left: 0;
- margin-left: auto;
- margin-right: auto;
- right: 0;
- }
- }
- }
- ///
- /// Sets the banner content to stacked layout.
- ///
- @mixin layout-stacked($query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- @include feature-targeting.targets($feat-structure) {
- .mdc-banner__content {
- flex-wrap: wrap;
- }
- .mdc-banner__graphic {
- margin-bottom: 12px;
- }
- .mdc-banner__text {
- @include rtl.reflexive-property(margin, 16px, 8px);
- padding-bottom: 4px;
- }
- .mdc-banner__actions {
- margin-left: auto;
- }
- }
- }
- // Sets the z-index of the banner.
- // @param {Number} $z-index
- @mixin z-index($z-index, $query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- @include feature-targeting.targets($feat-structure) {
- z-index: $z-index;
- }
- }
- // Sets the width of the banner fixed element. Use to adjust the width of the
- // fixed banner in cases where width is not the same as the viewport.
- // @param {Number} $width Width value in `px`.
- @mixin fixed-width($width, $query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-banner__fixed {
- @include feature-targeting.targets($feat-structure) {
- width: $width;
- }
- }
- }
- @mixin _supporting-text-typography(
- $typography-map,
- $query: feature-targeting.all()
- ) {
- $feat-typography: feature-targeting.create-target($query, typography);
- $font: map.get($typography-map, font);
- $size: map.get($typography-map, size);
- $tracking: map.get($typography-map, tracking);
- $weight: map.get($typography-map, weight);
- $line-height: map.get($typography-map, line-height);
- .mdc-banner__text {
- @include feature-targeting.targets($feat-typography) {
- @include theme.property(letter-spacing, $tracking);
- @include theme.property(font-size, $size);
- @include theme.property(font-family, $font);
- @include theme.property(font-weight, $weight);
- @include theme.property(line-height, $line-height);
- }
- }
- }
- @mixin _banner-shape($shape, $query: feature-targeting.all()) {
- @include shape-mixins.radius($shape, $query: $query);
- }
- @mixin _banner-elevation(
- $resolver,
- $elevation,
- $shadow-color,
- $query: feature-targeting.all()
- ) {
- $elevation-resolver: map.get($resolver, elevation);
- @include elevation-theme.with-resolver(
- $elevation-resolver,
- $elevation: $elevation,
- $shadow-color: $shadow-color,
- $query: $query
- );
- }
- @mixin _graphic-size($size, $query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-banner__graphic {
- @include feature-targeting.targets($feat-structure) {
- @include theme.property(height, $size);
- @include theme.property(width, $size);
- }
- }
- }
|