_button-toggle-theme.scss 5.7 KB

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