UNPKG

8.45 kBSCSSView Raw
1@use 'sass:color';
2@use 'sass:map';
3@use 'sass:math';
4@use 'sass:meta';
5@use '../core/style/private';
6@use '../core/theming/theming';
7@use '../core/typography/typography';
8@use '../core/typography/typography-utils';
9
10
11$selected-today-box-shadow-width: 1px;
12$selected-fade-amount: 0.6;
13$range-fade-amount: 0.2;
14$today-fade-amount: 0.2;
15$calendar-body-font-size: 13px !default;
16$calendar-weekday-table-font-size: 11px !default;
17
18@mixin _color($palette) {
19 @include date-range-colors(
20 theming.get-color-from-palette($palette, default, $range-fade-amount));
21
22 .mat-calendar-body-selected {
23 background-color: theming.get-color-from-palette($palette);
24 color: theming.get-color-from-palette($palette, default-contrast);
25 }
26
27 .mat-calendar-body-disabled > .mat-calendar-body-selected {
28 $background: theming.get-color-from-palette($palette);
29
30 @if (meta.type-of($background) == color) {
31 background-color: color.adjust($background, $alpha: -$selected-fade-amount);
32 }
33 @else {
34 // If we couldn't resolve to background to a color (e.g. it's a CSS variable),
35 // fall back to fading the content out via `opacity`.
36 opacity: $today-fade-amount;
37 }
38 }
39
40 .mat-calendar-body-today.mat-calendar-body-selected {
41 box-shadow: inset 0 0 0 $selected-today-box-shadow-width
42 theming.get-color-from-palette($palette, default-contrast);
43 }
44
45 .cdk-keyboard-focused .mat-calendar-body-active,
46 .cdk-program-focused .mat-calendar-body-active {
47 @include _highlighted-cell($palette);
48 }
49
50 @media (hover: hover) {
51 .mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover {
52 @include _highlighted-cell($palette);
53 }
54 }
55}
56
57// Utility mixin to target cells that aren't selected. Used to make selector easier to follow.
58@mixin _unselected-cell {
59 &:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical) {
60 @content;
61 }
62}
63
64// Styles for a highlighted calendar cell (e.g. hovered or focused).
65@mixin _highlighted-cell($palette) {
66 & > .mat-calendar-body-cell-content {
67 @include _unselected-cell {
68 background-color: theming.get-color-from-palette($palette, 0.3);
69 }
70 }
71}
72
73@mixin color($config-or-theme) {
74 $config: theming.get-color-config($config-or-theme);
75 $foreground: map.get($config, foreground);
76 $background: map.get($config, background);
77 $disabled-color: theming.get-color-from-palette($foreground, disabled-text);
78
79 .mat-calendar-arrow {
80 fill: theming.get-color-from-palette($foreground, icon);
81 }
82
83 // The prev/next buttons need a bit more specificity to
84 // avoid being overwritten by the .mat-icon-button.
85 .mat-datepicker-toggle,
86 .mat-datepicker-content .mat-calendar-next-button,
87 .mat-datepicker-content .mat-calendar-previous-button {
88 color: theming.get-color-from-palette($foreground, icon);
89 }
90
91 .mat-calendar-table-header-divider::after {
92 background: theming.get-color-from-palette($foreground, divider);
93 }
94
95 .mat-calendar-table-header,
96 .mat-calendar-body-label {
97 color: theming.get-color-from-palette($foreground, secondary-text);
98 }
99
100 .mat-calendar-body-cell-content,
101 .mat-date-range-input-separator {
102 color: theming.get-color-from-palette($foreground, text);
103 border-color: transparent;
104 }
105
106 .mat-calendar-body-disabled > .mat-calendar-body-cell-content {
107 @include _unselected-cell {
108 color: $disabled-color;
109 }
110 }
111
112 .mat-form-field-disabled .mat-date-range-input-separator {
113 color: $disabled-color;
114 }
115
116 .mat-calendar-body-in-preview {
117 $divider-color: theming.get-color-from-palette($foreground, divider);
118
119 @if meta.type-of($divider-color) == color {
120 // The divider color is set under the assumption that it'll be used
121 // for a solid border, but because we're using a dashed border for the
122 // preview range, we need to bump its opacity to ensure that it's visible.
123 color: rgba($divider-color, math.min(opacity($divider-color) * 2, 1));
124 }
125 @else {
126 color: $divider-color;
127 }
128 }
129
130 .mat-calendar-body-today {
131 @include _unselected-cell {
132 // Note: though it's not text, the border is a hint about the fact that this is today's date,
133 // so we use the hint color.
134 border-color: theming.get-color-from-palette($foreground, hint-text);
135 }
136 }
137
138 .mat-calendar-body-disabled > .mat-calendar-body-today {
139 @include _unselected-cell {
140 $color: theming.get-color-from-palette($foreground, hint-text);
141
142 @if (meta.type-of($color) == color) {
143 border-color: color.adjust($color, $alpha: -$today-fade-amount);
144 }
145 @else {
146 // If the color didn't resolve to a color value, but something like a CSS variable, we can't
147 // fade it out so we fall back to reducing the element opacity. Note that we don't use the
148 // $mat-datepicker-today-fade-amount, because hint text usually has some opacity applied
149 // to it already and we don't want them to stack on top of each other.
150 opacity: 0.5;
151 }
152 }
153 }
154
155 @include _color(map.get($config, primary));
156
157 .mat-datepicker-content {
158 @include private.private-theme-elevation(4, $config);
159 background-color: theming.get-color-from-palette($background, card);
160 color: theming.get-color-from-palette($foreground, text);
161
162 &.mat-accent {
163 @include _color(map.get($config, accent));
164 }
165
166 &.mat-warn {
167 @include _color(map.get($config, warn));
168 }
169 }
170
171 .mat-datepicker-content-touch {
172 @include private.private-theme-elevation(24, $config);
173 }
174
175 .mat-datepicker-toggle-active {
176 color: theming.get-color-from-palette(map.get($config, primary), text);
177
178 &.mat-accent {
179 color: theming.get-color-from-palette(map.get($config, accent), text);
180 }
181
182 &.mat-warn {
183 color: theming.get-color-from-palette(map.get($config, warn), text);
184 }
185 }
186
187 .mat-date-range-input-inner[disabled] {
188 color: theming.get-color-from-palette($foreground, disabled-text);
189 }
190}
191
192@mixin typography($config-or-theme) {
193 $config: typography.private-typography-to-2014-config(
194 theming.get-typography-config($config-or-theme));
195 .mat-calendar {
196 font-family: typography-utils.font-family($config);
197 }
198
199 .mat-calendar-body {
200 font-size: $calendar-body-font-size;
201 }
202
203 .mat-calendar-body-label,
204 .mat-calendar-period-button {
205 font: {
206 size: typography-utils.font-size($config, button);
207 weight: typography-utils.font-weight($config, button);
208 }
209 }
210
211 .mat-calendar-table-header th {
212 font: {
213 size: $calendar-weekday-table-font-size;
214 weight: typography-utils.font-weight($config, body-1);
215 }
216 }
217}
218
219@mixin date-range-colors(
220 $range-color,
221 $comparison-color: rgba(#f9ab00, $range-fade-amount),
222 $overlap-color: #a8dab5,
223 $overlap-selected-color: color.adjust($overlap-color, $lightness: -30%)) {
224
225 .mat-calendar-body-in-range::before {
226 background: $range-color;
227 }
228
229 .mat-calendar-body-comparison-identical,
230 .mat-calendar-body-in-comparison-range::before {
231 background: $comparison-color;
232 }
233
234 .mat-calendar-body-comparison-bridge-start::before,
235 [dir='rtl'] .mat-calendar-body-comparison-bridge-end::before {
236 background: linear-gradient(to right, $range-color 50%, $comparison-color 50%);
237 }
238
239 .mat-calendar-body-comparison-bridge-end::before,
240 [dir='rtl'] .mat-calendar-body-comparison-bridge-start::before {
241 background: linear-gradient(to left, $range-color 50%, $comparison-color 50%);
242 }
243
244 .mat-calendar-body-in-range > .mat-calendar-body-comparison-identical,
245 .mat-calendar-body-in-comparison-range.mat-calendar-body-in-range::after {
246 background: $overlap-color;
247 }
248
249 .mat-calendar-body-comparison-identical.mat-calendar-body-selected,
250 .mat-calendar-body-in-comparison-range > .mat-calendar-body-selected {
251 background: $overlap-selected-color;
252 }
253}
254
255@mixin _density($config-or-theme) {}
256
257@mixin theme($theme-or-color-config) {
258 $theme: theming.private-legacy-get-theme($theme-or-color-config);
259 @include theming.private-check-duplicate-theme-styles($theme, 'mat-datepicker') {
260 $color: theming.get-color-config($theme);
261 $density: theming.get-density-config($theme);
262 $typography: theming.get-typography-config($theme);
263
264 @if $color != null {
265 @include color($color);
266 }
267 @if $density != null {
268 @include _density($density);
269 }
270 @if $typography != null {
271 @include typography($typography);
272 }
273 }
274}