[ToyProject-Todomate] ํˆฌ๋‘๋ฉ”์ดํŠธ ํด๋ก  ํ”„๋กœ์ ํŠธ 05

2021. 12. 8. 00:33ใ†WEB Dev/ToyProject

728x90


๐Ÿ”ท CloneTodo โ˜‘ - Todomate Clone Project  |  Team CloneMate

 

CloneTodo : ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ์‚ฌ๋ž‘ํ•˜๋Š” ํˆฌ๋‘๋ฉ”์ดํŠธ๋ฅผ ํด๋ก ํ•˜์—ฌ ์›น ์„œ๋น„์Šค๋ฅผ ๋ฐฐํฌํ•ด๋ณด๋Š” ํ”„๋กœ์ ํŠธ

 


์–ด์ œ๋Š” ํด๋”ํŠธ๋ฆฌ๋ฅผ ๊ทธ๋ ค๋ณด์•˜๊ณ  ์˜ค๋Š˜์€ MUI ์‹ค์Šต์„ ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. 

 

'์ฝ”๋“œ์— ๋น ์ง€๋‹ค' ๋ผ๋Š” ๋ธ”๋กœ๊ทธ์—์„œ ์ข‹์€ ์‹ค์Šต ์ž๋ฃŒ๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผํ•˜๋ฉด์„œ ์ด๊ฒƒ ์ €๊ฒƒ ์ปดํฌ๋„ŒํŠธ๋ฅผ UI๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ์‚ฝ์ž…ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

์ด๋ฒˆ ์—ฐ์Šต์€ ๋ฆฌ์•กํŠธ ๊ฐ•์˜๋ฅผ ๋“ค์—ˆ๋˜ ์ฝ”๋”ฉ์• ํ”Œ ์‹ค์ŠตํŒŒ์ผ์— MUI๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ์ด๊ฒƒ์ €๊ฒƒ ์งœ๋ณด๋ ค๊ณ  ํ•˜๋Š”๋ฐ

์™œ๋ƒ

๊นƒํ—ˆ๋ธŒ ์ž”๋””๋ฅผ ํ•˜๋‚˜๋ผ๋„ ๋” ์ฑ„์›Œ์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—..!

 

 

๐Ÿ”ธ MUI Material-UI๋ž€?

 

๋ฆฌ์•กํŠธ์—๋„ ์ธ์ง€๋„๊ฐ€ ๋†’์€ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์ง€๋งŒ ์š”์ฆ˜์—” Material-UI ๋ผ๊ณ  ํŒ€์›๋ถ„๋“ค์ด ํ•˜์…”์„œ ์ฒ˜์Œ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค. ์—ญ์‹œ UI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ์œ ํ–‰์ด ๋นจ๋ฆฌ์ง€๋‚œ๋‹ค. ์ž‘๋…„์—๋งŒ ํ•ด๋„ ๋‹น์—ฐํžˆ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์“ด๋‹ค๊ณ  ๋ฐฐ์› ๋Š”๋ฐ ^^

 

Material-UI๋Š” ์„ธ๊ณ„์—์„œ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” ๋ฆฌ์•กํŠธ UI ํ”„๋ ˆ์ž„์›Œํฌ๋ผ๊ณ  ํ•œ๋‹ค. 

 

์šฐ๋ฆฌ๊ฐ€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋‹ค๊ฐ€ ์ž˜ ๋ชจ๋ฅด๋Š” ๋ถ€๋ถ„์„ ๊ตฌ๊ธ€๋งํ•ด์„œ ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ๋ธ”๋กœ๊ทธ์—์„œ ์ฝ”๋“œ ํ•œ ๋ถ€๋ถ„์„ ๋ณต์‚ฌ-๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•˜๋Š” ๊ฒƒ ์ฒ˜๋Ÿผ ๋ฏธ๋ฆฌ ๋””์ž์ธํ•ด ๋งŒ๋“ค์–ด ๋‘” ๋‹ค์–‘ํ•œ ๋ฒ„ํŠผ, ํ…Œ์ด๋ธ”, ๋ฐฐ๋„ˆ ๋“ฑ์˜ ์ฝ”๋“œ๋ฅผ ๋š ๋–ผ์™€์„œ ๋‚ด ์ฝ”๋“œ ์•ˆ์— ๋ถ™์—ฌ ๋„ฃ์–ด ๋งŒ๋“œ๋Š” ๊ฒƒ์ด UI๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค. 

 

 

 

๋‹ค ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”..

 

 

npm ํŒจํ‚ค์ง€๋‚˜ yarn์œผ๋กœ ์„ค์น˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

styled-components์—์„œ๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ์ด๋ฒˆ์—๋Š” npm์œผ๋กœ ์„ค์น˜ํ•ด์„œ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ž„ํฌํŠธํ•ด์„œ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•œ๋‹ค.

 

 

 

Installation - MUI

Install MUI, the world's most popular React UI framework.

mui.com

 

 

๐Ÿ”ธ MUI Material-UI ์„ค์น˜ํ•˜๊ธฐ

 

๋จผ์ € MUI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

// with npm
npm install @mui/material @emotion/react @emotion/styled

// with yarn
yarn add @mui/material @emotion/react @emotion/styled

 

๋‚˜๋Š” npm์„ ์ฃผ๋กœ ์ด์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— npm ๋ช…๋ น์–ด๋ฅผ ํ„ฐ๋ฏธ๋„์— ๋ถ™์—ฌ๋„ฃ์–ด ์„ค์น˜ํ–ˆ๋‹ค. (CDN๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.)

๊ทธ๋ฆฌ๊ณ  Roboto ๊ธ€๊ผด๊ณผ ์•„์ด์ฝ˜๋“ค์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๊ณต์‹๋ฌธ์„œ๊ฐ€ ์ œ์•ˆํ•˜๋Š”๋Œ€๋กœ link ํƒœ๊ทธ๋ฅผ public>index.html์— ์ถ”๊ฐ€ํ–ˆ๋‹ค.

 

<!-- Roboto -->
<link
  rel="stylesheet"
  href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>

<!-- Material Icons -->
<link
  rel="stylesheet"
  href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
// with npm
npm install @mui/icons-material

// with yarn
yarn add @mui/icons-material

 

์—ฌ๊ธฐ์„œ ๋ถ™์—ฌ๋„ฃ๊ฒŒ ๋  ์ปดํฌ๋„ŒํŠธ๋Š” ๊ฐ๊ฐ API(์‚ฌ์šฉํ•  ๋•Œ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋Š” ์กฐ๊ฑด๋“ค)์„ ์ œ๊ณตํ•˜๋Š”๋ฐ props๋‚˜ className, attr๋กœ ๊ฐ’์„ ๋„˜๊ฒจ์ค„ ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  CSS๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ MUI์—์„œ ์ œ๊ณตํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”๋ฐ ์ด๋ฅผ ์œ„ํ•ด์„œ ๋ณ„๋„์˜ ํŒจํ‚ค์ง€๋ฅผ ํ•˜๋‚˜ ๋” ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

 

// with npm
npm install @mui/styles

// with yarn
yarn add @mui/styles

 

import ํ•  ๋•Œ { makeStyles }๋ฅผ @mui/styles์—์„œ import ํ•ด์ค€๋‹ค. 

๊ธฐ๋ณธ CSS๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ์ฒ˜๋Ÿผ reset.css๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด CssBaseline ํŒจํ‚ค์ง€๋ฅผ import ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

 

import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';

export default function MyApp() {
  return (
    <React.Fragment>
      <CssBaseline />
      {/* The rest of your application */}
    </React.Fragment>
  );
}

 

 

 

๐Ÿ”ธ MUI Material-UI ์‚ฌ์šฉํ•˜๊ธฐ

 

๋ณ„ ๋ฌธ์ œ ์—†์ด ์„ค์น˜๋˜์—ˆ๋‹ค๋ฉด ์ฒ˜์Œ์œผ๋กœ ํ™”๋ฉด์— ๋ฒ„ํŠผ ํ•˜๋‚˜๋ฅผ ๋„์›Œ๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

App.js์˜ ๋‚ด๋ถ€๋ฅผ ๊น”๋”ํ•˜๊ฒŒ ์ง€์›Œ๋ฒ„๋ฆฌ๊ณ  npm start๋กœ ํ™”๋ฉด์„ ๋ธŒ๋ผ์šฐ์ €์— ๋„์šด๋‹ค.

 

 

import React from "react";
import './App.css';

function App() {
  return
}

export default App;

 

์ด ์ƒํƒœ์—์„œ๋Š” ์•„๋ฌด๊ฒƒ๋„ ์—†๋Š” ๋นˆ ํ™”๋ฉด์ด ๋“ฑ์žฅํ•˜๋Š”๋ฐ Button UI ์˜ˆ์ œ๋ฅผ ๋”ฐ๋ผํ•˜๊ธฐ ์œ„ํ•ด MUI๋ฅผ import ํ•œ๋‹ค.

Button ์ด๋ผ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์“ฐ๊ธฐ ์œ„ํ•ด์„œ๋Š” MUI-Button์˜ Button ์ปดํฌ๋„ŒํŠธ๋ฅผ importํ•ด์ค˜์•ผ ํ•œ๋‹ค.

 

 

import * as React from "react";
import ReactDOM from "react-dom";
import Button from "@mui/material/Button";
import CssBaseline from "@mui/material/CssBaseline";

 

์•„๋ž˜ ์ปดํฌ๋„ŒํŠธ๊นŒ์ง€ ์ž…๋ ฅํ•˜๋ฉด ์ด๋ ‡๊ฒŒ ๋œ๋‹ค.

 

 

import * as React from "react";
import ReactDOM from "react-dom";
import Button from "@mui/material/Button";
import CssBaseline from "@mui/material/CssBaseline";

function App() {
  return (
    <React.Fragment>
      <CssBaseline />
      <Button variant="contained">Hello World</Button>
    </React.Fragment>
  );
}

export default App;

์ด๋Ÿฐ ๋ฒ„ํŠผ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์™„์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

props ๋กœ ๋“ค์–ด๊ฐ„ variant๋Š” ๋ฒ„ํŠผ์˜ ์ข…๋ฅ˜(๋””์ž์ธ)์ธ๋ฐ ์•„๋ž˜์™€ ๊ฐ™์ด Text, Contained, Outlined ์„ธ ๊ฐ€์ง€์˜ ์กฐ๊ฑด์ด ์ œ๊ณต๋œ๋‹ค.

 

์œ„์™€ ๊ฐ™์ด ๋งŒ๋“  ๋ฒ„ํŠผ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ณ„๋„๋กœ ์„ธ์„ธํ•˜๊ฒŒ ์ˆ˜์ •ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด makeStyles ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

(์ด ๋ฐฉ์‹์€ ๋ฆฌ์•กํŠธ V5 ์—์„œ๋ถ€ํ„ฐ ๋ ˆ๊ฑฐ์‹œ๊ฐ€ ๋˜์—ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ˜ญ)

 

 

 

๋‚ด์ผ์€ MUI์—์„œ ์„ธ๋ถ€ CSS๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ฒ•๊ณผ (๊ทธ๋ƒฅ SCSS ์ ์šฉํ•ด๋„ ๋˜๋‚˜? ํ…Œ์ŠคํŠธํ•ด๋ณด๋‹ˆ App.css์— !important๋กœ ๋ฐ€์–ด๋„ฃ์–ด๋„ ๋ฌธ์ œ์—†์ด ์ ์šฉ๋˜์—ˆ๋‹ค.) ๋ฉ”์ธ ํ™”๋ฉด ์ค‘ ๋กœ๊ทธ์ธ ํ™”๋ฉด์„ ์ปดํฌ๋„ŒํŠธ๋กœ ์งœ๋ด์•ผ๊ฒ ๋‹ค.

 

 

 

 

Material UI ์Šคํƒ€์ผ๋ง

Engineering Blog by Dale Seo

www.daleseo.com

 

 

MUI: A popular React UI framework

MUI is a simple and customizable component library to build faster, beautiful, and more accessible React applications. Follow your own design system, or start with Material Design.

mui.com

 

728x90