_slider-theme.scss 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. @use '../core/theming/theming';
  2. @use '../core/theming/inspection';
  3. @use '../core/theming/validation';
  4. @use '../core/typography/typography';
  5. @use '../core/style/sass-utils';
  6. @use '../core/tokens/token-utils';
  7. @use '../core/tokens/m2/mat/slider' as tokens-mat-slider;
  8. @use '../core/tokens/m2/mdc/slider' as tokens-mdc-slider;
  9. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  10. /// for the mat-slider.
  11. /// @param {Map} $theme The theme to generate base styles for.
  12. @mixin base($theme) {
  13. @if inspection.get-theme-version($theme) == 1 {
  14. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  15. } @else {
  16. @include sass-utils.current-selector-or-root() {
  17. @include token-utils.create-token-values(
  18. tokens-mdc-slider.$prefix,
  19. tokens-mdc-slider.get-unthemable-tokens()
  20. );
  21. @include token-utils.create-token-values(
  22. tokens-mat-slider.$prefix,
  23. tokens-mat-slider.get-unthemable-tokens()
  24. );
  25. }
  26. }
  27. }
  28. /// Outputs color theme styles for the mat-slider.
  29. /// @param {Map} $theme The theme to generate color styles for.
  30. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  31. /// $color-variant: The color variant to use for the slider: primary, secondary, tertiary,
  32. /// or error (If not specified, default primary color will be used).
  33. @mixin color($theme, $options...) {
  34. @if inspection.get-theme-version($theme) == 1 {
  35. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  36. } @else {
  37. @include sass-utils.current-selector-or-root() {
  38. @include token-utils.create-token-values(
  39. tokens-mdc-slider.$prefix,
  40. tokens-mdc-slider.get-color-tokens($theme)
  41. );
  42. @include token-utils.create-token-values(
  43. tokens-mat-slider.$prefix,
  44. tokens-mat-slider.get-color-tokens($theme)
  45. );
  46. .mat-accent {
  47. @include token-utils.create-token-values(
  48. tokens-mdc-slider.$prefix,
  49. tokens-mdc-slider.private-get-color-palette-color-tokens($theme, accent)
  50. );
  51. @include token-utils.create-token-values(
  52. tokens-mat-slider.$prefix,
  53. tokens-mat-slider.private-get-color-palette-color-tokens($theme, accent)
  54. );
  55. }
  56. .mat-warn {
  57. @include token-utils.create-token-values(
  58. tokens-mdc-slider.$prefix,
  59. tokens-mdc-slider.private-get-color-palette-color-tokens($theme, warn)
  60. );
  61. @include token-utils.create-token-values(
  62. tokens-mat-slider.$prefix,
  63. tokens-mat-slider.private-get-color-palette-color-tokens($theme, warn)
  64. );
  65. }
  66. }
  67. }
  68. }
  69. /// Outputs typography theme styles for the mat-slider.
  70. /// @param {Map} $theme The theme to generate typography styles for.
  71. @mixin typography($theme) {
  72. @if inspection.get-theme-version($theme) == 1 {
  73. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  74. } @else {
  75. @include sass-utils.current-selector-or-root() {
  76. @include token-utils.create-token-values(
  77. tokens-mdc-slider.$prefix,
  78. tokens-mdc-slider.get-typography-tokens($theme)
  79. );
  80. }
  81. }
  82. }
  83. /// Outputs density theme styles for the mat-slider.
  84. /// @param {Map} $theme The theme to generate density styles for.
  85. @mixin density($theme) {
  86. @if inspection.get-theme-version($theme) == 1 {
  87. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  88. } @else {
  89. @include sass-utils.current-selector-or-root() {
  90. @include token-utils.create-token-values(
  91. tokens-mdc-slider.$prefix,
  92. tokens-mdc-slider.get-density-tokens($theme)
  93. );
  94. }
  95. }
  96. }
  97. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  98. @function _define-overrides() {
  99. @return (
  100. (
  101. namespace: tokens-mat-slider.$prefix,
  102. tokens: tokens-mat-slider.get-token-slots(),
  103. ),
  104. (
  105. namespace: tokens-mdc-slider.$prefix,
  106. tokens: tokens-mdc-slider.get-token-slots(),
  107. ),
  108. );
  109. }
  110. /// Outputs the CSS variable values for the given tokens.
  111. /// @param {Map} $tokens The token values to emit.
  112. @mixin overrides($tokens: ()) {
  113. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  114. }
  115. /// Outputs all (base, color, typography, and density) theme styles for the mat-option.
  116. /// @param {Map} $theme The theme to generate styles for.
  117. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  118. /// $color-variant: The color variant to use for the slider: primary, secondary, tertiary,
  119. /// or error (If not specified, default primary color will be used).
  120. @mixin theme($theme, $options...) {
  121. @include theming.private-check-duplicate-theme-styles($theme, 'mat-slider') {
  122. @if inspection.get-theme-version($theme) == 1 {
  123. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  124. } @else {
  125. @include base($theme);
  126. @if inspection.theme-has($theme, color) {
  127. @include color($theme);
  128. }
  129. @if inspection.theme-has($theme, density) {
  130. @include density($theme);
  131. }
  132. @if inspection.theme-has($theme, typography) {
  133. @include typography($theme);
  134. }
  135. }
  136. }
  137. }
  138. @mixin _theme-from-tokens($tokens, $options...) {
  139. @include validation.selector-defined(
  140. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  141. );
  142. $mdc-slider-tokens: token-utils.get-tokens-for($tokens, tokens-mdc-slider.$prefix, $options...);
  143. $mat-slider-tokens: token-utils.get-tokens-for($tokens, tokens-mat-slider.$prefix, $options...);
  144. @include token-utils.create-token-values(tokens-mdc-slider.$prefix, $mdc-slider-tokens);
  145. @include token-utils.create-token-values(tokens-mat-slider.$prefix, $mat-slider-tokens);
  146. }