Skip to content

Commit 663585a

Browse files
authored
feat(material/card): support filled variant (#29868)
* 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 * docs(material/card): add each appearance example update the example to contain `elevated`, `outlined` & `filled` variants
1 parent 32c25ae commit 663585a

File tree

10 files changed

+31
-10
lines changed

10 files changed

+31
-10
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/components-examples/material/card/card-overview/card-overview-example.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
<button matButton>LIKE</button>
1717
<button matButton>SHARE</button>
1818
</mat-card-actions>
19-
</mat-card>
19+
</mat-card>

src/dev-app/card/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ng_project(
1515
"//:node_modules/@angular/forms",
1616
"//src/material/button",
1717
"//src/material/card",
18-
"//src/material/checkbox",
18+
"//src/material/radio",
1919
],
2020
)
2121

src/dev-app/card/card-demo.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div class="demo-card-container">
2-
<mat-checkbox (change)="toggleAppearance()">Use outlined cards</mat-checkbox>
2+
<mat-radio-group (change)="appearance = $event.value">
3+
<mat-radio-button value="raised">Raised</mat-radio-button>
4+
<mat-radio-button value="outlined">Outlined</mat-radio-button>
5+
<mat-radio-button value="filled">Filled</mat-radio-button>
6+
</mat-radio-group>
37

48
<!-- TODO(jelbourn): re-add dividers and footers with progress bars once the MDC versions exist -->
59
<mat-card [appearance]="appearance">

src/dev-app/card/card-demo.scss

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
text-transform: uppercase;
1717
}
1818
}
19+
20+
mat-radio-group {
21+
margin-bottom: 10px;
22+
}

src/dev-app/card/card-demo.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/co
1010
import {FormsModule} from '@angular/forms';
1111
import {MatButtonModule} from '@angular/material/button';
1212
import {MatCardAppearance, MatCardModule} from '@angular/material/card';
13-
import {MatCheckboxModule} from '@angular/material/checkbox';
13+
import {MatRadioModule} from '@angular/material/radio';
1414

1515
@Component({
1616
selector: 'card-demo',
1717
templateUrl: 'card-demo.html',
1818
styleUrl: 'card-demo.css',
1919
encapsulation: ViewEncapsulation.None,
20-
imports: [MatCardModule, MatButtonModule, MatCheckboxModule, FormsModule],
20+
imports: [MatCardModule, MatButtonModule, MatRadioModule, FormsModule],
2121
changeDetection: ChangeDetectionStrategy.OnPush,
2222
})
2323
export class CardDemo {
@@ -28,7 +28,4 @@ export class CardDemo {
2828
As of some one gently rapping, rapping at my chamber door.
2929
“’Tis some visitor,” I muttered, “tapping at my chamber door—
3030
Only this and nothing more.”`;
31-
toggleAppearance() {
32-
this.appearance = this.appearance == 'raised' ? 'outlined' : 'raised';
33-
}
3431
}

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)