1
1
@use ' sass:color' ;
2
- @use ' sass:math' ;
3
2
@use ' @angular/cdk' ;
4
3
@use ' ../core/tokens/m2/mat/badge' as tokens-mat-badge ;
5
4
@use ' ../core/tokens/token-utils' ;
@@ -8,65 +7,33 @@ $default-size: 22px !default;
8
7
$small-size : $default-size - 6 ;
9
8
$large-size : $default-size + 6 ;
10
9
11
-
12
- // Mixin for building offset given different sizes
13
- @mixin _badge-size ($size , $font-size-token ) {
14
- .mat-badge-content {
15
- width : $size ;
16
- height : $size ;
17
- line-height : $size ;
18
-
19
- @if ($font-size-token ) {
20
- @include token-utils .use-tokens (tokens-mat-badge .$prefix ,
21
- tokens-mat-badge .get-token-slots ()) {
22
- @include token-utils .create-token-slot (font-size , $font-size-token );
23
- }
24
- }
25
- }
26
-
27
- & .mat-badge-above .mat-badge-content {
28
- top : math .div (- $size , 2 );
29
- }
30
-
31
- & .mat-badge-below .mat-badge-content {
32
- bottom : math .div (- $size , 2 );
33
- }
34
-
35
- & .mat-badge-before .mat-badge-content {
36
- left : - $size ;
37
- }
38
-
39
- [dir = ' rtl' ] & .mat-badge-before .mat-badge-content {
40
- left : auto ;
41
- right : - $size ;
42
- }
43
-
44
- & .mat-badge-after .mat-badge-content {
45
- right : - $size ;
46
- }
47
-
48
- [dir = ' rtl' ] & .mat-badge-after .mat-badge-content {
49
- right : auto ;
50
- left : - $size ;
51
- }
52
-
53
- & .mat-badge-overlap {
54
- & .mat-badge-before .mat-badge-content {
55
- left : math .div (- $size , 2 );
56
- }
57
-
58
- [dir = ' rtl' ] & .mat-badge-before .mat-badge-content {
59
- left : auto ;
60
- right : math .div (- $size , 2 );
61
- }
62
-
63
- & .mat-badge-after .mat-badge-content {
64
- right : math .div (- $size , 2 );
10
+ @mixin _badge-size ($size ) {
11
+ @include token-utils .use-tokens (tokens-mat-badge .$prefix , tokens-mat-badge .get-token-slots ()) {
12
+ $prefix : if ($size == ' medium' , ' ' , $size + ' -size-' );
13
+ $legacy-size-var : token-utils .get-token-variable (' legacy-#{$prefix } container-size' );
14
+ $size-var : token-utils .get-token-variable (' #{$prefix } container-size' );
15
+
16
+ .mat-badge-content {
17
+ // The M2 badge is implemented incorrectly because it uses `width` and `height` for its
18
+ // size which causes the text to be truncated. For M3 we want to fix this by emitting
19
+ // two declarations:
20
+ // * `legacy-container-size` token - targets width/height as in M2. In M3 the token is
21
+ // emitted as `unset`.
22
+ // * `container-size` token - In M2 the token is emitted as `unset` to preserve the legacy
23
+ // behavior while in M3 it targets `min-width` and `min-height` which allows the badge to
24
+ // grow with the content.
25
+ width : var (#{$legacy-size-var } , unset );
26
+ height : var (#{$legacy-size-var } , unset );
27
+ min-width : var (#{$size-var } , unset );
28
+ min-height : var (#{$size-var } , unset );
29
+ line-height : var ($legacy-size-var , var (#{$size-var } ));
30
+ @include token-utils .create-token-slot (padding , ' #{$prefix } container-padding' );
31
+ @include token-utils .create-token-slot (font-size , ' #{$prefix } text-size' );
32
+ @include token-utils .create-token-slot (margin , ' #{$prefix } container-offset' );
65
33
}
66
34
67
- [dir = ' rtl' ] & .mat-badge-after .mat-badge-content {
68
- right : auto ;
69
- left : math .div (- $size , 2 );
35
+ & .mat-badge-overlap .mat-badge-content {
36
+ @include token-utils .create-token-slot (margin , ' #{$prefix } container-overlap-offset' );
70
37
}
71
38
}
72
39
}
@@ -87,25 +54,51 @@ $large-size: $default-size + 6;
87
54
position : absolute ;
88
55
text-align : center ;
89
56
display : inline-block ;
90
- border-radius : 50% ;
91
57
transition : transform 200ms ease-in-out ;
92
58
transform : scale (0.6 );
93
59
overflow : hidden ;
94
60
white-space : nowrap ;
95
61
text-overflow : ellipsis ;
62
+ box-sizing : border-box ;
96
63
pointer-events : none ;
97
64
65
+ @include cdk .high-contrast (active , off) {
66
+ outline : solid 1px ;
67
+ border-radius : 0 ;
68
+ }
69
+
98
70
@include token-utils .use-tokens (tokens-mat-badge .$prefix , tokens-mat-badge .get-token-slots ()) {
99
71
@include token-utils .create-token-slot (background-color , background-color );
100
72
@include token-utils .create-token-slot (color , text- color);
101
73
@include token-utils .create-token-slot (font-family , text- font);
102
- @include token-utils .create-token-slot (font-size , text- size);
103
74
@include token-utils .create-token-slot (font-weight , text- weight);
104
- }
75
+ @include token-utils . create-token-slot ( border-radius , container - shape);
105
76
106
- @include cdk .high-contrast (active , off) {
107
- outline : solid 1px ;
108
- border-radius : 0 ;
77
+ .mat-badge-above & {
78
+ bottom : 100% ;
79
+ }
80
+
81
+ .mat-badge-below & {
82
+ top : 100% ;
83
+ }
84
+
85
+ .mat-badge-before & {
86
+ right : 100% ;
87
+ }
88
+
89
+ [dir = ' rtl' ] .mat-badge-before & {
90
+ right : auto ;
91
+ left : 100% ;
92
+ }
93
+
94
+ .mat-badge-after & {
95
+ left : 100% ;
96
+ }
97
+
98
+ [dir = ' rtl' ] .mat-badge-after & {
99
+ left : auto ;
100
+ right : 100% ;
101
+ }
109
102
}
110
103
}
111
104
@@ -133,13 +126,13 @@ $large-size: $default-size + 6;
133
126
}
134
127
135
128
.mat-badge-small {
136
- @include _badge-size ($ small-size , small - size - text - size );
129
+ @include _badge-size (' small' );
137
130
}
138
131
139
132
.mat-badge-medium {
140
- @include _badge-size ($default-size , null );
133
+ @include _badge-size (' medium ' );
141
134
}
142
135
143
136
.mat-badge-large {
144
- @include _badge-size ($ large-size , large - size - text - size );
137
+ @include _badge-size (' large' );
145
138
}
0 commit comments