blob: 74ace20528ebb8d0e7d0773aa58d4f0b3ced1fdd [file] [log] [blame]
@import '../core/theming/palette';
@import '../core/theming/theming';
@import '../core/style/form-common';
@import '../core/typography/typography-utils';
@import './form-field-fill-theme.scss';
@import './form-field-legacy-theme.scss';
@import './form-field-outline-theme.scss';
@import './form-field-standard-theme.scss';
// Color styles that apply to all appearances of the form-field.
@mixin mat-form-field-color($config-or-theme) {
$config: mat-get-color-config($config-or-theme);
$primary: map-get($config, primary);
$accent: map-get($config, accent);
$warn: map-get($config, warn);
$background: map-get($config, background);
$foreground: map-get($config, foreground);
$is-dark-theme: map-get($config, is-dark);
// Label colors. Required is used for the `*` star shown in the label.
$label-color: mat-color($foreground, secondary-text, if($is-dark-theme, 0.7, 0.6));
$focused-label-color: mat-color($primary, text);
$required-label-color: mat-color($accent, text);
// Underline colors.
$underline-color-base: mat-color($foreground, divider, if($is-dark-theme, 1, 0.87));
$underline-color-accent: mat-color($accent, text);
$underline-color-warn: mat-color($warn, text);
$underline-focused-color: mat-color($primary, text);
.mat-form-field-label {
color: $label-color;
}
.mat-hint {
color: $label-color;
}
.mat-form-field.mat-focused .mat-form-field-label {
color: $focused-label-color;
&.mat-accent {
color: $underline-color-accent;
}
&.mat-warn {
color: $underline-color-warn;
}
}
.mat-focused .mat-form-field-required-marker {
color: $required-label-color;
}
.mat-form-field-ripple {
background-color: $underline-color-base;
}
.mat-form-field.mat-focused {
.mat-form-field-ripple {
background-color: $underline-focused-color;
&.mat-accent {
background-color: $underline-color-accent;
}
&.mat-warn {
background-color: $underline-color-warn;
}
}
}
.mat-form-field-type-mat-native-select.mat-focused:not(.mat-form-field-invalid) {
.mat-form-field-infix::after {
color: $underline-focused-color;
}
&.mat-accent .mat-form-field-infix::after {
color: $underline-color-accent;
}
&.mat-warn .mat-form-field-infix::after {
color: $underline-color-warn;
}
}
// Styling for the error state of the form field. Note that while the same can be
// achieved with the ng-* classes, we use this approach in order to ensure that the same
// logic is used to style the error state and to show the error messages.
.mat-form-field.mat-form-field-invalid {
.mat-form-field-label {
color: $underline-color-warn;
&.mat-accent,
.mat-form-field-required-marker {
color: $underline-color-warn;
}
}
.mat-form-field-ripple,
.mat-form-field-ripple.mat-accent {
background-color: $underline-color-warn;
}
}
.mat-error {
color: $underline-color-warn;
}
@include mat-form-field-legacy-color($config);
@include mat-form-field-standard-color($config);
@include mat-form-field-fill-color($config);
@include mat-form-field-outline-color($config);
}
// 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.
$mat-form-field-dedupe: 0;
// Applies a floating label above the form field control itself.
@mixin _mat-form-field-label-floating($font-scale, $infix-padding, $infix-margin-top) {
transform: translateY(-$infix-margin-top - $infix-padding + $mat-form-field-dedupe)
scale($font-scale);
width: 100% / $font-scale + $mat-form-field-dedupe;
$mat-form-field-dedupe: $mat-form-field-dedupe + 0.00001 !global;
}
@mixin mat-form-field-typography($config-or-theme) {
$config: mat-get-typography-config($config-or-theme);
// The unit-less line-height from the font config.
$line-height: mat-line-height($config, input);
// The amount to scale the font for the floating label and subscript.
$subscript-font-scale: 0.75;
// The amount to scale the font for the prefix and suffix icons.
$prefix-suffix-icon-font-scale: 1.5;
// The padding on the infix. Mocks show half of the text size.
$infix-padding: 0.5em;
// The margin applied to the form-field-infix to reserve space for the floating label.
$infix-margin-top: 1em * $line-height * $subscript-font-scale;
// Font size to use for the label and subscript text.
$subscript-font-size: $subscript-font-scale * 100%;
// Font size to use for the for the prefix and suffix icons.
$prefix-suffix-icon-font-size: $prefix-suffix-icon-font-scale * 100%;
// The space between the bottom of the .mat-form-field-flex area and the subscript wrapper.
// Mocks show half of the text size, but this margin is applied to an element with the subscript
// text font size, so we need to divide by the scale factor to make it half of the original text
// size.
$subscript-margin-top: 0.5em / $subscript-font-scale;
// The padding applied to the form-field-wrapper to reserve space for the subscript, since it's
// absolutely positioned. This is a combination of the subscript's margin and line-height, but we
// need to multiply by the subscript font scale factor since the wrapper has a larger font size.
$wrapper-padding-bottom: ($subscript-margin-top + $line-height) * $subscript-font-scale;
.mat-form-field {
@include mat-typography-level-to-styles($config, input);
}
.mat-form-field-wrapper {
padding-bottom: $wrapper-padding-bottom;
}
.mat-form-field-prefix,
.mat-form-field-suffix {
// Allow icons in a prefix or suffix to adapt to the correct size.
.mat-icon {
font-size: $prefix-suffix-icon-font-size;
line-height: $line-height;
}
// Allow icon buttons in a prefix or suffix to adapt to the correct size.
.mat-icon-button {
height: $prefix-suffix-icon-font-scale * 1em;
width: $prefix-suffix-icon-font-scale * 1em;
.mat-icon {
height: $line-height * 1em;
line-height: $line-height;
}
}
}
.mat-form-field-infix {
padding: $infix-padding 0;
// Throws off the baseline if we do it as a real margin, so we do it as a border instead.
border-top: $infix-margin-top solid transparent;
}
.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 _mat-form-field-label-floating(
$subscript-font-scale, $infix-padding, $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]:not(:label-shown) + .mat-form-field-label-wrapper
.mat-form-field-label {
@include _mat-form-field-label-floating(
$subscript-font-scale, $infix-padding, $infix-margin-top);
}
}
.mat-form-field-label-wrapper {
top: -$infix-margin-top;
padding-top: $infix-margin-top;
}
.mat-form-field-label {
top: $infix-margin-top + $infix-padding;
}
.mat-form-field-underline {
// We want the underline to start at the end of the content box, not the padding box,
// so we move it up by the padding amount.
bottom: $wrapper-padding-bottom;
}
.mat-form-field-subscript-wrapper {
font-size: $subscript-font-size;
margin-top: $subscript-margin-top;
// We want the subscript to start at the end of the content box, not the padding box,
// so we move it up by the padding amount (adjusted for the smaller font size);
top: calc(100% - #{$wrapper-padding-bottom / $subscript-font-scale});
}
@include mat-form-field-legacy-typography($config);
@include mat-form-field-standard-typography($config);
@include mat-form-field-fill-typography($config);
@include mat-form-field-outline-typography($config);
}
@mixin mat-form-field-density($config-or-theme) {
$density-scale: mat-get-density-config($config-or-theme);
@include mat-private-form-field-legacy-density($density-scale);
@include mat-private-form-field-standard-density($density-scale);
@include mat-private-form-field-fill-density($density-scale);
@include mat-private-form-field-outline-density($density-scale);
}
@mixin mat-form-field-theme($theme-or-color-config) {
$theme: mat-private-legacy-get-theme($theme-or-color-config);
@include mat-private-check-duplicate-theme-styles($theme, 'mat-form-field') {
$color: mat-get-color-config($theme);
$density: mat-get-density-config($theme);
$typography: mat-get-typography-config($theme);
@if $color != null {
@include mat-form-field-color($color);
}
@if $density != null {
@include mat-form-field-density($density);
}
@if $typography != null {
@include mat-form-field-typography($typography);
}
}
}