/
_checkbox-theme.scss
153 lines (135 loc) · 5.21 KB
/
_checkbox-theme.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
@use '@material/checkbox/checkbox' as mdc-checkbox;
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
@use '@material/ripple/ripple-theme' as mdc-ripple-theme;
@use '@material/form-field' as mdc-form-field;
@use '@material/theme/theme-color' as mdc-theme-color;
@use '@material/theme/theme';
@use 'sass:map';
@use '../mdc-helpers/mdc-helpers';
@use '../../material/core/typography/typography';
@use '../../material/core/theming/theming';
@use '../../material/core/ripple/ripple-theme';
// Mixin that includes the checkbox theme styles with a given palette.
// By default, the MDC checkbox always uses the `secondary` palette.
@mixin private-checkbox-styles-with-color($color) {
@include mdc-checkbox-theme.theme(
(
density-scale: null,
checkmark-color: mdc-theme-color.prop-value(on-#{$color}),
container-checked-color: $color,
container-checked-hover-color: null,
container-disabled-color: rgba(mdc-theme-color.prop-value(on-surface), 0.38),
outline-color: rgba(mdc-theme-color.prop-value(on-surface), 0.54),
outline-hover-color: null,
ripple-color: mdc-theme-color.prop-value(on-surface),
ripple-opacity: mdc-ripple-theme.$dark-ink-opacities,
ripple-checked-color: $color,
ripple-checked-opacity: mdc-ripple-theme.$dark-ink-opacities,
)
);
}
// Apply ripple colors to the MatRipple element and the MDC ripple element when the
// checkbox is selected.
@mixin _selected-ripple-colors($theme, $mdcColor) {
.mdc-checkbox--selected ~ {
.mat-mdc-checkbox-ripple {
@include ripple-theme.theme((
foreground: (
base: mdc-theme-color.prop-value($mdcColor)
),
));
}
.mdc-checkbox__ripple {
background: $theme;
}
}
}
@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);
$primary: theming.get-color-from-palette(map.get($config, primary));
$accent: theming.get-color-from-palette(map.get($config, accent));
$warn: theming.get-color-from-palette(map.get($config, warn));
// Save original values of MDC global variables. We need to save these so we can restore the
// variables to their original values and prevent unintended side effects from using this mixin.
$orig-border-color: mdc-checkbox-theme.$border-color;
$orig-disabled-color: mdc-checkbox-theme.$disabled-color;
@include mdc-helpers.mat-using-mdc-theme($config) {
mdc-checkbox-theme.$border-color: rgba(
mdc-theme-color.prop-value(on-surface),
0.54
);
mdc-checkbox-theme.$disabled-color: rgba(
mdc-theme-color.prop-value(on-surface),
0.26
);
.mat-mdc-checkbox {
@include private-checkbox-styles-with-color(primary);
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-theme-styles-query);
@include ripple-theme.theme((
foreground: (
base: mdc-theme-color.prop-value(on-surface)
),
));
.mdc-checkbox__ripple {
background: mdc-theme-color.prop-value(on-surface);
}
// MDC's checkbox doesn't support a `color` property. We add support for it by adding a CSS
// class for accent and warn style, and applying the appropriate overrides below. Since we
// don't use MDC's ripple, we also need to set the color for our replacement ripple.
&.mat-primary {
@include private-checkbox-styles-with-color(primary);
@include _selected-ripple-colors($primary, primary);
}
&.mat-accent {
@include private-checkbox-styles-with-color(secondary);
@include _selected-ripple-colors($accent, secondary);
}
&.mat-warn {
@include private-checkbox-styles-with-color(error);
@include _selected-ripple-colors($warn, error);
}
}
}
// Restore original values of MDC global variables.
mdc-checkbox-theme.$border-color: $orig-border-color;
mdc-checkbox-theme.$disabled-color: $orig-disabled-color;
}
@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
@include mdc-helpers.mat-using-mdc-typography($config) {
@include mdc-checkbox.without-ripple($query: mdc-helpers.$mat-typography-styles-query);
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-typography-styles-query);
}
}
@mixin density($config-or-theme) {
$density-scale: theming.get-density-config($config-or-theme);
.mat-mdc-checkbox .mdc-checkbox {
@include mdc-checkbox-theme.density(
$density-scale,
$query: mdc-helpers.$mat-base-styles-query
);
}
@if ($density-scale == -2 or $density-scale == 'minimum') {
.mat-mdc-checkbox-touch-target {
display: none;
}
}
}
@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);
@include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-checkbox') {
$color: theming.get-color-config($theme);
$density: theming.get-density-config($theme);
$typography: theming.get-typography-config($theme);
@if $color != null {
@include color($color);
}
@if $density != null {
@include density($density);
}
@if $typography != null {
@include typography($typography);
}
}
}