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