|
1 |
| -This is a placeholder for the MDC-based implementation of dialog. |
| 1 | +This is a prototype of an alternate version of `MatDialog` 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 `MatDialogModule` and add it to the module that declares your |
| 32 | + component: |
| 33 | + |
| 34 | + ```ts |
| 35 | + import {MatDialogModule} from '@angular/material-experimental/mdc-dialog'; |
| 36 | + |
| 37 | + @NgModule({ |
| 38 | + declarations: [MyComponent], |
| 39 | + imports: [MatDialogModule], |
| 40 | + }) |
| 41 | + export class MyModule {} |
| 42 | + ``` |
| 43 | + |
| 44 | +4. Use the `MatDialog` service in your components by injecting the service, just like you would |
| 45 | + use the normal dialog. |
| 46 | + |
| 47 | +5. Ensure color and typography styles for `@angular/material-experimental` are set up. Either |
| 48 | + use a custom theme and use the `mat-mdc-dialog-theme` mixin, or use a prebuilt theme |
| 49 | + from `@angular/material-experimental/mdc-theming/prebuilt`. |
| 50 | + |
| 51 | +## API differences |
| 52 | + |
| 53 | +The runtime API for the `MatDialog` service is fully compatible and no changes are needed. Visually |
| 54 | +the dialog has changed a little bit with the MDC-based implementation. In concrete, the dialog no |
| 55 | +longer has outer padding by default. |
| 56 | + |
| 57 | +If content elements such as `matDialogContent` or `matDialogTitle` are used though, the MDC dialog |
| 58 | +will display as with the current non-experimental dialog. The padding change will only surface if |
| 59 | +you have custom content within the dialog that is not wrapped with `matDialogContent`, |
| 60 | +`matDialogActions` or `matDialogTitle`. |
| 61 | + |
| 62 | +We provide a backwards compatibility mixin that re-adds the outer padding. The use of this mixin |
| 63 | +is generally not recommended as it results in inefficient CSS for the dialog because padding from |
| 64 | +the content elements would need to be off set (to not have stacked padding).Ideally, if you have |
| 65 | +custom content outside of the provided dialog sections, add the necessary padding to the element |
| 66 | +directly through CSS, or move them into one of the defined sections the Angular Material dialog |
| 67 | +provides. |
| 68 | + |
| 69 | +```scss |
| 70 | +@import '@angular/material-experimental/mdc-dialog/dialog-legacy-padding'; |
| 71 | + |
| 72 | +@include mat-mdc-dialog-legacy-padding(); |
| 73 | +``` |
0 commit comments