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

[Material Design] Material-UI(MUI)๋กœ react & styled component ์‚ฌ์šฉํ•˜๊ธฐ <๋ ˆ๋ฒจ๋ฐ”, ์ง„ํ–‰๋ฐ”, Progressbar, Levelbar>

Jaeseo Kim 2022. 10. 8. 23:40

 

https://mui.com/material-ui/react-progress/

 

Circular, Linear progress React components - Material UI

Progress indicators commonly known as spinners, express an unspecified wait time or display the length of a process.

mui.com

์ง„ํ–‰๋ฐ”๋ฅผ ์‚ฌ์šฉํ•ด์„œ, ๋ ˆ๋ฒจ๋ฐ”๋ฅผ ๊ตฌํ˜„ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

 

 

00. Linear progress


๋ณธ๋ชจ์Šต์€ ์›๋ž˜ ์ด๋ ‡๊ฒŒ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค.

 

 

 

01. Linear progress Customization


mui์—์„œ ๋‚˜์˜จ ๊ฒƒ์ฒ˜๋Ÿผ, ์ด์™€ ๊ฐ™์ด ์ปค์Šคํ…€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

import { styled } from '@mui/material/styles';
import CircularProgress, {
  circularProgressClasses,
  CircularProgressProps,
} from '@mui/material/CircularProgress';
import LinearProgress, { linearProgressClasses } from '@mui/material/LinearProgress';

const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({
  height: 10,
  borderRadius: 5,
  [`&.${linearProgressClasses.colorPrimary}`]: {
    backgroundColor: theme.palette.grey[theme.palette.mode === 'light' ? 200 : 800],
  },
  [`& .${linearProgressClasses.bar}`]: {
    borderRadius: 5,
    backgroundColor: theme.palette.mode === 'light' ? '#1a90ff' : '#308fe8',
  },
}));

์ด ์ฝ”๋“œ๋Š” dark, light ๋ชจ๋“œ๋ฅผ ์ง€์›ํ•˜๋Š๋ผ theme.palette.mode === 'light' ๋ฅผ ์ž‘์„ฑํ•œ ๊ฒƒ์œผ๋กœ...

 

 

์ด๊ฒƒ๋„! ์ข‹์ง€๋งŒ,, ์ €๋Š” ๊ฒŒ์ž„ ํšจ๊ณผ๊ฐ€ ๋‚˜๋Š”! ๋ฐ‹๋ฐ‹๊ณผ ์‹ฌํ”Œ๋ณด๋‹จ ์ข€ ๋” ์บ๋ฆญํ„ฐ์Šค๋Ÿฌ์šด ๋ ˆ๋ฒจ๋ฐ”๊ฐ€ ์ข‹๊ธฐ ๋•Œ๋ฌธ์—

์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

 

02. Level Bar


/** Level Progress Bar */
  const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({
    height: "2.4rem",
    borderRadius: "100rem",
    [`&.${linearProgressClasses.colorPrimary}`]: {
      backgroundColor: theme.palette.grey[300],
      boxShadow: "0 1px 2px #999 inset, 0 1px #ffffff",
    },
    [`& .${linearProgressClasses.bar}`]: {
      borderRadius: "100rem",
      backgroundColor: "#C8F2A7",
      boxShadow: "0px -3px 0px 9px #76D22D inset",
      width: "50%", // xp ๊ฐ’์— ๋”ฐ๋ผ ์–˜๋ฅผ ์กฐ์ ˆํ•˜๊ธฐ
    },
  }));
  
  const levelProgressBar = (
    <Box>
      <BorderLinearProgress variant="determinate" value={100} />
    </Box>
  );

์ฃผ์˜ ํ•˜์‹ค ์ ์€ <BorderLinearProgress variant="determinate" value={100} />์—์„œ 100์œผ๋กœ ํ•ด๋†“๋Š” ์ด์œ ๊ฐ€

์•„๋ž˜์™€ ๊ฐ™์ด, ์„ ํƒํ•œ ๋ถ€๋ถ„์„ ์–ผ๋งŒํผ ์ˆจ๊ธฐ์ง€ ์•Š๊ณ  ๋ณด์—ฌ์ค„ ๊ฒƒ์ธ๊ฐ€์ด๊ธฐ ๋•Œ๋ฌธ์— 100์œผ๋กœ ํ•œ ๊ฒ๋‹ˆ๋‹ค!

์ฝ”๋“œ ์ง์ ‘ ์ˆ˜์ •ํ•˜์‹œ๋ฉด์„œ ์•„์‹ค ์ˆ˜ ์žˆ์„ ๊ฑฐ์—์š”! ๐Ÿ˜๐Ÿ˜

๊ทธ๋ฆฌ๊ณ  XP ๊ฐ’์— ๋”ฐ๋ผ ๋ฐ”๋€” ๋ฐ”์˜ ๊ธธ์ด๋Š” linearProgressClasses.bar์˜ width๋ฅผ ํ†ตํ•ด ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์ฃ โœจโœจ

 

์œ„ ์ฝ”๋“œ๋Š”, ์ œ๊ฐ€ ์ง์ ‘ ํ•˜๋‚˜ํ•˜๋‚˜ ํ•ด๋ณด๋ฉด์„œ ๊ตฌํ˜„ํ•œ ๊ฑฐ๋ผ์„œ ๋ณธ์ธ์˜ ์ปดํฌ๋„ŒํŠธ์— ๋งž๊ฒŒ ์ฐธ๊ณ ํ•˜์…”์„œ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~!

 

์š”์ƒˆ ๋‚ ์”จ๊ฐ€ ๋„ˆ๋ฌด ์ข‹์•„์„œ ์ข‹์Œ๐ŸŒž๐ŸŒž๐ŸŒž