๋ฐ์ํ์ ์ํ breakpoint ์ ๋๋ค.
์ผ์ ๋๋น ์ด์ ํน์ ์ดํ๊ฐ ๋์ ๋, ์ปดํฌ๋ํธ์ ์์ฑ์ ๋ฐ๊พธ์ด ํ๋ฉด์ ๋ง๊ฒ ์กฐ์ ํ๋ ๊ฒ์ด์ฃ !
์ด๋์ ์ผ์ ๋๋น๊ฐ breakpoint ์ธ ๊ฒ์ ๋๋ค. ๐
https://mui.com/material-ui/customization/breakpoints/
Breakpoints - Material UI
API that enables the use of breakpoints in a wide variety of contexts.
mui.com
00. Default breakpoints
๋ฉํ ๋ฆฌ์ผ ๋์์ธ์ breakpoint ๊ธฐ๋ณธ๊ฐ์ ๋๋ค.
xs, sm, md, lg, xl ๋ก ๋๋น๊ฐ ๋๋์ด์ ธ ์์ต๋๋ค.
01. breakpoints ์ปค์คํฐ๋ง์ด์ง
๋ฌผ๋ก ! ์ปค์คํฐ๋ง์ด์ง ๊ฐ๋ฅํฉ๋๋ค๐ฅ๐ฅ
https://avoc-o-d.tistory.com/45
[Material Design] Material-UI(MUI)๋ก react & styled component ์ฌ์ฉํ๊ธฐ <๊ธฐ๋ณธ theme๋ฅผ ์ปค์คํฐ๋ง์ด์งํ๊ธฐ>
https://mui.com/material-ui/customization/theming/ Theming - Material UI Customize MUI with your theme. You can change the colors, the typography and much more. mui.com theme๋ฅผ ์ ์ํ๋ฉด, ์ปดํฌ๋ํธ๋ฅผ..
avoc-o-d.tistory.com
const theme = createTheme({
breakpoints: {
/** ์๋ ์ซ์๋ค์ ๋ณธ์ธ์ ํ๋ก์ ํธ์ ๋ง๊ฒ ์ค์ ํ์ธ์ */
values: {
xs: 0,
sm: 600,
md: 900,
lg: 1200,
xl: 1536,
},
},
});
๊ผญ xs, sm, md, lg, xl ๊ฐ ์๋๊ณ , ์๋์ฒ๋ผ ์์ ๋ก์ด ์ด๋ฆ์ ์ ํ ์ ์์ต๋๋ค!
const theme = createTheme({
breakpoints: {
values: {
mobile: 0,
tablet: 640,
laptop: 1024,
desktop: 1200,
},
},
});
02. ์ ์ฉ
์ ์์ ์ฝ๋์ ๋๋ค.
md(900px) ์ด์์ผ ๋ ๋ฐ์ค์ ๋๋น๊ฐ 50rem
sm(600px) ์ด์์ด๊ณ , md(900px) ์ดํ์ผ ๋ ๋ฐ์ค์ ๋๋น๊ฐ 24rem
xs(0px) ์ด์์ด๊ณ , sm(600px) ์ดํ์ผ ๋ ๋ฐ์ค์ ๋๋น๊ฐ 15rem
๊ฐ ๋๋๋ก ์์ฑํ์์ต๋๋ค.
import "./styles.css";
import React from "react";
import { Box, Typography } from "@mui/material";
import { useTheme } from "@mui/material/styles";
export default function App() {
/**
* (๋ฐ์ํ) breakPoints์ ๋ฐ๋ผ HTML์ ์ ์ฉํ๋ ์คํ์ผ์ ์ ํํ๋๋ก ํจ.
*
* useTheme : ํ์ฌ ์ ์ํ ํ
๋ง๋ฅผ ๋ฆฌํดํ๋ hook
* - ํ์ฌ ์ ์ํ breakPoints์ ์ ๊ทผ ๊ฐ๋ฅ
*/
const theme = useTheme();
const boxSx = {
backgroundColor: "#FFDAD6",
[theme.breakpoints.down("sm") && theme.breakpoints.up("xs")]: {
width: "15rem"
},
[theme.breakpoints.down("md") && theme.breakpoints.up("sm")]: {
width: "24rem"
},
[theme.breakpoints.up("md")]: { width: "50rem" }
};
return (
<div className="App">
<Box sx={boxSx}>
<Typography variant="h1">๋ฐ์ค</Typography>
</Box>
</div>
);
}
์ ์์ ์ฝ๋์ ๋๋ค.
md(900px) ์ด์์ผ ๋ row๋ฐฉํฅ(๊ฐ๋ก)
md(900px) ์ดํ์ผ ๋ column๋ฐฉํฅ(์ธ๋ก)
์ผ๋ก ์์ด๋๋ก ์์ฑํ์์ต๋๋ค.
import "./styles.css";
import React from "react";
import { Box, Typography } from "@mui/material";
import { useTheme } from "@mui/material/styles";
export default function App() {
/**
* (๋ฐ์ํ) breakPoints์ ๋ฐ๋ผ HTML์ ์ ์ฉํ๋ ์คํ์ผ์ ์ ํํ๋๋ก ํจ.
*
* useTheme : ํ์ฌ ์ ์ํ ํ
๋ง๋ฅผ ๋ฆฌํดํ๋ hook
* - ํ์ฌ ์ ์ํ breakPoints์ ์ ๊ทผ ๊ฐ๋ฅ
*/
const theme = useTheme();
const boxSx = {
display: "flex",
gap: (theme) => theme.spacing(4),
[theme.breakpoints.down("md")]: {
flexDirection: "column"
},
[theme.breakpoints.up("md")]: { flexDirection: "row" }
};
return (
<div className="App">
<Box sx={boxSx}>
<Typography variant="h1">Item1</Typography>
<Typography variant="h1">Item2</Typography>
<Typography variant="h1">Item3</Typography>
<Typography variant="h1">Item4</Typography>
</Box>
</div>
);
}
๐คฉ๋ฐ์ํ~๐คฉ