|
| 1 | +@use 'sass:map'; |
| 2 | +@use '../../../theming/theming'; |
| 3 | +@use '../../token-utils'; |
| 4 | +@use '../../../style/sass-utils'; |
| 5 | +@use '../../../typography/typography-utils'; |
| 6 | + |
| 7 | +// The prefix used to generate the fully qualified name for tokens in this file. |
| 8 | +$prefix: (mdc, slider); |
| 9 | + |
| 10 | +// Tokens that can't be configured through Angular Material's current theming API, |
| 11 | +// but may be in a future version of the theming API. |
| 12 | +// |
| 13 | +// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`. |
| 14 | +// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in |
| 15 | +// our CSS. |
| 16 | +@function get-unthemable-tokens() { |
| 17 | + @return ( |
| 18 | + // Height of active track. |
| 19 | + active-track-height: 6px, |
| 20 | + // Border radius of active track. |
| 21 | + active-track-shape: 9999px, |
| 22 | + // Height of handle. |
| 23 | + handle-height: 20px, |
| 24 | + // Border radius of handle. |
| 25 | + handle-shape: 50%, |
| 26 | + // Width of handle. |
| 27 | + handle-width: 20px, |
| 28 | + // Height of inactive track. |
| 29 | + inactive-track-height: 4px, |
| 30 | + // Border radius of inactive track. |
| 31 | + inactive-track-shape: 9999px, |
| 32 | + // Width of handle when overlapping with another handle below it. |
| 33 | + with-overlap-handle-outline-width: 1px, |
| 34 | + // Opacity of active container with tick marks. |
| 35 | + with-tick-marks-active-container-opacity: 0.6, |
| 36 | + // Border radius of container with tick marks. |
| 37 | + with-tick-marks-container-shape: 50%, |
| 38 | + // Size of container with tick marks. |
| 39 | + with-tick-marks-container-size: 2px, |
| 40 | + // Opacity of inactive container with tick marks. |
| 41 | + with-tick-marks-inactive-container-opacity: 0.6, |
| 42 | + // ============================================================================================= |
| 43 | + // = TOKENS NOT USED IN ANGULAR MATERIAL = |
| 44 | + // ============================================================================================= |
| 45 | + disabled-handle-elevation: null, |
| 46 | + label-container-elevation: null, |
| 47 | + label-container-height: null, |
| 48 | + track-elevation: null, |
| 49 | + focus-state-layer-opacity: null, |
| 50 | + hover-state-layer-opacity: null, |
| 51 | + pressed-state-layer-opacity: null, |
| 52 | + // MDC does not seem to use these tokens. |
| 53 | + hover-state-layer-color: null, |
| 54 | + pressed-handle-color: null, |
| 55 | + ); |
| 56 | +} |
| 57 | + |
| 58 | +// Tokens that can be configured through Angular Material's color theming API. |
| 59 | +@function get-color-tokens($config) { |
| 60 | + $foreground: map.get($config, foreground); |
| 61 | + $elevation: theming.get-color-from-palette($foreground, elevation); |
| 62 | + $is-dark: map.get($config, is-dark); |
| 63 | + $on-surface: if($is-dark, #fff, #000); |
| 64 | + |
| 65 | + // The default for tokens that rely on the theme will use the primary palette |
| 66 | + $primary: map.get($config, primary); |
| 67 | + $theme-color-tokens: private-get-color-palette-color-tokens($primary); |
| 68 | + |
| 69 | + @return map.merge( |
| 70 | + $theme-color-tokens, |
| 71 | + ( |
| 72 | + // Color of active track when disabled. |
| 73 | + disabled-active-track-color: $on-surface, |
| 74 | + // Color of handle when disabled. |
| 75 | + disabled-handle-color: $on-surface, |
| 76 | + // Color of inactive track when disabled. |
| 77 | + disabled-inactive-track-color: $on-surface, |
| 78 | + // Color of container label. |
| 79 | + label-container-color: $on-surface, |
| 80 | + // Color of label text. |
| 81 | + label-label-text-color: if($is-dark, #000, #fff), |
| 82 | + // Color of handle outline when overlapping with another handle below it. |
| 83 | + with-overlap-handle-outline-color: #fff, |
| 84 | + // Color of container with tick marks when disabled. |
| 85 | + with-tick-marks-disabled-container-color: $on-surface, |
| 86 | + // (Part of the color tokens because it needs to be combined with the |
| 87 | + // shadow color to generate the box-shadow.) |
| 88 | + // Elevation level for handle. |
| 89 | + handle-elevation: 1, |
| 90 | + // Color of handle shadow. |
| 91 | + handle-shadow-color: if($elevation != null, $elevation, elevation.$color), |
| 92 | + ) |
| 93 | + ); |
| 94 | +} |
| 95 | + |
| 96 | +// Generates tokens for the slider properties that change based on the theme. |
| 97 | +@function private-get-color-palette-color-tokens($color-palette) { |
| 98 | + $color: theming.get-color-from-palette($color-palette); |
| 99 | + $on-color: map.get($color-palette, default-contrast); |
| 100 | + |
| 101 | + @return ( |
| 102 | + // Color of handle. |
| 103 | + handle-color: $color, |
| 104 | + // Color of handle when focused. |
| 105 | + focus-handle-color: $color, |
| 106 | + // Color of handle on hover. |
| 107 | + hover-handle-color: $color, |
| 108 | + // Color of handle when active. |
| 109 | + active-track-color: $color, |
| 110 | + // Color of inactive track. |
| 111 | + inactive-track-color: $color, |
| 112 | + // Color of inactive container with tick marks. |
| 113 | + with-tick-marks-inactive-container-color: $color, |
| 114 | + // Color of active container with tick marks. |
| 115 | + with-tick-marks-active-container-color: $on-color, |
| 116 | + ); |
| 117 | +} |
| 118 | + |
| 119 | +// Tokens that can be configured through Angular Material's typography theming API. |
| 120 | +@function get-typography-tokens($config) { |
| 121 | + @if ($config == null) { |
| 122 | + $config: mdc-helpers.private-fallback-typography-from-mdc(); |
| 123 | + } |
| 124 | + |
| 125 | + @return ( |
| 126 | + // Font for label text. |
| 127 | + label-label-text-font: typography-utils.font-family($config, subtitle-2) |
| 128 | + or typography-utils.font-family($config), |
| 129 | + // Font size of label text. |
| 130 | + label-label-text-size: typography-utils.font-size($config, subtitle-2), |
| 131 | + // Line height of label text. |
| 132 | + label-label-text-line-height: typography-utils.line-height($config, subtitle-2), |
| 133 | + // Letter spacing of label text. |
| 134 | + label-label-text-tracking: typography-utils.letter-spacing($config, subtitle-2), |
| 135 | + // Font weight of label text. |
| 136 | + label-label-text-weight: typography-utils.font-weight($config, subtitle-2), |
| 137 | + ); |
| 138 | +} |
| 139 | + |
| 140 | +// Tokens that can be configured through Angular Material's density theming API. |
| 141 | +@function get-density-tokens($config) { |
| 142 | + @return (); |
| 143 | +} |
| 144 | + |
| 145 | +// Combines the tokens generated by the above functions into a single map with placeholder values. |
| 146 | +// This is used to create token slots. |
| 147 | +@function get-token-slots() { |
| 148 | + @return sass-utils.deep-merge-all( |
| 149 | + get-unthemable-tokens(), |
| 150 | + get-color-tokens(token-utils.$placeholder-color-config), |
| 151 | + get-typography-tokens(token-utils.$placeholder-typography-config), |
| 152 | + get-density-tokens(token-utils.$placeholder-density-config) |
| 153 | + ); |
| 154 | +} |
0 commit comments