| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- //
- // Copyright 2021 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.
- //
- // stylelint-disable selector-class-pattern --
- // Selector '.mdc-*' should only be used in this project.
- @use 'sass:map';
- @use 'sass:meta';
- @use '@material/elevation/elevation-theme';
- @use '@material/ripple/ripple-theme';
- @use '@material/theme/keys';
- @use '@material/theme/state';
- @use '@material/theme/theme';
- @use '@material/theme/validate';
- @use '@material/theme/theme-color';
- @use '@material/typography/typography';
- @use '@material/tokens/resolvers';
- $primary-light-theme: (
- active-focus-state-layer-color: theme-color.$primary,
- active-focus-state-layer-opacity: 0.12,
- active-hover-state-layer-color: theme-color.$primary,
- active-hover-state-layer-opacity: 0.04,
- active-pressed-state-layer-color: theme-color.$primary,
- active-pressed-state-layer-opacity: 0.1,
- container-color: theme-color.$surface,
- container-elevation: elevation-theme.get-elevation(0),
- container-height: 48px,
- container-shape: 0,
- inactive-focus-state-layer-color: theme-color.$on-surface,
- inactive-focus-state-layer-opacity: 0.12,
- inactive-hover-state-layer-color: theme-color.$on-surface,
- inactive-hover-state-layer-opacity: 0.04,
- inactive-pressed-state-layer-color: theme-color.$on-surface,
- inactive-pressed-state-layer-opacity: 0.1,
- with-icon-active-focus-icon-color: theme-color.$primary,
- with-icon-active-hover-icon-color: theme-color.$primary,
- with-icon-active-icon-color: theme-color.$primary,
- with-icon-active-pressed-icon-color: theme-color.$primary,
- with-icon-and-label-text-container-height: 64px,
- with-icon-icon-size: 24px,
- with-icon-inactive-focus-icon-color: theme-color.$on-surface,
- with-icon-inactive-hover-icon-color: theme-color.$on-surface,
- with-icon-inactive-icon-color: theme-color.$on-surface,
- with-icon-inactive-pressed-icon-color: theme-color.$on-surface,
- with-label-text-active-focus-label-text-color: theme-color.$primary,
- with-label-text-active-hover-label-text-color: theme-color.$primary,
- with-label-text-active-label-text-color: theme-color.$primary,
- with-label-text-active-pressed-label-text-color: theme-color.$primary,
- with-label-text-inactive-focus-label-text-color: theme-color.$on-surface,
- with-label-text-inactive-hover-label-text-color: theme-color.$on-surface,
- with-label-text-inactive-label-text-color: theme-color.$on-surface,
- with-label-text-inactive-pressed-label-text-color: theme-color.$on-surface,
- with-label-text-label-text-font: typography.get-font(subhead2),
- with-label-text-label-text-size: typography.get-size(subhead2),
- with-label-text-label-text-letter-spacing: typography.get-tracking(subhead2),
- with-label-text-label-text-line-height: typography.get-line-height(subhead2),
- with-label-text-label-text-weight: typography.get-weight(subhead2),
- );
- $secondary-light-theme: (
- active-label-text-color: null,
- container-color: null,
- container-elevation: null,
- container-height: null,
- container-shadow-color: null,
- container-shape: null,
- focus-label-text-color: null,
- focus-state-layer-color: null,
- focus-state-layer-opacity: null,
- hover-label-text-color: null,
- hover-state-layer-color: null,
- hover-state-layer-opacity: null,
- inactive-label-text-color: null,
- label-text-font: null,
- label-text-size: null,
- label-text-letter-spacing: null,
- label-text-line-height: null,
- label-text-weight: null,
- pressed-label-text-color: null,
- pressed-state-layer-color: null,
- pressed-state-layer-opacity: null,
- with-icon-active-icon-color: null,
- with-icon-focus-icon-color: null,
- with-icon-hover-icon-color: null,
- with-icon-inactive-icon-color: null,
- with-icon-pressed-icon-color: null,
- with-icon-icon-size: null,
- );
- $_ripple-target: '.mdc-tab__ripple';
- $custom-property-prefix: 'tab';
- $custom-property-prefix-primary: 'primary-navigation-tab';
- $custom-property-prefix-secondary: 'secondary-navigation-tab';
- @mixin primary-navigation-tab-theme($theme, $resolvers: resolvers.$material) {
- $theme: validate.theme($primary-light-theme, $theme);
- $theme: typography.resolve-theme(
- $theme,
- map.get($resolvers, typography),
- with-label-text-label-text
- );
- @include keys.declare-custom-properties(
- $theme,
- $prefix: $custom-property-prefix-primary
- );
- }
- @mixin secondary-navigation-tab-theme($theme, $resolvers: resolvers.$material) {
- $theme: validate.theme($secondary-light-theme, $theme);
- $theme: typography.resolve-theme(
- $theme,
- map.get($resolvers, typography),
- label-text
- );
- @include keys.declare-custom-properties(
- $theme,
- $prefix: $custom-property-prefix-secondary
- );
- }
- @mixin primary-navigation-tab-theme-styles(
- $theme,
- $resolvers: resolvers.$material
- ) {
- // TODO(b/251881053): Use theme-styles mixin from validate module
- // when all customers are migrated
- @include theme.validate-theme-styles($primary-light-theme, $theme);
- $theme: typography.resolve-theme(
- $theme,
- map.get($resolvers, typography),
- with-label-text-label-text
- );
- $theme: keys.create-theme-properties(
- $theme,
- $prefix: $custom-property-prefix-primary
- );
- // TODO(b/191298796): Use independent state layer color mixins when available.
- @include _active-state-layer-color(
- map.get($theme, active-hover-state-layer-color) or
- map.get($theme, active-focus-state-layer-color) or
- map.get($theme, active-pressed-state-layer-color)
- );
- @include _active-state-layer-opacity(
- (
- hover: map.get($theme, active-hover-state-layer-opacity),
- focus: map.get($theme, active-focus-state-layer-opacity),
- pressed: map.get($theme, active-pressed-state-layer-opacity),
- )
- );
- // TODO(b/191298796): Use independent state layer color mixins when available.
- @include _inactive-state-layer-color(
- map.get($theme, inactive-hover-state-layer-color) or
- map.get($theme, inactive-focus-state-layer-color) or
- map.get($theme, inactive-pressed-state-layer-color)
- );
- @include _inactive-state-layer-opacity(
- (
- hover: map.get($theme, inactive-hover-state-layer-opacity),
- focus: map.get($theme, inactive-focus-state-layer-opacity),
- pressed: map.get($theme, inactive-pressed-state-layer-opacity),
- )
- );
- @include _container-color(map.get($theme, container-color));
- @include _container-elevation(map.get($theme, container-elevation));
- @include _container-height(map.get($theme, container-height));
- @include _container-shape(map.get($theme, container-shape));
- @include _with-icon-and-label-text-container-height(
- map.get($theme, with-icon-and-label-text-container-height)
- );
- @include _icon-size(map.get($theme, with-icon-icon-size));
- @include _active-icon-color(
- (
- default: map.get($theme, with-icon-active-icon-color),
- hover: map.get($theme, with-icon-active-hover-icon-color),
- focus: map.get($theme, with-icon-active-focus-icon-color),
- pressed: map.get($theme, with-icon-active-pressed-icon-color),
- )
- );
- @include _inactive-icon-color(
- (
- default: map.get($theme, with-icon-inactive-icon-color),
- hover: map.get($theme, with-icon-inactive-hover-icon-color),
- focus: map.get($theme, with-icon-inactive-focus-icon-color),
- pressed: map.get($theme, with-icon-inactive-pressed-icon-color),
- )
- );
- @include _active-label-text-color(
- (
- default: map.get($theme, with-label-text-active-label-text-color),
- hover: map.get($theme, with-label-text-active-hover-label-text-color),
- focus: map.get($theme, with-label-text-active-focus-label-text-color),
- pressed: map.get($theme, with-label-text-active-pressed-label-text-color),
- )
- );
- @include _inactive-label-text-color(
- (
- default: map.get($theme, with-label-text-inactive-label-text-color),
- hover: map.get($theme, with-label-text-inactive-hover-label-text-color),
- focus: map.get($theme, with-label-text-inactive-focus-label-text-color),
- pressed:
- map.get($theme, with-label-text-inactive-pressed-label-text-color),
- )
- );
- @include _label-text-font-family(
- map.get($theme, with-label-text-label-text-font)
- );
- @include _label-text-font-size(
- map.get($theme, with-label-text-label-text-size)
- );
- @include _label-text-letter-spacing(
- map.get($theme, with-label-text-label-text-letter-spacing)
- );
- @include _label-text-line-height(
- map.get($theme, with-label-text-label-text-line-height)
- );
- @include _label-text-weight(
- map.get($theme, with-label-text-label-text-weight)
- );
- }
- @mixin secondary-navigation-tab-theme-styles(
- $theme,
- $resolvers: resolvers.$material
- ) {
- // TODO(b/251881053): Use theme-styles mixin from validate module
- // when all customers are migrated
- @include theme.validate-theme-styles($secondary-light-theme, $theme);
- $theme: typography.resolve-theme(
- $theme,
- map.get($resolvers, typography),
- label-text
- );
- $theme: keys.create-theme-properties(
- $theme,
- $prefix: $custom-property-prefix-secondary
- );
- // TODO(b/191298796): Use independent state layer color mixins when available.
- @include _active-state-layer-color(
- map.get($theme, hover-state-layer-color) or
- map.get($theme, focus-state-layer-color) or
- map.get($theme, pressed-state-layer-color)
- );
- @include _active-state-layer-opacity(
- (
- hover: map.get($theme, hover-state-layer-opacity),
- focus: map.get($theme, focus-state-layer-opacity),
- pressed: map.get($theme, pressed-state-layer-opacity),
- )
- );
- // TODO(b/191298796): Use independent state layer color mixins when available.
- @include _inactive-state-layer-color(
- map.get($theme, hover-state-layer-color) or
- map.get($theme, focus-state-layer-color) or
- map.get($theme, pressed-state-layer-color)
- );
- @include _inactive-state-layer-opacity(
- (
- hover: map.get($theme, hover-state-layer-opacity),
- focus: map.get($theme, focus-state-layer-opacity),
- pressed: map.get($theme, pressed-state-layer-opacity),
- )
- );
- @include _container-color(map.get($theme, container-color));
- @include _container-elevation(map.get($theme, container-elevation));
- @include _container-height(map.get($theme, container-height));
- @include _container-shape(map.get($theme, container-shape));
- @include _icon-size(map.get($theme, with-icon-icon-size));
- @include _active-icon-color(
- (
- default: map.get($theme, with-icon-active-icon-color),
- hover: map.get($theme, with-icon-hover-icon-color),
- focus: map.get($theme, with-icon-focus-icon-color),
- pressed: map.get($theme, with-icon-pressed-icon-color),
- )
- );
- @include _inactive-icon-color(
- (
- default: map.get($theme, with-icon-inactive-icon-color),
- hover: map.get($theme, with-icon-hover-icon-color),
- focus: map.get($theme, with-icon-focus-icon-color),
- pressed: map.get($theme, with-icon-pressed-icon-color),
- )
- );
- @include _active-label-text-color(
- (
- default: map.get($theme, active-label-text-color),
- hover: map.get($theme, hover-label-text-color),
- focus: map.get($theme, focus-label-text-color),
- pressed: map.get($theme, pressed-label-text-color),
- )
- );
- @include _inactive-label-text-color(
- (
- default: map.get($theme, inactive-label-text-color),
- hover: map.get($theme, hover-label-text-color),
- focus: map.get($theme, focus-label-text-color),
- pressed: map.get($theme, pressed-label-text-color),
- )
- );
- @include _label-text-font-family(map.get($theme, label-text-font));
- @include _label-text-font-size(map.get($theme, label-text-size));
- @include _label-text-letter-spacing(
- map.get($theme, label-text-letter-spacing)
- );
- @include _label-text-line-height(map.get($theme, label-text-line-height));
- @include _label-text-weight(map.get($theme, label-text-weight));
- }
- @mixin _icon-color($color) {
- .mdc-tab__icon {
- @include theme.property(color, $color);
- fill: currentColor;
- }
- }
- @mixin _active-icon-color($color-or-map) {
- &:not(:disabled) {
- @include _set-active-icon-color(state.get-default-state($color-or-map));
- &:hover {
- @include _set-active-icon-color(state.get-hover-state($color-or-map));
- }
- &:focus {
- @include _set-active-icon-color(state.get-focus-state($color-or-map));
- }
- &:active {
- @include _set-active-icon-color(state.get-pressed-state($color-or-map));
- }
- }
- &:disabled {
- @include _set-active-icon-color(state.get-disabled-state($color-or-map));
- }
- }
- @mixin _set-active-icon-color($color) {
- @include _is-active() {
- @include _icon-color($color);
- }
- }
- @mixin _inactive-icon-color($color-or-map) {
- &:not(:disabled) {
- @include _set-inactive-icon-color(state.get-default-state($color-or-map));
- &:hover {
- @include _set-inactive-icon-color(state.get-hover-state($color-or-map));
- }
- &:focus {
- @include _set-inactive-icon-color(state.get-focus-state($color-or-map));
- }
- &:active {
- @include _set-inactive-icon-color(state.get-pressed-state($color-or-map));
- }
- }
- &:disabled {
- @include _set-inactive-icon-color(state.get-disabled-state($color-or-map));
- }
- }
- @mixin _set-inactive-icon-color($color) {
- @include _is-inactive() {
- @include _icon-color($color);
- }
- }
- @mixin _label-text-color($color) {
- .mdc-tab__text-label {
- @include theme.property(color, $color);
- }
- }
- @mixin _active-label-text-color($color-or-map) {
- &:not(:disabled) {
- @include _set-active-label-text-color(
- state.get-default-state($color-or-map)
- );
- &:hover {
- @include _set-active-label-text-color(
- state.get-hover-state($color-or-map)
- );
- }
- &:focus {
- @include _set-active-label-text-color(
- state.get-focus-state($color-or-map)
- );
- }
- &:active {
- @include _set-active-label-text-color(
- state.get-pressed-state($color-or-map)
- );
- }
- }
- &:disabled {
- @include _set-active-label-text-color(
- state.get-disabled-state($color-or-map)
- );
- }
- }
- @mixin _set-active-label-text-color($color) {
- @include _is-active() {
- @include _label-text-color($color);
- }
- }
- @mixin _inactive-label-text-color($color-or-map) {
- &:not(:disabled) {
- @include _set-inactive-label-text-color(
- state.get-default-state($color-or-map)
- );
- &:hover {
- @include _set-inactive-label-text-color(
- state.get-hover-state($color-or-map)
- );
- }
- &:focus {
- @include _set-inactive-label-text-color(
- state.get-focus-state($color-or-map)
- );
- }
- &:active {
- @include _set-inactive-label-text-color(
- state.get-pressed-state($color-or-map)
- );
- }
- }
- &:disabled {
- @include _set-inactive-label-text-color(
- state.get-disabled-state($color-or-map)
- );
- }
- }
- @mixin _set-inactive-label-text-color($color) {
- @include _is-inactive() {
- @include _label-text-color($color);
- }
- }
- @mixin _container-color($color) {
- @include theme.property(background-color, $color);
- }
- @mixin _active-state-layer-color($color) {
- @include _is-active() {
- @include _state-layer-color($color);
- }
- }
- @mixin _inactive-state-layer-color($color) {
- @include _is-inactive() {
- @include _state-layer-color($color);
- }
- }
- @mixin _active-state-layer-opacity($opacity-or-map) {
- @include _is-active() {
- @include _hover-state-layer-opacity(state.get-hover-state($opacity-or-map));
- @include _focus-state-layer-opacity(state.get-focus-state($opacity-or-map));
- @include _pressed-state-layer-opacity(
- state.get-pressed-state($opacity-or-map)
- );
- }
- }
- @mixin _inactive-state-layer-opacity($opacity-or-map) {
- @include _is-inactive() {
- @include _hover-state-layer-opacity(state.get-hover-state($opacity-or-map));
- @include _focus-state-layer-opacity(state.get-focus-state($opacity-or-map));
- @include _pressed-state-layer-opacity(
- state.get-pressed-state($opacity-or-map)
- );
- }
- }
- @mixin _hover-state-layer-opacity($opacity) {
- @include ripple-theme.states-hover-opacity(
- $opacity,
- $ripple-target: $_ripple-target
- );
- }
- @mixin _focus-state-layer-opacity($opacity) {
- @include ripple-theme.states-focus-opacity(
- $opacity,
- $ripple-target: $_ripple-target
- );
- }
- @mixin _pressed-state-layer-opacity($opacity) {
- @include ripple-theme.states-press-opacity(
- $opacity,
- $ripple-target: $_ripple-target
- );
- }
- // TODO(b/191298796): support focused & pressed key colors.
- @mixin _state-layer-color($color) {
- @include ripple-theme.states-base-color(
- $color,
- $ripple-target: $_ripple-target
- );
- }
- @mixin _focus-state-layer-opacity($opacity) {
- @include ripple-theme.states-focus-opacity(
- $opacity,
- $ripple-target: $_ripple-target
- );
- }
- @mixin _pressed-state-layer-opacity($opacity) {
- @include ripple-theme.states-press-opacity(
- $opacity,
- $ripple-target: $_ripple-target
- );
- }
- @mixin _container-elevation($elevation) {
- // TODO(b/188905911): Use elevation's theme() mixin.
- @if $elevation and map.get($elevation, box-shadow) {
- @include elevation-theme.shadow(map.get($elevation, box-shadow));
- }
- @if $elevation and map.get($elevation, overlay-opacity) {
- @include elevation-theme.overlay-opacity(
- map.get($elevation, overlay-opacity)
- );
- }
- }
- @mixin _container-shape($shape-radius) {
- @include theme.property(border-radius, $shape-radius);
- .mdc-tab__ripple {
- @include theme.property(border-radius, $shape-radius);
- }
- }
- @mixin _icon-size($size) {
- @include theme.property('width', $size);
- @include theme.property('height', $size);
- @include theme.property('font-size', $size);
- }
- @mixin _label-text-font-family($font-family) {
- .mdc-tab__text-label {
- @include theme.property('font-family', $font-family);
- }
- }
- @mixin _label-text-font-size($font-size) {
- .mdc-tab__text-label {
- @include theme.property('font-size', $font-size);
- }
- }
- @mixin _label-text-letter-spacing($letter-spacing) {
- .mdc-tab__text-label {
- @include theme.property('letter-spacing', $letter-spacing);
- }
- }
- @mixin _label-text-line-height($line-height) {
- .mdc-tab__text-label {
- @include theme.property('line-height', $line-height);
- }
- }
- @mixin _label-text-weight($weight) {
- .mdc-tab__text-label {
- @include theme.property('font-weight', $weight);
- }
- }
- @mixin _height($height) {
- @include theme.property(height, $height);
- }
- @mixin _container-height($height) {
- &:not(.mdc-tab--stacked) {
- @include _height($height);
- }
- }
- @mixin _with-icon-and-label-text-container-height($height) {
- &.mdc-tab--stacked {
- @include _height($height);
- }
- }
- @mixin _is-active() {
- &.mdc-tab--active {
- @content;
- }
- }
- @mixin _is-inactive() {
- &:not(.mdc-tab--active) {
- @content;
- }
- }
|