Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use material-ui framework? [closed]

I'm planning to use Material-UI CSS framework (http://material-ui.com) in order to design front-end of a website, but I don't have any idea about how to use this framework.

I'm not familiar a lot with NPM, Browserify, etc. I just need to know how shall I start in order to learn the way to use this CSS framework.

Thanks for any help!

like image 376
jmosawy Avatar asked Mar 22 '15 14:03

jmosawy


People also ask

How do I use material UI offline?

After a file has been downloaded, indicate that it's available offline by displaying the offline pin icon. After a file has been downloaded, indicate that it's available offline by displaying the offline pin icon. The download and offline pin icons are available in the Material icon library.

Can I use material UI without React?

No, you cannot use Material-UI without React. Material-UI is a library of React components.

How do I run a material interface?

We must install the Material-UI to access its different functionalities or components. Open your terminal, and ensure that you are inside your application's master folder. Type npm install @material-ui/core in the terminal and click enter. Run the command below to use Material-UI icons in our project.

How do I start material UI in React?

First, create a new react application, react-materialui-app using Create React App or Rollup bundler by following instruction in Creating a React application chapter. Next, open the application in your favorite editor. Next, create src folder under the root directory of the application.


3 Answers

Don't be intimidated by the (apparent) complexity of webpack and other (great) build tools, and don't be discouraged by envious jerks who say things like "To be honest, I think you got a big problem to use this stuff."

The reason why the material-ui implementation (usage) is based on these tools is because is currently the best way to write software and understanding this and other frameworks is a great way to learn why this is the "right" way, and become proficient at writing quality modular code.

Webpack, and the other build tools, exist for one purpose: to create one "main" file from your app's source code that can be read and delivered to your users' browser in an efficient manner. Long gone are the days when we would write a bunch of include (script) tags for every resource (file) we need in our pages and thus have our users wait until all these were downloaded from our server (or multiple locations e.g.: cdns) and then the page would load. The efficiency is based on the fact that you can deliver one (often minified/compressed) file that contains all your code and any code it depends on (e.g. React or even jQuery).

Build tools accomplish this by asking you 3 things: what file to start with (entry main file), what tools (loaders) to use to process non-native JavaScript code within your code (scss, jsx, etc) and what file to create as the result (converted and minified output). This output file will be the one you use in your html import/script tag. It will contain your code plus all other dependencies, which would be a nightmare to include and resolve manually yourself. Here is a good beginners' guide.

Material-ui, like many other frameworks (reason why I took the time to explain all of the above) is built with modularity in mind: pieces of code can be "glued" or "pieced" together like Legos, in order to easily build bigger parts. You do this by simply including the components you need in any component you create. They are React components which are a simple way to define (write/create) the "building blocks" of your site/app. There are tons of great videos and tutorials to get you started with React (my favorite is reactjsprogram.com by Tyler McGinnis).

To get you started with material-ui, they have created a couple of examples to get started using webpack. Follow the simple steps to install npm and the dependencies (you can find them in package.json) and open the /src directory in your editor. You'll figure it out in no time.

You are in the right track with the right attitude by asking questions, learning to be a good developer, researching and trying to find the easiest way to accomplish your goal.

like image 91
acyuta108 Avatar answered Oct 07 '22 01:10

acyuta108


Had pretty much the same problem. Wanted a simple way to start using material-ui without the gibberish. Here's what I did:

npm install material-ui
npm install -g webpack
webpack node_modules/material-ui/lib/index.js material-ui.js

This gave me a javascript file, material-ui.js, I could then include in my HTML. In my case I'm using electron, so this is my HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>examples</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
    <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
</head>
<body>
    <div id="content"></div>

    <script>
        require('./material-ui.js')
    </script>

    <script type="text/babel">      
        import React from 'react';
        import FlatButton from 'material-ui/lib/flat-button';


        const FlatButtonExampleSimple = () => (
          <div>
            <FlatButton label="Default" />
            <FlatButton label="Primary" primary={true} />
            <FlatButton label="Secondary" secondary={true} />
            <FlatButton label="Disabled" disabled={true} />
          </div>
        );      

        ReactDOM.render(
          <FlatButtonExampleSimple />,
          document.getElementById('content')
        );
    </script>
</body>
</html>
like image 24
dkantowitz Avatar answered Oct 06 '22 23:10

dkantowitz


Material-UI is a set of React components in addition to being a CSS framework. I don't know if you can get much use out of it without understanding React.

The easiest way to get started is to install the examples and start from there.

If you don't want to deal with a frontend framework like React, and just want CSS and JS files with a setup time as quick as Bootstrap, check out the Materialize library.

like image 11
clay_to_n Avatar answered Oct 07 '22 01:10

clay_to_n