|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +@use 'sass:map'; |
| 8 | +@use 'sass:meta'; |
| 9 | +@use '@material/elevation/elevation-theme'; |
| 10 | +@use '@material/ripple/ripple-theme'; |
| 11 | +@use '@material/theme/state'; |
| 12 | +@use '@material/theme/theme'; |
| 13 | +@use '@material/tokens/resolvers'; |
| 14 | + |
| 15 | +@use './button-theme'; |
| 16 | + |
| 17 | +$_selectors: button-theme.$selectors; |
| 18 | + |
| 19 | +@mixin theme-styles($theme, $resolvers) { |
| 20 | + $elevation-resolver: map.get($resolvers, elevation); |
| 21 | + @include _elevation( |
| 22 | + $elevation-resolver, |
| 23 | + $elevation-map: ( |
| 24 | + default: map.get($theme, container-elevation), |
| 25 | + disabled: map.get($theme, disabled-container-elevation), |
| 26 | + focus: map.get($theme, focus-container-elevation), |
| 27 | + hover: map.get($theme, hover-container-elevation), |
| 28 | + pressed: map.get($theme, pressed-container-elevation) |
| 29 | + ), |
| 30 | + $shadow-color: map.get($theme, container-shadow-color) |
| 31 | + ); |
| 32 | +} |
| 33 | + |
| 34 | +@mixin _elevation($elevation-resolver, $elevation-map, $shadow-color) { |
| 35 | + @include state.default($_selectors) { |
| 36 | + @include elevation-theme.with-resolver( |
| 37 | + $elevation-resolver, |
| 38 | + $elevation: state.get-default-state($elevation-map), |
| 39 | + $shadow-color: $shadow-color |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + @include state.focus($_selectors) { |
| 44 | + @include elevation-theme.with-resolver( |
| 45 | + $elevation-resolver, |
| 46 | + $elevation: state.get-focus-state($elevation-map), |
| 47 | + $shadow-color: $shadow-color |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + @include state.hover($_selectors) { |
| 52 | + @include elevation-theme.with-resolver( |
| 53 | + $elevation-resolver, |
| 54 | + $elevation: state.get-hover-state($elevation-map), |
| 55 | + $shadow-color: $shadow-color |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + @include state.pressed($_selectors) { |
| 60 | + @include elevation-theme.with-resolver( |
| 61 | + $elevation-resolver, |
| 62 | + $elevation: state.get-pressed-state($elevation-map), |
| 63 | + $shadow-color: $shadow-color |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + @include state.disabled($_selectors) { |
| 68 | + @include elevation-theme.with-resolver( |
| 69 | + $elevation-resolver, |
| 70 | + $elevation: state.get-disabled-state($elevation-map), |
| 71 | + $shadow-color: $shadow-color |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +@function resolve-theme-elevation-keys($theme, $resolver) { |
| 77 | + $elevation-resolver: map.get($resolver, elevation); |
| 78 | + $shadow-color: map.get($theme, container-shadow-color); |
| 79 | + @if $elevation-resolver == null { |
| 80 | + @return $theme; |
| 81 | + } |
| 82 | + |
| 83 | + $elevation-keys: ( |
| 84 | + container-elevation, |
| 85 | + hover-container-elevation, |
| 86 | + focus-container-elevation, |
| 87 | + pressed-container-elevation, |
| 88 | + disabled-container-elevation |
| 89 | + ); |
| 90 | + |
| 91 | + @each $key in $elevation-keys { |
| 92 | + $elevation: map.get($theme, $key); |
| 93 | + $resolved-value: meta.call( |
| 94 | + $resolver, |
| 95 | + $elevation: $elevation, |
| 96 | + $shadow-color: $shadow-color |
| 97 | + ); |
| 98 | + // Update the key with the resolved value. |
| 99 | + $theme: map.set($theme, $key, $resolved-value); |
| 100 | + } |
| 101 | + @return $theme; |
| 102 | +} |
0 commit comments