UNPKG

2.04 kBMarkdownView Raw
1# Material Components Web (MDC Web)
2
3This package contains the master library for Material Components Web. It simply wraps all of its
4sibling packages up into one comprehensive library for convenience.
5
6## Installation
7
8```
9npm 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
23import * as mdc from 'material-components-web';
24const checkbox = new mdc.checkbox.MDCCheckbox(document.querySelector('.mdc-checkbox'));
25// OR
26import {checkbox} from 'material-components-web';
27const 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
39The `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
41with zero configuration or manual work.
42
43For example, say you want to use an [icon button toggle](../mdc-icon-button). Simply render the necessary
44DOM, 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
56Then at the bottom of your html, insert this one-line script tag:
57
58```html
59<script>mdc.autoInit()</script>
60```
61
62This will automatically initialize the icon button toggle, as well as any other components marked with the
63auto init data attribute. See [mdc-auto-init](../mdc-auto-init) for more info.