@use 'sass:map'; @use 'sass:math'; @use '../core/theming/theming'; @use '../core/typography/typography'; @use '../core/typography/typography-utils'; // Theme styles that only apply to the fill appearance of the form-field. /// @deprecated Use `mat.form-field-fill-color` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. /// @breaking-change 17.0.0 @mixin fill-color($config-or-theme) { $config: theming.get-color-config($config-or-theme); $foreground: map.get($config, foreground); $is-dark-theme: map.get($config, is-dark); $fill-background: theming.get-color-from-palette($foreground, base, if($is-dark-theme, 0.1, 0.04)); $fill-disabled-background: theming.get-color-from-palette($foreground, base, if($is-dark-theme, 0.05, 0.02)); $underline-color: theming.get-color-from-palette($foreground, divider, if($is-dark-theme, 0.5, 0.42)); $label-disabled-color: theming.get-color-from-palette($foreground, disabled-text); .mat-form-field-appearance-fill { .mat-form-field-flex { background-color: $fill-background; } &.mat-form-field-disabled .mat-form-field-flex { background-color: $fill-disabled-background; } .mat-form-field-underline::before { background-color: $underline-color; } &.mat-form-field-disabled { .mat-form-field-label { color: $label-disabled-color; } .mat-form-field-underline::before { background-color: transparent; } } } } // Used to make instances of the _mat-form-field-label-floating mixin negligibly different, // and prevent Google's CSS Optimizer from collapsing the declarations. This is needed because some // of the selectors contain pseudo-classes not recognized in all browsers. If a browser encounters // an unknown pseudo-class it will discard the entire rule set. $fill-dedupe: 0; // Applies a floating label above the form field control itself. @mixin _label-floating($font-scale, $infix-padding, $infix-margin-top) { transform: translateY(-$infix-margin-top - $infix-padding + $fill-dedupe) scale($font-scale); width: math.div(100%, $font-scale) + $fill-dedupe; $fill-dedupe: $fill-dedupe + 0.00001 !global; } /// @deprecated Use `mat.form-field-fill-typography` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. /// @breaking-change 17.0.0 @mixin fill-typography($config-or-theme) { $config: typography.private-typography-to-2014-config( theming.get-typography-config($config-or-theme)); // The unit-less line-height from the font config. $line-height: typography-utils.line-height($config, input); // The amount to scale the font for the floating label and subscript. $subscript-font-scale: 0.75; // The padding on top of the infix. $infix-padding-top: 0.25em; // The padding below the infix. $infix-padding-bottom: 0.75em; // The margin applied to the form-field-infix to reserve space for the floating label. $infix-margin-top: $subscript-font-scale * typography-utils.private-coerce-unitless-to-em($line-height); // The amount we offset the label from the input text in the fill appearance. $fill-appearance-label-offset: -0.5em; .mat-form-field-appearance-fill { .mat-form-field-infix { padding: $infix-padding-top 0 $infix-padding-bottom 0; } .mat-form-field-label { top: $infix-margin-top + $infix-padding-top; margin-top: $fill-appearance-label-offset; } &.mat-form-field-can-float { &.mat-form-field-should-float .mat-form-field-label, .mat-input-server:focus + .mat-form-field-label-wrapper .mat-form-field-label { @include _label-floating( $subscript-font-scale, $infix-padding-top + $fill-appearance-label-offset, $infix-margin-top); } // Server-side rendered matInput with a label attribute but label not shown // (used as a pure CSS stand-in for mat-form-field-should-float). .mat-input-server[label] + .mat-form-field-label-wrapper .mat-form-field-label { @include _label-floating( $subscript-font-scale, $infix-padding-top + $fill-appearance-label-offset, $infix-margin-top); } } } } /// @deprecated Use `mat.form-field-private-form-field-fill-density` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. /// @breaking-change 17.0.0 @mixin private-form-field-fill-density($config-or-theme) {} /// @deprecated Use `mat.form-field-fill-theme` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. /// @breaking-change 17.0.0 @mixin fill-theme($theme-or-color-config) { $theme: theming.private-legacy-get-theme($theme-or-color-config); @include theming.private-check-duplicate-theme-styles($theme, 'mat-form-field-fill') { $color: theming.get-color-config($theme); $density: theming.get-density-config($theme); $typography: theming.get-typography-config($theme); @if $color != null { @include fill-color($color); } @if $density != null { @include private-form-field-fill-density($density); } @if $typography != null { @include fill-typography($typography); } } }