-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/badge): move structural styles out of theme (#28452)
Historically we've had the structural styles for the badge in the theme, because Angular doesn't support adding styles to a directive. This can lead to duplicate CSS and can be problematic for M3. These changes move the styles into a dummy component that is used to load the style only once per app. (cherry picked from commit 23e2f3e)
- Loading branch information
Showing
8 changed files
with
208 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
@use 'sass:color'; | ||
@use 'sass:math'; | ||
@use '@angular/cdk'; | ||
@use '../core/tokens/m2/mat/badge' as tokens-mat-badge; | ||
@use '../core/tokens/token-utils'; | ||
|
||
$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, $font-size-token) { | ||
.mat-badge-content { | ||
width: $size; | ||
height: $size; | ||
line-height: $size; | ||
|
||
@if ($font-size-token) { | ||
@include token-utils.use-tokens(tokens-mat-badge.$prefix, | ||
tokens-mat-badge.get-token-slots()) { | ||
@include token-utils.create-token-slot(font-size, $font-size-token); | ||
} | ||
} | ||
} | ||
|
||
&.mat-badge-above .mat-badge-content { | ||
top: math.div(-$size, 2); | ||
} | ||
|
||
&.mat-badge-below .mat-badge-content { | ||
bottom: math.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: math.div(-$size, 2); | ||
} | ||
|
||
[dir='rtl'] &.mat-badge-before .mat-badge-content { | ||
left: auto; | ||
right: math.div(-$size, 2); | ||
} | ||
|
||
&.mat-badge-after .mat-badge-content { | ||
right: math.div(-$size, 2); | ||
} | ||
|
||
[dir='rtl'] &.mat-badge-after .mat-badge-content { | ||
right: auto; | ||
left: math.div(-$size, 2); | ||
} | ||
} | ||
} | ||
|
||
.mat-badge { | ||
position: relative; | ||
|
||
// The badge should make sure its host is overflow visible so that the badge content | ||
// can be rendered outside of the element. Some components such as <mat-icon> explicitly | ||
// style `overflow: hidden` so this requires extra specificity so that it does not | ||
// depend on style load order. | ||
&.mat-badge { | ||
overflow: visible; | ||
} | ||
} | ||
|
||
.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; | ||
|
||
@include token-utils.use-tokens(tokens-mat-badge.$prefix, tokens-mat-badge.get-token-slots()) { | ||
@include token-utils.create-token-slot(background-color, background-color); | ||
@include token-utils.create-token-slot(color, text-color); | ||
@include token-utils.create-token-slot(font-family, text-font); | ||
@include token-utils.create-token-slot(font-size, text-size); | ||
@include token-utils.create-token-slot(font-weight, text-weight); | ||
} | ||
|
||
@include cdk.high-contrast(active, off) { | ||
outline: solid 1px; | ||
border-radius: 0; | ||
} | ||
} | ||
|
||
.mat-badge-disabled .mat-badge-content { | ||
@include token-utils.use-tokens(tokens-mat-badge.$prefix, tokens-mat-badge.get-token-slots()) { | ||
@include token-utils.create-token-slot(background-color, disabled-state-background-color); | ||
@include token-utils.create-token-slot(color, disabled-state-text-color); | ||
} | ||
} | ||
|
||
.mat-badge-hidden .mat-badge-content { | ||
display: 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, small-size-text-size); | ||
} | ||
|
||
.mat-badge-medium { | ||
@include _badge-size($default-size, null); | ||
} | ||
|
||
.mat-badge-large { | ||
@include _badge-size($large-size, large-size-text-size); | ||
} |
Oops, something went wrong.