|
| 1 | +@use 'sass:map'; |
| 2 | +@use 'sass:meta'; |
| 3 | +@use '../../../style/sass-utils'; |
| 4 | +@use '../../token-definition'; |
| 5 | + |
| 6 | +// The prefix used to generate the fully qualified name for tokens in this file. |
| 7 | +$prefix: (mat, tonal-button); |
| 8 | + |
| 9 | +/// Generates custom tokens for the mat-flat-button. |
| 10 | +/// @param {Map} $systems The MDC system tokens |
| 11 | +/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values |
| 12 | +/// @param {Map} $token-slots Possible token slots |
| 13 | +/// @return {Map} A set of custom tokens for the mat-flat-button |
| 14 | +@function get-tokens($systems, $exclude-hardcoded, $token-slots) { |
| 15 | + $mdc-tokens: token-definition.get-mdc-tokens('filled-tonal-button', $systems, $exclude-hardcoded); |
| 16 | + |
| 17 | + $tokens: map.merge($mdc-tokens, ( |
| 18 | + horizontal-padding: token-definition.hardcode(24px, $exclude-hardcoded), |
| 19 | + icon-spacing: token-definition.hardcode(8px, $exclude-hardcoded), |
| 20 | + icon-offset: token-definition.hardcode(-8px, $exclude-hardcoded), |
| 21 | + state-layer-color: map.get($systems, md-sys-color, on-secondary-container), |
| 22 | + disabled-state-layer-color: map.get($systems, md-sys-color, on-surface-variant), |
| 23 | + ripple-color: sass-utils.safe-color-change( |
| 24 | + map.get($systems, md-sys-color, on-secondary-container), |
| 25 | + $alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity) |
| 26 | + ), |
| 27 | + hover-state-layer-opacity: map.get($systems, md-sys-state, hover-state-layer-opacity), |
| 28 | + focus-state-layer-opacity: map.get($systems, md-sys-state, focus-state-layer-opacity), |
| 29 | + pressed-state-layer-opacity: map.get($systems, md-sys-state, pressed-state-layer-opacity), |
| 30 | + )); |
| 31 | + |
| 32 | + $variant-tokens: ( |
| 33 | + // Color variants: |
| 34 | + primary: (), |
| 35 | + secondary: (), |
| 36 | + tertiary: ( |
| 37 | + container-color: map.get($systems, md-sys-color, tertiary-container), |
| 38 | + focus-label-text-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 39 | + focus-state-layer-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 40 | + hover-label-text-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 41 | + hover-state-layer-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 42 | + label-text-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 43 | + pressed-label-text-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 44 | + pressed-state-layer-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 45 | + with-icon-focus-icon-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 46 | + with-icon-hover-icon-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 47 | + with-icon-icon-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 48 | + with-icon-pressed-icon-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 49 | + state-layer-color: map.get($systems, md-sys-color, on-tertiary-container), |
| 50 | + ripple-color: sass-utils.safe-color-change( |
| 51 | + map.get($systems, md-sys-color, on-tertiary-container), |
| 52 | + $alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity) |
| 53 | + ), |
| 54 | + ), |
| 55 | + error: ( |
| 56 | + container-color: map.get($systems, md-sys-color, error-container), |
| 57 | + focus-label-text-color: map.get($systems, md-sys-color, on-error-container), |
| 58 | + focus-state-layer-color: map.get($systems, md-sys-color, on-error-container), |
| 59 | + hover-label-text-color: map.get($systems, md-sys-color, on-error-container), |
| 60 | + hover-state-layer-color: map.get($systems, md-sys-color, on-error-container), |
| 61 | + label-text-color: map.get($systems, md-sys-color, on-error-container), |
| 62 | + pressed-label-text-color: map.get($systems, md-sys-color, on-error-container), |
| 63 | + pressed-state-layer-color: map.get($systems, md-sys-color, on-error-container), |
| 64 | + with-icon-focus-icon-color: map.get($systems, md-sys-color, on-error-container), |
| 65 | + with-icon-hover-icon-color: map.get($systems, md-sys-color, on-error-container), |
| 66 | + with-icon-icon-color: map.get($systems, md-sys-color, on-error-container), |
| 67 | + with-icon-pressed-icon-color: map.get($systems, md-sys-color, on-error-container), |
| 68 | + state-layer-color: map.get($systems, md-sys-color, on-error-container), |
| 69 | + ripple-color: sass-utils.safe-color-change( |
| 70 | + map.get($systems, md-sys-color, on-error-container), |
| 71 | + $alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity) |
| 72 | + ), |
| 73 | + ) |
| 74 | + ); |
| 75 | + |
| 76 | + @return token-definition.namespace-tokens($prefix, ( |
| 77 | + _fix-tokens($tokens), |
| 78 | + token-definition.map-values($variant-tokens, meta.get-function(_fix-tokens)) |
| 79 | + ), $token-slots); |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | +/// Fixes inconsistent values in the tonal button tokens so that they can produce valid styles. |
| 84 | +/// @param {Map} $initial-tokens Map of tonal button tokens currently being generated. |
| 85 | +/// @return {Map} The given tokens, with the invalid values replaced with valid ones. |
| 86 | +@function _fix-tokens($initial-tokens) { |
| 87 | + // Need to get the hardcoded values, because they include opacities that are used for the disabled |
| 88 | + // state. |
| 89 | + $hardcoded-tokens: token-definition.get-mdc-tokens('filled-tonal-button', (), false); |
| 90 | + |
| 91 | + @return token-definition.combine-color-tokens($initial-tokens, $hardcoded-tokens, ( |
| 92 | + ( |
| 93 | + color: disabled-label-text-color, |
| 94 | + opacity: disabled-label-text-opacity, |
| 95 | + ), |
| 96 | + ( |
| 97 | + color: disabled-container-color, |
| 98 | + opacity: disabled-container-opacity, |
| 99 | + ) |
| 100 | + )); |
| 101 | +} |
0 commit comments