| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- //
- // Copyright 2022 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 --
- // NOTE: this is the implementation of the aforementioned classes.
- @use 'sass:map';
- @use '@material/tokens/resolvers';
- @use '@material/floating-label/mixins' as floating-label-mixins;
- @use '@material/theme/theme';
- @use '@material/typography/typography';
- $_light-theme: (
- active-indicator-color: null,
- active-indicator-height: null,
- caret-color: null,
- container-color: null,
- container-height: null,
- container-shape: null,
- disabled-active-indicator-color: null,
- disabled-active-indicator-height: null,
- disabled-active-indicator-opacity: null,
- disabled-container-color: null,
- disabled-container-opacity: null,
- disabled-input-text-color: null,
- disabled-input-text-opacity: null,
- disabled-label-text-color: null,
- disabled-label-text-opacity: null,
- disabled-leading-icon-color: null,
- disabled-leading-icon-opacity: null,
- disabled-outline-color: null,
- disabled-outline-opacity: null,
- disabled-outline-width: null,
- disabled-supporting-text-color: null,
- disabled-supporting-text-opacity: null,
- disabled-trailing-icon-color: null,
- disabled-trailing-icon-opacity: null,
- error-active-indicator-color: null,
- // Token key `error-caret-color` not available on DSDB.
- error-caret-color: null,
- error-focus-active-indicator-color: null,
- error-focus-caret-color: null,
- error-focus-input-text-color: null,
- error-focus-label-text-color: null,
- error-focus-leading-icon-color: null,
- error-focus-outline-color: null,
- error-focus-supporting-text-color: null,
- error-focus-trailing-icon-color: null,
- error-hover-active-indicator-color: null,
- // Token key `error-hover-caret-color` not available on DSDB.
- error-hover-caret-color: null,
- error-hover-input-text-color: null,
- error-hover-label-text-color: null,
- error-hover-leading-icon-color: null,
- error-hover-outline-color: null,
- error-hover-state-layer-color: null,
- error-hover-state-layer-opacity: null,
- error-hover-supporting-text-color: null,
- error-hover-trailing-icon-color: null,
- error-input-text-color: null,
- error-label-text-color: null,
- error-leading-icon-color: null,
- error-outline-color: null,
- error-supporting-text-color: null,
- error-trailing-icon-color: null,
- focus-active-indicator-color: null,
- focus-active-indicator-height: null,
- // Token key `focus-caret-color` not available on DSDB.
- focus-caret-color: null,
- focus-input-text-color: null,
- focus-label-text-color: null,
- focus-leading-icon-color: null,
- focus-outline-color: null,
- focus-outline-width: null,
- focus-supporting-text-color: null,
- focus-trailing-icon-color: null,
- hover-active-indicator-color: null,
- hover-active-indicator-height: null,
- // Token key `hover-caret-color` not available on DSDB.
- hover-caret-color: null,
- hover-input-text-color: null,
- hover-label-text-color: null,
- hover-leading-icon-color: null,
- hover-outline-color: null,
- hover-outline-width: null,
- hover-state-layer-color: null,
- hover-state-layer-opacity: null,
- hover-supporting-text-color: null,
- hover-trailing-icon-color: null,
- input-text-color: null,
- input-text-font: null,
- input-text-line-height: null,
- input-text-placeholder-color: null,
- input-text-prefix-color: null,
- input-text-size: null,
- input-text-suffix-color: null,
- input-text-tracking: null,
- input-text-type: null,
- input-text-weight: null,
- label-text-color: null,
- label-text-font: null,
- label-text-line-height: null,
- label-text-populated-line-height: null,
- label-text-populated-size: null,
- label-text-size: null,
- label-text-tracking: null,
- label-text-type: null,
- label-text-weight: null,
- leading-icon-color: null,
- leading-icon-size: null,
- outline-color: null,
- outline-width: null,
- supporting-text-color: null,
- supporting-text-font: null,
- supporting-text-line-height: null,
- supporting-text-size: null,
- supporting-text-tracking: null,
- supporting-text-type: null,
- supporting-text-weight: null,
- trailing-icon-color: null,
- trailing-icon-size: null,
- );
- @mixin theme-styles($theme, $resolvers: resolvers.$material) {
- @include theme.validate-theme-styles($_light-theme, $theme);
- // TODO(b/261633818): Remove support for extraneous `*-caret-color` tokens.
- @include _caret-color(
- (
- default: map.get($theme, caret-color),
- hover: map.get($theme, hover-caret-color),
- focus: map.get($theme, focus-caret-color),
- )
- );
- @include _error-caret-color(
- (
- default: map.get($theme, error-caret-color),
- hover: map.get($theme, error-hover-caret-color),
- focus: map.get($theme, error-focus-caret-color),
- )
- );
- @include _input-text-color(
- (
- default: map.get($theme, input-text-color),
- hover: map.get($theme, hover-input-text-color),
- focus: map.get($theme, focus-input-text-color),
- disabled: map.get($theme, disabled-input-text-color),
- )
- );
- @include _error-input-text-color(
- (
- default: map.get($theme, error-input-text-color),
- hover: map.get($theme, error-hover-input-text-color),
- focus: map.get($theme, error-focus-input-text-color),
- )
- );
- @include _label-text-color(
- (
- default: map.get($theme, label-text-color),
- hover: map.get($theme, hover-label-text-color),
- focus: map.get($theme, focus-label-text-color),
- disabled: map.get($theme, disabled-label-text-color),
- )
- );
- @include _error-label-text-color(
- (
- default: map.get($theme, error-label-text-color),
- hover: map.get($theme, error-hover-label-text-color),
- focus: map.get($theme, error-focus-label-text-color),
- )
- );
- @include _leading-icon-color(
- (
- default: map.get($theme, leading-icon-color),
- hover: map.get($theme, hover-leading-icon-color),
- focus: map.get($theme, focus-leading-icon-color),
- disabled: map.get($theme, disabled-leading-icon-color),
- )
- );
- @include _error-leading-icon-color(
- (
- default: map.get($theme, error-leading-icon-color),
- hover: map.get($theme, error-hover-leading-icon-color),
- focus: map.get($theme, error-focus-leading-icon-color),
- )
- );
- @include _trailing-icon-color(
- (
- default: map.get($theme, trailing-icon-color),
- hover: map.get($theme, hover-trailing-icon-color),
- focus: map.get($theme, focus-trailing-icon-color),
- disabled: map.get($theme, disabled-trailing-icon-color),
- )
- );
- @include _error-trailing-icon-color(
- (
- default: map.get($theme, error-trailing-icon-color),
- hover: map.get($theme, error-hover-trailing-icon-color),
- focus: map.get($theme, error-focus-trailing-icon-color),
- )
- );
- @include _supporting-text-color(
- (
- default: map.get($theme, supporting-text-color),
- hover: map.get($theme, hover-supporting-text-color),
- focus: map.get($theme, focus-supporting-text-color),
- disabled: map.get($theme, disabled-supporting-text-color),
- )
- );
- @include _error-supporting-text-color(
- (
- default: map.get($theme, error-supporting-text-color),
- hover: map.get($theme, error-hover-supporting-text-color),
- focus: map.get($theme, error-focus-supporting-text-color),
- )
- );
- @include _input-text-typography(
- (
- font: map.get($theme, input-text-font),
- line-height: map.get($theme, input-text-line-height),
- size: map.get($theme, input-text-size),
- tracking: map.get($theme, input-text-tracking),
- weight: map.get($theme, input-text-weight),
- )
- );
- @include _label-text-typography(
- (
- font: map.get($theme, label-text-font),
- line-height: map.get($theme, label-text-line-height),
- size: map.get($theme, label-text-size),
- tracking: map.get($theme, label-text-tracking),
- weight: map.get($theme, label-text-weight),
- )
- );
- @include _label-text-populated-typography(
- (
- line-height: map.get($theme, label-text-populated-line-height),
- size: map.get($theme, label-text-populated-size),
- )
- );
- @include _supporting-text-typography(
- (
- font: map.get($theme, supporting-text-font),
- line-height: map.get($theme, supporting-text-line-height),
- size: map.get($theme, supporting-text-size),
- tracking: map.get($theme, supporting-text-tracking),
- weight: map.get($theme, supporting-text-weight),
- )
- );
- }
- @mixin _caret-color($colors) {
- @include if-enabled {
- @include _set-caret-color(map.get($colors, default));
- @include if-hovered {
- @include _set-caret-color(map.get($colors, hover));
- }
- @include if-focused {
- @include _set-caret-color(map.get($colors, focus));
- }
- }
- }
- @mixin _set-caret-color($color) {
- .mdc-text-field__input {
- @include theme.property(caret-color, $color);
- }
- }
- @mixin _error-caret-color($colors) {
- &.mdc-text-field--invalid {
- @include _caret-color($colors);
- }
- }
- @mixin _input-text-color($colors) {
- @include if-enabled {
- @include _set-input-text-color(map.get($colors, default));
- @include if-hovered {
- @include _set-input-text-color(map.get($colors, hover));
- }
- @include if-focused {
- @include _set-input-text-color(map.get($colors, focus));
- }
- }
- @include if-disabled {
- @include _set-input-text-color(map.get($colors, disabled));
- }
- }
- @mixin _set-input-text-color($color) {
- @if $color {
- .mdc-text-field__input {
- @include theme.property(color, $color);
- }
- }
- }
- @mixin _error-input-text-color($color) {
- &.mdc-text-field--invalid {
- @include _input-text-color($color);
- }
- }
- @mixin _label-text-color($colors) {
- @include if-enabled {
- @include _set-label-text-color(map.get($colors, default));
- @include if-focused {
- @include _set-label-text-color(map.get($colors, focus));
- }
- @include if-hovered {
- @include _set-label-text-color(map.get($colors, hover));
- }
- }
- @include if-disabled {
- @include _set-label-text-color(map.get($colors, disabled));
- }
- }
- @mixin _set-label-text-color($color) {
- .mdc-floating-label,
- .mdc-floating-label--float-above {
- @include floating-label-mixins.ink-color($color);
- }
- }
- @mixin _error-label-text-color($color) {
- &.mdc-text-field--invalid {
- @include _label-text-color($color);
- }
- }
- @mixin _leading-icon-color($colors) {
- @include if-enabled {
- @include _set-leading-icon-color(map.get($colors, default));
- @include if-hovered {
- @include _set-leading-icon-color(map.get($colors, hover));
- }
- @include if-focused {
- @include _set-leading-icon-color(map.get($colors, focus));
- }
- }
- @include if-disabled {
- @include _set-leading-icon-color(map.get($colors, disabled));
- }
- }
- @mixin _set-leading-icon-color($color) {
- .mdc-text-field__icon--leading {
- @include theme.property(color, $color);
- }
- }
- @mixin _error-leading-icon-color($color) {
- &.mdc-text-field--invalid {
- @include _leading-icon-color($color);
- }
- }
- @mixin _trailing-icon-color($colors) {
- @include if-enabled {
- @include _set-trailing-icon-color(map.get($colors, default));
- @include if-hovered {
- @include _set-trailing-icon-color(map.get($colors, hover));
- }
- @include if-focused {
- @include _set-trailing-icon-color(map.get($colors, focus));
- }
- }
- @include if-disabled {
- @include _set-trailing-icon-color(map.get($colors, disabled));
- }
- }
- @mixin _set-trailing-icon-color($color) {
- .mdc-text-field__icon--trailing {
- @include theme.property(color, $color);
- }
- }
- @mixin _error-trailing-icon-color($color) {
- &.mdc-text-field--invalid {
- @include _trailing-icon-color($color);
- }
- }
- @mixin _supporting-text-color($colors) {
- @include if-enabled {
- @include _set-supporting-text-color(map.get($colors, default));
- @include if-hovered {
- @include _set-supporting-text-color(map.get($colors, hover));
- }
- @include if-focused {
- @include _set-supporting-text-color(map.get($colors, focus));
- }
- }
- @include if-disabled {
- @include _set-supporting-text-color(map.get($colors, disabled));
- }
- }
- @mixin _error-supporting-text-color($color) {
- &.mdc-text-field--invalid {
- @include _supporting-text-color($color);
- }
- }
- @mixin _set-supporting-text-color($color) {
- & + .mdc-text-field-helper-line .mdc-text-field-helper-text,
- & + .mdc-text-field-helper-line .mdc-text-field-character-counter {
- @include theme.property(color, $color);
- }
- }
- @mixin _input-text-typography($typography-theme) {
- .mdc-text-field__input {
- @include typography.theme-styles($typography-theme);
- }
- }
- @mixin _label-text-typography($typography-theme) {
- .mdc-floating-label {
- @include typography.theme-styles($typography-theme);
- }
- }
- @mixin _label-text-populated-typography($typography-theme) {
- .mdc-floating-label--float-above {
- @include typography.theme-styles($typography-theme);
- }
- }
- @mixin _supporting-text-typography($typography-theme) {
- & + .mdc-text-field-helper-line .mdc-text-field-helper-text,
- & + .mdc-text-field-helper-line .mdc-text-field-character-counter {
- @include typography.theme-styles($typography-theme);
- }
- }
- /// Selector for hovered state
- @mixin if-hovered {
- &:not(.mdc-text-field--focused):hover {
- @content;
- }
- }
- /// Selector for focused state
- @mixin if-focused {
- &.mdc-text-field--focused {
- @content;
- }
- }
- /// Selector for enabled state
- @mixin if-enabled {
- &:not(.mdc-text-field--disabled) {
- @content;
- }
- }
- /// Selector for disabled state
- @mixin if-disabled {
- &.mdc-text-field--disabled {
- @content;
- }
- }
|