/
_badge-theme.scss
232 lines (200 loc) · 5.66 KB
/
_badge-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
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
// This contains all of the styles for the badge
// rather than just the color/theme because of
// no style sheet support for directives.
@use 'sass:color';
@use 'sass:map';
@use 'sass:meta';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/typography/typography-utils';
@use '../core/style/private';
@use '../../cdk/a11y';
$font-size: 12px;
$font-weight: 600;
$default-size: 22px !default;
$small-size: $default-size - 6;
$large-size: $default-size + 6;
// Mixin for building offset given different sizes
@mixin _badge-size($size) {
.mat-badge-content {
width: $size;
height: $size;
line-height: $size;
}
&.mat-badge-above {
.mat-badge-content {
top: private.private-div(-$size, 2);
}
}
&.mat-badge-below {
.mat-badge-content {
bottom: private.private-div(-$size, 2);
}
}
&.mat-badge-before {
.mat-badge-content {
left: -$size;
}
}
[dir='rtl'] &.mat-badge-before {
.mat-badge-content {
left: auto;
right: -$size;
}
}
&.mat-badge-after {
.mat-badge-content {
right: -$size;
}
}
[dir='rtl'] &.mat-badge-after {
.mat-badge-content {
right: auto;
left: -$size;
}
}
&.mat-badge-overlap {
&.mat-badge-before {
.mat-badge-content {
left: private.private-div(-$size, 2);
}
}
[dir='rtl'] &.mat-badge-before {
.mat-badge-content {
left: auto;
right: private.private-div(-$size, 2);
}
}
&.mat-badge-after {
.mat-badge-content {
right: private.private-div(-$size, 2);
}
}
[dir='rtl'] &.mat-badge-after {
.mat-badge-content {
right: auto;
left: private.private-div(-$size, 2);
}
}
}
}
@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);
$accent: map.get($config, accent);
$warn: map.get($config, warn);
$primary: map.get($config, primary);
$background: map.get($config, background);
$foreground: map.get($config, foreground);
.mat-badge-content {
color: theming.get-color-from-palette($primary, default-contrast);
background: theming.get-color-from-palette($primary);
@include a11y.high-contrast(active, off) {
outline: solid 1px;
border-radius: 0;
}
}
.mat-badge-accent {
.mat-badge-content {
background: theming.get-color-from-palette($accent);
color: theming.get-color-from-palette($accent, default-contrast);
}
}
.mat-badge-warn {
.mat-badge-content {
color: theming.get-color-from-palette($warn, default-contrast);
background: theming.get-color-from-palette($warn);
}
}
.mat-badge {
position: relative;
}
.mat-badge-hidden {
.mat-badge-content {
display: none;
}
}
.mat-badge-disabled {
.mat-badge-content {
$app-background: theming.get-color-from-palette($background, 'background');
$badge-color: theming.get-color-from-palette($foreground, disabled-button);
// The disabled color usually has some kind of opacity, but because the badge is overlayed
// on top of something else, it won't look good if it's opaque. If it is a color *type*,
// we convert it into a solid color by taking the opacity from the rgba value and using
// the value to determine the percentage of the background to put into foreground when
// mixing the colors together.
@if (meta.type-of($badge-color) == color and meta.type-of($app-background) == color) {
$badge-opacity: opacity($badge-color);
background: color.mix($app-background, rgba($badge-color, 1), (1 - $badge-opacity) * 100%);
}
@else {
background: $badge-color;
}
color: theming.get-color-from-palette($foreground, disabled-text);
}
}
.mat-badge-content {
position: absolute;
text-align: center;
display: inline-block;
border-radius: 50%;
transition: transform 200ms ease-in-out;
transform: scale(0.6);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
pointer-events: none;
}
.ng-animate-disabled .mat-badge-content,
.mat-badge-content._mat-animation-noopable {
transition: none;
}
// The active class is added after the element is added
// so it can animate scale to default
.mat-badge-content.mat-badge-active {
// Scale to `none` instead of `1` to avoid blurry text in some browsers.
transform: none;
}
.mat-badge-small {
@include _badge-size($small-size);
}
.mat-badge-medium {
@include _badge-size($default-size);
}
.mat-badge-large {
@include _badge-size($large-size);
}
}
@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2014-config(
theming.get-typography-config($config-or-theme));
.mat-badge-content {
font-weight: $font-weight;
font-size: $font-size;
font-family: typography-utils.font-family($config);
}
.mat-badge-small .mat-badge-content {
// Set the font size to 75% of the original.
font-size: $font-size * 0.75;
}
.mat-badge-large .mat-badge-content {
font-size: $font-size * 2;
}
}
@mixin _density($config-or-theme) {}
@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-badge') {
$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);
}
}
}