๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐Ÿ–ฅ dev-ruby

[๋ฆฌ์•กํŠธ]Material UI ์ปดํฌ๋„ŒํŠธ์— Css Style ์ ์šฉํ•˜๊ธฐ - ๋‚˜๋งŒ์˜ ์ปดํฌ๋„ŒํŠธ ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

React

[๋ฆฌ์•กํŠธ]Material UI ์ปดํฌ๋„ŒํŠธ์— Css Style ์ ์šฉํ•˜๊ธฐ - ๋‚˜๋งŒ์˜ ์ปดํฌ๋„ŒํŠธ ๋งŒ๋“ค๊ธฐ

ruby_s 2021. 12. 1. 02:24
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://mui.com/styles/basics/

 

@mui/styles - MUI

The legacy styling solution of MUI.

mui.com

 

meterial ui์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” styles api๊ฐ€ ๋”ฐ๋กœ ์žˆ๋‹ค.

๋จผ์ €, ์„ค์น˜๋ฅผ ํ•ด์ค€๋‹ค.

npm install @mui/styles

 

react hook์—์„œ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•œ๋‹ค.

import * as React from 'react';
import { makeStyles } from '@mui/styles';
import Button from '@mui/material/Button';

const useStyles = makeStyles({
  root: {
    background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
    border: 0,
    borderRadius: 3,
    boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
    color: 'white',
    height: 48,
    padding: '0 30px',
  },
});

export default function Hook() {
  const classes = useStyles();
  return <Button className={classes.root}>Hook</Button>;
}

const useStyles์ฒ˜๋Ÿผ ์Šคํƒ€์ผ ํ•จ์ˆ˜๋ฅผ ๋”ฐ๋กœ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

 

makeStyles์•ˆ์— root์ฒ˜๋Ÿผ, container gnb ๋“ฑ๋“ฑ ํด๋ž˜์Šค์˜ ์ด๋ฆ„ ์•ˆ์— ๊ฐ์ฒด ํ˜•์‹์œผ๋กœ css๋ฅผ ์ž‘์„ฑํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

์Šคํƒ€์ผ์„ ์ƒ์„ฑํ–ˆ์œผ๋ฉด, ํ•จ์ˆ˜ ์•ˆ์—์„œ ๋ณ€์ˆ˜์— useStylesํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ํƒœ๊ทธ์˜ className์— ์ ์šฉ์‹œ์ผœ์ฃผ๋ฉด ์›ํ•˜๋Š” ๋””์ž์ธ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค~

 

728x90
๋ฐ˜์‘ํ˜•
LIST