/
calendar-body.scss
229 lines (194 loc) · 7.75 KB
/
calendar-body.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
@use '../core/style/private';
@use '../../cdk/a11y';
$calendar-body-label-padding-start: 5% !default;
// We don't want the label to jump around when we switch between month and year views, so we use
// the same amount of padding regardless of the number of columns. We align the header label with
// the one third mark of the first cell, this was chosen somewhat arbitrarily to make it look
// roughly like the mock. Half way is too far since the cell text is center aligned.
$calendar-body-label-side-padding: private.private-div(33%, 7) !default;
$calendar-body-cell-min-size: 32px !default;
$calendar-body-cell-content-margin: 5% !default;
$calendar-body-cell-content-border-width: 1px !default;
$calendar-body-cell-radius: 999px !default;
$calendar-body-preview-cell-border: dashed 1px;
$calendar-body-min-size: 7 * $calendar-body-cell-min-size !default;
$calendar-body-cell-content-size: 100% - $calendar-body-cell-content-margin * 2 !default;
$calendar-range-end-body-cell-size:
$calendar-body-cell-content-size + $calendar-body-cell-content-margin !default;
.mat-calendar-body {
min-width: $calendar-body-min-size;
}
.mat-calendar-body-label {
height: 0;
line-height: 0;
text-align: left;
padding-left: $calendar-body-label-side-padding;
padding-right: $calendar-body-label-side-padding;
}
.mat-calendar-body-cell {
position: relative;
height: 0;
line-height: 0;
text-align: center;
outline: none;
cursor: pointer;
}
// We use ::before to apply a background to the body cell, because we need to apply a border
// radius to the start/end which means that part of the element will be cut off, making hovering
// through all the cells look glitchy. We can't do it on the cell itself, because it's the one
// that has the event listener and it can't be on the cell content, because it always has a
// border radius. Note that this and the selectors below can be much simpler if we were to use
// two separate elements for the main and comparison ranges, like we're doing for the preview
// range. We don't follow the simpler approach, because the range colors usually have some
// kind of opacity, which means that they'll start mixing when they're layered on top of each
// other, making the calendar look messy.
.mat-calendar-body-cell::before,
.mat-calendar-body-cell::after,
.mat-calendar-body-cell-preview {
content: '';
position: absolute;
top: $calendar-body-cell-content-margin;
left: 0;
z-index: 0;
box-sizing: border-box;
// We want the range background to be slightly shorter than the cell so
// that there's a gap when the range goes across multiple rows.
height: $calendar-body-cell-content-size;
width: 100%;
}
.mat-calendar-body-range-start:not(.mat-calendar-body-in-comparison-range)::before,
.mat-calendar-body-range-start::after,
.mat-calendar-body-comparison-start:not(.mat-calendar-body-comparison-bridge-start)::before,
.mat-calendar-body-comparison-start::after,
.mat-calendar-body-preview-start .mat-calendar-body-cell-preview {
// Since the range background isn't a perfect circle, we need to size
// and offset the start so that it aligns with the main circle.
left: $calendar-body-cell-content-margin;
width: $calendar-range-end-body-cell-size;
border-top-left-radius: $calendar-body-cell-radius;
border-bottom-left-radius: $calendar-body-cell-radius;
[dir='rtl'] & {
left: 0;
border-radius: 0;
border-top-right-radius: $calendar-body-cell-radius;
border-bottom-right-radius: $calendar-body-cell-radius;
}
}
@mixin _range-right-radius {
// Since the range background isn't a perfect circle, we need to
// resize the end so that it aligns with the main circle.
width: $calendar-range-end-body-cell-size;
border-top-right-radius: $calendar-body-cell-radius;
border-bottom-right-radius: $calendar-body-cell-radius;
}
.mat-calendar-body-range-end:not(.mat-calendar-body-in-comparison-range)::before,
.mat-calendar-body-range-end::after,
.mat-calendar-body-comparison-end:not(.mat-calendar-body-comparison-bridge-end)::before,
.mat-calendar-body-comparison-end::after,
.mat-calendar-body-preview-end .mat-calendar-body-cell-preview {
@include _range-right-radius;
[dir='rtl'] & {
left: $calendar-body-cell-content-margin;
border-radius: 0;
border-top-left-radius: $calendar-body-cell-radius;
border-bottom-left-radius: $calendar-body-cell-radius;
}
}
// Styles necessary to make RTL work.
[dir='rtl'] {
.mat-calendar-body-comparison-bridge-start.mat-calendar-body-range-end::after,
.mat-calendar-body-comparison-bridge-end.mat-calendar-body-range-start::after {
@include _range-right-radius;
}
}
// Prevents the extra overlap range indication from showing up when it's not supposed to.
.mat-calendar-body-comparison-start.mat-calendar-body-range-end::after,
.mat-calendar-body-comparison-end.mat-calendar-body-range-start::after {
// Note that the RTL selector here is redundant, but we need to keep it in order to
// raise the specificity since it can be overridden by some of the styles from above.
&, [dir='rtl'] & {
width: $calendar-body-cell-content-size;
}
}
.mat-calendar-body-in-preview .mat-calendar-body-cell-preview {
border-top: $calendar-body-preview-cell-border;
border-bottom: $calendar-body-preview-cell-border;
}
.mat-calendar-body-preview-start .mat-calendar-body-cell-preview {
border-left: $calendar-body-preview-cell-border;
[dir='rtl'] & {
border-left: 0;
border-right: $calendar-body-preview-cell-border;
}
}
.mat-calendar-body-preview-end .mat-calendar-body-cell-preview {
border-right: $calendar-body-preview-cell-border;
[dir='rtl'] & {
border-right: 0;
border-left: $calendar-body-preview-cell-border;
}
}
.mat-calendar-body-disabled {
cursor: default;
// Fade out the disabled cells so that they can be distinguished from the enabled ones. Note that
// ideally we'd use `color: GreyText` here which is what the browser uses for disabled buttons,
// but we can't because Firefox doesn't recognize it.
@include a11y.high-contrast(active, off) {
opacity: 0.5;
}
}
.mat-calendar-body-cell-content {
top: $calendar-body-cell-content-margin;
left: $calendar-body-cell-content-margin;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
width: $calendar-body-cell-content-size;
height: $calendar-body-cell-content-size;
// Prevents text being off-center on Android.
line-height: 1;
border-width: $calendar-body-cell-content-border-width;
border-style: solid;
// Choosing a value clearly larger than the height ensures we get the correct capsule shape.
border-radius: $calendar-body-cell-radius;
// Increase specificity because focus indicator styles are part of the `mat-core` mixin and can
// potentially overwrite the absolute position of the container.
&.mat-focus-indicator {
position: absolute;
}
@include a11y.high-contrast(active, off) {
border: none;
}
}
@include a11y.high-contrast(active, off) {
.mat-datepicker-popup:not(:empty),
.mat-calendar-body-selected {
outline: solid 1px;
}
.mat-calendar-body-today {
outline: dotted 1px;
}
.cdk-keyboard-focused .mat-calendar-body-active,
.cdk-program-focused .mat-calendar-body-active {
& > .mat-calendar-body-cell-content:not(.mat-calendar-body-selected) {
outline: dotted 2px;
}
}
}
[dir='rtl'] {
.mat-calendar-body-label {
text-align: right;
}
}
// Disable the hover styles on non-hover devices. Since this is more of a progressive
// enhancement and not all desktop browsers support this kind of media query, we can't
// use something like `@media (hover)`.
@media (hover: none) {
.mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover {
& > .mat-calendar-body-cell-content:not(.mat-calendar-body-selected) {
background-color: transparent;
}
}
}