1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | @use 'sass:color';
|
27 | @use 'sass:map';
|
28 | @use '@material/animation/functions' as functions2;
|
29 | @use '@material/animation/variables' as variables2;
|
30 | @use '@material/base/mixins' as base-mixins;
|
31 | @use '@material/feature-targeting/feature-targeting';
|
32 | @use '@material/theme/css';
|
33 | @use '@material/theme/custom-properties';
|
34 | @use '@material/theme/theme';
|
35 | @use '@material/theme/theme-color';
|
36 |
|
37 | $fade-in-duration: 75ms !default;
|
38 | $fade-out-duration: 150ms !default;
|
39 | $translate-duration: 225ms !default;
|
40 | $states-wash-duration: 15ms !default;
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | $dark-ink-opacities: (
|
48 | hover: 0.04,
|
49 | focus: 0.12,
|
50 | press: 0.12,
|
51 | selected: 0.08,
|
52 | activated: 0.12,
|
53 | ) !default;
|
54 |
|
55 | $light-ink-opacities: (
|
56 | hover: 0.08,
|
57 | focus: 0.24,
|
58 | press: 0.24,
|
59 | selected: 0.16,
|
60 | activated: 0.24,
|
61 | ) !default;
|
62 |
|
63 |
|
64 |
|
65 | $pressed-dark-ink-opacity: 0.16 !default;
|
66 | $pressed-light-ink-opacity: 0.32 !default;
|
67 |
|
68 |
|
69 | $_hover-selector: '&:hover';
|
70 | $_focus-selector: '&.mdc-ripple-upgraded--background-focused, &:not(.mdc-ripple-upgraded):focus';
|
71 | $_active-selector: '&:active:active';
|
72 |
|
73 | @mixin states-base-color(
|
74 | $color,
|
75 | $query: feature-targeting.all(),
|
76 | $ripple-target: '&'
|
77 | ) {
|
78 | $feat-color: feature-targeting.create-target($query, color);
|
79 |
|
80 | @if not custom-properties.is-custom-prop($color) {
|
81 | $color: custom-properties.create(
|
82 | --mdc-ripple-color,
|
83 | theme-color.get-custom-property($color)
|
84 | );
|
85 | }
|
86 |
|
87 | #{$ripple-target}::before,
|
88 | #{$ripple-target}::after {
|
89 | @include feature-targeting.targets($feat-color) {
|
90 | @if color.alpha(theme-color.prop-value($color)) > 0 {
|
91 | @include theme.property(background-color, $color);
|
92 | } @else {
|
93 |
|
94 |
|
95 | content: none;
|
96 | }
|
97 | }
|
98 | }
|
99 | }
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | @mixin states-opacities(
|
108 | $opacity-map: (),
|
109 | $has-nested-focusable-element: false,
|
110 | $ripple-target: '&',
|
111 | $query: feature-targeting.all()
|
112 | ) {
|
113 |
|
114 | @if map.get($opacity-map, hover) {
|
115 | @include states-hover-opacity(
|
116 | map.get($opacity-map, hover),
|
117 | $ripple-target: $ripple-target,
|
118 | $query: $query
|
119 | );
|
120 | }
|
121 |
|
122 | @if map.get($opacity-map, focus) {
|
123 | @include states-focus-opacity(
|
124 | map.get($opacity-map, focus),
|
125 | $ripple-target: $ripple-target,
|
126 | $has-nested-focusable-element: $has-nested-focusable-element,
|
127 | $query: $query
|
128 | );
|
129 | }
|
130 |
|
131 | @if map.get($opacity-map, press) {
|
132 | @include states-press-opacity(
|
133 | map.get($opacity-map, press),
|
134 | $ripple-target: $ripple-target,
|
135 | $query: $query
|
136 | );
|
137 | }
|
138 | }
|
139 |
|
140 | @mixin states-hover-opacity(
|
141 | $opacity,
|
142 | $query: feature-targeting.all(),
|
143 | $ripple-target: '&'
|
144 | ) {
|
145 | $feat-color: feature-targeting.create-target($query, color);
|
146 |
|
147 |
|
148 | &:hover,
|
149 | &.mdc-ripple-surface--hover {
|
150 | #{$ripple-target}::before {
|
151 |
|
152 | @include feature-targeting.targets($feat-color) {
|
153 | @include theme.property(
|
154 | opacity,
|
155 | custom-properties.create(--mdc-ripple-hover-opacity, $opacity)
|
156 | );
|
157 | }
|
158 | }
|
159 | }
|
160 | }
|
161 |
|
162 | @mixin states-focus-opacity(
|
163 | $opacity,
|
164 | $has-nested-focusable-element: false,
|
165 | $query: feature-targeting.all(),
|
166 | $ripple-target: '&'
|
167 | ) {
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | @if $has-nested-focusable-element {
|
174 |
|
175 | &.mdc-ripple-upgraded--background-focused,
|
176 | &.mdc-ripple-upgraded:focus-within,
|
177 |
|
178 | &:not(.mdc-ripple-upgraded):focus,
|
179 | &:not(.mdc-ripple-upgraded):focus-within {
|
180 | #{$ripple-target}::before {
|
181 | @include states-focus-opacity-properties_(
|
182 | $opacity: $opacity,
|
183 | $query: $query
|
184 | );
|
185 | }
|
186 | }
|
187 | } @else {
|
188 |
|
189 | &.mdc-ripple-upgraded--background-focused,
|
190 |
|
191 | &:not(.mdc-ripple-upgraded):focus {
|
192 | #{$ripple-target}::before {
|
193 | @include states-focus-opacity-properties_(
|
194 | $opacity: $opacity,
|
195 | $query: $query
|
196 | );
|
197 | }
|
198 | }
|
199 | }
|
200 | }
|
201 |
|
202 | @mixin states-focus-opacity-properties_($opacity, $query) {
|
203 | $feat-animation: feature-targeting.create-target($query, animation);
|
204 |
|
205 | $feat-color: feature-targeting.create-target($query, color);
|
206 |
|
207 |
|
208 | @include feature-targeting.targets($feat-animation) {
|
209 | transition-duration: 75ms;
|
210 | }
|
211 |
|
212 | @include feature-targeting.targets($feat-color) {
|
213 | @include theme.property(
|
214 | opacity,
|
215 | custom-properties.create(--mdc-ripple-focus-opacity, $opacity)
|
216 | );
|
217 | }
|
218 | }
|
219 |
|
220 | @mixin states-press-opacity(
|
221 | $opacity,
|
222 | $query: feature-targeting.all(),
|
223 | $ripple-target: '&'
|
224 | ) {
|
225 | $feat-animation: feature-targeting.create-target($query, animation);
|
226 | $feat-color: feature-targeting.create-target($query, color);
|
227 |
|
228 |
|
229 |
|
230 | &:not(.mdc-ripple-upgraded) {
|
231 |
|
232 | #{$ripple-target}::after {
|
233 | @include feature-targeting.targets($feat-animation) {
|
234 | transition: opacity $fade-out-duration linear;
|
235 | }
|
236 | }
|
237 |
|
238 | &:active {
|
239 | #{$ripple-target}::after {
|
240 | @include feature-targeting.targets($feat-animation) {
|
241 | transition-duration: $fade-in-duration;
|
242 | }
|
243 |
|
244 |
|
245 | @include feature-targeting.targets($feat-color) {
|
246 | @include theme.property(
|
247 | opacity,
|
248 | custom-properties.create(--mdc-ripple-press-opacity, $opacity)
|
249 | );
|
250 | }
|
251 | }
|
252 | }
|
253 | }
|
254 |
|
255 | &.mdc-ripple-upgraded {
|
256 | @include feature-targeting.targets($feat-color) {
|
257 | --mdc-ripple-fg-opacity: var(--mdc-ripple-press-opacity, #{$opacity});
|
258 | }
|
259 | }
|
260 | }
|
261 |
|
262 |
|
263 |
|
264 | @mixin states(
|
265 | $color: theme-color.prop-value(on-surface),
|
266 | $has-nested-focusable-element: false,
|
267 | $query: feature-targeting.all(),
|
268 | $ripple-target: '&',
|
269 | $opacity-map: null
|
270 | ) {
|
271 | @include states-interactions_(
|
272 | $color: $color,
|
273 | $has-nested-focusable-element: $has-nested-focusable-element,
|
274 | $query: $query,
|
275 | $ripple-target: $ripple-target,
|
276 | $opacity-map: $opacity-map
|
277 | );
|
278 | }
|
279 |
|
280 |
|
281 |
|
282 | @mixin states-activated(
|
283 | $color,
|
284 | $has-nested-focusable-element: false,
|
285 | $query: feature-targeting.all(),
|
286 | $ripple-target: '&'
|
287 | ) {
|
288 | $feat-color: feature-targeting.create-target($query, color);
|
289 | $activated-opacity: states-opacity($color, activated);
|
290 |
|
291 | &--activated {
|
292 |
|
293 |
|
294 | #{$ripple-target}::before {
|
295 |
|
296 | @include feature-targeting.targets($feat-color) {
|
297 | @include theme.property(
|
298 | opacity,
|
299 | custom-properties.create(
|
300 | --mdc-ripple-activated-opacity,
|
301 | $activated-opacity
|
302 | )
|
303 | );
|
304 | }
|
305 | }
|
306 |
|
307 | @include states-interactions_(
|
308 | $color: $color,
|
309 | $has-nested-focusable-element: $has-nested-focusable-element,
|
310 | $opacity-modifier: $activated-opacity,
|
311 | $query: $query,
|
312 | $ripple-target: $ripple-target
|
313 | );
|
314 | }
|
315 | }
|
316 |
|
317 |
|
318 |
|
319 | @mixin states-selected(
|
320 | $color,
|
321 | $has-nested-focusable-element: false,
|
322 | $query: feature-targeting.all(),
|
323 | $ripple-target: '&'
|
324 | ) {
|
325 | $feat-color: feature-targeting.create-target($query, color);
|
326 | $selected-opacity: states-opacity($color, selected);
|
327 |
|
328 | &--selected {
|
329 |
|
330 | #{$ripple-target}::before {
|
331 |
|
332 | @include feature-targeting.targets($feat-color) {
|
333 | @include theme.property(
|
334 | opacity,
|
335 | custom-properties.create(
|
336 | --mdc-ripple-selected-opacity,
|
337 | $selected-opacity
|
338 | )
|
339 | );
|
340 | }
|
341 | }
|
342 |
|
343 | @include states-interactions_(
|
344 | $color: $color,
|
345 | $has-nested-focusable-element: $has-nested-focusable-element,
|
346 | $opacity-modifier: $selected-opacity,
|
347 | $query: $query,
|
348 | $ripple-target: $ripple-target
|
349 | );
|
350 | }
|
351 | }
|
352 |
|
353 | @mixin states-interactions_(
|
354 | $color,
|
355 | $has-nested-focusable-element,
|
356 | $opacity-modifier: 0,
|
357 | $query: feature-targeting.all(),
|
358 | $ripple-target: '&',
|
359 | $opacity-map: null
|
360 | ) {
|
361 | @include target-selector($ripple-target) {
|
362 | @include states-base-color($color, $query);
|
363 | }
|
364 |
|
365 | @if $opacity-map == null {
|
366 | $opacity-map: (
|
367 | hover: states-opacity($color, hover) + $opacity-modifier,
|
368 | focus: states-opacity($color, focus) + $opacity-modifier,
|
369 | press: states-opacity($color, press) + $opacity-modifier,
|
370 | );
|
371 | }
|
372 |
|
373 | @include states-opacities(
|
374 | $opacity-map,
|
375 | $has-nested-focusable-element: $has-nested-focusable-element,
|
376 | $ripple-target: $ripple-target,
|
377 | $query: $query
|
378 | );
|
379 | }
|
380 |
|
381 |
|
382 | @mixin target-selector($ripple-target: '&') {
|
383 | @if $ripple-target == '&' {
|
384 | @content;
|
385 | } @else {
|
386 | #{$ripple-target} {
|
387 | @content;
|
388 | }
|
389 | }
|
390 | }
|
391 |
|
392 |
|
393 | @mixin states-selector() {
|
394 | #{$_hover-selector},
|
395 | #{$_focus-selector},
|
396 | #{$_active-selector} {
|
397 | @content;
|
398 | }
|
399 | }
|
400 |
|
401 |
|
402 |
|
403 |
|
404 | @mixin focus() {
|
405 | #{$_focus-selector} {
|
406 | @content;
|
407 | }
|
408 | }
|
409 |
|
410 |
|
411 | @mixin active() {
|
412 | #{$_active-selector} {
|
413 | @content;
|
414 | }
|
415 | }
|
416 |
|
417 |
|
418 | @mixin behind-content(
|
419 | $ripple-target,
|
420 | $content-root-selector: '&',
|
421 | $query: feature-targeting.all()
|
422 | ) {
|
423 |
|
424 |
|
425 | $feat-structure: feature-targeting.create-target($query, structure);
|
426 |
|
427 | #{$content-root-selector} {
|
428 | @include feature-targeting.targets($feat-structure) {
|
429 | z-index: 0;
|
430 | }
|
431 | }
|
432 |
|
433 | #{$ripple-target}::before,
|
434 | #{$ripple-target}::after {
|
435 | @include feature-targeting.targets($feat-structure) {
|
436 | @include theme.property(
|
437 | z-index,
|
438 | custom-properties.create(--mdc-ripple-z-index, -1)
|
439 | );
|
440 | }
|
441 | }
|
442 | }
|
443 |
|
444 | @function states-opacity($color, $state) {
|
445 | $color-value: theme-color.prop-value($color);
|
446 | $opacity-map: if(
|
447 | theme-color.tone($color-value) == 'light',
|
448 | $light-ink-opacities,
|
449 | $dark-ink-opacities
|
450 | );
|
451 |
|
452 | @if not map.has-key($opacity-map, $state) {
|
453 | @error "Invalid state: '#{$state}'. Choose one of: #{map.keys($opacity-map)}";
|
454 | }
|
455 |
|
456 | @return map.get($opacity-map, $state);
|
457 | }
|