|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -/// TODO: theming mixin applicable to all variants; split into submodules if necessary. |
| 7 | +// stylelint-disable selector-class-pattern -- |
| 8 | +// Selector '.mdc-*' should only be used in this project. |
| 9 | + |
| 10 | +@use 'sass:map'; |
| 11 | +@use '@material/ripple/ripple-theme'; |
| 12 | +@use '@material/shape/shape'; |
| 13 | +@use '@material/theme/state'; |
| 14 | +@use '@material/theme/theme'; |
| 15 | +@use '@material/typography/typography'; |
| 16 | + |
| 17 | +$_ripple-target: '.mdc-button__ripple'; |
| 18 | +$selectors: ( |
| 19 | + // :not(:disabled) is used to support link styled as button |
| 20 | + // as link does not support :enabled style |
| 21 | + enabled: ':not(:disabled)', |
| 22 | + disabled: ':disabled', |
| 23 | + focus: ':focus', |
| 24 | + hover: ':hover', |
| 25 | + pressed: ':active' |
| 26 | +); |
| 27 | + |
| 28 | +@mixin theme-styles($theme, $resolvers) { |
| 29 | + @include _set-label-text-typography( |
| 30 | + ( |
| 31 | + family: map.get($theme, label-text-font), |
| 32 | + size: map.get($theme, label-text-size), |
| 33 | + tracking: map.get($theme, label-text-tracking), |
| 34 | + weight: map.get($theme, label-text-weight), |
| 35 | + transform: map.get($theme, label-text-transform), |
| 36 | + ) |
| 37 | + ); |
| 38 | + |
| 39 | + @include _container-fill-color( |
| 40 | + ( |
| 41 | + default: map.get($theme, container-color), |
| 42 | + disabled: map.get($theme, disabled-container-color), |
| 43 | + ) |
| 44 | + ); |
| 45 | + |
| 46 | + @include _ink-color( |
| 47 | + ( |
| 48 | + default: map.get($theme, label-text-color), |
| 49 | + hover: map.get($theme, hover-label-text-color), |
| 50 | + focus: map.get($theme, focus-label-text-color), |
| 51 | + pressed: map.get($theme, pressed-label-text-color), |
| 52 | + disabled: map.get($theme, disabled-label-text-color), |
| 53 | + ) |
| 54 | + ); |
| 55 | + |
| 56 | + @include ripple-theme.theme( |
| 57 | + ( |
| 58 | + hover-state-layer-color: map.get($theme, hover-state-layer-color), |
| 59 | + focus-state-layer-color: map.get($theme, focus-state-layer-color), |
| 60 | + pressed-state-layer-color: map.get($theme, pressed-state-layer-color), |
| 61 | + hover-state-layer-opacity: map.get($theme, hover-state-layer-opacity), |
| 62 | + focus-state-layer-opacity: map.get($theme, focus-state-layer-opacity), |
| 63 | + pressed-state-layer-opacity: map.get($theme, pressed-state-layer-opacity), |
| 64 | + ) |
| 65 | + ); |
| 66 | + |
| 67 | + $container-height: map.get($theme, container-height); |
| 68 | + @include _set-height($container-height); |
| 69 | + |
| 70 | + $shape: map.get($theme, container-shape); |
| 71 | + @include _set-shape-radius($shape); |
| 72 | +} |
| 73 | + |
| 74 | +@mixin _container-fill-color($color-or-map) { |
| 75 | + @include state.default($selectors) { |
| 76 | + @include _set-container-fill-color(state.get-default-state($color-or-map)); |
| 77 | + } |
| 78 | + |
| 79 | + @include state.hover($selectors) { |
| 80 | + @include _set-container-fill-color(state.get-hover-state($color-or-map)); |
| 81 | + } |
| 82 | + |
| 83 | + @include state.focus($selectors) { |
| 84 | + @include _set-container-fill-color(state.get-focus-state($color-or-map)); |
| 85 | + } |
| 86 | + |
| 87 | + @include state.pressed($selectors) { |
| 88 | + @include _set-container-fill-color(state.get-pressed-state($color-or-map)); |
| 89 | + } |
| 90 | + |
| 91 | + @include state.disabled($selectors) { |
| 92 | + @include _set-container-fill-color(state.get-disabled-state($color-or-map)); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +@mixin _ink-color($color-or-map) { |
| 97 | + @include state.default($selectors) { |
| 98 | + @include _set-ink-color(state.get-default-state($color-or-map)); |
| 99 | + } |
| 100 | + |
| 101 | + @include state.hover($selectors) { |
| 102 | + @include _set-ink-color(state.get-hover-state($color-or-map)); |
| 103 | + } |
| 104 | + |
| 105 | + @include state.focus($selectors) { |
| 106 | + @include _set-ink-color(state.get-focus-state($color-or-map)); |
| 107 | + } |
| 108 | + |
| 109 | + @include state.pressed($selectors) { |
| 110 | + @include _set-ink-color(state.get-pressed-state($color-or-map)); |
| 111 | + } |
| 112 | + |
| 113 | + @include state.disabled($selectors) { |
| 114 | + @include _set-ink-color(state.get-disabled-state($color-or-map)); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +@mixin _set-height($height) { |
| 119 | + @include theme.property(height, $height); |
| 120 | +} |
| 121 | + |
| 122 | +@mixin _set-shape-radius($radius) { |
| 123 | + @include shape.radius($radius); |
| 124 | + |
| 125 | + #{$_ripple-target} { |
| 126 | + @include shape.radius($radius); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +@mixin _set-container-fill-color($color) { |
| 131 | + @include theme.property(background-color, $color); |
| 132 | +} |
| 133 | + |
| 134 | +@mixin _set-ink-color($color) { |
| 135 | + @include theme.property(color, $color); |
| 136 | +} |
| 137 | + |
| 138 | +@mixin _set-label-text-typography($typography-map) { |
| 139 | + $family: map.get($typography-map, family); |
| 140 | + $size: map.get($typography-map, size); |
| 141 | + $tracking: map.get($typography-map, tracking); |
| 142 | + $weight: map.get($typography-map, weight); |
| 143 | + $transform: map.get($typography-map, transform); |
| 144 | + |
| 145 | + @include theme.property(font-family, $family); |
| 146 | + @include theme.property(font-size, $size); |
| 147 | + @include theme.property(letter-spacing, $tracking); |
| 148 | + @include theme.property(font-weight, $weight); |
| 149 | + @include theme.property(text-transform, $transform); |
| 150 | +} |
| 151 | + |
| 152 | +@mixin container-padding($padding) { |
| 153 | + @include theme.property(padding-inline-start, $padding); |
| 154 | + @include theme.property(padding-inline-end, $padding); |
| 155 | +} |
| 156 | + |
| 157 | +@mixin container-with-icon-padding($icon-padding) { |
| 158 | + &.mdc-button--icon-trailing { |
| 159 | + @include theme.property(padding-inline-end, $icon-padding); |
| 160 | + } |
| 161 | + |
| 162 | + &.mdc-button--icon-leading { |
| 163 | + @include theme.property(padding-inline-start, $icon-padding); |
| 164 | + } |
| 165 | +} |
0 commit comments