• Stars
    star
    2,018
  • Rank 22,933 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Material Components for React (MDC React)

Build Status codecov Chat

Material Components for React (MDC React)

NOTE: MDC-React is no longer under active development

We created MDC-React in 2018 to implement the updated Material Design guidelines. Since then, the open-source React community has embraced the new guidelines and created a number of excellent unofficial implementations. See Material Design Components - Web Framework Wrappers for a partial list.

In order to increase our focus on implementing our core, framework-independent libraries (MDC-Web and MWC), we’re passing the Material+React baton back to the community. That means Material Design will no longer be updating and maintaining this repo. We recommend that you switch to another implementation and keep building beautiful, usable apps based on Material Design. Thanks for being part of the project!

MDC React was an official implementation of Google's Material Design components for React. It is a wrapper library for MDC Web. Please refer to our MDC Web Catalog to play and interact with the Components.

mpmgq9h6b9x

Components

The following is a list of the components that are ready to be used, with corresponding links to the material.io design spec and MDC Web code.

Component Spec MDC Web
Button Button Design Page MDC Button
Card Card Design Page MDC Card
Checkbox Checkbox Design Page MDC Checkbox
Chips Chips Design Page MDC Chips
Dialog Dialog Design Page MDC Dialog
Drawer Drawer Design Page MDC Drawer
Fab Fab Design Page MDC Fab
Floating Label Text Field Design Page MDC Floating Label
Icon Button Icon Button Design Page MDC Icon Button
Layout Grid Layout Grid Design Page MDC Layout Grid
Line Ripple Text Field Design Page MDC Line Ripple
Linear Progress Linear Progress Design Page MDC Linear Progress
List List Design Page MDC List
Material Icon Material Icon Design Page Material Icon Tool
Menu Surface Menu Surface Design Page MDC Menu Surface
Menu Menu Design Page MDC Menu
Notched Outline Text Field Design Page MDC Notched Outline
Radio Radio Design Page MDC Radio
Ripple Ripple Design Page MDC Ripple
Select Select Design Page MDC Select
Snackbar Snackbar Design Page MDC Snackbar
Switch Switch Design Page MDC Switch
Tab Tabs Design Page MDC Tab
Tab Bar Tabs Design Page MDC Tab Bar
Tab Indicator Tabs Design Page MDC Tab Indicator
Tab Scroller Tabs Design Page MDC Tab Scroller
Text Field Text Field Design Page MDC Text Field
Top App Bar Top App Bar Design Page MDC Top App Bar
Typography Typography Design Page MDC Typography

Getting Started

With StackBlitz

If you're looking to see how it looks without having to install a bunch of npm modules in your environment, please have a look at this Starter Stackblitz.

With create-react-app

create-react-app is a popular CLI tool to getting started with React. If you're new to React or Webpack, you might be starting out here. This section will walk you through configuring create-react-app to install and use our components.

If you're using an older version (v1) of create-react-app, please refer to our create-react-app-v1 doc.

Recommended things to know

  1. node/npm
  2. JavaScript
  3. HTML/CSS
  4. ES6

NOTE: If you haven't used create-react-app before, you may want to read the Overview Guide.

Step 1: Install create-react-app

NOTE: all npm commands can be replaced with yarn

Install create-react-app:

npx create-react-app my-app
cd my-app
npm start
Use with Typescript

It is recommended to use Typescript with our components. You will need to add a few more modules for this to work"

npm i @types/react @types/react-dom @types/classnames @types/node typescript
npm start

Step 2: Install Components

Install Button:

npm install @material/react-button

Step 3: Using Sass

If you want to use the compiled CSS and not customize any colors, text, etc. you can skip to Step 3a.

Most likely you'll want to start using the Sass mixins to customize your app. MDC Sass files are not supported out of the box, since we do not prepend ~ to our module imports. See this Github issue explaining the issue in detail. There is a workaround, but requires some work on your end (we promise it is not too difficult).

Add environment variable

To get MDC React Components to work with create-react-app you need to set a SASS_PATH environment variable that points to your node_modules directory. To quickly do this on OS X or Linux enter the following in your command line:

export SASS_PATH=./node_modules

If you're on Windows use the following:

SET SASS_PATH=.\node_modules

Rename your src/App.css file to src/App.scss. You will also need to install node-sass:

npm install node-sass

If you permanently want to add this to your environment, read adding environment variables. You're now ready to start using MDC React Sass modules in your create-react-app.

NOTE: this assumes that you will run npm start (or yarn start) from the root directory. By default this is how create-react-app is setup.

// ./src/App.scss

@import "@material/react-button/index.scss";
@import "./react-button-overrides";

...
// ./react-button-overrides.scss

@import "@material/button/mixins";

.button-alternate {
  @include mdc-button-container-fill-color(lightblue);
}

Step 3a: Use Compiled CSS

If you performed Step 3, then you can skip to Step 4.

If you don't need to customize your app, then using the CSS is a quicker way to get started with MDC React Components. Each package comes with a /dist directory, which includes the CSS files compiled from our Sass files. create-react-app is ready to import CSS files. To import the Button CSS copy the following line into ./src/App.js imports:

import '@material/react-button/dist/button.css';

If you want to use the minified version, the import instead looks like:

import '@material/react-button/dist/button.min.css';

Step 4: Use MDC React Button

Open ./src/App.js. Then replace the boilerplate App code (entire file) with the barebones MDC React Button:

import React, {Component} from 'react';
import Button from '@material/react-button';

import './App.scss';
// add the appropriate line(s) in Step 3a if you are using compiled CSS instead.

class App extends Component {
  render() {
    return (
      <div>
        <Button
          raised
          className='button-alternate'
          onClick={() => console.log('clicked!')}
        >
          Click Me!
        </Button>
      </div>
    );
  }
}

export default App;

You can also use these same configurations for your own Webpack build pipeline without create-react-app. But this is the quickest way to getting started with MDC React Components. Button is one of our simpler components, but you should be able to apply these same principles you learn here to any the components. Thanks for trying out MDC React Components, and remember to tell a friend! Enjoy!

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.

More Repositories

1

material-components-web

Modular and customizable Material Design UI components for the web
TypeScript
17,138
star
2

material-components-android

Modular and customizable Material Design UI components for Android
Java
16,311
star
3

material-web

Material Design Web Components
TypeScript
9,320
star
4

material-components-ios

[In maintenance mode] Modular and customizable Material Design UI components for iOS
Objective-C
4,725
star
5

material-components-android-examples

Companion example apps and code for MDC-Android.
Kotlin
2,486
star
6

material-components

Documentation and policies for Material Components (all platforms)
1,072
star
7

material-components-flutter

Modular and customizable Material Design UI components for Flutter
Dart
894
star
8

material-components-android-compose-theme-adapter

A library that enables reuse of Material themes defined in XML for theming in Jetpack Compose.
Kotlin
408
star
9

material-components-android-codelabs

Codelabs for Material Components for Android (MDC-Android)
Java
219
star
10

material-components-flutter-codelabs

Codelabs for Material Components for Flutter
Dart
212
star
11

material-components-android-motion-codelab

Kotlin
173
star
12

material-components-flutter-experimental

Work in progress code, implementation options, and design prototypes
Dart
130
star
13

material-components-web-codelabs

Codelabs for Material Components for Web (MDC Web)
HTML
128
star
14

material-components-web-catalog

Catalog of Material Components for the web (MDC Web)
JavaScript
116
star
15

material-components-site-generator

Generator of Material Components documentation sites.
JavaScript
79
star
16

material-design-for-wordpress

Material Design plugin for WordPress
JavaScript
78
star
17

material-components-flutter-motion-codelab

Codelab for Material motion for Flutter
Dart
60
star
18

material-components-ios-codelabs

Codelabs for Material Components for iOS (MDC-iOS)
Objective-C
38
star
19

material-components-flutter-gallery

Dart
22
star
20

material-components-flutter-codelabs-packages

Assets for Material Flutter codelabs
21
star
21

material-components-design-codelabs

Material Design codelabs for designers
16
star
22

material-components-ios-codelabs-2017

Codelabs for Material Components for iOS (MDC-iOS) 2017
Objective-C
15
star
23

material-components-ios-skeleton-objc

A template and sample code that you can use to start a new Material Components for iOS (MDC-iOS) application.
5
star
24

material-components-motion-experimental

Experimental work around motion
5
star
25

.github

3
star
26

.allstar

1
star