_select-theme.scss 4.8 KB

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