_icon-theme.scss 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. @use '../core/theming/theming';
  2. @use '../core/theming/inspection';
  3. @use '../core/theming/validation';
  4. @use '../core/tokens/m2/mat/icon' as tokens-mat-icon;
  5. @use '../core/tokens/token-utils';
  6. @use '../core/style/sass-utils';
  7. @mixin _palette-colors($theme, $palette-name) {
  8. $color: inspection.get-theme-color($theme, $palette-name, text);
  9. $tokens: tokens-mat-icon.private-get-icon-color-tokens($color);
  10. @include token-utils.create-token-values(tokens-mat-icon.$prefix, $tokens);
  11. }
  12. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  13. /// for the mat-icon.
  14. /// @param {Map} $theme The theme to generate base styles for.
  15. @mixin base($theme) {
  16. @if inspection.get-theme-version($theme) == 1 {
  17. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  18. } @else {
  19. }
  20. }
  21. /// Outputs color theme styles for the mat-icon.
  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 icon: primary, secondary, tertiary, or error
  25. /// (If not specified, default neutral 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-icon.$prefix,
  33. tokens-mat-icon.get-color-tokens($theme)
  34. );
  35. }
  36. .mat-icon {
  37. &.mat-primary {
  38. @include _palette-colors($theme, primary);
  39. }
  40. &.mat-accent {
  41. @include _palette-colors($theme, accent);
  42. }
  43. &.mat-warn {
  44. @include _palette-colors($theme, warn);
  45. }
  46. }
  47. }
  48. }
  49. /// Outputs typography theme styles for the mat-icon.
  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. }
  56. }
  57. /// Outputs density theme styles for the mat-icon.
  58. /// @param {Map} $theme The theme to generate density styles for.
  59. @mixin density($theme) {
  60. @if inspection.get-theme-version($theme) == 1 {
  61. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  62. } @else {
  63. }
  64. }
  65. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  66. @function _define-overrides() {
  67. @return (
  68. (
  69. namespace: tokens-mat-icon.$prefix,
  70. tokens: tokens-mat-icon.get-token-slots(),
  71. ),
  72. );
  73. }
  74. /// Outputs the CSS variable values for the given tokens.
  75. /// @param {Map} $tokens The token values to emit.
  76. @mixin overrides($tokens: ()) {
  77. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  78. }
  79. /// Outputs all (base, color, typography, and density) theme styles for the mat-icon.
  80. /// @param {Map} $theme The theme to generate styles for.
  81. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  82. /// $color-variant: The color variant to use for the icon: surface, primary, secondary, tertiary,
  83. /// or error (If not specified, default surface color will be used).
  84. @mixin theme($theme, $options...) {
  85. @include theming.private-check-duplicate-theme-styles($theme, 'mat-icon') {
  86. @if inspection.get-theme-version($theme) == 1 {
  87. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  88. } @else {
  89. @include base($theme);
  90. @if inspection.theme-has($theme, color) {
  91. @include color($theme);
  92. }
  93. @if inspection.theme-has($theme, density) {
  94. @include density($theme);
  95. }
  96. @if inspection.theme-has($theme, typography) {
  97. @include typography($theme);
  98. }
  99. }
  100. }
  101. }
  102. @mixin _theme-from-tokens($tokens, $options...) {
  103. @include validation.selector-defined(
  104. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  105. );
  106. $mat-icon-tokens: token-utils.get-tokens-for($tokens, tokens-mat-icon.$prefix, $options...);
  107. @include token-utils.create-token-values(tokens-mat-icon.$prefix, $mat-icon-tokens);
  108. }