_expansion-theme.scss 3.2 KB

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