๐Ÿ’ป My Work/๐ŸŽจ Material Design

[Material Design] Material-UI(MUI)๋กœ react & styled component ์‚ฌ์šฉํ•˜๊ธฐ <๊ธฐ๋ณธ theme์—์„œ ์ปดํฌ๋„ŒํŠธ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•˜๊ธฐ>

Jaeseo Kim 2022. 9. 12. 23:55

๊ธฐ๋ณธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์„ค๋ช…์ž…๋‹ˆ๋‹ค. ๐Ÿ”ฅ

https://avoc-o-d.tistory.com/43

 

[Material Design] Material-UI(MUI)๋กœ react & styled component ์‚ฌ์šฉํ•˜๊ธฐ <๊ธฐ๋ณธ ์ปดํฌ๋„ŒํŠธ ์‚ฌ์šฉํ•˜๊ธฐ>

https://mui.com/material-ui/getting-started/overview/ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ์™ผ์ชฝ ์‚ฌ์ด๋“œ๋ฐ”์—์„œ Components์— ์žˆ์Šต๋‹ˆ๋‹ค. ๐ŸŽ† 00. ์ปดํฌ๋„ŒํŠธ ์‚ฌ์šฉํ•˜๊ธฐ ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฒ„ํŠผ์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ Button ์œผ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. https..

avoc-o-d.tistory.com

 

00. Styled Component


 styled ํ•  ์ปดํฌ๋„ŒํŠธ๋ฅผ import ํ•ฉ๋‹ˆ๋‹ค. (์ €๋Š” ์˜ˆ๋ฅผ ๋“ค์–ด ๋ฒ„ํŠผ์„ import ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!)

๊ทธ๋ฆฌ๊ณ  styled๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด, styled๋ฅผ import ํ•ฉ๋‹ˆ๋‹ค.

import { styled } from "@mui/material/styles";

 

๊ธฐ์กด ๋ฉ”ํ…Œ๋ฆฌ์–ผ ๋””์ž์ธ 2๊ฐ€ ์ž…ํžŒ Button ์ž…๋‹ˆ๋‹ค.

import "./styles.css";
import React from "react";
import Button from "@mui/material/Button";

export default function App() {
  return (
    <div className="App">
      <Button variant="contained">๋กœ๊ทธ์ธ</Button>
    </div>
  );
}

 

์‚ฌ์šฉ์ž๊ฐ€ styled๋ฅผ ์ •์˜ํ•œ Button์ž…๋‹ˆ๋‹ค.

import "./styles.css";
import React from "react";
import { styled } from "@mui/material/styles";
import Button from "@mui/material/Button";

const MyButton = styled(Button)`
  background: linear-gradient(45deg, #fe6b8b 30%, #ff8e53 90%);
  box-shadow: 0 3px 5px 2px rgba(255, 105, 135, 0.3);
  font-family: "Noto Sans KR";
`;

export default function App() {
  return (
    <div className="App">
      <MyButton variant="contained">๋กœ๊ทธ์ธ</MyButton>
    </div>
  );
}

 

01. sx parameter (MUI ๊ฐ€์ด๋“œ)


mui ๊ฐ€์ด๋“œ์— ๋‚˜์˜จ ๊ฒƒ์ฒ˜๋Ÿผ sx ์ธ์ž๋ฅผ ๋ณด๋‚ด์„œ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

import "./styles.css";
import React from "react";
import Button from "@mui/material/Button";

export default function App() {
  return (
    <div className="App">
      <Button variant="contained" sx={{ height: 100 }}>๋กœ๊ทธ์ธ</Button>
    </div>
  );
}

 ์ด๊ฒƒ๋„ ๋‹น์—ฐํžˆ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค!

import "./styles.css";
import React from "react";
import { styled } from "@mui/material/styles";
import Button from "@mui/material/Button";

const MyButton = styled(Button)`
  background: linear-gradient(45deg, #fe6b8b 30%, #ff8e53 90%);
  box-shadow: 0 3px 5px 2px rgba(255, 105, 135, 0.3);
  font-family: "Noto Sans KR";
`;

export default function App() {
  return (
    <div className="App">
      <MyButton variant="contained" sx={{ height: 100 }}>
        ๋กœ๊ทธ์ธ
      </MyButton>
    </div>
  );
}

 

 

๐Ÿ“Œ ํ˜„์žฌ๋Š” ๊ธฐ๋ณธ๊ฐ’์ธ theme์—์„œ styled๋ฅผ ํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ์ง€๋งŒ, ๋‹ค์Œ์€ theme๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•˜๋Š” ๋ฒ•์— ๋Œ€ํ•ด ๊ธฐ์ˆ ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.