_datepicker-theme.scss 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. @use 'sass:color';
  2. @use 'sass:map';
  3. @use '../core/tokens/m2/mat/datepicker' as tokens-mat-datepicker;
  4. @use '../core/theming/theming';
  5. @use '../core/theming/inspection';
  6. @use '../core/theming/validation';
  7. @use '../core/tokens/token-utils';
  8. @use '../core/style/sass-utils';
  9. @use '../core/typography/typography';
  10. @use '../button/icon-button-theme';
  11. // TODO(crisbeto): these variables aren't used anymore and should be removed.
  12. $selected-today-box-shadow-width: 1px;
  13. $selected-fade-amount: 0.6;
  14. $range-fade-amount: 0.2;
  15. $today-fade-amount: 0.2;
  16. $calendar-body-font-size: 13px !default;
  17. $calendar-weekday-table-font-size: 11px !default;
  18. @mixin _calendar-color($theme, $palette-name) {
  19. $palette-color: inspection.get-theme-color($theme, $palette-name);
  20. $range-color: tokens-mat-datepicker.private-get-range-background-color($palette-color);
  21. $range-tokens: tokens-mat-datepicker.get-range-color-tokens($range-color);
  22. $calendar-tokens: tokens-mat-datepicker.private-get-calendar-color-palette-color-tokens(
  23. $theme,
  24. $palette-name
  25. );
  26. @include token-utils.create-token-values(
  27. tokens-mat-datepicker.$prefix,
  28. map.merge($calendar-tokens, $range-tokens)
  29. );
  30. }
  31. /// Outputs base theme styles (styles not dependent on the color, typography, or density settings)
  32. /// for the mat-datepicker.
  33. /// @param {Map} $theme The theme to generate base styles for.
  34. @mixin base($theme) {
  35. @if inspection.get-theme-version($theme) == 1 {
  36. @include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
  37. } @else {
  38. @include sass-utils.current-selector-or-root() {
  39. @include token-utils.create-token-values(
  40. tokens-mat-datepicker.$prefix,
  41. tokens-mat-datepicker.get-unthemable-tokens()
  42. );
  43. }
  44. }
  45. }
  46. /// Outputs color theme styles for the mat-datepicker.
  47. /// @param {Map} $theme The theme to generate color styles for.
  48. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  49. /// $color-variant: The color variant to use for the main selection: primary, secondary, tertiary,
  50. /// or error (If not specified, default primary color will be used).
  51. @mixin color($theme, $options...) {
  52. @if inspection.get-theme-version($theme) == 1 {
  53. @include _theme-from-tokens(inspection.get-theme-tokens($theme, color), $options...);
  54. } @else {
  55. @include sass-utils.current-selector-or-root() {
  56. @include token-utils.create-token-values(
  57. tokens-mat-datepicker.$prefix,
  58. tokens-mat-datepicker.get-color-tokens($theme)
  59. );
  60. }
  61. .mat-datepicker-content {
  62. &.mat-accent {
  63. @include _calendar-color($theme, accent);
  64. }
  65. &.mat-warn {
  66. @include _calendar-color($theme, warn);
  67. }
  68. }
  69. .mat-datepicker-toggle-active {
  70. &.mat-accent {
  71. $accent-tokens: tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens(
  72. $theme,
  73. accent
  74. );
  75. @include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $accent-tokens);
  76. }
  77. &.mat-warn {
  78. $warn-tokens: tokens-mat-datepicker.private-get-toggle-color-palette-color-tokens(
  79. $theme,
  80. warn
  81. );
  82. @include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $warn-tokens);
  83. }
  84. }
  85. }
  86. }
  87. /// Outputs typography theme styles for the mat-datepicker.
  88. /// @param {Map} $theme The theme to generate typography styles for.
  89. @mixin typography($theme) {
  90. @if inspection.get-theme-version($theme) == 1 {
  91. @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
  92. } @else {
  93. @include sass-utils.current-selector-or-root() {
  94. @include token-utils.create-token-values(
  95. tokens-mat-datepicker.$prefix,
  96. tokens-mat-datepicker.get-typography-tokens($theme)
  97. );
  98. }
  99. }
  100. }
  101. @mixin date-range-colors(
  102. $range-color,
  103. $comparison-color: tokens-mat-datepicker.$private-default-comparison-color,
  104. $overlap-color: tokens-mat-datepicker.$private-default-overlap-color,
  105. $overlap-selected-color:
  106. tokens-mat-datepicker.private-get-default-overlap-selected-color($overlap-color)
  107. ) {
  108. $tokens: tokens-mat-datepicker.get-range-color-tokens(
  109. $range-color: $range-color,
  110. $comparison-color: $comparison-color,
  111. $overlap-color: $overlap-color,
  112. $overlap-selected-color: $overlap-selected-color,
  113. );
  114. @include sass-utils.current-selector-or-root() {
  115. @include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $tokens);
  116. }
  117. }
  118. /// Outputs density theme styles for the mat-datepicker.
  119. /// @param {Map} $theme The theme to generate density styles for.
  120. @mixin density($theme) {
  121. @if inspection.get-theme-version($theme) == 1 {
  122. @include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
  123. } @else {
  124. // TODO(crisbeto): move this into the structural styles
  125. // once the icon button density is switched to tokens.
  126. // Regardless of the user-passed density, we want the calendar
  127. // previous/next buttons to remain at density -2
  128. .mat-calendar-controls {
  129. @include icon-button-theme.density(-2);
  130. }
  131. }
  132. }
  133. /// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
  134. @function _define-overrides() {
  135. @return (
  136. (
  137. namespace: tokens-mat-datepicker.$prefix,
  138. tokens: tokens-mat-datepicker.get-token-slots(),
  139. ),
  140. );
  141. }
  142. /// Outputs the CSS variable values for the given tokens.
  143. /// @param {Map} $tokens The token values to emit.
  144. @mixin overrides($tokens: ()) {
  145. @include token-utils.batch-create-token-values($tokens, _define-overrides()...);
  146. }
  147. /// Outputs all (base, color, typography, and density) theme styles for the mat-datepicker.
  148. /// @param {Map} $theme The theme to generate styles for.
  149. /// @param {ArgList} Additional optional arguments (only supported for M3 themes):
  150. /// $color-variant: The color variant to use for the main selection: primary, secondary, tertiary,
  151. /// or error (If not specified, default primary color will be used).
  152. @mixin theme($theme, $options...) {
  153. @include theming.private-check-duplicate-theme-styles($theme, 'mat-datepicker') {
  154. @if inspection.get-theme-version($theme) == 1 {
  155. @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...);
  156. } @else {
  157. @include base($theme);
  158. @if inspection.theme-has($theme, color) {
  159. @include color($theme);
  160. }
  161. @if inspection.theme-has($theme, density) {
  162. @include density($theme);
  163. }
  164. @if inspection.theme-has($theme, typography) {
  165. @include typography($theme);
  166. }
  167. }
  168. }
  169. }
  170. @mixin _theme-from-tokens($tokens, $options...) {
  171. @include validation.selector-defined(
  172. 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector'
  173. );
  174. $mat-datepicker-tokens: token-utils.get-tokens-for(
  175. $tokens,
  176. tokens-mat-datepicker.$prefix,
  177. $options...
  178. );
  179. @include token-utils.create-token-values(tokens-mat-datepicker.$prefix, $mat-datepicker-tokens);
  180. }