/
checkbox.scss
519 lines (431 loc) · 13.1 KB
/
checkbox.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
@use 'sass:math';
@use '../core/style/elevation';
@use '../core/style/checkbox-common';
@use '../core/style/layout-common';
@use '../core/style/vendor-prefixes';
@use '../core/style/private';
@use '../../cdk/a11y';
@use '../core/style/variables';
// Manual calculation done on SVG
$_path-length: 22.910259;
$_indeterminate-checked-easing-function: cubic-bezier(0.14, 0, 0, 1);
// The ripple size of the checkbox
$_ripple-radius: 20px;
// The amount of spacing between the checkbox and its label.
$_item-spacing: variables.$toggle-padding;
// The width of the line used to draw the checkmark / mixedmark.
$_mark-stroke-size: private.private-div(2, 15) * checkbox-common.$size !default;
// Fades in the background of the checkbox when it goes from unchecked -> {checked,indeterminate}.
@keyframes mat-checkbox-fade-in-background {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
}
// Fades out the background of the checkbox when it goes from {checked,indeterminate} -> unchecked.
@keyframes mat-checkbox-fade-out-background {
0%, 50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
// "Draws" in the checkmark when the checkbox goes from unchecked -> checked.
@keyframes mat-checkbox-unchecked-checked-checkmark-path {
0%, 50% {
stroke-dashoffset: $_path-length;
}
50% {
animation-timing-function: variables.$linear-out-slow-in-timing-function;
}
100% {
stroke-dashoffset: 0;
}
}
// Horizontally expands the mixedmark when the checkbox goes from unchecked -> indeterminate.
@keyframes mat-checkbox-unchecked-indeterminate-mixedmark {
0%, 68.2% {
transform: scaleX(0);
}
68.2% {
animation-timing-function: cubic-bezier(0, 0, 0, 1);
}
100% {
transform: scaleX(1);
}
}
// "Erases" the checkmark when the checkbox goes from checked -> unchecked.
@keyframes mat-checkbox-checked-unchecked-checkmark-path {
from {
animation-timing-function: variables.$fast-out-linear-in-timing-function;
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: $_path-length * -1;
}
}
// Rotates and fades out the checkmark when the checkbox goes from checked -> indeterminate. This
// animation helps provide the illusion of the checkmark "morphing" into the mixedmark.
@keyframes mat-checkbox-checked-indeterminate-checkmark {
from {
animation-timing-function: variables.$linear-out-slow-in-timing-function;
opacity: 1;
transform: rotate(0deg);
}
to {
opacity: 0;
transform: rotate(45deg);
}
}
// Rotates and fades the checkmark back into position when the checkbox goes from indeterminate ->
// checked. This animation helps provide the illusion that the mixedmark is "morphing" into the
// checkmark.
@keyframes mat-checkbox-indeterminate-checked-checkmark {
from {
animation-timing-function: $_indeterminate-checked-easing-function;
opacity: 0;
transform: rotate(45deg);
}
to {
opacity: 1;
transform: rotate(360deg);
}
}
// Rotates and fades in the mixedmark when the checkbox goes from checked -> indeterminate. This
// animation, similar to mat-checkbox-checked-indeterminate-checkmark, helps provide an illusion
// of "morphing" from checkmark -> mixedmark.
@keyframes mat-checkbox-checked-indeterminate-mixedmark {
from {
animation-timing-function: variables.$linear-out-slow-in-timing-function;
opacity: 0;
transform: rotate(-45deg);
}
to {
opacity: 1;
transform: rotate(0deg);
}
}
// Rotates and fades out the mixedmark when the checkbox goes from indeterminate -> checked. This
// animation, similar to mat-checkbox-indeterminate-checked-checkmark, helps provide an illusion
// of "morphing" from mixedmark -> checkmark.
@keyframes mat-checkbox-indeterminate-checked-mixedmark {
from {
animation-timing-function: $_indeterminate-checked-easing-function;
opacity: 1;
transform: rotate(0deg);
}
to {
opacity: 0;
transform: rotate(315deg);
}
}
// Horizontally collapses and fades out the mixedmark when the checkbox goes from indeterminate ->
// unchecked.
@keyframes mat-checkbox-indeterminate-unchecked-mixedmark {
0% {
animation-timing-function: linear;
opacity: 1;
transform: scaleX(1);
}
32.8%, 100% {
opacity: 0;
transform: scaleX(0);
}
}
// Applied to elements that appear to make up the outer box of the checkmark, such as the frame
// that contains the border and the actual background element that contains the marks.
%mat-checkbox-outer-box {
@include layout-common.fill;
border-radius: 2px;
box-sizing: border-box;
pointer-events: none;
}
.mat-checkbox {
@include private.private-animation-noop();
// The host node defaults to `diplay: inline` so
// we have to change it in order for margins to work.
display: inline-block;
// Animation
transition: background variables.$swift-ease-out-duration
variables.$swift-ease-out-timing-function, elevation.private-transition-property-value();
cursor: pointer;
-webkit-tap-highlight-color: transparent;
.mat-ripple-element:not(.mat-checkbox-persistent-ripple) {
opacity: 0.16;
}
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
// potentially overwrite the absolute position of the container.
.mat-checkbox-ripple {
position: absolute;
left: calc(50% - #{$_ripple-radius});
top: calc(50% - #{$_ripple-radius});
height: $_ripple-radius * 2;
width: $_ripple-radius * 2;
z-index: 1;
pointer-events: none;
}
&.cdk-keyboard-focused .mat-checkbox-ripple {
@include a11y.high-contrast(active, off) {
outline: solid 3px;
}
}
}
.mat-checkbox-layout {
// Disable text selection on the label itself, because having text selected
// will prevent focus from reaching the label. Below we'll re-enable it only
// for the label's content so that people can still select the text.
@include vendor-prefixes.user-select(none);
// `cursor: inherit` ensures that the wrapper element gets the same cursor as the mat-checkbox
// (e.g. pointer by default, regular when disabled), instead of the browser default.
cursor: inherit;
align-items: baseline;
vertical-align: middle;
display: inline-flex;
white-space: nowrap;
}
.mat-checkbox-label {
// Re-enable text selection for the checkbox's content since
// we disabled it above in the `.mat-checkbox-layout`.
@include vendor-prefixes.user-select(auto);
}
.mat-checkbox-inner-container {
display: inline-block;
height: checkbox-common.$size;
line-height: 0;
margin: auto;
margin-right: $_item-spacing;
order: 0;
position: relative;
vertical-align: middle;
white-space: nowrap;
width: checkbox-common.$size;
flex-shrink: 0;
[dir='rtl'] & {
margin: {
left: $_item-spacing;
right: auto;
}
}
}
.mat-checkbox-inner-container-no-side-margin {
margin: {
left: 0;
right: 0;
}
}
.mat-checkbox-frame {
@extend %mat-checkbox-outer-box;
background-color: transparent;
transition: border-color checkbox-common.$transition-duration
variables.$linear-out-slow-in-timing-function;
border: {
width: checkbox-common.$border-width;
style: solid;
}
._mat-animation-noopable & {
transition: none;
}
}
.mat-checkbox-background {
@extend %mat-checkbox-outer-box;
align-items: center;
display: inline-flex;
justify-content: center;
transition: background-color checkbox-common.$transition-duration
variables.$linear-out-slow-in-timing-function, opacity checkbox-common.$transition-duration
variables.$linear-out-slow-in-timing-function;
// force browser to show background-color when using the print function
@include vendor-prefixes.private-color-adjust(exact);
._mat-animation-noopable & {
transition: none;
}
// `.mat-checkbox` here is redundant, but we need it to increase the specificity so that
// these styles don't get overwritten by the `background-color` from the theme.
.mat-checkbox & {
@include a11y.high-contrast(active, off) {
// Needs to be removed because it hides the checkbox outline.
background: none;
}
}
}
.mat-checkbox-persistent-ripple {
display: block;
width: 100%;
height: 100%;
transform: none;
.mat-checkbox-inner-container:hover & {
opacity: 0.04;
}
.mat-checkbox.cdk-keyboard-focused & {
opacity: 0.12;
}
// We do this here, rather than having a `:not(.mat-checkbox-disabled)`
// above in the `:hover`, because the `:not` will bump the specificity
// a lot and will cause it to overide the focus styles.
&, .mat-checkbox.mat-checkbox-disabled .mat-checkbox-inner-container:hover & {
opacity: 0;
}
// Hover styles will be displayed after tapping on touch devices.
// Disable the hover styling if the user's device doesn't support hovering.
@media (hover: none) {
// Note that we only negate the `:hover` rather than setting it to always be `display: none`,
// in order to maintain the focus indication for hybrid touch + keyboard devices.
.mat-checkbox-inner-container:hover & {
display: none;
}
}
}
.mat-checkbox-checkmark {
@include layout-common.fill;
width: 100%;
}
.mat-checkbox-checkmark-path {
stroke: {
dashoffset: $_path-length;
dasharray: $_path-length;
width: $_mark-stroke-size;
}
@include a11y.high-contrast(black-on-white, off) {
// In the checkbox theme this `stroke` has !important which ends up overriding the browser's
// automatic color inversion so we need to re-invert it ourselves for black-on-white.
stroke: #000 !important;
}
}
.mat-checkbox-mixedmark {
$height: math.floor($_mark-stroke-size);
width: calc(100% - 6px);
height: $height;
opacity: 0;
transform: scaleX(0) rotate(0deg);
border-radius: 2px;
@include a11y.high-contrast(active, off) {
height: 0;
border-top: solid $height;
margin-top: $height;
}
}
.mat-checkbox-label-before {
.mat-checkbox-inner-container {
order: 1;
margin: {
left: $_item-spacing;
right: auto;
}
[dir='rtl'] & {
margin: {
left: auto;
right: $_item-spacing;
}
}
}
}
.mat-checkbox-checked {
.mat-checkbox-checkmark {
opacity: 1;
}
.mat-checkbox-checkmark-path {
stroke-dashoffset: 0;
}
.mat-checkbox-mixedmark {
transform: scaleX(1) rotate(-45deg);
}
}
.mat-checkbox-indeterminate {
.mat-checkbox-checkmark {
opacity: 0;
transform: rotate(45deg);
}
.mat-checkbox-checkmark-path {
stroke-dashoffset: 0;
}
.mat-checkbox-mixedmark {
opacity: 1;
transform: scaleX(1) rotate(0deg);
}
}
.mat-checkbox-unchecked {
.mat-checkbox-background {
background-color: transparent;
}
}
.mat-checkbox-disabled {
cursor: default;
@include a11y.high-contrast(active, off) {
opacity: 0.5;
}
}
.mat-checkbox-anim {
$indeterminate-change-duration: 500ms;
&-unchecked-checked {
.mat-checkbox-background {
animation: checkbox-common.$transition-duration * 2 linear 0ms
mat-checkbox-fade-in-background;
}
.mat-checkbox-checkmark-path {
// Instead of delaying the animation, we simply multiply its length by 2 and begin the
// animation at 50% in order to prevent a flash of styles applied to a checked checkmark
// as the background is fading in before the animation begins.
animation: checkbox-common.$transition-duration * 2 linear 0ms
mat-checkbox-unchecked-checked-checkmark-path;
}
}
&-unchecked-indeterminate {
.mat-checkbox-background {
animation: checkbox-common.$transition-duration * 2 linear 0ms
mat-checkbox-fade-in-background;
}
.mat-checkbox-mixedmark {
animation: checkbox-common.$transition-duration linear 0ms
mat-checkbox-unchecked-indeterminate-mixedmark;
}
}
&-checked-unchecked {
.mat-checkbox-background {
animation: checkbox-common.$transition-duration * 2 linear 0ms
mat-checkbox-fade-out-background;
}
.mat-checkbox-checkmark-path {
animation: checkbox-common.$transition-duration linear 0ms
mat-checkbox-checked-unchecked-checkmark-path;
}
}
&-checked-indeterminate {
.mat-checkbox-checkmark {
animation: checkbox-common.$transition-duration linear 0ms
mat-checkbox-checked-indeterminate-checkmark;
}
.mat-checkbox-mixedmark {
animation: checkbox-common.$transition-duration linear 0ms
mat-checkbox-checked-indeterminate-mixedmark;
}
}
&-indeterminate-checked {
.mat-checkbox-checkmark {
animation: $indeterminate-change-duration linear 0ms
mat-checkbox-indeterminate-checked-checkmark;
}
.mat-checkbox-mixedmark {
animation: $indeterminate-change-duration linear 0ms
mat-checkbox-indeterminate-checked-mixedmark;
}
}
&-indeterminate-unchecked {
.mat-checkbox-background {
animation: checkbox-common.$transition-duration * 2 linear 0ms
mat-checkbox-fade-out-background;
}
.mat-checkbox-mixedmark {
animation: $indeterminate-change-duration * 0.6 linear 0ms
mat-checkbox-indeterminate-unchecked-mixedmark;
}
}
}
.mat-checkbox-input {
// Move the input to the bottom and in the middle.
// Visual improvement to properly show browser popups when being required.
bottom: 0;
left: 50%;
}