|
| 1 | +This is prototype of an alternate version of `<mat-progress-spinner>` built on top of |
| 2 | +[MDC Web](https://github.com/material-components/material-components-web). It demonstrates how |
| 3 | +Angular Material could use MDC Web under the hood while still exposing the same API Angular users as |
| 4 | +the existing `<mat-progress-spinner>`. This component is experimental and should not be used in |
| 5 | +production. |
| 6 | + |
| 7 | +## How to use |
| 8 | +Assuming your application is already up and running using Angular Material, you can add this |
| 9 | +component by following these steps: |
| 10 | + |
| 11 | +1. Install Angular Material Experimental & MDC WEB: |
| 12 | + |
| 13 | + ```bash |
| 14 | + npm i material-components-web @angular/material-experimental |
| 15 | + ``` |
| 16 | + |
| 17 | +2. In your `angular.json`, make sure `node_modules/` is listed as a Sass include path. This is |
| 18 | + needed for the Sass compiler to be able to find the MDC Web Sass files. |
| 19 | + |
| 20 | + ```json |
| 21 | + ... |
| 22 | + "styles": [ |
| 23 | + "src/styles.scss" |
| 24 | + ], |
| 25 | + "stylePreprocessorOptions": { |
| 26 | + "includePaths": [ |
| 27 | + "node_modules/" |
| 28 | + ] |
| 29 | + }, |
| 30 | + ... |
| 31 | + ``` |
| 32 | + |
| 33 | +3. Import the experimental `MatProgressSpinnerModule` and add it to the module that declares your |
| 34 | + component: |
| 35 | + |
| 36 | + ```ts |
| 37 | + import {MatProgressSpinnerModule} from '@angular/material-experimental/mdc-progress-spinner'; |
| 38 | + |
| 39 | + @NgModule({ |
| 40 | + declarations: [MyComponent], |
| 41 | + imports: [MatProgressSpinnerModule], |
| 42 | + }) |
| 43 | + export class MyModule {} |
| 44 | + ``` |
| 45 | + |
| 46 | +4. Add use `<mat-progress-spinner>` in your component's template, just like you would the normal |
| 47 | + `<mat-progress-spinner>`: |
| 48 | + |
| 49 | + ```html |
| 50 | + <mat-progress-spinner [value]="42"></mat-progress-spinner> |
| 51 | + ``` |
| 52 | + |
| 53 | +5. Add the theme and typography mixins to your Sass. (There is currently no pre-built CSS option for |
| 54 | + the experimental `<mat-progress-spinner>`): |
| 55 | + |
| 56 | + ```scss |
| 57 | + @import '~@angular/material/theming'; |
| 58 | + @import '~@angular/material-experimental/mdc-progress-spinner'; |
| 59 | + |
| 60 | + $my-primary: mat-palette($mat-indigo); |
| 61 | + $my-accent: mat-palette($mat-pink, A200, A100, A400); |
| 62 | + $my-theme: mat-light-theme(( |
| 63 | + color: ( |
| 64 | + primary: $my-primary, |
| 65 | + accent: $my-accent |
| 66 | + ) |
| 67 | + )); |
| 68 | + |
| 69 | + @include mat-mdc-progress-spinner-theme($my-theme); |
| 70 | + @include mat-mdc-progress-spinner-typography(); |
| 71 | + ``` |
| 72 | + |
| 73 | +## Replacing the standard progress spinner in an existing app |
| 74 | +Because the experimental API mirrors the API for the standard progress spinner, it can easily be swapped |
| 75 | +in by just changing the import paths. There is currently no schematic for this, but you can run the |
| 76 | +following string replace across your TypeScript files: |
| 77 | + |
| 78 | +```bash |
| 79 | +grep -lr --include="*.ts" --exclude-dir="node_modules" \ |
| 80 | + --exclude="*.d.ts" "['\"]@angular/material/progress-spinner['\"]" | xargs sed -i \ |
| 81 | + "s/['\"]@angular\/material\/progress-spinner['\"]/'@angular\/material-experimental\/mdc-progress-spinner'/g" |
| 82 | +``` |
| 83 | + |
| 84 | +CSS styles and tests that depend on implementation details of mat-progress-spinner (such as getting |
| 85 | +elements from the template by class name) will need to be manually updated. |
| 86 | + |
| 87 | +There are some small visual differences between this progress and the standard `mat-progress-spinner`. |
| 88 | +This progress spinner has slightly different animation timings and easing curves. |
0 commit comments