UNPKG

6.96 kBSCSSView Raw
1//
2// Copyright 2022 Google Inc.
3//
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20// THE SOFTWARE.
21//
22
23// Selector '.mdc-*' should only be used in this project.
24// stylelint-disable selector-class-pattern --
25// NOTE: this is the implementation of the aforementioned classes.
26
27@use 'sass:map';
28@use '@material/line-ripple/mixins' as line-ripple-mixins;
29@use '@material/theme/theme';
30@use '@material/tokens/resolvers';
31@use './text-field-theme';
32@use './mixins';
33
34$_light-theme: (
35 active-indicator-color: null,
36 active-indicator-height: null,
37 caret-color: null,
38 container-color: null,
39 container-height: null,
40 container-shape: null,
41 disabled-active-indicator-color: null,
42 disabled-active-indicator-height: null,
43 disabled-active-indicator-opacity: null,
44 disabled-container-color: null,
45 disabled-container-opacity: null,
46 disabled-input-text-color: null,
47 disabled-input-text-opacity: null,
48 disabled-label-text-color: null,
49 disabled-label-text-opacity: null,
50 disabled-leading-icon-color: null,
51 disabled-leading-icon-opacity: null,
52 disabled-supporting-text-color: null,
53 disabled-supporting-text-opacity: null,
54 disabled-trailing-icon-color: null,
55 disabled-trailing-icon-opacity: null,
56 error-active-indicator-color: null,
57 error-caret-color: null,
58 error-focus-active-indicator-color: null,
59 error-focus-caret-color: null,
60 error-focus-input-text-color: null,
61 error-focus-label-text-color: null,
62 error-focus-leading-icon-color: null,
63 error-focus-supporting-text-color: null,
64 error-focus-trailing-icon-color: null,
65 error-hover-active-indicator-color: null,
66 error-hover-caret-color: null,
67 error-hover-input-text-color: null,
68 error-hover-label-text-color: null,
69 error-hover-leading-icon-color: null,
70 error-hover-state-layer-color: null,
71 error-hover-state-layer-opacity: null,
72 error-hover-supporting-text-color: null,
73 error-hover-trailing-icon-color: null,
74 error-input-text-color: null,
75 error-label-text-color: null,
76 error-leading-icon-color: null,
77 error-supporting-text-color: null,
78 error-trailing-icon-color: null,
79 focus-active-indicator-color: null,
80 focus-active-indicator-height: null,
81 focus-caret-color: null,
82 focus-input-text-color: null,
83 focus-label-text-color: null,
84 focus-leading-icon-color: null,
85 focus-supporting-text-color: null,
86 focus-trailing-icon-color: null,
87 hover-active-indicator-color: null,
88 hover-active-indicator-height: null,
89 hover-caret-color: null,
90 hover-input-text-color: null,
91 hover-label-text-color: null,
92 hover-leading-icon-color: null,
93 hover-state-layer-color: null,
94 hover-state-layer-opacity: null,
95 hover-supporting-text-color: null,
96 hover-trailing-icon-color: null,
97 input-text-color: null,
98 input-text-font: null,
99 input-text-line-height: null,
100 input-text-size: null,
101 input-text-tracking: null,
102 input-text-type: null,
103 input-text-weight: null,
104 label-text-color: null,
105 label-text-font: null,
106 label-text-line-height: null,
107 label-text-populated-line-height: null,
108 label-text-populated-size: null,
109 label-text-size: null,
110 label-text-tracking: null,
111 label-text-type: null,
112 label-text-weight: null,
113 leading-icon-color: null,
114 leading-icon-size: null,
115 supporting-text-color: null,
116 supporting-text-font: null,
117 supporting-text-line-height: null,
118 supporting-text-size: null,
119 supporting-text-tracking: null,
120 supporting-text-weight: null,
121 trailing-icon-color: null,
122 trailing-icon-size: null,
123);
124
125@mixin theme-styles($theme, $resolvers: resolvers.$material) {
126 @include theme.validate-theme($_light-theme, $theme);
127 @include text-field-theme.theme-styles($theme, $resolvers: $resolvers);
128
129 @if map.get($theme, container-height) {
130 @include mixins.height(map.get($theme, container-height));
131 }
132 @if map.get($theme, container-shape) {
133 @include mixins.shape-radius(map.get($theme, container-shape));
134 }
135
136 @include _container-color(
137 (
138 default: map.get($theme, container-color),
139 disabled: map.get($theme, disabled-container-color),
140 )
141 );
142 @include _active-indicator-color(
143 (
144 default: map.get($theme, active-indicator-color),
145 hover: map.get($theme, hover-active-indicator-color),
146 focus: map.get($theme, focus-active-indicator-color),
147 disabled: map.get($theme, disabled-indicator-color),
148 )
149 );
150 @include _error-active-indicator-color(
151 (
152 default: map.get($theme, error-active-indicator-color),
153 hover: map.get($theme, error-hover-active-indicator-color),
154 focus: map.get($theme, error-focus-active-indicator-color),
155 )
156 );
157 @include _active-indicator-height(map.get($theme, active-indicator-height));
158}
159
160@mixin _container-color($colors) {
161 @include text-field-theme.if-enabled {
162 @include _set-container-color(map.get($colors, default));
163 }
164
165 @include text-field-theme.if-disabled {
166 @include _set-container-color(map.get($colors, disabled));
167 }
168}
169
170@mixin _set-container-color($color) {
171 @include theme.property(background-color, $color);
172}
173
174@mixin _active-indicator-color($colors) {
175 @include text-field-theme.if-enabled {
176 @include _set-active-indicator-color(map.get($colors, default));
177
178 &:hover {
179 @include _set-active-indicator-color(map.get($colors, hover));
180 }
181
182 @include _focused-line-ripple-color(map.get($colors, focus));
183 }
184
185 @include text-field-theme.if-disabled {
186 @include _set-active-indicator-color(map.get($colors, disabled));
187 }
188}
189
190@mixin _set-active-indicator-color($color) {
191 .mdc-line-ripple {
192 @include line-ripple-mixins.inactive-color($color);
193 }
194}
195
196@mixin _focused-line-ripple-color($color) {
197 .mdc-line-ripple {
198 @include line-ripple-mixins.active-color($color);
199 }
200}
201
202@mixin _error-active-indicator-color($colors) {
203 &.mdc-text-field--invalid {
204 @include _active-indicator-color($colors);
205 }
206}
207
208@mixin _active-indicator-height($height) {
209 .mdc-line-ripple {
210 @include line-ripple-mixins.height($height);
211 }
212}