|
| 1 | +@use 'sass:map'; |
| 2 | +@use '../../token-utils'; |
| 3 | +@use '../../../theming/theming'; |
| 4 | +@use '../../../style/sass-utils'; |
| 5 | +@use '../../../typography/typography-utils'; |
| 6 | +@use '../../../mdc-helpers/mdc-helpers'; |
| 7 | + |
| 8 | +// The prefix used to generate the fully qualified name for tokens in this file. |
| 9 | +$prefix: (mat, option); |
| 10 | + |
| 11 | +// Tokens that can't be configured through Angular Material's current theming API, |
| 12 | +// but may be in a future version of the theming API. |
| 13 | +@function get-unthemable-tokens() { |
| 14 | + @return (); |
| 15 | +} |
| 16 | + |
| 17 | +// Tokens that can be configured through Angular Material's color theming API. |
| 18 | +@function get-color-tokens($config) { |
| 19 | + $is-dark: map.get($config, is-dark); |
| 20 | + $foreground: map.get($config, foreground); |
| 21 | + $primary: map.get($config, primary); |
| 22 | + $on-surface: if($is-dark, #fff, #000); |
| 23 | + $active-state-layer-color: rgba($on-surface, if($is-dark, 0.08, 0.04)); |
| 24 | + $palette-tokens: private-get-color-palette-color-tokens($primary); |
| 25 | + |
| 26 | + @return map.merge($palette-tokens, ( |
| 27 | + label-text-color: theming.get-color-from-palette($foreground, text), |
| 28 | + hover-state-layer-color: $active-state-layer-color, |
| 29 | + focus-state-layer-color: $active-state-layer-color, |
| 30 | + selected-state-layer-color: $active-state-layer-color, |
| 31 | + )); |
| 32 | +} |
| 33 | + |
| 34 | +// Tokens that can be configured through Angular Material's typography theming API. |
| 35 | +@function get-typography-tokens($config) { |
| 36 | + // TODO(crisbeto): The earlier implementation of the option used MDC's APIs to create the |
| 37 | + // typography tokens. As a result, we unintentionally allowed `null` typography configs to be |
| 38 | + // passed in. Since there a lot of apps that now depend on this pattern, we need this temporary |
| 39 | + // fallback. |
| 40 | + @if ($config == null) { |
| 41 | + $config: mdc-helpers.private-fallback-typography-from-mdc(); |
| 42 | + } |
| 43 | + |
| 44 | + @return ( |
| 45 | + label-text-font: typography-utils.font-family($config, body-1) or |
| 46 | + typography-utils.font-family($config), |
| 47 | + label-text-line-height: typography-utils.line-height($config, body-1), |
| 48 | + label-text-size: typography-utils.font-size($config, body-1), |
| 49 | + label-text-tracking: typography-utils.letter-spacing($config, body-1), |
| 50 | + label-text-weight: typography-utils.font-weight($config, body-1) |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +// Generates the tokens used to theme the option based on a palette. |
| 55 | +@function private-get-color-palette-color-tokens($palette) { |
| 56 | + @return ( |
| 57 | + selected-state-label-text-color: theming.get-color-from-palette($palette), |
| 58 | + ); |
| 59 | +} |
| 60 | + |
| 61 | +// Tokens that can be configured through Angular Material's density theming API. |
| 62 | +@function get-density-tokens($config) { |
| 63 | + @return (); |
| 64 | +} |
| 65 | + |
| 66 | +// Combines the tokens generated by the above functions into a single map with placeholder values. |
| 67 | +// This is used to create token slots. |
| 68 | +@function get-token-slots() { |
| 69 | + @return sass-utils.deep-merge-all( |
| 70 | + get-unthemable-tokens(), |
| 71 | + get-color-tokens(token-utils.$placeholder-color-config), |
| 72 | + get-typography-tokens(token-utils.$placeholder-typography-config), |
| 73 | + get-density-tokens(token-utils.$placeholder-density-config) |
| 74 | + ); |
| 75 | +} |
0 commit comments