1 | @use 'sass:map';
|
---|
2 | @use '../core/theming/theming';
|
---|
3 | @use '../core/typography/typography';
|
---|
4 | @use '../core/typography/typography-utils';
|
---|
5 | @use '../core/style/private';
|
---|
6 |
|
---|
7 | @use './form-field-fill-theme.scss';
|
---|
8 | @use './form-field-legacy-theme.scss';
|
---|
9 | @use './form-field-outline-theme.scss';
|
---|
10 | @use './form-field-standard-theme.scss';
|
---|
11 |
|
---|
12 | // Color styles that apply to all appearances of the form-field.
|
---|
13 | @mixin color($config-or-theme) {
|
---|
14 | $config: theming.get-color-config($config-or-theme);
|
---|
15 | $primary: map.get($config, primary);
|
---|
16 | $accent: map.get($config, accent);
|
---|
17 | $warn: map.get($config, warn);
|
---|
18 | $background: map.get($config, background);
|
---|
19 | $foreground: map.get($config, foreground);
|
---|
20 | $is-dark-theme: map.get($config, is-dark);
|
---|
21 |
|
---|
22 | // Label colors. Required is used for the `*` star shown in the label.
|
---|
23 | $label-color:
|
---|
24 | theming.get-color-from-palette($foreground, secondary-text, if($is-dark-theme, 0.7, 0.6));
|
---|
25 | $focused-label-color: theming.get-color-from-palette($primary, text);
|
---|
26 | $required-label-color: theming.get-color-from-palette($accent, text);
|
---|
27 |
|
---|
28 | // Underline colors.
|
---|
29 | $underline-color-base:
|
---|
30 | theming.get-color-from-palette($foreground, divider, if($is-dark-theme, 1, 0.87));
|
---|
31 | $underline-color-accent: theming.get-color-from-palette($accent, text);
|
---|
32 | $underline-color-warn: theming.get-color-from-palette($warn, text);
|
---|
33 | $underline-focused-color: theming.get-color-from-palette($primary, text);
|
---|
34 |
|
---|
35 | .mat-form-field-label {
|
---|
36 | color: $label-color;
|
---|
37 | }
|
---|
38 |
|
---|
39 | .mat-hint {
|
---|
40 | color: $label-color;
|
---|
41 | }
|
---|
42 |
|
---|
43 | .mat-form-field.mat-focused .mat-form-field-label {
|
---|
44 | color: $focused-label-color;
|
---|
45 |
|
---|
46 | &.mat-accent {
|
---|
47 | color: $underline-color-accent;
|
---|
48 | }
|
---|
49 |
|
---|
50 | &.mat-warn {
|
---|
51 | color: $underline-color-warn;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | .mat-focused .mat-form-field-required-marker {
|
---|
56 | color: $required-label-color;
|
---|
57 | }
|
---|
58 |
|
---|
59 | .mat-form-field-ripple {
|
---|
60 | background-color: $underline-color-base;
|
---|
61 | }
|
---|
62 |
|
---|
63 | .mat-form-field.mat-focused {
|
---|
64 | .mat-form-field-ripple {
|
---|
65 | background-color: $underline-focused-color;
|
---|
66 |
|
---|
67 | &.mat-accent {
|
---|
68 | background-color: $underline-color-accent;
|
---|
69 | }
|
---|
70 |
|
---|
71 | &.mat-warn {
|
---|
72 | background-color: $underline-color-warn;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | .mat-form-field-type-mat-native-select.mat-focused:not(.mat-form-field-invalid) {
|
---|
78 | .mat-form-field-infix::after {
|
---|
79 | color: $underline-focused-color;
|
---|
80 | }
|
---|
81 |
|
---|
82 | &.mat-accent .mat-form-field-infix::after {
|
---|
83 | color: $underline-color-accent;
|
---|
84 | }
|
---|
85 |
|
---|
86 | &.mat-warn .mat-form-field-infix::after {
|
---|
87 | color: $underline-color-warn;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | // Styling for the error state of the form field. Note that while the same can be
|
---|
92 | // achieved with the ng-* classes, we use this approach in order to ensure that the same
|
---|
93 | // logic is used to style the error state and to show the error messages.
|
---|
94 | .mat-form-field.mat-form-field-invalid {
|
---|
95 | .mat-form-field-label {
|
---|
96 | color: $underline-color-warn;
|
---|
97 |
|
---|
98 | &.mat-accent,
|
---|
99 | .mat-form-field-required-marker {
|
---|
100 | color: $underline-color-warn;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | .mat-form-field-ripple,
|
---|
105 | .mat-form-field-ripple.mat-accent {
|
---|
106 | background-color: $underline-color-warn;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | .mat-error {
|
---|
111 | color: $underline-color-warn;
|
---|
112 | }
|
---|
113 |
|
---|
114 | @include form-field-legacy-theme.legacy-color($config);
|
---|
115 | @include form-field-standard-theme.standard-color($config);
|
---|
116 | @include form-field-fill-theme.fill-color($config);
|
---|
117 | @include form-field-outline-theme.outline-color($config);
|
---|
118 | }
|
---|
119 |
|
---|
120 | // Used to make instances of the _mat-form-field-label-floating mixin negligibly different,
|
---|
121 | // and prevent Google's CSS Optimizer from collapsing the declarations. This is needed because some
|
---|
122 | // of the selectors contain pseudo-classes not recognized in all browsers. If a browser encounters
|
---|
123 | // an unknown pseudo-class it will discard the entire rule set.
|
---|
124 | $dedupe: 0;
|
---|
125 |
|
---|
126 | // Applies a floating label above the form field control itself.
|
---|
127 | @mixin _label-floating($font-scale, $infix-padding, $infix-margin-top) {
|
---|
128 | transform: translateY(-$infix-margin-top - $infix-padding + $dedupe)
|
---|
129 | scale($font-scale);
|
---|
130 | width: private.private-div(100%, $font-scale) + $dedupe;
|
---|
131 |
|
---|
132 | $dedupe: $dedupe + 0.00001 !global;
|
---|
133 | }
|
---|
134 |
|
---|
135 | @mixin typography($config-or-theme) {
|
---|
136 | $config: typography.private-typography-to-2014-config(
|
---|
137 | theming.get-typography-config($config-or-theme));
|
---|
138 | // The unit-less line-height from the font config.
|
---|
139 | $line-height: typography-utils.line-height($config, input);
|
---|
140 |
|
---|
141 | // The amount to scale the font for the floating label and subscript.
|
---|
142 | $subscript-font-scale: 0.75;
|
---|
143 | // The amount to scale the font for the prefix and suffix icons.
|
---|
144 | $prefix-suffix-icon-font-scale: 1.5;
|
---|
145 |
|
---|
146 | // The padding on the infix. Mocks show half of the text size.
|
---|
147 | $infix-padding: 0.5em;
|
---|
148 | // The margin applied to the form-field-infix to reserve space for the floating label.
|
---|
149 | // If the line-height is given as a unitless number, coerce it to `em`.
|
---|
150 | $infix-margin-top: $subscript-font-scale *
|
---|
151 | typography-utils.private-coerce-unitless-to-em($line-height);
|
---|
152 | // Font size to use for the label and subscript text.
|
---|
153 | $subscript-font-size: $subscript-font-scale * 100%;
|
---|
154 | // Font size to use for the for the prefix and suffix icons.
|
---|
155 | $prefix-suffix-icon-font-size: $prefix-suffix-icon-font-scale * 100%;
|
---|
156 | // The space between the bottom of the .mat-form-field-flex area and the subscript wrapper.
|
---|
157 | // Mocks show half of the text size, but this margin is applied to an element with the subscript
|
---|
158 | // text font size, so we need to divide by the scale factor to make it half of the original text
|
---|
159 | // size.
|
---|
160 | $subscript-margin-top: private.private-div(0.5em, $subscript-font-scale);
|
---|
161 | // The padding applied to the form-field-wrapper to reserve space for the subscript, since it's
|
---|
162 | // absolutely positioned. This is a combination of the subscript's margin and line-height, but we
|
---|
163 | // need to multiply by the subscript font scale factor since the wrapper has a larger font size.
|
---|
164 | $wrapper-padding-bottom: ($subscript-margin-top + $line-height) * $subscript-font-scale;
|
---|
165 |
|
---|
166 | .mat-form-field {
|
---|
167 | @include typography-utils.typography-level($config, input);
|
---|
168 | }
|
---|
169 |
|
---|
170 | .mat-form-field-wrapper {
|
---|
171 | padding-bottom: $wrapper-padding-bottom;
|
---|
172 | }
|
---|
173 |
|
---|
174 | .mat-form-field-prefix,
|
---|
175 | .mat-form-field-suffix {
|
---|
176 | // Allow icons in a prefix or suffix to adapt to the correct size.
|
---|
177 | .mat-icon {
|
---|
178 | font-size: $prefix-suffix-icon-font-size;
|
---|
179 | line-height: $line-height;
|
---|
180 | }
|
---|
181 |
|
---|
182 | // Allow icon buttons in a prefix or suffix to adapt to the correct size.
|
---|
183 | .mat-icon-button {
|
---|
184 | height: $prefix-suffix-icon-font-scale * 1em;
|
---|
185 | width: $prefix-suffix-icon-font-scale * 1em;
|
---|
186 |
|
---|
187 | .mat-icon {
|
---|
188 | height: typography-utils.private-coerce-unitless-to-em($line-height);
|
---|
189 | line-height: $line-height;
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | .mat-form-field-infix {
|
---|
195 | padding: $infix-padding 0;
|
---|
196 | // Throws off the baseline if we do it as a real margin, so we do it as a border instead.
|
---|
197 | border-top: $infix-margin-top solid transparent;
|
---|
198 | }
|
---|
199 |
|
---|
200 | .mat-form-field-can-float {
|
---|
201 | &.mat-form-field-should-float .mat-form-field-label,
|
---|
202 | .mat-input-server:focus + .mat-form-field-label-wrapper .mat-form-field-label {
|
---|
203 | @include _label-floating(
|
---|
204 | $subscript-font-scale, $infix-padding, $infix-margin-top);
|
---|
205 | }
|
---|
206 |
|
---|
207 | // Server-side rendered matInput with a label attribute but label not shown
|
---|
208 | // (used as a pure CSS stand-in for mat-form-field-should-float).
|
---|
209 | .mat-input-server[label]:not(:label-shown) + .mat-form-field-label-wrapper
|
---|
210 | .mat-form-field-label {
|
---|
211 | @include _label-floating(
|
---|
212 | $subscript-font-scale, $infix-padding, $infix-margin-top);
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | .mat-form-field-label-wrapper {
|
---|
217 | top: -$infix-margin-top;
|
---|
218 | padding-top: $infix-margin-top;
|
---|
219 | }
|
---|
220 |
|
---|
221 | .mat-form-field-label {
|
---|
222 | top: $infix-margin-top + $infix-padding;
|
---|
223 | }
|
---|
224 |
|
---|
225 | .mat-form-field-underline {
|
---|
226 | // We want the underline to start at the end of the content box, not the padding box,
|
---|
227 | // so we move it up by the padding amount.
|
---|
228 | bottom: $wrapper-padding-bottom;
|
---|
229 | }
|
---|
230 |
|
---|
231 | .mat-form-field-subscript-wrapper {
|
---|
232 | font-size: $subscript-font-size;
|
---|
233 | margin-top: $subscript-margin-top;
|
---|
234 |
|
---|
235 | // We want the subscript to start at the end of the content box, not the padding box,
|
---|
236 | // so we move it up by the padding amount (adjusted for the smaller font size);
|
---|
237 | top: calc(100% - #{private.private-div($wrapper-padding-bottom, $subscript-font-scale)});
|
---|
238 | }
|
---|
239 |
|
---|
240 | @include form-field-legacy-theme.legacy-typography($config);
|
---|
241 | @include form-field-standard-theme.standard-typography($config);
|
---|
242 | @include form-field-fill-theme.fill-typography($config);
|
---|
243 | @include form-field-outline-theme.outline-typography($config);
|
---|
244 | }
|
---|
245 |
|
---|
246 | @mixin density($config-or-theme) {
|
---|
247 | $density-scale: theming.get-density-config($config-or-theme);
|
---|
248 | @include form-field-legacy-theme.private-form-field-legacy-density($density-scale);
|
---|
249 | @include form-field-standard-theme.private-form-field-standard-density($density-scale);
|
---|
250 | @include form-field-fill-theme.private-form-field-fill-density($density-scale);
|
---|
251 | @include form-field-outline-theme.private-form-field-outline-density($density-scale);
|
---|
252 | }
|
---|
253 |
|
---|
254 | @mixin theme($theme-or-color-config) {
|
---|
255 | $theme: theming.private-legacy-get-theme($theme-or-color-config);
|
---|
256 | @include theming.private-check-duplicate-theme-styles($theme, 'mat-form-field') {
|
---|
257 | $color: theming.get-color-config($theme);
|
---|
258 | $density: theming.get-density-config($theme);
|
---|
259 | $typography: theming.get-typography-config($theme);
|
---|
260 |
|
---|
261 | @if $color != null {
|
---|
262 | @include color($color);
|
---|
263 | }
|
---|
264 | @if $density != null {
|
---|
265 | @include density($density);
|
---|
266 | }
|
---|
267 | @if $typography != null {
|
---|
268 | @include typography($typography);
|
---|
269 | }
|
---|
270 | }
|
---|
271 | }
|
---|