Skip to content

Commit 7a5b102

Browse files
committed
feat(material/card): support filled variant
this commit add `filled` variant for material card which provides subtle seperation from background and has less emphasis than elevated or outlined cards fixes #29840
1 parent 4e0ea8e commit 7a5b102

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

goldens/material/card/index.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class MatCardActions {
3232
}
3333

3434
// @public (undocumented)
35-
export type MatCardAppearance = 'outlined' | 'raised';
35+
export type MatCardAppearance = 'outlined' | 'raised' | 'filled';
3636

3737
// @public
3838
export class MatCardAvatar {

src/material/card/_m2-card.scss

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $prefix: (mat, card);
1212
@return (
1313
elevated-container-shape: 4px,
1414
outlined-container-shape: 4px,
15+
filled-container-shape: 4px,
1516
outlined-outline-width: 1px,
1617
);
1718
}
@@ -25,6 +26,8 @@ $prefix: (mat, card);
2526
outlined-container-elevation: elevation.get-box-shadow(0),
2627
outlined-outline-color: rgba(inspection.get-theme-color($theme, foreground, base), 0.12),
2728
subtitle-text-color: inspection.get-theme-color($theme, foreground, secondary-text),
29+
filled-container-color: inspection.get-theme-color($theme, background, card),
30+
filled-container-elevation: elevation.get-box-shadow(0)
2831
);
2932
}
3033

src/material/card/_m3-card.scss

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ $prefix: (mat, card);
2525
outlined-container-shape: map.get($systems, md-sys-shape, corner-medium),
2626
outlined-outline-color: map.get($systems, md-sys-color, outline-variant),
2727
outlined-outline-width: if($exclude-hardcoded, null, 1px),
28+
filled-container-color: map.get($systems, md-sys-color, surface-container-highest),
29+
filled-container-elevation: map.get($systems, md-sys-elevation, level0),
30+
filled-container-shape: map.get($systems, md-sys-shape, corner-medium),
2831
),
2932
);
3033

src/material/card/card.scss

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ $mat-card-default-padding: 16px !default;
5151
}
5252
}
5353

54+
.mat-mdc-card-filled {
55+
@include token-utils.use-tokens(m2-card.$prefix, m2-card.get-token-slots()) {
56+
background-color: token-utils.slot(filled-container-color);
57+
border-radius: token-utils.slot(filled-container-shape);
58+
box-shadow: token-utils.slot(filled-container-elevation);
59+
}
60+
}
61+
5462
.mdc-card__media {
5563
position: relative;
5664
box-sizing: border-box;

src/material/card/card.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
inject,
1717
} from '@angular/core';
1818

19-
export type MatCardAppearance = 'outlined' | 'raised';
19+
export type MatCardAppearance = 'outlined' | 'raised' | 'filled';
2020

2121
/** Object that can be used to configure the default options for the card module. */
2222
export interface MatCardConfig {
@@ -41,6 +41,8 @@ export const MAT_CARD_CONFIG = new InjectionToken<MatCardConfig>('MAT_CARD_CONFI
4141
'class': 'mat-mdc-card mdc-card',
4242
'[class.mat-mdc-card-outlined]': 'appearance === "outlined"',
4343
'[class.mdc-card--outlined]': 'appearance === "outlined"',
44+
'[class.mat-mdc-card-filled]': 'appearance === "filled"',
45+
'[class.mdc-card--filled]': 'appearance === "filled"',
4446
},
4547
exportAs: 'matCard',
4648
encapsulation: ViewEncapsulation.None,

0 commit comments

Comments
 (0)