项目作者: mlaursen

项目描述 :
React material design - An accessible React component library built from the Material Design guidelines in Sass
高级语言: TypeScript
项目地址: git://github.com/mlaursen/react-md.git
创建时间: 2015-11-23T19:39:04Z
项目社区:https://github.com/mlaursen/react-md

开源协议:MIT License

下载


react-md license codecov Actions Status

npm
downloads
Join the Chat at Slack
Donate

Create an accessible React application with the
material design specifications and Scss.

Highlights/Features

  • Matches the accessibility guidelines from
    www.w3.org
  • Low level customizable components
  • Easily themeable on a global and component level
  • Uses css variables for dynamic themes with fallbacks for older browsers
  • Out of the box dark theme mode support
  • Out of the box left-to-right and right-to-left language support
  • UMD Bundles and pre-compiled css available on https://unpkg.com (see more
    information here)
  • Written and maintained in Typescript

Creating a new project

Check out the examples folder to see completed examples with
different build tools such as Next.js, Gatsby, and create-react-app.

First use create-react-app to create your project:

  1. npx create-react-app my-app
  2. cd my-app
  3. npm start

npx comes with npm 5.2+ and higher, if you have an older version you will need
to install create-react-app globally instead

Or with yarn:

  1. yarn create react-app my-app
  2. cd my-app

NOTE: You can also add the --typescript flag to bootstrap a react-app with
typescript support

Next, install react-md and sass:

  1. npm install --save react-md sass

Next, create a src/App.scss file to include all the react-md styles and
import the App.scss file in the src/App.js:

  1. @use "react-md" as *;
  2. // this will include all the styles from react-md
  3. @include react-md-utils;
  1. +import './App.scss';
  2. import logo from './logo.svg';
  3. import './App.css';

Finally, update the public/index.html to include the Roboto font and the
Material Icons font icons stylesheets from Google fonts:

  1. <meta charset="utf-8" />
  2. <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
  3. <meta name="viewport" content="width=device-width, initial-scale=1" />
  4. <meta name="theme-color" content="#000000" />
  5. <!--
  6. manifest.json provides metadata used when your web app is installed on a
  7. user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
  8. -->
  9. <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
  10. + <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons">
  11. <!--
  12. Notice the use of %PUBLIC_URL% in the tags above.
  13. It will be replaced with the URL of the `public` folder during the build.
  14. Only files inside the `public` folder can be referenced from the HTML.
  15. Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
  16. work correctly both with client-side routing and a non-root public URL.
  17. Learn how to configure a non-root public URL by running `npm run build`.
  18. -->
  19. <title>React App</title>
  20. </head>
  21. - <body>
  22. + <body class="rmd-typography">

Once you have the styles, fonts, and font icons setup, you can start creating
components from react-md. It is generally recommended to update your base
src/App.js to include some default configuration components:

  1. import './App.scss';
  2. -import logo from './logo.svg';
  3. -import './App.css';
  4. -
  5. -function App() {
  6. - return (
  7. - <div className="App">
  8. - <header className="App-header">
  9. - <img src={logo} className="App-logo" alt="logo" />
  10. - <p>
  11. - Edit <code>src/App.js</code> and save to reload.
  12. - </p>
  13. - <a
  14. - className="App-link"
  15. - href="https://reactjs.org"
  16. - target="_blank"
  17. - rel="noopener noreferrer">
  18. - Learn React
  19. - </a>
  20. - </header>
  21. - </div>
  22. - );
  23. -}
  24. +import {
  25. + Configuration,
  26. + Layout,
  27. + useLayoutNavigation,
  28. + Typography,
  29. + Button,
  30. +} from 'react-md';
  31. +
  32. +// see @react-md/layout package for info on the main navigation
  33. +const routes = {};
  34. +function App() {
  35. + return (
  36. + <Configuration>
  37. + <Layout
  38. + title="My Title"
  39. + navHeaderTitle="My Nav Title"
  40. + treeProps={...useLayoutNavigation(routes, pathname)}
  41. + >
  42. + <Typography type="headline-4">Hello, world!</Typography>
  43. + <Button theme="primary">Example button</Button>
  44. + </Layout>
  45. + </Configuration>
  46. + );
  47. +}
  48. export default App;

More information can be found on the documentation site’s page
about creating projects

Library Size

The base react-md package (non-scoped) is the only package that also provides
pre-built css themes and a UMD bundle. If you are interested in seeing what an
estimated size for this library, check out the results below:

  1. yarn dev-utils libsize
  2. The gzipped UMD bundle sizes are:
  3. - dist/umd/react-md.production.min.js 92.51 kB
  4. - dist/umd/react-md-with-font-icons.production.min.js 211.46 kB
  5. - dist/umd/react-md-with-svg-icons.production.min.js 211.5 kB
  6. The min and max gzipped CSS bundle sizes are:
  7. - themes/react-md.grey-red-700-light.min.css 18.08 kB
  8. - themes/react-md.lime-teal-200-dark.min.css 18.15 kB

Contributing

Please read the contributing guidelines if you
would like to contribute.