1 | @use 'sass:map';
|
---|
2 | @use '../core/theming/theming';
|
---|
3 | @use '../core/style/private';
|
---|
4 | @use '../core/typography/typography';
|
---|
5 | @use '../core/typography/typography-utils';
|
---|
6 |
|
---|
7 |
|
---|
8 | // Theme styles that only apply to the outline appearance of the form-field.
|
---|
9 |
|
---|
10 | @mixin outline-color($config-or-theme) {
|
---|
11 | $config: theming.get-color-config($config-or-theme);
|
---|
12 | $primary: map.get($config, primary);
|
---|
13 | $accent: map.get($config, accent);
|
---|
14 | $warn: map.get($config, warn);
|
---|
15 | $foreground: map.get($config, foreground);
|
---|
16 | $is-dark-theme: map.get($config, is-dark);
|
---|
17 |
|
---|
18 | $label-disabled-color: theming.get-color-from-palette($foreground, disabled-text);
|
---|
19 | $outline-color:
|
---|
20 | theming.get-color-from-palette($foreground, divider, if($is-dark-theme, 0.3, 0.12));
|
---|
21 | $outline-color-hover:
|
---|
22 | theming.get-color-from-palette($foreground, divider, if($is-dark-theme, 1, 0.87));
|
---|
23 | $outline-color-primary: theming.get-color-from-palette($primary);
|
---|
24 | $outline-color-accent: theming.get-color-from-palette($accent);
|
---|
25 | $outline-color-warn: theming.get-color-from-palette($warn);
|
---|
26 | $outline-color-disabled:
|
---|
27 | theming.get-color-from-palette($foreground, divider, if($is-dark-theme, 0.15, 0.06));
|
---|
28 |
|
---|
29 | .mat-form-field-appearance-outline {
|
---|
30 | .mat-form-field-outline {
|
---|
31 | color: $outline-color;
|
---|
32 | }
|
---|
33 |
|
---|
34 | .mat-form-field-outline-thick {
|
---|
35 | color: $outline-color-hover;
|
---|
36 | }
|
---|
37 |
|
---|
38 | &.mat-focused {
|
---|
39 | .mat-form-field-outline-thick {
|
---|
40 | color: $outline-color-primary;
|
---|
41 | }
|
---|
42 |
|
---|
43 | &.mat-accent .mat-form-field-outline-thick {
|
---|
44 | color: $outline-color-accent;
|
---|
45 | }
|
---|
46 |
|
---|
47 | &.mat-warn .mat-form-field-outline-thick {
|
---|
48 | color: $outline-color-warn;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | // Class repeated so that rule is specific enough to override focused accent color case.
|
---|
53 | &.mat-form-field-invalid.mat-form-field-invalid {
|
---|
54 | .mat-form-field-outline-thick {
|
---|
55 | color: $outline-color-warn;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | &.mat-form-field-disabled {
|
---|
60 | .mat-form-field-label {
|
---|
61 | color: $label-disabled-color;
|
---|
62 | }
|
---|
63 |
|
---|
64 | .mat-form-field-outline {
|
---|
65 | color: $outline-color-disabled;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | // Used to make instances of the _mat-form-field-label-floating mixin negligibly different,
|
---|
72 | // and prevent Google's CSS Optimizer from collapsing the declarations. This is needed because some
|
---|
73 | // of the selectors contain pseudo-classes not recognized in all browsers. If a browser encounters
|
---|
74 | // an unknown pseudo-class it will discard the entire rule set.
|
---|
75 | $outline-dedupe: 0;
|
---|
76 |
|
---|
77 | // Applies a floating label above the form field control itself.
|
---|
78 | @mixin _label-floating($font-scale, $infix-padding, $infix-margin-top) {
|
---|
79 | transform: translateY(-$infix-margin-top - $infix-padding + $outline-dedupe)
|
---|
80 | scale($font-scale);
|
---|
81 | width: private.private-div(100%, $font-scale) + $outline-dedupe;
|
---|
82 |
|
---|
83 | $outline-dedupe: $outline-dedupe + 0.00001 !global;
|
---|
84 | }
|
---|
85 |
|
---|
86 | @mixin outline-typography($config-or-theme) {
|
---|
87 | $config: typography.private-typography-to-2014-config(
|
---|
88 | theming.get-typography-config($config-or-theme));
|
---|
89 | // The unit-less line-height from the font config.
|
---|
90 | $line-height: typography-utils.line-height($config, input);
|
---|
91 | // The amount to scale the font for the floating label and subscript.
|
---|
92 | $subscript-font-scale: 0.75;
|
---|
93 | // The padding above and below the infix.
|
---|
94 | $infix-padding: 1em;
|
---|
95 | // The margin applied to the form-field-infix to reserve space for the floating label.
|
---|
96 | $infix-margin-top:
|
---|
97 | $subscript-font-scale * typography-utils.private-coerce-unitless-to-em($line-height);
|
---|
98 | // The space between the bottom of the .mat-form-field-flex area and the subscript wrapper.
|
---|
99 | // Mocks show half of the text size, but this margin is applied to an element with the subscript
|
---|
100 | // text font size, so we need to divide by the scale factor to make it half of the original text
|
---|
101 | // size.
|
---|
102 | $subscript-margin-top: private.private-div(0.5em, $subscript-font-scale);
|
---|
103 | // The padding applied to the form-field-wrapper to reserve space for the subscript, since it's
|
---|
104 | // absolutely positioned. This is a combination of the subscript's margin and line-height, but we
|
---|
105 | // need to multiply by the subscript font scale factor since the wrapper has a larger font size.
|
---|
106 | $wrapper-padding-bottom: ($subscript-margin-top + $line-height) * $subscript-font-scale;
|
---|
107 | // The amount we offset the label from the input text in the outline appearance.
|
---|
108 | $outline-appearance-label-offset: -0.25em;
|
---|
109 |
|
---|
110 | .mat-form-field-appearance-outline {
|
---|
111 | .mat-form-field-infix {
|
---|
112 | padding: $infix-padding 0 $infix-padding 0;
|
---|
113 | }
|
---|
114 |
|
---|
115 | .mat-form-field-label {
|
---|
116 | top: $infix-margin-top + $infix-padding;
|
---|
117 | margin-top: $outline-appearance-label-offset;
|
---|
118 | }
|
---|
119 |
|
---|
120 | &.mat-form-field-can-float {
|
---|
121 | &.mat-form-field-should-float .mat-form-field-label,
|
---|
122 | .mat-input-server:focus + .mat-form-field-label-wrapper .mat-form-field-label {
|
---|
123 | @include _label-floating(
|
---|
124 | $subscript-font-scale, $infix-padding + $outline-appearance-label-offset,
|
---|
125 | $infix-margin-top);
|
---|
126 | }
|
---|
127 |
|
---|
128 | // Server-side rendered matInput with a label attribute but label not shown
|
---|
129 | // (used as a pure CSS stand-in for mat-form-field-should-float).
|
---|
130 | .mat-input-server[label]:not(:label-shown) + .mat-form-field-label-wrapper
|
---|
131 | .mat-form-field-label {
|
---|
132 | @include _label-floating(
|
---|
133 | $subscript-font-scale, $infix-padding + $outline-appearance-label-offset,
|
---|
134 | $infix-margin-top);
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | @mixin private-form-field-outline-density($config-or-theme) {}
|
---|
141 |
|
---|
142 | @mixin outline-theme($theme-or-color-config) {
|
---|
143 | $theme: theming.private-legacy-get-theme($theme-or-color-config);
|
---|
144 | @include theming.private-check-duplicate-theme-styles($theme, 'mat-form-field-outline') {
|
---|
145 | $color: theming.get-color-config($theme);
|
---|
146 | $density: theming.get-density-config($theme);
|
---|
147 | $typography: theming.get-typography-config($theme);
|
---|
148 |
|
---|
149 | @if $color != null {
|
---|
150 | @include outline-color($color);
|
---|
151 | }
|
---|
152 | @if $density != null {
|
---|
153 | @include private-form-field-outline-density($density);
|
---|
154 | }
|
---|
155 | @if $typography != null {
|
---|
156 | @include outline-typography($typography);
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|