Material UI
1. Material UI
- https://m3.material.io/
- 구글이 2014년 안드로이드 스마트폰에 적용하면서 알려짐
- 구글이 선도하는 디자인 시스템이라 업데이트가 자주 이루어지고 체계적임
- https://mui.com/core/
- 각종 테마들
2. 예제 1 : 기본 사용법
shellscript
1npm install @mui/material @emotion/react @emotion/styled # 기본 설치2npm install @mui/icons-material # Icons
2.1 index.html
index.html에 다음 link 태그 추가
html
1<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />2<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
- 각각 Roboto font, Icons
2.2 App.js
jsx
1// Webpack CSS import2// import 'onsenui/css/onsenui.css';3// import 'onsenui/css/onsen-css-components.css';4// import OnesenUIExample from './components/OnsenUI/OnesenUIExample';5// import AntDesignExample from './components/AntDesign/AntDesignExample';6// import 'semantic-ui-css/semantic.min.css';7// import ReactSemanticUIExample from './components/ReactSemanticUI/ReactSemanticUIExample';8// import 'bootstrap/dist/css/bootstrap.min.css';9// import ReactBootstrapExample from './components/ReactBootstrap/ReactBootstrapExample';10import MaterialUIExample from './components/MaterialUI/MaterialUIExample'1112export default function App() {13return (14<>15<MaterialUIExample />16{/* <ReactBootstrapExample /> */}17{/* <ReactSemanticUIExample /> */}18{/* <AntDesignExample /> */}19{/* <OnesenUIExample /> */}20</>21)22}
2.3 ButtonExample
jsx
1import Button from '@mui/material/Button'23export default function ButtonExample() {4return <Button variant="contained">Hello World</Button>5}
2.4 MaterialUIExample
jsx
1import ButtonExample from './ButtonExample'23export default function MaterialUIExample() {4return (5<div>6<ButtonExample />7</div>8)9}
3. 공식 사이트 CRA 예제
- https://github.com/mui/material-ui/tree/master/examples/create-react-app
- 위 Github를 clone(복제)하거나 Zip으로 다운받아 만들어놓은 예제를 볼 수 있다.
- 아니면 공식 사이트에 예제별로 Code SandBox가 잘 되어 있다.
4. 예제3 : Grid
jsx
1import * as React from 'react'2import { styled } from '@mui/material/styles'3import Box from '@mui/material/Box'4import Paper from '@mui/material/Paper'5import Grid from '@mui/material/Grid'67const Item = styled(Paper)(({ theme }) => ({8backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',9...theme.typography.body2,10padding: theme.spacing(1),11textAlign: 'center',12color: theme.palette.text.secondary,13}))1415export default function BasicGrid() {16return (17<Box sx={{ flexGrow: 1 }}>18<Grid container spacing={2}>19<Grid item xs={8}>20<Item>xs=8</Item>21</Grid>22<Grid item xs={4}>23<Item>xs=4</Item>24</Grid>25<Grid item xs={4}>26<Item>xs=4</Item>27</Grid>28<Grid item xs={8}>29<Item>xs=8</Item>30</Grid>31</Grid>32</Box>33)34}
MaterialUIExample에 추가