Skip to content

Instantly share code, notes, and snippets.

@aidiary
Created October 1, 2021 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aidiary/0aa88f675c4cd911aa4d72f67e5d5f1a to your computer and use it in GitHub Desktop.
Save aidiary/0aa88f675c4cd911aa4d72f67e5d5f1a to your computer and use it in GitHub Desktop.
MUI tutorial
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import Button from "@mui/material/Button";
import ButtonGroup from "@mui/material/ButtonGroup";
import SaveIcon from "@mui/icons-material/Save";
import DeleteIcon from "@mui/icons-material/Delete";
import Checkbox from "@mui/material/Checkbox";
import FormControlLabel from "@mui/material/FormControlLabel";
import TextField from "@mui/material/TextField";
import { styled, ThemeProvider, createTheme } from "@mui/material/styles";
import { green, orange } from "@mui/material/colors";
import "@fontsource/roboto";
import Typography from "@mui/material/Typography";
import Container from "@mui/material/Container";
import Paper from "@mui/material/Paper";
import Grid from "@mui/material/Grid";
import AppBar from "@mui/material/AppBar";
import ToolBar from "@mui/material/Toolbar";
import IconButton from "@mui/material/IconButton";
import MenuIcon from "@mui/icons-material/Menu";
const ButtonStyled = styled(Button)({
background: "linear-gradient(45deg, #FE6B8B, #FF8E53)",
border: 0,
marginBottom: 15,
borderRadius: 15,
color: "white",
padding: "5px 30px",
});
const theme = createTheme({
typography: {
h2: {
fontSize: 84,
marginBottom: 20,
},
},
palette: {
primary: {
main: green[400],
},
secondary: {
main: orange[400],
},
},
});
function CheckboxExample() {
const [checked, setChecked] = React.useState(true);
return (
<div>
<FormControlLabel
control={
<Checkbox
checked={checked}
icon={<DeleteIcon />}
checkedIcon={<SaveIcon />}
onChange={(e) => setChecked(e.target.checked)}
inputProps={{ "aria-label": "secondary checkbox" }}
/>
}
label="Testing Checkbox"
/>
</div>
);
}
function App() {
return (
<ThemeProvider theme={theme}>
<Container maxWidth="lg">
<div className="App">
<header className="App-header">
<AppBar color="secondary">
<ToolBar>
<IconButton>
<MenuIcon />
</IconButton>
<Typography variant="h6">MUI Themeing</Typography>
<Button>Login</Button>
</ToolBar>
</AppBar>
<Typography variant="h2">Welcome to MUI</Typography>
<Typography variant="subtitle1">
Learn how to use Material UI
</Typography>
<ButtonStyled>TEST STYLED BUTTON</ButtonStyled>
<Grid container spacing={2} justifyContent="center">
<Grid item xs={3} sm={6}>
<Paper style={{ height: 75, width: "100%" }} />
</Grid>
<Grid item xs={3}>
<Paper style={{ height: 75, width: "100%" }} />
</Grid>
<Grid item xs={3} lg={12}>
<Paper style={{ height: 75, width: "100%" }} />
</Grid>
</Grid>
<TextField
variant="filled"
color="secondary"
type="email"
label="Email"
placeholder="test@test.com"
/>
<CheckboxExample />
<ButtonGroup variant="contained" color="primary">
<Button startIcon={<SaveIcon />}>Save</Button>
<Button startIcon={<DeleteIcon />}>Discard</Button>
</ButtonGroup>
<img src={logo} className="App-logo" alt="logo" />
</header>
</div>
</Container>
</ThemeProvider>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment