Skip to content

Commit 30a61a5

Browse files
committed
8. Add user documentation
Adds documentation explaining what this component is and how to experiment with it in your app.
1 parent d412cd4 commit 30a61a5

File tree

1 file changed

+91
-0
lines changed
  • src/material-experimental/mdc-checkbox

1 file changed

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

0 commit comments

Comments
 (0)