_badge-theme.scss 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. @use 'sass:color';
  2. @use '../core/theming/theming';
  3. @use '../core/theming/inspection';
  4. @use '../core/theming/validation';
  5. @use '../core/typography/typography';
  6. @use '../core/tokens/m2/mat/badge' as tokens-mat-badge;
  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-badge.
  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-badge.$prefix,
  19. tokens-mat-badge.get-unthemable-tokens()
  20. );
  21. }
  22. }
  23. }
  24. /// Outputs color theme styles for the mat-badge.
  25. /// @param {Map} $theme The theme to generate color styles for.
  26. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  27. /// $color-variant: The color variant to use for the badge: primary, secondary, tertiary,
  28. /// or error (If not specified, default error color will be used).
  29. @mixin color($theme, $options...) {
  30. @if inspection.get-theme-version($theme) == 1 {
  31. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  32. } @else {
  33. @include sass-utils.current-selector-or-root() {
  34. @include token-utils.create-token-values(
  35. tokens-mat-badge.$prefix,
  36. tokens-mat-badge.get-color-tokens($theme)
  37. );
  38. }
  39. .mat-badge-accent {
  40. @include token-utils.create-token-values(
  41. tokens-mat-badge.$prefix,
  42. tokens-mat-badge.private-get-color-palette-color-tokens($theme, accent)
  43. );
  44. }
  45. .mat-badge-warn {
  46. @include token-utils.create-token-values(
  47. tokens-mat-badge.$prefix,
  48. tokens-mat-badge.private-get-color-palette-color-tokens($theme, warn)
  49. );
  50. }
  51. }
  52. }
  53. /// Outputs typography theme styles for the mat-badge.
  54. /// @param {Map} $theme The theme to generate typography styles for.
  55. @mixin typography($theme) {
  56. @if inspection.get-theme-version($theme) == 1 {
  57. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  58. } @else {
  59. @include sass-utils.current-selector-or-root() {
  60. @include token-utils.create-token-values(
  61. tokens-mat-badge.$prefix,
  62. tokens-mat-badge.get-typography-tokens($theme)
  63. );
  64. }
  65. }
  66. }
  67. /// Outputs density theme styles for the mat-badge.
  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. }
  74. }
  75. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  76. @function _define-overrides() {
  77. @return (
  78. (
  79. namespace: tokens-mat-badge.$prefix,
  80. tokens: tokens-mat-badge.get-token-slots(),
  81. ),
  82. );
  83. }
  84. /// Outputs the CSS variable values for the given tokens.
  85. /// @param {Map} $tokens The token values to emit.
  86. @mixin overrides($tokens: ()) {
  87. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  88. }
  89. /// Outputs all (base, color, typography, and density) theme styles for the mat-badge.
  90. /// @param {Map} $theme The theme to generate styles for.
  91. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  92. /// $color-variant: The color variant to use for the badge: primary, secondary, tertiary,
  93. /// or error (If not specified, default error color will be used).
  94. @mixin theme($theme, $options...) {
  95. @include theming.private-check-duplicate-theme-styles($theme, 'mat-badge') {
  96. @if inspection.get-theme-version($theme) == 1 {
  97. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  98. } @else {
  99. @include base($theme);
  100. @if inspection.theme-has($theme, color) {
  101. @include color($theme);
  102. }
  103. @if inspection.theme-has($theme, density) {
  104. @include density($theme);
  105. }
  106. @if inspection.theme-has($theme, typography) {
  107. @include typography($theme);
  108. }
  109. }
  110. }
  111. }
  112. @mixin _theme-from-tokens($tokens, $options...) {
  113. @include validation.selector-defined(
  114. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  115. );
  116. $mat-badge-tokens: token-utils.get-tokens-for($tokens, tokens-mat-badge.$prefix, $options...);
  117. @include token-utils.create-token-values(tokens-mat-badge.$prefix, $mat-badge-tokens);
  118. }