_slide-toggle-theme.scss 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. @use '../core/style/sass-utils';
  2. @use '../core/theming/theming';
  3. @use '../core/theming/inspection';
  4. @use '../core/theming/validation';
  5. @use '../core/tokens/token-utils';
  6. @use '../core/typography/typography';
  7. @use '../core/tokens/m2/mat/switch' as tokens-mat-switch;
  8. @use '../core/tokens/m2/mdc/switch' as tokens-mdc-switch;
  9. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  10. /// for the mat-slide-toggle.
  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-switch.$prefix,
  19. tokens-mdc-switch.get-unthemable-tokens()
  20. );
  21. .mat-mdc-slide-toggle {
  22. @include token-utils.create-token-values(
  23. tokens-mat-switch.$prefix,
  24. tokens-mat-switch.get-unthemable-tokens()
  25. );
  26. }
  27. }
  28. }
  29. }
  30. /// Outputs color theme styles for the mat-slide-toggle.
  31. /// @param {Map} $theme The theme to generate color styles for.
  32. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  33. /// $color-variant: The color variant to use for the slide-toggle: primary, secondary, tertiary,
  34. /// or error (If not specified, default primary color will be used).
  35. @mixin color($theme, $options...) {
  36. @if inspection.get-theme-version($theme) == 1 {
  37. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  38. } @else {
  39. $mdc-tokens: tokens-mdc-switch.get-color-tokens($theme);
  40. // Add values for MDC slide toggles tokens
  41. @include sass-utils.current-selector-or-root() {
  42. @include token-utils.create-token-values(
  43. tokens-mdc-switch.$prefix,
  44. tokens-mdc-switch.get-color-tokens($theme)
  45. );
  46. & {
  47. // TODO(wagnermaciel): Use our token system to define this css variable.
  48. --mdc-switch-disabled-label-text-color: #{inspection.get-theme-color(
  49. $theme,
  50. foreground,
  51. disabled-text
  52. )};
  53. }
  54. .mat-mdc-slide-toggle {
  55. @include token-utils.create-token-values(
  56. tokens-mat-switch.$prefix,
  57. tokens-mat-switch.get-color-tokens($theme)
  58. );
  59. // Change the color palette related tokens to accent or warn if applicable
  60. &.mat-accent {
  61. @include token-utils.create-token-values(
  62. tokens-mdc-switch.$prefix,
  63. tokens-mdc-switch.private-get-color-palette-color-tokens($theme, accent)
  64. );
  65. }
  66. &.mat-warn {
  67. @include token-utils.create-token-values(
  68. tokens-mdc-switch.$prefix,
  69. tokens-mdc-switch.private-get-color-palette-color-tokens($theme, warn)
  70. );
  71. }
  72. }
  73. }
  74. }
  75. }
  76. /// Outputs typography theme styles for the mat-slide-toggle.
  77. /// @param {Map} $theme The theme to generate typography styles for.
  78. @mixin typography($theme) {
  79. @if inspection.get-theme-version($theme) == 1 {
  80. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  81. } @else {
  82. @include sass-utils.current-selector-or-root() {
  83. @include token-utils.create-token-values(
  84. tokens-mdc-switch.$prefix,
  85. tokens-mdc-switch.get-typography-tokens($theme)
  86. );
  87. .mat-mdc-slide-toggle {
  88. @include token-utils.create-token-values(
  89. tokens-mat-switch.$prefix,
  90. tokens-mat-switch.get-typography-tokens($theme)
  91. );
  92. }
  93. }
  94. }
  95. }
  96. /// Outputs density theme styles for the mat-slide-toggle.
  97. /// @param {Map} $theme The theme to generate density styles for.
  98. @mixin density($theme) {
  99. @if inspection.get-theme-version($theme) == 1 {
  100. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  101. } @else {
  102. @include sass-utils.current-selector-or-root() {
  103. @include token-utils.create-token-values(
  104. tokens-mdc-switch.$prefix,
  105. tokens-mdc-switch.get-density-tokens($theme)
  106. );
  107. .mat-mdc-slide-toggle {
  108. @include token-utils.create-token-values(
  109. tokens-mat-switch.$prefix,
  110. tokens-mat-switch.get-density-tokens($theme)
  111. );
  112. }
  113. }
  114. }
  115. }
  116. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  117. @function _define-overrides() {
  118. @return (
  119. (
  120. namespace: tokens-mat-switch.$prefix,
  121. tokens: tokens-mat-switch.get-token-slots(),
  122. ),
  123. (
  124. namespace: tokens-mdc-switch.$prefix,
  125. tokens: tokens-mdc-switch.get-token-slots(),
  126. ),
  127. );
  128. }
  129. /// Outputs the CSS variable values for the given tokens.
  130. /// @param {Map} $tokens The token values to emit.
  131. @mixin overrides($tokens: ()) {
  132. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  133. }
  134. /// Outputs all (base, color, typography, and density) theme styles for the mat-icon.
  135. /// @param {Map} $theme The theme to generate styles for.
  136. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  137. /// $color-variant: The color variant to use for the slide-toggle: primary, secondary, tertiary,
  138. /// or error (If not specified, default primary color will be used).
  139. @mixin theme($theme, $options...) {
  140. @include theming.private-check-duplicate-theme-styles($theme, 'mat-slide-toggle') {
  141. @if inspection.get-theme-version($theme) == 1 {
  142. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  143. } @else {
  144. @include base($theme);
  145. @if inspection.theme-has($theme, color) {
  146. @include color($theme);
  147. }
  148. @if inspection.theme-has($theme, density) {
  149. @include density($theme);
  150. }
  151. @if inspection.theme-has($theme, typography) {
  152. @include typography($theme);
  153. }
  154. }
  155. }
  156. }
  157. @mixin _theme-from-tokens($tokens, $options...) {
  158. @include validation.selector-defined(
  159. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  160. );
  161. $mdc-switch-tokens: token-utils.get-tokens-for($tokens, tokens-mdc-switch.$prefix, $options...);
  162. // Don't pass $options here, since the mat-switch doesn't support color options,
  163. // only the mdc-switch does.
  164. $mat-switch-tokens: token-utils.get-tokens-for($tokens, tokens-mat-switch.$prefix);
  165. @include token-utils.create-token-values(tokens-mdc-switch.$prefix, $mdc-switch-tokens);
  166. @include token-utils.create-token-values(tokens-mat-switch.$prefix, $mat-switch-tokens);
  167. }