_list-theme.scss 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. @use 'sass:map';
  2. @use '../core/style/sass-utils';
  3. @use '../core/theming/theming';
  4. @use '../core/theming/inspection';
  5. @use '../core/theming/validation';
  6. @use '../core/tokens/m2/mat/list' as tokens-mat-list;
  7. @use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
  8. @use '../core/tokens/m2/mdc/radio' as tokens-mdc-radio;
  9. @use '../core/tokens/m2/mdc/list' as tokens-mdc-list;
  10. @use '../core/tokens/token-utils';
  11. @use '../core/typography/typography';
  12. @mixin base($theme) {
  13. // Add default values for tokens not related to color, typography, or density.
  14. @if inspection.get-theme-version($theme) == 1 {
  15. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  16. } @else {
  17. @include sass-utils.current-selector-or-root() {
  18. @include token-utils.create-token-values(
  19. tokens-mdc-list.$prefix,
  20. tokens-mdc-list.get-unthemable-tokens()
  21. );
  22. @include token-utils.create-token-values(
  23. tokens-mat-list.$prefix,
  24. tokens-mat-list.get-unthemable-tokens()
  25. );
  26. }
  27. }
  28. }
  29. @mixin color($theme) {
  30. @if inspection.get-theme-version($theme) == 1 {
  31. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
  32. } @else {
  33. @include sass-utils.current-selector-or-root() {
  34. @include token-utils.create-token-values(
  35. tokens-mdc-list.$prefix,
  36. tokens-mdc-list.get-color-tokens($theme)
  37. );
  38. @include token-utils.create-token-values(
  39. tokens-mat-list.$prefix,
  40. tokens-mat-list.get-color-tokens($theme)
  41. );
  42. }
  43. .mdc-list-item__start,
  44. .mdc-list-item__end {
  45. @include token-utils.create-token-values(
  46. tokens-mdc-radio.$prefix,
  47. tokens-mdc-radio.get-color-tokens($theme, primary)
  48. );
  49. }
  50. .mat-accent {
  51. .mdc-list-item__start,
  52. .mdc-list-item__end {
  53. @include token-utils.create-token-values(
  54. tokens-mdc-radio.$prefix,
  55. tokens-mdc-radio.get-color-tokens($theme, accent)
  56. );
  57. }
  58. }
  59. .mat-warn {
  60. .mdc-list-item__start,
  61. .mdc-list-item__end {
  62. @include token-utils.create-token-values(
  63. tokens-mdc-radio.$prefix,
  64. tokens-mdc-radio.get-color-tokens($theme, warn)
  65. );
  66. }
  67. }
  68. .mat-mdc-list-option {
  69. @include token-utils.create-token-values(
  70. tokens-mdc-checkbox.$prefix,
  71. tokens-mdc-checkbox.get-color-tokens($theme, primary)
  72. );
  73. }
  74. .mat-mdc-list-option.mat-accent {
  75. @include token-utils.create-token-values(
  76. tokens-mdc-checkbox.$prefix,
  77. tokens-mdc-checkbox.get-color-tokens($theme, accent)
  78. );
  79. }
  80. .mat-mdc-list-option.mat-warn {
  81. @include token-utils.create-token-values(
  82. tokens-mdc-checkbox.$prefix,
  83. tokens-mdc-checkbox.get-color-tokens($theme, warn)
  84. );
  85. }
  86. // There is no token for activated color on nav list.
  87. // TODO(mmalerba): Add a token to MDC or make a custom one.
  88. .mat-mdc-list-base.mat-mdc-list-base {
  89. .mdc-list-item--selected,
  90. .mdc-list-item--activated {
  91. .mdc-list-item__primary-text,
  92. .mdc-list-item__start {
  93. color: inspection.get-theme-color($theme, primary);
  94. }
  95. }
  96. }
  97. // TODO(mmalerba): Leaking styles from the old MDC list mixins used in other components can
  98. // cause opacity issues, so we need this override for now. We can remove it when all
  99. // Angular Material components stop using the old MDC mixins.
  100. .mat-mdc-list-base .mdc-list-item--disabled {
  101. .mdc-list-item__start,
  102. .mdc-list-item__content,
  103. .mdc-list-item__end {
  104. opacity: 1;
  105. }
  106. }
  107. }
  108. }
  109. @mixin density($theme) {
  110. @if inspection.get-theme-version($theme) == 1 {
  111. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  112. } @else {
  113. $density-scale: inspection.get-theme-density($theme);
  114. @include sass-utils.current-selector-or-root() {
  115. @include token-utils.create-token-values(
  116. tokens-mdc-list.$prefix,
  117. tokens-mdc-list.get-density-tokens($theme)
  118. );
  119. @include token-utils.create-token-values(
  120. tokens-mat-list.$prefix,
  121. tokens-mat-list.get-density-tokens($theme)
  122. );
  123. }
  124. .mdc-list-item__start,
  125. .mdc-list-item__end {
  126. @include token-utils.create-token-values(
  127. tokens-mdc-radio.$prefix,
  128. tokens-mdc-radio.get-density-tokens($theme)
  129. );
  130. }
  131. // TODO(mmalerba): This is added to maintain the same style MDC used prior to the token-based
  132. // API, to avoid screenshot diffs. We should remove it in favor of following MDC's current
  133. // style, or add custom tokens for it.
  134. .mat-mdc-list-item {
  135. &.mdc-list-item--with-leading-avatar,
  136. &.mdc-list-item--with-leading-checkbox,
  137. &.mdc-list-item--with-leading-icon {
  138. &.mdc-list-item--with-one-line {
  139. height: map.get(
  140. (
  141. 0: 56px,
  142. -1: 52px,
  143. -2: 48px,
  144. -3: 44px,
  145. -4: 40px,
  146. -5: 40px,
  147. ),
  148. $density-scale
  149. );
  150. }
  151. &.mdc-list-item--with-two-lines {
  152. height: map.get(
  153. (
  154. 0: 72px,
  155. -1: 68px,
  156. -2: 64px,
  157. -3: 60px,
  158. -4: 56px,
  159. -5: 56px,
  160. ),
  161. $density-scale
  162. );
  163. }
  164. }
  165. }
  166. }
  167. }
  168. @mixin typography($theme) {
  169. @if inspection.get-theme-version($theme) == 1 {
  170. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  171. } @else {
  172. @include sass-utils.current-selector-or-root() {
  173. @include token-utils.create-token-values(
  174. tokens-mdc-list.$prefix,
  175. tokens-mdc-list.get-typography-tokens($theme)
  176. );
  177. @include token-utils.create-token-values(
  178. tokens-mat-list.$prefix,
  179. tokens-mat-list.get-typography-tokens($theme)
  180. );
  181. }
  182. // MDC does not have tokens for the subheader.
  183. // TODO(mmalerba): Discuss with MDC about adding them, or create custom tokens.
  184. .mdc-list-group__subheader {
  185. font: inspection.get-theme-typography($theme, subtitle-1, font);
  186. letter-spacing: inspection.get-theme-typography($theme, subtitle-1, letter-spacing);
  187. }
  188. }
  189. }
  190. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  191. @function _define-overrides() {
  192. @return (
  193. (
  194. namespace: tokens-mat-list.$prefix,
  195. tokens: tokens-mat-list.get-token-slots(),
  196. ),
  197. (
  198. namespace: tokens-mdc-list.$prefix,
  199. tokens: tokens-mdc-list.get-token-slots(),
  200. ),
  201. );
  202. }
  203. @mixin overrides($tokens: ()) {
  204. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  205. }
  206. @mixin theme($theme) {
  207. @include theming.private-check-duplicate-theme-styles($theme, 'mat-list') {
  208. @if inspection.get-theme-version($theme) == 1 {
  209. @include _theme-from-tokens(inspection.get-theme-tokens($theme));
  210. } @else {
  211. @include base($theme);
  212. @if inspection.theme-has($theme, color) {
  213. @include color($theme);
  214. }
  215. @if inspection.theme-has($theme, density) {
  216. @include density($theme);
  217. }
  218. @if inspection.theme-has($theme, typography) {
  219. @include typography($theme);
  220. }
  221. }
  222. }
  223. }
  224. @mixin _theme-from-tokens($tokens) {
  225. @include validation.selector-defined(
  226. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  227. );
  228. $mdc-list-tokens: token-utils.get-tokens-for($tokens, tokens-mdc-list.$prefix);
  229. $mat-list-tokens: token-utils.get-tokens-for($tokens, tokens-mat-list.$prefix);
  230. @include token-utils.create-token-values(tokens-mdc-list.$prefix, $mdc-list-tokens);
  231. @include token-utils.create-token-values(tokens-mat-list.$prefix, $mat-list-tokens);
  232. }