1 | # Material Components Web (MDC Web)
|
2 |
|
3 | This package contains the master library for Material Components Web. It simply wraps all of its
|
4 | sibling packages up into one comprehensive library for convenience.
|
5 |
|
6 | ## Installation
|
7 |
|
8 | ```
|
9 | npm install material-components-web
|
10 | ```
|
11 |
|
12 | ## Usage
|
13 |
|
14 | ### Including the Sass
|
15 |
|
16 | ```scss
|
17 | @use "material-components-web/material-components-web";
|
18 | ```
|
19 |
|
20 | ### Including the Javascript
|
21 |
|
22 | ```js
|
23 | import * as mdc from 'material-components-web';
|
24 | const checkbox = new mdc.checkbox.MDCCheckbox(document.querySelector('.mdc-checkbox'));
|
25 | // OR
|
26 | import {checkbox} from 'material-components-web';
|
27 | const checkbox = new checkbox.MDCCheckbox(document.querySelector('.mdc-checkbox'));
|
28 | ```
|
29 |
|
30 | > See [Importing the JS component](../../docs/importing-js.md) for more information on how to import JavaScript.
|
31 |
|
32 | > NOTE: Since switch is a reserved word in JS, switch is instead named `switchControl`.
|
33 |
|
34 | > NOTE: Built CSS files as well as UMD JS bundles will be available as part of the package.
|
35 |
|
36 |
|
37 | ### Auto-initialization of components
|
38 |
|
39 | The `material-components-web` package automatically registers all MDC Web components with
|
40 | [mdc-auto-init](../mdc-auto-init), making it dead simple to create and initialize components
|
41 | with zero configuration or manual work.
|
42 |
|
43 | For example, say you want to use an [icon button toggle](../mdc-icon-button). Simply render the necessary
|
44 | DOM, and attach the `data-mdc-auto-init="MDCIconButtonToggle"` attribute.
|
45 |
|
46 | ```html
|
47 | <button class="mdc-icon-button"
|
48 | aria-label="Add to favorites"
|
49 | aria-pressed="false"
|
50 | data-mdc-auto-init="MDCIconButtonToggle">
|
51 | <i class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">favorite</i>
|
52 | <i class="material-icons mdc-icon-button__icon">favorite_border</i>
|
53 | </button>
|
54 | ```
|
55 |
|
56 | Then at the bottom of your html, insert this one-line script tag:
|
57 |
|
58 | ```html
|
59 | <script>mdc.autoInit()</script>
|
60 | ```
|
61 |
|
62 | This will automatically initialize the icon button toggle, as well as any other components marked with the
|
63 | auto init data attribute. See [mdc-auto-init](../mdc-auto-init) for more info.
|