_tree-theme.scss 3.0 KB

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