_checkbox-theme.scss 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. @use '../core/style/sass-utils';
  2. @use '../core/theming/theming';
  3. @use '../core/theming/inspection';
  4. @use '../core/theming/validation';
  5. @use '../core/tokens/token-utils';
  6. @use '../core/typography/typography';
  7. @use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
  8. @use '../core/tokens/m2/mat/checkbox' as tokens-mat-checkbox;
  9. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  10. /// for the mat-checkbox.
  11. /// @param {Map} $theme The theme to generate base styles for.
  12. @mixin base($theme) {
  13. @if inspection.get-theme-version($theme) == 1 {
  14. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  15. } @else {
  16. @include sass-utils.current-selector-or-root() {
  17. @include token-utils.create-token-values(
  18. tokens-mdc-checkbox.$prefix,
  19. tokens-mdc-checkbox.get-unthemable-tokens()
  20. );
  21. @include token-utils.create-token-values(
  22. tokens-mat-checkbox.$prefix,
  23. tokens-mat-checkbox.get-unthemable-tokens()
  24. );
  25. }
  26. }
  27. }
  28. /// Outputs color theme styles for the mat-checkbox.
  29. /// @param {Map} $theme The theme to generate color styles for.
  30. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  31. /// $color-variant: The color variant to use for the checkbox: primary, secondary, tertiary, or
  32. /// error (If not specified, default primary color will be used).
  33. @mixin color($theme, $options...) {
  34. @if inspection.get-theme-version($theme) == 1 {
  35. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  36. } @else {
  37. @include sass-utils.current-selector-or-root() {
  38. @include token-utils.create-token-values(
  39. tokens-mdc-checkbox.$prefix,
  40. tokens-mdc-checkbox.get-color-tokens($theme)
  41. );
  42. @include token-utils.create-token-values(
  43. tokens-mat-checkbox.$prefix,
  44. tokens-mat-checkbox.get-color-tokens($theme)
  45. );
  46. }
  47. .mat-mdc-checkbox {
  48. &.mat-primary {
  49. @include token-utils.create-token-values(
  50. tokens-mdc-checkbox.$prefix,
  51. tokens-mdc-checkbox.get-color-tokens($theme, primary)
  52. );
  53. }
  54. &.mat-warn {
  55. @include token-utils.create-token-values(
  56. tokens-mdc-checkbox.$prefix,
  57. tokens-mdc-checkbox.get-color-tokens($theme, warn)
  58. );
  59. }
  60. }
  61. }
  62. }
  63. /// Outputs typography theme styles for the mat-checkbox.
  64. /// @param {Map} $theme The theme to generate typography styles for.
  65. @mixin typography($theme) {
  66. @if inspection.get-theme-version($theme) == 1 {
  67. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  68. } @else {
  69. @include sass-utils.current-selector-or-root() {
  70. @include token-utils.create-token-values(
  71. tokens-mdc-checkbox.$prefix,
  72. tokens-mdc-checkbox.get-typography-tokens($theme)
  73. );
  74. @include token-utils.create-token-values(
  75. tokens-mat-checkbox.$prefix,
  76. tokens-mat-checkbox.get-typography-tokens($theme)
  77. );
  78. }
  79. }
  80. }
  81. /// Outputs density theme styles for the mat-checkbox.
  82. /// @param {Map} $theme The theme to generate density styles for.
  83. @mixin density($theme) {
  84. $density-scale: inspection.get-theme-density($theme);
  85. @if inspection.get-theme-version($theme) == 1 {
  86. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  87. } @else {
  88. @include sass-utils.current-selector-or-root() {
  89. @include token-utils.create-token-values(
  90. tokens-mdc-checkbox.$prefix,
  91. tokens-mdc-checkbox.get-density-tokens($theme)
  92. );
  93. @include token-utils.create-token-values(
  94. tokens-mat-checkbox.$prefix,
  95. tokens-mat-checkbox.get-density-tokens($theme)
  96. );
  97. }
  98. }
  99. }
  100. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  101. @function _define-overrides() {
  102. @return (
  103. (
  104. namespace: tokens-mat-checkbox.$prefix,
  105. tokens: tokens-mat-checkbox.get-token-slots(),
  106. ),
  107. (
  108. namespace: tokens-mdc-checkbox.$prefix,
  109. tokens: tokens-mdc-checkbox.get-token-slots(),
  110. ),
  111. );
  112. }
  113. /// Outputs the CSS variable values for the given tokens.
  114. /// @param {Map} $tokens The token values to emit.
  115. @mixin overrides($tokens: ()) {
  116. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  117. }
  118. /// Outputs all (base, color, typography, and density) theme styles for the mat-checkbox.
  119. /// @param {Map} $theme The theme to generate styles for.
  120. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  121. /// $color-variant: The color variant to use for the checkbox: primary, secondary, tertiary, or
  122. /// error (If not specified, default primary color will be used).
  123. @mixin theme($theme, $options...) {
  124. @include theming.private-check-duplicate-theme-styles($theme, 'mat-checkbox') {
  125. @if inspection.get-theme-version($theme) == 1 {
  126. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  127. } @else {
  128. @include base($theme);
  129. @if inspection.theme-has($theme, color) {
  130. @include color($theme);
  131. }
  132. @if inspection.theme-has($theme, density) {
  133. @include density($theme);
  134. }
  135. @if inspection.theme-has($theme, typography) {
  136. @include typography($theme);
  137. }
  138. }
  139. }
  140. }
  141. @mixin _theme-from-tokens($tokens, $options...) {
  142. @include validation.selector-defined(
  143. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  144. );
  145. $mdc-checkbox-tokens: token-utils.get-tokens-for(
  146. $tokens,
  147. tokens-mdc-checkbox.$prefix,
  148. $options...
  149. );
  150. // Don't pass $options here, since the mdc-checkbox doesn't support color options,
  151. // only the mdc-checkbox does.
  152. $mat-checkbox-tokens: token-utils.get-tokens-for($tokens, tokens-mat-checkbox.$prefix);
  153. @include token-utils.create-token-values(tokens-mdc-checkbox.$prefix, $mdc-checkbox-tokens);
  154. @include token-utils.create-token-values(tokens-mat-checkbox.$prefix, $mat-checkbox-tokens);
  155. }