|
1 | | -### TODO |
2 | | -- Consider supporting the selector "button[mat-outlined-button]" for the stroked button |
3 | | -- Consider if we want to add a "appearance/type" input to button, similar to form field (outline/stroked, flat, raised) |
| 1 | +This is a prototype of an alternate version of `MatButton` 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 `MatButtonModule` and add it to the module that declares your component: |
| 32 | + |
| 33 | + ```ts |
| 34 | + import {MatButtonModule} from '@angular/material-experimental/mdc-button'; |
| 35 | + |
| 36 | + @NgModule({ |
| 37 | + declarations: [MyComponent], |
| 38 | + imports: [MatButtonModule], |
| 39 | + }) |
| 40 | + export class MyModule {} |
| 41 | + ``` |
| 42 | + |
| 43 | +4. Use the buttons in your component's template: |
| 44 | + |
| 45 | + ```html |
| 46 | + <button mat-button> Basic </button> |
| 47 | + <button mat-raised-button> Raised </button> |
| 48 | + <button mat-stroked-button> Stroked </button> |
| 49 | + <button mat-flat-button> Flat </button> |
| 50 | + <button mat-icon-button> |
| 51 | + <mat-icon>save</mat-icon> |
| 52 | + </button> |
| 53 | + <button mat-fab> |
| 54 | + <mat-icon>add</mat-icon> |
| 55 | + </button> |
| 56 | + ``` |
| 57 | + |
| 58 | +5. Add the theme and typography mixins to your Sass. Note that there are three separate mixins for |
| 59 | +the button variants: standard buttons, icon buttons, and floating action buttons. Include only the mixins of the |
| 60 | +button variants you are using: |
| 61 | + |
| 62 | + ```scss |
| 63 | + @import '~@angular/material/theming'; |
| 64 | + @import '~@angular/material-experimental/mdc-button/button-theme'; |
| 65 | + |
| 66 | + $candy-app-primary: mat-palette($mat-indigo); |
| 67 | + $candy-app-accent: mat-palette($mat-pink, A200, A100, A400); |
| 68 | + $candy-app-theme: mat-light-theme(( |
| 69 | + color: ( |
| 70 | + primary: $candy-app-primary, |
| 71 | + accent: $candy-app-accent, |
| 72 | + ) |
| 73 | + )); |
| 74 | + |
| 75 | + |
| 76 | + @include mat-mdc-button-theme($candy-app-theme); |
| 77 | + @include mat-mdc-fab-theme($candy-app-theme); |
| 78 | + @include mat-mdc-icon-button-theme($candy-app-theme); |
| 79 | + ``` |
| 80 | + |
| 81 | +## API differences |
| 82 | + |
| 83 | +The API of the buttons matches the one from `@angular/material/button`. Simply replace imports to |
| 84 | +`@angular/material/button` with imports to `@angular/material-experimental/mdc-button`. |
0 commit comments