|
1 | | -This is a placeholder for the MDC-based implementation of card. |
| 1 | +This is a prototype of an alternate version of `MatCard` built on top of |
| 2 | +[MDC Web](https://github.com/material-components/material-components-web). This component is |
| 3 | +experimental and should not be used in production. |
| 4 | + |
| 5 | +## How to use |
| 6 | +Assuming your application is already up and running using Angular Material, you can add this |
| 7 | +component by following these steps: |
| 8 | + |
| 9 | +1. Install `@angular/material-experimental` and MDC Web: |
| 10 | + |
| 11 | + ```bash |
| 12 | + npm i material-components-web @angular/material-experimental |
| 13 | + ``` |
| 14 | + |
| 15 | +2. In your `angular.json`, make sure `node_modules/` is listed as a Sass include path. This is |
| 16 | + needed for the Sass compiler to be able to find the MDC Web Sass files. |
| 17 | + |
| 18 | + ```json |
| 19 | + ... |
| 20 | + "styles": [ |
| 21 | + "src/styles.scss" |
| 22 | + ], |
| 23 | + "stylePreprocessorOptions": { |
| 24 | + "includePaths": [ |
| 25 | + "node_modules/" |
| 26 | + ] |
| 27 | + }, |
| 28 | + ... |
| 29 | + ``` |
| 30 | + |
| 31 | +3. Import the experimental `MatCardModule` and add it to the module that declares your component: |
| 32 | + |
| 33 | + ```ts |
| 34 | + import {MatCardModule} from '@angular/material-experimental/mdc-card'; |
| 35 | + |
| 36 | + @NgModule({ |
| 37 | + declarations: [MyComponent], |
| 38 | + imports: [MatCardModule], |
| 39 | + }) |
| 40 | + export class MyModule {} |
| 41 | + ``` |
| 42 | + |
| 43 | +4. Use the card in your component's template: |
| 44 | + |
| 45 | + ```html |
| 46 | + <mat-card> |
| 47 | + <mat-card-title> My Card Title </mat-card-title> |
| 48 | + <mat-card-content> |
| 49 | + Card content! |
| 50 | + </mat-card-content> |
| 51 | + <mat-card-actions> |
| 52 | + <button> Like </button> |
| 53 | + <button> Share </button> |
| 54 | + </mat-card-actions> |
| 55 | + </mat-card> |
| 56 | + ``` |
| 57 | + |
| 58 | +5. Add the theme and typography mixins to your Sass: |
| 59 | + |
| 60 | + ```scss |
| 61 | + @import '~@angular/material/theming'; |
| 62 | + @import '~@angular/material-experimental/mdc-card/card-theme'; |
| 63 | + |
| 64 | + $candy-app-primary: mat-palette($mat-indigo); |
| 65 | + $candy-app-accent: mat-palette($mat-pink, A200, A100, A400); |
| 66 | + $candy-app-theme: mat-light-theme(( |
| 67 | + color: ( |
| 68 | + primary: $candy-app-primary, |
| 69 | + accent: $candy-app-accent, |
| 70 | + ) |
| 71 | + )); |
| 72 | + |
| 73 | + |
| 74 | + @include mat-mdc-card-theme($candy-app-theme); |
| 75 | + ``` |
| 76 | + |
| 77 | +## API differences |
| 78 | + |
| 79 | +The API of the card matches the one from `@angular/material/card`. Simply replace imports to |
| 80 | +`@angular/material/card` with imports to `@angular/material-experimental/mdc-card`. |
0 commit comments