UNPKG

10.4 kBMarkdownView Raw
1# react-md [![license](https://img.shields.io/npm/l/react-md)](https://github.com/mlaursen/react-md/blob/master/LICENSE) [![codecov](https://codecov.io/gh/mlaursen/react-md/branch/master/graph/badge.svg)](https://codecov.io/gh/mlaursen/react-md) [![Actions Status](https://github.com/mlaursen/react-md/workflows/Build,%20Lint,%20and%20Test/badge.svg)](https://github.com/mlaursen/react-md/actions)
2
3[![npm](https://img.shields.io/npm/v/react-md)](https://www.npmjs.com/package/react-md)
4[![downloads](https://img.shields.io/npm/dw/react-md)](https://www.npmjs.com/package/react-md)
5[![Build Status](https://travis-ci.org/mlaursen/react-md.svg?branch=master)](https://travis-ci.org/mlaursen/react-md)
6[![Join the Chat at Slack](https://react-md.herokuapp.com/badge.svg)](https://react-md.herokuapp.com)
7[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/mlaursen03)
8
9Create an accessible React application with the
10[material design specifications](https://material.io/design/) and Scss.
11
12- [Installing packages](https://react-md.dev/guides/installation) - How to
13 install related components and packages within react-md for building your
14 application
15- [Creating a new app](https://react-md.dev/guides/creating-a-new-app) - How to
16 create a new app with react-md
17- [Examples with Build Tools](https://github.com/mlaursen/react-md/tree/master/examples) -
18 View and download examples of using ReactMD with build tools such as
19 [create-react-app], [Next.js], and [Gatsby]
20- [Working from v1](https://react-md.dev/guides/working-with-v1) - How to use
21 migrate from v1 of `react-md` to v2.
22- [Customizing your theme](https://react-md.dev/guides/customizing-your-theme) -
23 How to implement a different theme for your React application
24- [Full documentation](https://react-md.dev) - All the remaining documentation
25 along with every single guide, API Reference, and examples
26- [Library Size](#library-size) - The UMD bundle size for the entire `react-md`
27 library and sizes for some of the pre-built css files.
28
29#### If you are still on v1, please see the [v1 documentation site](https://react-md.dev/v1) and [branch](../../tree/v1) instead
30
31## Installation
32
33react-md has been updated to use
34[scoped packages](https://react-md.dev/guides/scoped-packages) starting with the
35v2 release to help slowly transition to the new components and API. If you do
36not need to slowly transition over this package can be used instead which is a
37convenience package for exporting all the functionality from a single entry
38point.
39
40```sh
41$ npm install --save react-md
42```
43
44or with `yarn`:
45
46```sh
47$ yarn add react-md
48```
49
50For convenience, here is a list of all the included react-md scoped packages and
51a link to their demo documentation page:
52
53- [@react-md/alert](https://react-md.dev/packages/alert/demos)
54- [@react-md/app-bar](https://react-md.dev/packages/app-bar/demos)
55- [@react-md/autocomplete](https://react-md.dev/packages/autocomplete/demos)
56- [@react-md/avatar](https://react-md.dev/packages/avatar/demos)
57- [@react-md/badge](https://react-md.dev/packages/badge/demos)
58- [@react-md/button](https://react-md.dev/packages/button/demos)
59- [@react-md/card](https://react-md.dev/packages/card/demos)
60- [@react-md/chip](https://react-md.dev/packages/chip/demos)
61- [@react-md/dialog](https://react-md.dev/packages/dialog/demos)
62- [@react-md/divider](https://react-md.dev/packages/divider/demos)
63- [@react-md/elevation](https://react-md.dev/packages/elevation/demos)
64- [@react-md/expansion-panel](https://react-md.dev/packages/expansion-panel/demos)
65- [@react-md/form](https://react-md.dev/packages/form/demos)
66- [@react-md/icon](https://react-md.dev/packages/icon/demos)
67- [@react-md/layout](https://react-md.dev/packages/layout/demos)
68- [@react-md/link](https://react-md.dev/packages/link/demos)
69- [@react-md/list](https://react-md.dev/packages/list/demos)
70- [@react-md/material-icons](https://react-md.dev/packages/material-icons/demos)
71- [@react-md/media](https://react-md.dev/packages/media/demos)
72- [@react-md/menu](https://react-md.dev/packages/menu/demos)
73- [@react-md/overlay](https://react-md.dev/packages/overlay/demos)
74- [@react-md/portal](https://react-md.dev/packages/portal/demos)
75- [@react-md/progress](https://react-md.dev/packages/progress/demos)
76- [@react-md/sheet](https://react-md.dev/packages/sheet/demos)
77- [@react-md/states](https://react-md.dev/packages/states/demos)
78- [@react-md/table](https://react-md.dev/packages/table/demos)
79- [@react-md/tabs](https://react-md.dev/packages/tabs/demos)
80- [@react-md/theme](https://react-md.dev/packages/theme/demos)
81- [@react-md/tooltip](https://react-md.dev/packages/tooltip/demos)
82- [@react-md/transition](https://react-md.dev/packages/transition/demos)
83- [@react-md/tree](https://react-md.dev/packages/tree/demos)
84- [@react-md/typography](https://react-md.dev/packages/typography/demos)
85- [@react-md/utils](https://react-md.dev/packages/utils/demos)
86
87### Highlights/Features
88
89- Matches the accessibility guidelines from
90 [www.w3.org](https://www.w3.org/TR/wai-aria-practices)
91- Low level customizable components
92- Easily themeable on a global and component level
93- Uses css variables for dynamic themes with fallbacks for older browsers
94- Out of the box dark theme mode support
95- Out of the box left-to-right and right-to-left language support
96- UMD Bundles and pre-compiled css available on https://unpkg.com (see more
97 information
98 [here](https://react-md.dev/guides/advanced-installation#using-the-cdn-hosted-pre-compiled-themes))
99- Written and maintained in [Typescript]
100
101## Creating a new project
102
103> Check out the [examples folder](./examples) to see completed examples with
104> different build tools such as [Next.js], [Gatsby], and [create-react-app].
105
106First use [create-react-app] to create your project:
107
108```sh
109$ npx create-react-app my-app
110$ cd my-app
111$ npm start
112```
113
114> npx comes with npm 5.2+ and higher, if you have an older version you will need
115> to install `create-react-app` globally instead
116
117Or with `yarn`:
118
119```sh
120$ yarn create react-app my-app
121$ cd my-app
122```
123
124> NOTE: You can also add the `--typescript` flag to bootstrap a react-app with
125> typescript support
126
127Next, install `react-md` and `node-sass`:
128
129```sh
130$ npm install --save react-md node-sass
131```
132
133Next, create a `src/App.scss` file to include all the `react-md` styles and
134import the `App.scss` file in the `src/App.js`:
135
136```scss
137@import "~react-md/dist/scss/react-md";
138
139// this will include all the styles from react-md
140@include react-md-utils;
141```
142
143```diff
144 import React from 'react';
145 import logo from './logo.svg';
146 import './App.css';
147+import './App.scss';
148```
149
150Finally, update the `public/index.html` to include the `Roboto` font and the
151Material Icons font icons stylesheets from Google fonts:
152
153```diff
154 <meta charset="utf-8" />
155 <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
156 <meta name="viewport" content="width=device-width, initial-scale=1" />
157 <meta name="theme-color" content="#000000" />
158 <!--
159 manifest.json provides metadata used when your web app is installed on a
160 user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
161 -->
162 <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
163+ <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons">
164 <!--
165 Notice the use of %PUBLIC_URL% in the tags above.
166 It will be replaced with the URL of the `public` folder during the build.
167 Only files inside the `public` folder can be referenced from the HTML.
168
169 Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
170 work correctly both with client-side routing and a non-root public URL.
171 Learn how to configure a non-root public URL by running `npm run build`.
172 -->
173 <title>React App</title>
174 </head>
175- <body>
176+ <body class="rmd-typography">
177```
178
179Once you have the styles, fonts, and font icons setup, you can start creating
180components from react-md. It is generally recommended to update your base
181`src/App.js` to include some default configuration components:
182
183```diff
184 import React from 'react';
185-import logo from './logo.svg';
186-import './App.css';
187-import './App.scss';
188-
189-function App() {
190- return (
191- <div className="App">
192- <header className="App-header">
193- <img src={logo} className="App-logo" alt="logo" />
194- <p>
195- Edit <code>src/App.js</code> and save to reload.
196- </p>
197- <a
198- className="App-link"
199- href="https://reactjs.org"
200- target="_blank"
201- rel="noopener noreferrer">
202- Learn React
203- </a>
204- </header>
205- </div>
206- );
207-}
208+import {
209+ Configuration,
210+ Layout,
211+ useLayoutNavigation,
212+ Text,
213+ Button,
214+} from 'react-md';
215+import './App.scss';
216+
217+// see @react-md/layout package for info on the main navigation
218+const routes = {};
219+function App() {
220+ return (
221+ <Configuration>
222+ <Layout
223+ title="My Title"
224+ navHeaderTitle="My Nav Title"
225+ treeProps={...useLayoutNavigation(routes, pathname)}
226+ >
227+ <Text type="headline-4">Hello, world!</Text>
228+ <Button theme="primary">Example button</Button>
229+ </Layout>
230+ </Configuration>
231+ );
232+}
233
234export default App;
235```
236
237More information can be found on the documentation site's page
238[about creating projects](https://react-md.dev/guides/installation)
239
240## Library Size
241
242The base `react-md` package (non-scoped) is the only package that also provides
243pre-built css themes and a UMD bundle. If you are interested in seeing what an
244estimated size for this library, check out the results below:
245
246```sh
247$ yarn dev-utils libsize
248
249The gzipped UMD bundle sizes are:
250 - dist/umd/react-md.production.min.js 86.49 KB
251 - dist/umd/react-md-with-font-icons.production.min.js 196.05 KB
252 - dist/umd/react-md-with-svg-icons.production.min.js 196.03 KB
253
254
255The min and max gzipped CSS bundle sizes are:
256 - dist/css/react-md.grey-deep_orange-200-light.min.css 15.65 KB
257 - dist/css/react-md.indigo-blue-400-dark.min.css 15.71 KB
258```
259
260## Contributing
261
262Please read the [contributing guidelines](./.github/CONTRIBUTING.md) if you
263would like to contribute.
264
265[typescript]: https://www.typescriptlang.org/
266[next.js]: https://nextjs.org/
267[gatsby]: https://www.gatsbyjs.org
268[create-react-app]: https://facebook.github.io/create-react-app