_tabs-theme.scss 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. @use '../core/style/sass-utils';
  2. @use '../core/tokens/m2/mdc/secondary-navigation-tab' as tokens-mdc-secondary-navigation-tab;
  3. @use '../core/tokens/m2/mdc/tab-indicator' as tokens-mdc-tab-indicator;
  4. @use '../core/tokens/m2/mat/tab-header' as tokens-mat-tab-header;
  5. @use '../core/tokens/m2/mat/tab-header-with-background' as tokens-mat-tab-header-with-background;
  6. @use '../core/theming/theming';
  7. @use '../core/theming/inspection';
  8. @use '../core/theming/validation';
  9. @use '../core/typography/typography';
  10. @use '../core/tokens/token-utils';
  11. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  12. /// for the mat-tab.
  13. /// @param {Map} $theme The theme to generate base styles for.
  14. @mixin base($theme) {
  15. @if inspection.get-theme-version($theme) == 1 {
  16. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  17. } @else {
  18. @include sass-utils.current-selector-or-root() {
  19. @include token-utils.create-token-values(
  20. tokens-mdc-secondary-navigation-tab.$prefix,
  21. tokens-mdc-secondary-navigation-tab.get-unthemable-tokens()
  22. );
  23. @include token-utils.create-token-values(
  24. tokens-mdc-tab-indicator.$prefix,
  25. tokens-mdc-tab-indicator.get-unthemable-tokens()
  26. );
  27. @include token-utils.create-token-values(
  28. tokens-mat-tab-header.$prefix,
  29. tokens-mat-tab-header.get-unthemable-tokens()
  30. );
  31. @include token-utils.create-token-values(
  32. tokens-mat-tab-header-with-background.$prefix,
  33. tokens-mat-tab-header-with-background.get-unthemable-tokens()
  34. );
  35. }
  36. }
  37. }
  38. /// Outputs color theme styles for the mat-tab.
  39. /// @param {Map} $theme The theme to generate color styles for.
  40. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  41. /// $color-variant: The color variant to use for the tab indicator: primary, secondary,
  42. /// tertiary, or error (If not specified, default primary color will be used).
  43. @mixin color($theme, $options...) {
  44. @if inspection.get-theme-version($theme) == 1 {
  45. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  46. } @else {
  47. .mat-mdc-tab-group,
  48. .mat-mdc-tab-nav-bar {
  49. @include _palette-styles($theme, primary);
  50. &.mat-accent {
  51. @include _palette-styles($theme, accent);
  52. }
  53. &.mat-warn {
  54. @include _palette-styles($theme, warn);
  55. }
  56. &.mat-background-primary {
  57. @include _background-styles($theme, primary);
  58. }
  59. &.mat-background-accent {
  60. @include _background-styles($theme, accent);
  61. }
  62. &.mat-background-warn {
  63. @include _background-styles($theme, warn);
  64. }
  65. }
  66. }
  67. }
  68. @mixin _background-styles($theme, $palette-name) {
  69. @include token-utils.create-token-values(
  70. tokens-mat-tab-header-with-background.$prefix,
  71. tokens-mat-tab-header-with-background.get-color-tokens($theme, $palette-name)
  72. );
  73. }
  74. @mixin _palette-styles($theme, $palette-name) {
  75. @include token-utils.create-token-values(
  76. tokens-mdc-secondary-navigation-tab.$prefix,
  77. tokens-mdc-secondary-navigation-tab.get-color-tokens($theme, $palette-name)
  78. );
  79. @include token-utils.create-token-values(
  80. tokens-mdc-tab-indicator.$prefix,
  81. tokens-mdc-tab-indicator.get-color-tokens($theme, $palette-name)
  82. );
  83. @include token-utils.create-token-values(
  84. tokens-mat-tab-header.$prefix,
  85. tokens-mat-tab-header.get-color-tokens($theme, $palette-name)
  86. );
  87. }
  88. /// Outputs typography theme styles for the mat-tab.
  89. /// @param {Map} $theme The theme to generate typography styles for.
  90. @mixin typography($theme) {
  91. @if inspection.get-theme-version($theme) == 1 {
  92. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  93. } @else {
  94. .mat-mdc-tab-header {
  95. @include token-utils.create-token-values(
  96. tokens-mdc-secondary-navigation-tab.$prefix,
  97. tokens-mdc-secondary-navigation-tab.get-typography-tokens($theme)
  98. );
  99. @include token-utils.create-token-values(
  100. tokens-mdc-tab-indicator.$prefix,
  101. tokens-mdc-tab-indicator.get-typography-tokens($theme)
  102. );
  103. @include token-utils.create-token-values(
  104. tokens-mat-tab-header.$prefix,
  105. tokens-mat-tab-header.get-typography-tokens($theme)
  106. );
  107. @include token-utils.create-token-values(
  108. tokens-mat-tab-header-with-background.$prefix,
  109. tokens-mat-tab-header-with-background.get-typography-tokens($theme)
  110. );
  111. }
  112. }
  113. }
  114. /// Outputs density theme styles for the mat-tab.
  115. /// @param {Map} $theme The theme to generate density styles for.
  116. @mixin density($theme) {
  117. @if inspection.get-theme-version($theme) == 1 {
  118. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  119. } @else {
  120. .mat-mdc-tab-header {
  121. @include token-utils.create-token-values(
  122. tokens-mdc-secondary-navigation-tab.$prefix,
  123. tokens-mdc-secondary-navigation-tab.get-density-tokens($theme)
  124. );
  125. @include token-utils.create-token-values(
  126. tokens-mdc-tab-indicator.$prefix,
  127. tokens-mdc-tab-indicator.get-density-tokens($theme)
  128. );
  129. @include token-utils.create-token-values(
  130. tokens-mat-tab-header.$prefix,
  131. tokens-mat-tab-header.get-density-tokens($theme)
  132. );
  133. @include token-utils.create-token-values(
  134. tokens-mat-tab-header-with-background.$prefix,
  135. tokens-mat-tab-header-with-background.get-density-tokens($theme)
  136. );
  137. }
  138. }
  139. }
  140. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  141. @function _define-overrides() {
  142. $tab-tokens: tokens-mdc-secondary-navigation-tab.get-token-slots();
  143. $tab-indicator-tokens: tokens-mdc-tab-indicator.get-token-slots();
  144. $tab-header-tokens: tokens-mat-tab-header.get-token-slots();
  145. $tab-header-with-background-tokens: tokens-mat-tab-header-with-background.get-token-slots();
  146. @return (
  147. (
  148. namespace: tokens-mdc-secondary-navigation-tab.$prefix,
  149. tokens: $tab-tokens,
  150. ),
  151. (
  152. namespace: tokens-mdc-tab-indicator.$prefix,
  153. tokens: $tab-indicator-tokens,
  154. ),
  155. (
  156. namespace: tokens-mat-tab-header.$prefix,
  157. tokens: $tab-header-tokens,
  158. ),
  159. (
  160. namespace: tokens-mat-tab-header-with-background.$prefix,
  161. tokens: $tab-header-with-background-tokens,
  162. ),
  163. );
  164. }
  165. /// Outputs the CSS variable values for the given tokens.
  166. /// @param {Map} $tokens The token values to emit.
  167. @mixin overrides($tokens: ()) {
  168. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  169. }
  170. /// Outputs all (base, color, typography, and density) theme styles for the mat-tab.
  171. /// @param {Map} $theme The theme to generate styles for.
  172. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  173. /// $color-variant: The color variant to use for the tab indicator: primary, secondary,
  174. /// tertiary, or error (If not specified, default primary color will be used).
  175. @mixin theme($theme, $options...) {
  176. @include theming.private-check-duplicate-theme-styles($theme, 'mat-tabs') {
  177. @if inspection.get-theme-version($theme) == 1 {
  178. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  179. } @else {
  180. @include base($theme);
  181. @if inspection.theme-has($theme, color) {
  182. @include color($theme);
  183. }
  184. @if inspection.theme-has($theme, density) {
  185. @include density($theme);
  186. }
  187. @if inspection.theme-has($theme, typography) {
  188. @include typography($theme);
  189. }
  190. }
  191. }
  192. }
  193. @mixin _theme-from-tokens($tokens, $options...) {
  194. @include validation.selector-defined(
  195. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  196. );
  197. $mdc-tab-indicator-tokens: token-utils.get-tokens-for(
  198. $tokens,
  199. tokens-mdc-tab-indicator.$prefix,
  200. $options...
  201. );
  202. $mat-tab-header-tokens: token-utils.get-tokens-for(
  203. $tokens,
  204. tokens-mat-tab-header.$prefix,
  205. $options...
  206. );
  207. // Don't pass $options here, because the mdc-tab doesn't have color variants,
  208. // only the mdc-tab-indicator and mat-tab-header do.
  209. $mdc-secondary-navigation-tab-tokens: token-utils.get-tokens-for(
  210. $tokens,
  211. tokens-mdc-secondary-navigation-tab.$prefix
  212. );
  213. @include token-utils.create-token-values(
  214. tokens-mdc-secondary-navigation-tab.$prefix,
  215. $mdc-secondary-navigation-tab-tokens
  216. );
  217. @include token-utils.create-token-values(
  218. tokens-mdc-tab-indicator.$prefix,
  219. $mdc-tab-indicator-tokens
  220. );
  221. @include token-utils.create-token-values(tokens-mat-tab-header.$prefix, $mat-tab-header-tokens);
  222. }