_toolbar-theme.scss 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. @use 'sass:map';
  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/toolbar' as tokens-mat-toolbar;
  7. @use '../core/tokens/token-utils';
  8. @use '../core/style/sass-utils';
  9. @mixin _palette-styles($theme, $palette-name) {
  10. @include token-utils.create-token-values(
  11. tokens-mat-toolbar.$prefix,
  12. tokens-mat-toolbar.private-get-color-palette-color-tokens(
  13. $background-color: inspection.get-theme-color($theme, $palette-name),
  14. $text-color: inspection.get-theme-color($theme, $palette-name, default-contrast)
  15. )
  16. );
  17. }
  18. @mixin base($theme) {
  19. }
  20. @mixin color($theme) {
  21. @if inspection.get-theme-version($theme) == 1 {
  22. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
  23. } @else {
  24. @include sass-utils.current-selector-or-root() {
  25. @include token-utils.create-token-values(
  26. tokens-mat-toolbar.$prefix,
  27. tokens-mat-toolbar.get-color-tokens($theme)
  28. );
  29. }
  30. .mat-toolbar {
  31. &.mat-primary {
  32. @include _palette-styles($theme, primary);
  33. }
  34. &.mat-accent {
  35. @include _palette-styles($theme, accent);
  36. }
  37. &.mat-warn {
  38. @include _palette-styles($theme, warn);
  39. }
  40. }
  41. }
  42. }
  43. @mixin typography($theme) {
  44. @if inspection.get-theme-version($theme) == 1 {
  45. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  46. } @else {
  47. // TODO(mmalerba): Stop calling this and resolve resulting screen diffs.
  48. $theme: inspection.private-get-typography-back-compat-theme($theme);
  49. @include sass-utils.current-selector-or-root() {
  50. @include token-utils.create-token-values(
  51. tokens-mat-toolbar.$prefix,
  52. tokens-mat-toolbar.get-typography-tokens($theme)
  53. );
  54. }
  55. }
  56. }
  57. @mixin density($theme) {
  58. @if inspection.get-theme-version($theme) == 1 {
  59. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  60. } @else {
  61. @include sass-utils.current-selector-or-root() {
  62. @include token-utils.create-token-values(
  63. tokens-mat-toolbar.$prefix,
  64. tokens-mat-toolbar.get-density-tokens($theme)
  65. );
  66. }
  67. }
  68. }
  69. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  70. @function _define-overrides() {
  71. @return (
  72. (
  73. namespace: tokens-mat-toolbar.$prefix,
  74. tokens: tokens-mat-toolbar.get-token-slots(),
  75. ),
  76. );
  77. }
  78. /// Outputs the CSS variable values for the given tokens.
  79. /// @param {Map} $tokens The token values to emit.
  80. @mixin overrides($tokens: ()) {
  81. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  82. }
  83. @mixin theme($theme) {
  84. @include theming.private-check-duplicate-theme-styles($theme, 'mat-toolbar') {
  85. @if inspection.get-theme-version($theme) == 1 {
  86. @include _theme-from-tokens(inspection.get-theme-tokens($theme));
  87. } @else {
  88. @include base($theme);
  89. @if inspection.theme-has($theme, color) {
  90. @include color($theme);
  91. }
  92. @if inspection.theme-has($theme, density) {
  93. @include density($theme);
  94. }
  95. @if inspection.theme-has($theme, typography) {
  96. @include typography($theme);
  97. }
  98. }
  99. }
  100. }
  101. @mixin _theme-from-tokens($tokens) {
  102. @include validation.selector-defined(
  103. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  104. );
  105. @if ($tokens != ()) {
  106. @include token-utils.create-token-values(
  107. tokens-mat-toolbar.$prefix,
  108. map.get($tokens, tokens-mat-toolbar.$prefix)
  109. );
  110. }
  111. }