Material UI React Project startup
|
Create your react application project folders and files:
|
npx create-react-app <project_name> |
|
Navigate into your newly created project folder
|
cd <project_name> |
|
Launch VS Code (or preferred IDE) using
code . and press Enter |
|
In your terminal window, install the Material UI package:
|
npm install @material-ui/core |
|
Material UI defines Roboto as the default font. Edit index.html and add the following statement inside your <head> block:
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" /> |
|
Modify the global style sheet index.css and place Roboto in the first position (see below)
|
body { ... font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Oxygen', ... } |
|
Add a link for the FONT Icons. Place it just below the 'Roboto' link
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" /> |
|
Install SVG icons:
|
npm install @material-ui/icons |
import App from './App/App';)import React from 'react'
import { Button as MuiButton, makeStyles } from '@material-ui/core'
const useStyles = makeStyles((theme) => ({
root: {
margin: theme.spacing(0.5)
},
label: {
textTransform: "none"
}
}))
const Input= (props) => {
const { text, size, color, variant, onClick, ...other} = props
const classes = useStyles();
return (
<MuiButton
variant={variant || "contained"}
size={size || "small"}
color={color || "primary"}
onClick={onClick}
{...other}
classes={{ root:classes.root, label:classes.label }}
>
{text}
</MuiButton>
)
}
export default Input
---
`**Example use of this component**`
<Controls.Button
text="Cancel"
onClick={handleCancel}
/>
...other parameter will allow to make use of ALL available properties.import Button from './Button'
import Input from './Input'
import Select from './Select'
const Controls = {
Button,
Input,
Select
}
export default Controls;
---
`**Now in your other components, simply import everything using the following:**`
import Controls from '../../components/controls/Controls';
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.