mirror of
https://github.com/material-components/material-web.git
synced 2024-10-27 14:07:17 +03:00
9a1fe7c6ec
* docs: updating Edge native support PiperOrigin-RevId: 298449151 * docs: update Edge native support * chore: add latest edge test target
222 lines
20 KiB
Markdown
222 lines
20 KiB
Markdown
# Material Web Components [![Test Status](https://github.com/material-components/material-components-web-components/workflows/tests/badge.svg?branch=master)](https://github.com/material-components/material-components-web-components/actions?query=workflow%3Atests+branch%3Amaster)
|
|
|
|
> IMPORTANT: The Material Web Components are a work in progress and subject to major changes until 1.0 release.
|
|
|
|
The Material Web Components (MWC) are a collection of [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) maintained by Google that implement [Material Design](https://material.io/design/).
|
|
|
|
[Demos on Glitch](https://mwc-demos.glitch.me/demos/).
|
|
|
|
## Components
|
|
|
|
| Component | Status | Issues
|
|
| ----------| ------ | ------
|
|
| [`<mwc-button>`](https://github.com/material-components/material-components-web-components/tree/master/packages/button) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-button.svg)](https://www.npmjs.com/package/@material/mwc-button) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Button%22)
|
|
| `<mwc-bottom-app-bar>` | [*Planned*](https://github.com/material-components/material-components-web-components/issues/298) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Bottom+App+Bar%22)
|
|
| `<mwc-card>` | [*Planned*](https://github.com/material-components/material-components-web-components/issues/231) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Card%22)
|
|
| [`<mwc-checkbox>`](https://github.com/material-components/material-components-web-components/tree/master/packages/checkbox) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-checkbox.svg)](https://www.npmjs.com/package/@material/mwc-fab) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Checkbox%22)
|
|
| `<mwc-chip>` | [*Planned*](https://github.com/material-components/material-components-web-components/issues/418) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Chip%22)
|
|
| `<mwc-circular-progress>` | [*Planned*](https://github.com/material-components/material-components-web-components/issues/500) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Circular+Progress%22)
|
|
| `<mwc-data-table>` | [*Planned*](https://github.com/material-components/material-components-web-components/issues/386) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Data+Table%22)
|
|
| [`<mwc-dialog>`](https://github.com/material-components/material-components-web-components/tree/master/packages/dialog) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-dialog.svg)](https://www.npmjs.com/package/@material/mwc-dialog) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Dialog%22)
|
|
| [`<mwc-drawer>`](https://github.com/material-components/material-components-web-components/tree/master/packages/drawer) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-drawer.svg)](https://www.npmjs.com/package/@material/mwc-drawer) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Drawer%22)
|
|
| [`<mwc-fab>`](https://github.com/material-components/material-components-web-components/tree/master/packages/fab) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-fab.svg)](https://www.npmjs.com/package/@material/mwc-fab) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Fab%22)
|
|
| [`<mwc-formfield>`](https://github.com/material-components/material-components-web-components/tree/master/packages/formfield) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-formfield.svg)](https://www.npmjs.com/package/@material/mwc-formfield) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Form+Field%22)
|
|
| [`<mwc-icon-button-toggle>`](https://github.com/material-components/material-components-web-components/tree/master/packages/icon-button-toggle) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-icon-button-toggle.svg)](https://www.npmjs.com/package/@material/mwc-icon-button-toggle) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Icon+Button%22)
|
|
| [`<mwc-icon-button>`](https://github.com/material-components/material-components-web-components/tree/master/packages/icon-button) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-icon-button.svg)](https://www.npmjs.com/package/@material/mwc-icon-button) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Icon+Button%22)
|
|
| [`<mwc-icon>`](https://github.com/material-components/material-components-web-components/tree/master/packages/icon) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-icon.svg)](https://www.npmjs.com/package/@material/mwc-icon) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Icon%22)
|
|
| [`<mwc-linear-progress>`](https://github.com/material-components/material-components-web-components/tree/master/packages/linear-progress) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-linear-progress.svg)](https://www.npmjs.com/package/@material/mwc-linear-progress) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Linear+Progress%22)
|
|
| [`<mwc-list>`](https://github.com/material-components/material-components-web-components/tree/master/packages/list) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-list.svg)](https://www.npmjs.com/package/@material/mwc-list) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+List%22)
|
|
| [`<mwc-menu>`](https://github.com/material-components/material-components-web-components/tree/master/packages/menu) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-menu.svg)](https://www.npmjs.com/package/@material/mwc-menu) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aopen+is%3Aissue+label%3A%22Component%3A+Menu%22)
|
|
| [`<mwc-radio>`](https://github.com/material-components/material-components-web-components/tree/master/packages/radio) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-radio.svg)](https://www.npmjs.com/package/@material/mwc-radio) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Radio%22)
|
|
| [`<mwc-select>`](https://github.com/material-components/material-components-web-components/tree/master/packages/select) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-select.svg)](https://www.npmjs.com/package/@material/mwc-select) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Select%22)
|
|
| [`<mwc-slider>`](https://github.com/material-components/material-components-web-components/tree/master/packages/slider) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-slider.svg)](https://www.npmjs.com/package/@material/mwc-slider) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Slider%22)
|
|
| [`<mwc-snackbar>`](https://github.com/material-components/material-components-web-components/tree/master/packages/snackbar) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-snackbar.svg)](https://www.npmjs.com/package/@material/mwc-snackbar) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Snackbar%22)
|
|
| [`<mwc-switch>`](https://github.com/material-components/material-components-web-components/tree/master/packages/switch) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-switch.svg)](https://www.npmjs.com/package/@material/mwc-switch) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Switch%22)
|
|
| [`<mwc-tab-bar>`](https://github.com/material-components/material-components-web-components/tree/master/packages/tab-bar) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-tab-bar.svg)](https://www.npmjs.com/package/@material/mwc-tab-bar) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Tab%22)
|
|
| [`<mwc-tab>`](https://github.com/material-components/material-components-web-components/tree/master/packages/tab) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-tab.svg)](https://www.npmjs.com/package/@material/mwc-tab) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Tab%22)
|
|
| [`<mwc-textarea>`](https://github.com/material-components/material-components-web-components/tree/master/packages/textarea) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-textarea.svg)](https://www.npmjs.com/package/@material/mwc-textarea) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Text+Field%22)
|
|
| [`<mwc-textfield>`](https://github.com/material-components/material-components-web-components/tree/master/packages/textfield) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-textfield.svg)](https://www.npmjs.com/package/@material/mwc-textfield) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Text+Field%22)
|
|
| [`<mwc-top-app-bar-fixed>`](https://github.com/material-components/material-components-web-components/tree/master/packages/top-app-bar-fixed) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-top-app-bar-fixed.svg)](https://www.npmjs.com/package/@material/mwc-top-app-bar-fixed) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Top+App+bar%22)
|
|
| [`<mwc-top-app-bar>`](https://github.com/material-components/material-components-web-components/tree/master/packages/top-app-bar) | [![Published on npm](https://img.shields.io/npm/v/@material/mwc-top-app-bar.svg)](https://www.npmjs.com/package/@material/mwc-top-app-bar) | [*Issues*](https://github.com/material-components/material-components-web-components/issues?q=is%3Aissue+is%3Aopen+label%3A%22Component%3A+Top+App+Bar%22)
|
|
|
|
## Quick start
|
|
|
|
#### 1) Install
|
|
|
|
Install a component from NPM:
|
|
|
|
```sh
|
|
npm install @material/mwc-button @webcomponents/webcomponentsjs
|
|
```
|
|
|
|
#### 2) Write HTML and JavaScript
|
|
|
|
Import the component's JavaScript module, use the component in your HTML, and control it with JavaScript, just like you would with a built-in element such as `<button>`:
|
|
|
|
```html
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>My Example App</title>
|
|
|
|
<!-- Add support for Web Components to older browsers. -->
|
|
<script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
|
|
|
|
<!-- Your application must load the Roboto and Material Icons fonts. -->
|
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<!-- Use Web Components in your HTML like regular built-in elements. -->
|
|
<mwc-button id="myButton" label="Click Me!" raised></mwc-button>
|
|
|
|
<!-- The Material Web Components use standard JavaScript modules. -->
|
|
<script type="module">
|
|
|
|
// Importing this module registers <mwc-button> as an element that you
|
|
// can use in this page.
|
|
//
|
|
// Note this import is a bare module specifier, so it must be converted
|
|
// to a path using a server such as es-dev-server.
|
|
import '@material/mwc-button';
|
|
|
|
// Standard DOM APIs work with Web Components just like they do for
|
|
// built-in elements.
|
|
const button = document.querySelector('#myButton');
|
|
button.addEventListener('click', () => {
|
|
alert('You clicked!');
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
#### 3) Serve
|
|
|
|
Serve your HTML with any server or build process that supports *bare module specifier resolution* (see next section):
|
|
|
|
```sh
|
|
npm install -g es-dev-server
|
|
es-dev-server --node-resolve
|
|
```
|
|
|
|
## Bare module specifiers
|
|
|
|
The Material Web Components are published as standard [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) that use *bare module specifiers*. Bare module specifiers are not yet supported by browsers, so it is necessary to use a tool that transforms
|
|
them to a *path* (for example from `@material/mwc-button` to `./node_modules/@material/mwc-button/mwc-button.js`).
|
|
|
|
Two great choices for tools that do this are:
|
|
|
|
- During local development, use open-wc's [`es-dev-server`](https://open-wc.org/developing/es-dev-server.html) with the `--node-resolve` flag.
|
|
- For your production deployment, build your application with [Rollup](https://rollupjs.org/guide/en/) using the [`rollup-plugin-node-resolve`](https://github.com/rollup/rollup-plugin-node-resolve) plugin.
|
|
|
|
|
|
## Fonts
|
|
|
|
Most applications should include the following tags in their main HTML file to ensure that text and icons
|
|
render correctly:
|
|
|
|
```html
|
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet">
|
|
```
|
|
|
|
The Material Web Components default to using the [Roboto](https://fonts.google.com/specimen/Roboto) font for text, and the [Material Icons](https://google.github.io/material-design-icons/) font for icons. These fonts
|
|
are *not* automatically loaded, so it is the application's responsiblity to ensure that they are loaded.
|
|
|
|
Note that if you load the Material Icons font in a different way to the recommendation shown above, be sure to include [`font-display: block`](https://google.github.io/material-design-icons/) in your `@font-face` CSS rule. This prevents icons from initially displaying their raw *ligature* text before the font has loaded. The `<link>` tag recommended above automaticaly handles this setting.
|
|
|
|
|
|
## Supporting older browsers
|
|
|
|
The Material Web Components use modern browser features that are natively supported in the latest versions of Chrome, Safari, Firefox, and Edge. IE11 and some older versions of other browsers are also supported, but they require additional build steps and polyfills.
|
|
|
|
<table>
|
|
<tr>
|
|
<th><i>Feature</i></th>
|
|
<th><img src="images/chrome.png" width="20px" height="20px"><br>Chrome</th>
|
|
<th><img src="images/safari.png" width="20px" height="20px"><br>Safari</th>
|
|
<th><img src="images/firefox.png" width="20px" height="20px"><br>Firefox</th>
|
|
<th><img src="images/edge.png" width="20px" height="20px"><br>Edge</th>
|
|
<th><img src="images/ie.png" width="20px" height="20px"><br>IE11</th>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components">Web Components</a></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td class="ie11"><img src="images/orange-check.png" width="20px" height="20px"class="check" alt="Polyfill"> <a href="#web-components">*</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">Modules</a></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td class="ie11"><img src="images/orange-check.png" width="20px" height="20px"class="check" alt="Transform"> <a href="#modules">*</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="https://developers.google.com/web/shows/ttt/series-2/es2015">ES2015</a></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td><img src="images/check-green.png" width="20px" height="20px"class="check" alt="Yes"></td>
|
|
<td class="ie11"><img src="images/orange-check.png" width="20px" height="20px"class="check" alt="Transpile"> <a href="#es2015">*</a></td>
|
|
</tr>
|
|
</table>
|
|
|
|
#### Web Components
|
|
|
|
To support Web Components in IE11 and other older browsers, install the [Web Components Polyfills](https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs):
|
|
|
|
```sh
|
|
npm install @webcomponents/webcomponentsjs
|
|
```
|
|
|
|
And include the `webcomponents-loader.js` script in your HTML, which detects when polyfills are needed and loads them automatically:
|
|
|
|
```html
|
|
<!-- Add support for Web Components to IE11. -->
|
|
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
|
|
```
|
|
|
|
#### Modules
|
|
|
|
To support IE11 or other older browsers that do not support JavaScript modules, you must transform JavaScript modules to classic JavaScript scripts. [Rollup](https://rollupjs.org/guide/en/) is a popular tool that can consume JavaScript modules and produce a number of other formats, such as AMD. Be sure to use the [`rollup-plugin-node-resolve`](https://github.com/rollup/rollup-plugin-node-resolve) plugin to resolve *bare module specifiers*, as mentioned [above](#bare-module-specifiers).
|
|
|
|
#### ES2015
|
|
|
|
If you support IE11 or other older browsers that do not support the latest version of JavaScript, you must *transpile* your application to ES5. [Babel](https://babeljs.io/) is a popular tool that does this. You can integrate Babel transpilation into a Rollup configuration using [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel).
|
|
|
|
## Contributing
|
|
|
|
Clone and setup the repo:
|
|
|
|
```sh
|
|
git clone git@github.com:material-components/material-components-web-components.git mwc
|
|
cd mwc
|
|
npm install
|
|
npm run build
|
|
```
|
|
|
|
View the demos:
|
|
|
|
```sh
|
|
npm run dev
|
|
http://127.0.0.1:8001/demos
|
|
```
|
|
|
|
Run all tests:
|
|
|
|
```sh
|
|
npm run test
|
|
```
|
|
|
|
Run tests for a specific component:
|
|
|
|
```sh
|
|
npm run test -- --packages=mwc-button
|
|
```
|