_chips-theme.scss 6.2 KB

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