Skip to content

Commit edd0cc8

Browse files
Revert "refactor(material/badge): switch to tokens theming API (#27492)"
This reverts commit fd8f7f6.
1 parent 88f6648 commit edd0cc8

File tree

2 files changed

+118
-162
lines changed

2 files changed

+118
-162
lines changed

src/material/badge/_badge-theme.scss

Lines changed: 118 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,96 @@
1+
// This contains all of the styles for the badge
2+
// rather than just the color/theme because of
3+
// no style sheet support for directives.
14
@use 'sass:color';
25
@use 'sass:map';
6+
@use 'sass:meta';
37
@use 'sass:math';
48
@use '@angular/cdk';
59

610
@use '../core/theming/theming';
711
@use '../core/typography/typography';
8-
@use '../core/tokens/m2/mat/badge' as tokens-mat-badge;
9-
@use '../core/tokens/token-utils';
10-
@use '../core/style/sass-utils';
12+
@use '../core/typography/typography-utils';
1113

12-
// TODO(crisbeto): some of these variables aren't used anymore and should be deleted.
1314
$font-size: 12px;
1415
$font-weight: 600;
1516
$default-size: 22px !default;
1617
$small-size: $default-size - 6;
1718
$large-size: $default-size + 6;
1819
$_badge-structure-emitted: false !default;
1920

20-
// Internally there are some builds that throw an error if they can't figure out the values
21-
// of CSS variables during compliation. This flag temporarily enables fallbacks for these builds.
22-
// Eventually we should clean them up.
23-
$_emit-fallback-vars: true;
24-
2521
// Mixin for building offset given different sizes
26-
@mixin _badge-size($size, $font-size-token) {
22+
@mixin _badge-size($size) {
2723
// This mixin isn't used in the context of a theme so we can disable the ampersand check.
2824
// stylelint-disable material/no-ampersand-beyond-selector-start
2925
.mat-badge-content {
3026
width: $size;
3127
height: $size;
3228
line-height: $size;
33-
34-
@if ($font-size-token) {
35-
@include token-utils.use-tokens(tokens-mat-badge.$prefix,
36-
tokens-mat-badge.get-token-slots()) {
37-
@include token-utils.create-token-slot(font-size, $font-size-token, $_emit-fallback-vars);
38-
}
39-
}
4029
}
4130

42-
&.mat-badge-above .mat-badge-content {
43-
top: math.div(-$size, 2);
31+
&.mat-badge-above {
32+
.mat-badge-content {
33+
top: math.div(-$size, 2);
34+
}
4435
}
4536

46-
&.mat-badge-below .mat-badge-content {
47-
bottom: math.div(-$size, 2);
37+
&.mat-badge-below {
38+
.mat-badge-content {
39+
bottom: math.div(-$size, 2);
40+
}
4841
}
4942

50-
&.mat-badge-before .mat-badge-content {
51-
left: -$size;
43+
&.mat-badge-before {
44+
.mat-badge-content {
45+
left: -$size;
46+
}
5247
}
5348

54-
[dir='rtl'] &.mat-badge-before .mat-badge-content {
55-
left: auto;
56-
right: -$size;
49+
[dir='rtl'] &.mat-badge-before {
50+
.mat-badge-content {
51+
left: auto;
52+
right: -$size;
53+
}
5754
}
5855

59-
&.mat-badge-after .mat-badge-content {
60-
right: -$size;
56+
&.mat-badge-after {
57+
.mat-badge-content {
58+
right: -$size;
59+
}
6160
}
6261

63-
[dir='rtl'] &.mat-badge-after .mat-badge-content {
64-
right: auto;
65-
left: -$size;
62+
[dir='rtl'] &.mat-badge-after {
63+
.mat-badge-content {
64+
right: auto;
65+
left: -$size;
66+
}
6667
}
6768

6869
&.mat-badge-overlap {
69-
&.mat-badge-before .mat-badge-content {
70-
left: math.div(-$size, 2);
70+
&.mat-badge-before {
71+
.mat-badge-content {
72+
left: math.div(-$size, 2);
73+
}
7174
}
7275

73-
[dir='rtl'] &.mat-badge-before .mat-badge-content {
74-
left: auto;
75-
right: math.div(-$size, 2);
76+
[dir='rtl'] &.mat-badge-before {
77+
.mat-badge-content {
78+
left: auto;
79+
right: math.div(-$size, 2);
80+
}
7681
}
7782

78-
&.mat-badge-after .mat-badge-content {
79-
right: math.div(-$size, 2);
83+
&.mat-badge-after {
84+
.mat-badge-content {
85+
right: math.div(-$size, 2);
86+
}
8087
}
8188

82-
[dir='rtl'] &.mat-badge-after .mat-badge-content {
83-
right: auto;
84-
left: math.div(-$size, 2);
89+
[dir='rtl'] &.mat-badge-after {
90+
.mat-badge-content {
91+
right: auto;
92+
left: math.div(-$size, 2);
93+
}
8594
}
8695
}
8796
// stylelint-enable
@@ -92,13 +101,19 @@ $_emit-fallback-vars: true;
92101
@mixin _badge-structure {
93102
.mat-badge {
94103
position: relative;
104+
}
95105

96-
// The badge should make sure its host is overflow visible so that the badge content
97-
// can be rendered outside of the element. Some components such as <mat-icon> explicitly
98-
// style `overflow: hidden` so this requires extra specificity so that it does not
99-
// depend on style load order.
100-
&.mat-badge {
101-
overflow: visible;
106+
// The badge should make sure its host is overflow visible so that the badge content
107+
// can be rendered outside of the element. Some components such as <mat-icon> explicitly
108+
// style `overflow: hidden` so this requires extra specificity so that it does not
109+
// depend on style load order.
110+
.mat-badge.mat-badge {
111+
overflow: visible;
112+
}
113+
114+
.mat-badge-hidden {
115+
.mat-badge-content {
116+
display: none;
102117
}
103118
}
104119

@@ -113,30 +128,6 @@ $_emit-fallback-vars: true;
113128
white-space: nowrap;
114129
text-overflow: ellipsis;
115130
pointer-events: none;
116-
117-
@include token-utils.use-tokens(tokens-mat-badge.$prefix, tokens-mat-badge.get-token-slots()) {
118-
@include token-utils.create-token-slot(background-color, background-color);
119-
@include token-utils.create-token-slot(color, text-color);
120-
@include token-utils.create-token-slot(font-family, text-font, $_emit-fallback-vars);
121-
@include token-utils.create-token-slot(font-size, text-size, $_emit-fallback-vars);
122-
@include token-utils.create-token-slot(font-weight, text-weight, $_emit-fallback-vars);
123-
}
124-
125-
@include cdk.high-contrast(active, off) {
126-
outline: solid 1px;
127-
border-radius: 0;
128-
}
129-
}
130-
131-
.mat-badge-disabled .mat-badge-content {
132-
@include token-utils.use-tokens(tokens-mat-badge.$prefix, tokens-mat-badge.get-token-slots()) {
133-
@include token-utils.create-token-slot(background-color, disabled-state-background-color);
134-
@include token-utils.create-token-slot(color, disabled-state-text-color);
135-
}
136-
}
137-
138-
.mat-badge-hidden .mat-badge-content {
139-
display: none;
140131
}
141132

142133
.ng-animate-disabled .mat-badge-content,
@@ -152,46 +143,89 @@ $_emit-fallback-vars: true;
152143
}
153144

154145
.mat-badge-small {
155-
@include _badge-size($small-size, small-size-text-size);
146+
@include _badge-size($small-size);
156147
}
157148

158149
.mat-badge-medium {
159-
@include _badge-size($default-size, null);
150+
@include _badge-size($default-size);
160151
}
161152

162153
.mat-badge-large {
163-
@include _badge-size($large-size, large-size-text-size);
154+
@include _badge-size($large-size);
164155
}
165156
}
166157

167158
@mixin color($config-or-theme) {
168159
$config: theming.get-color-config($config-or-theme);
169160
$accent: map.get($config, accent);
170161
$warn: map.get($config, warn);
162+
$primary: map.get($config, primary);
163+
$background: map.get($config, background);
164+
$foreground: map.get($config, foreground);
171165

172-
@include sass-utils.current-selector-or-root() {
173-
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
174-
tokens-mat-badge.get-color-tokens($config));
166+
.mat-badge-content {
167+
color: theming.get-color-from-palette($primary, default-contrast);
168+
background: theming.get-color-from-palette($primary);
169+
170+
@include cdk.high-contrast(active, off) {
171+
outline: solid 1px;
172+
border-radius: 0;
173+
}
175174
}
176175

177176
.mat-badge-accent {
178-
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
179-
tokens-mat-badge.private-get-color-palette-color-tokens($accent));
177+
.mat-badge-content {
178+
background: theming.get-color-from-palette($accent);
179+
color: theming.get-color-from-palette($accent, default-contrast);
180+
}
180181
}
181182

182183
.mat-badge-warn {
183-
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
184-
tokens-mat-badge.private-get-color-palette-color-tokens($warn));
184+
.mat-badge-content {
185+
color: theming.get-color-from-palette($warn, default-contrast);
186+
background: theming.get-color-from-palette($warn);
187+
}
188+
}
189+
190+
.mat-badge-disabled {
191+
.mat-badge-content {
192+
$app-background: theming.get-color-from-palette($background, 'background');
193+
$badge-color: theming.get-color-from-palette($foreground, disabled-button);
194+
195+
// The disabled color usually has some kind of opacity, but because the badge is overlayed
196+
// on top of something else, it won't look good if it's opaque. If it is a color *type*,
197+
// we convert it into a solid color by taking the opacity from the rgba value and using
198+
// the value to determine the percentage of the background to put into foreground when
199+
// mixing the colors together.
200+
@if (meta.type-of($badge-color) == color and meta.type-of($app-background) == color) {
201+
$badge-opacity: opacity($badge-color);
202+
background: color.mix($app-background, rgba($badge-color, 1), (1 - $badge-opacity) * 100%);
203+
}
204+
@else {
205+
background: $badge-color;
206+
}
207+
208+
color: theming.get-color-from-palette($foreground, disabled-text);
209+
}
185210
}
186211
}
187212

188213
@mixin typography($config-or-theme) {
189214
$config: typography.private-typography-to-2014-config(
190215
theming.get-typography-config($config-or-theme));
216+
.mat-badge-content {
217+
font-weight: $font-weight;
218+
font-size: $font-size;
219+
font-family: typography-utils.font-family($config);
220+
}
221+
222+
.mat-badge-small .mat-badge-content {
223+
// Set the font size to 75% of the original.
224+
font-size: $font-size * 0.75;
225+
}
191226

192-
@include sass-utils.current-selector-or-root() {
193-
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
194-
tokens-mat-badge.get-typography-tokens($config));
227+
.mat-badge-large .mat-badge-content {
228+
font-size: $font-size * 2;
195229
}
196230
}
197231

src/material/core/tokens/m2/mat/_badge.scss

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)