material-components-web README

The project's README from github.com/material-components/material-components-web. As one markdown file: README.md.

Version Chat

Note:

This project is no longer actively maintained. While automated updates may still occur, the team will not be prioritizing new features or bug fixes, and those updates will be turned off in the future.

For Angular users, our friends at Angular Material moved away from this library, and they expect that this may actually allow for faster iteration - see their blog post for more information.

Material Components for the web

Material Components for the web helps developers execute Material Design. Developed by a core team of engineers and UX designers at Google, these components enable a reliable development workflow to build beautiful and functional web projects.

Material Web strives to seamlessly incorporate into a wider range of usage contexts, from simple static websites to complex, JavaScript-heavy applications to hybrid client/server rendering systems. In short, whether you're already heavily invested in another framework or not, it should be easy to incorporate Material Components into your site in a lightweight, idiomatic fashion.

Material Components for the web is the successor to Material Design Lite. In addition to implementing the Material Design guidelines, it provides more flexible theming customization, not only in terms of color, but also typography, shape, states, and more. It is also specifically architected for adaptability to various major web frameworks.

NOTE: Material Components Web tends to release breaking changes on a monthly basis, but follows semver so you can control when you incorporate them. We typically follow a 2-week release schedule which includes one major release per month with breaking changes, and intermediate patch releases with bug fixes.

Quick start

Using via CDN

<!-- Required styles for Material Web -->
<link rel="stylesheet" href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">

<!-- Render textfield component -->
<label class="mdc-text-field mdc-text-field--filled">
  <span class="mdc-text-field__ripple"></span>
  <span class="mdc-floating-label" id="my-label">Label</span>
  <input type="text" class="mdc-text-field__input" aria-labelledby="my-label">
  <span class="mdc-line-ripple"></span>
</label>

<!-- Required Material Web JavaScript library -->
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
<!-- Instantiate single textfield component rendered in the document -->
<script>
  mdc.textField.MDCTextField.attachTo(document.querySelector<HTMLElement>('.mdc-text-field'));
</script>

Please see quick start demo on codepen for full example.

Using NPM

This guide assumes you have webpack configured to compile Sass into CSS. To configure webpack, please see the full getting started guide. You can also see the final code and result in the Material Starter Kit.

Install textfield node module to your project.

npm install @material/textfield

HTML

Sample usage of text field component. Please see Textfield component page for more options.

<label class="mdc-text-field mdc-text-field--filled">
  <span class="mdc-text-field__ripple"></span>
  <input type="text" class="mdc-text-field__input" aria-labelledby="my-label">
  <span class="mdc-floating-label" id="my-label">Label</span>
  <span class="mdc-line-ripple"></span>
</label>

CSS

Load styles required for text field component.

@use "@material/floating-label/mdc-floating-label";
@use "@material/line-ripple/mdc-line-ripple";
@use "@material/notched-outline/mdc-notched-outline";
@use "@material/textfield";

@include textfield.core-styles;

JavaScript

Import MDCTextField module to instantiate text field component.

import {MDCTextField} from '@material/textfield';
const textField = new MDCTextField(document.querySelector<HTMLElement>('.mdc-text-field'));

This'll initialize text field component on a single .mdc-text-field element.

Please see quick start demo on glitch for full example.

Need help?

We're constantly trying to improve our components. If Github Issues don't fit your needs, then please visit us on our Discord Channel.

material-components-web (material-components/material-components-web)

Searching Database…

这是什么?这是 Material Components for the web(MDC Web):由 Google 的工程师和用户体验设计师团队打造的一套模块化、可自定义的 Material Design 界面组件。
它绑定某个特定的 JavaScript 框架吗?不,它是一个组件库,不是框架:这些组件在架构上可以适配主流的 Web 框架,从静态网站到服务端渲染的应用都能用。
怎么把一个组件添加到我的项目里?先安装该组件的 npm 包(比如 textfield),导入它的 Sass/CSS 样式,然后在元素上实例化它的 JS 类,例如 MDCTextField;走 CDN 的话可以完全不用 npm。
这需要像 webpack 这样的构建环境吗?走 npm 这条路需要:指南默认已配置好 webpack,把 Sass 编译成 CSS。走 CDN 就不需要任何构建工具。
这个项目还在积极维护吗?没有了。它已被归档:团队不会优先开发新功能或修复 bug,自动化更新最终也会停止。Angular Material 也已经不再使用它,所以把它当作冻结的项目来看待。
它和 Material Design Lite 有什么区别?它是 MDL 的官方后继者。除了实现 Material Design 规范之外,它还提供更灵活的主题定制:颜色、字体、形状和状态,并且架构上能适配主流框架。
我可以什么都不安装就试用吗?可以。README 里链接了 CodePen 上的快速上手演示,组件也可以通过 CDN 引入,所以你可以在配置 npm 和 webpack 之前先在浏览器里试一试。
有没有可以照抄的完整入门示例?有。快速上手部分指向 Material Starter Kit,里面包含设置流程的最终代码和成品效果。
Size
86.5 MB
Stars
17K
Age
9y
Commits · 90 Days