Material UI Sync ํ๋ฌ๊ทธ์ธ ๐งช
Sync๋ ๋์์ธ์์ ๋ฐ๋ก Material UI ํ ๋ง๋ฅผ ์์ฑํ๋ Figma ํ๋ฌ๊ทธ์ธ์ด์์.
์ถ์ฒ: ๋ฌธ์
๋ณธ๋ฌธ
:::error Material UI Sync ํ๋ฌ๊ทธ์ธ์ ๊ฐ๋ฐ์ 2024๋ ์ ์ค๋จ๋์ด์. ์์ผ๋ก ์ด ํ๋ก์ ํธ์ ๋ํ ์ ๋ฐ์ดํธ๋ฅผ ๊ธฐ๋ํ์ง ์๋ ๊ฒ ์ข์์. :::
์๊ฐ
Material UI Sync๋ Material UI for Figma ๋์์ธ ํคํธ์์ ํ ๋ง๋ฅผ ์์ฑํ๊ฒ ํด ์ฃผ๋ Figma ํ๋ฌ๊ทธ์ธ์ด์์.
Sync๋ Material UI for Figma ๋์์ธ ํคํธ v5.16.0 ์ดํ ๋ฒ์ ๊ณผ ํจ๊ป ๋์ํด์.
ํ๋ฌ๊ทธ์ธ ์คํ
Material UI for Figma ๋์์ธ ํคํธ์ ์์ ํ๊ณ ์ต์ ๋ฒ์ ์ ์ค์นํ์ง ์์๋ค๋ฉด, ์ปค๋ฎค๋ํฐ ๋ฒ์ ์ผ๋ก ํ๋ฌ๊ทธ์ธ์ ํ ์คํธํ ์ ์์ด์.
์ค์นํ๊ณ Figma์์ ์ฐ ๋ค์, Community ํญ์ Material UI Sync ํ๋ฌ๊ทธ์ธ ํ์ด์ง๋ก ์ด๋ํด์ **Open inโฆ**์ ํด๋ฆญํ๊ณ Material UI for Figma ๋์์ธ ํคํธ๋ฅผ ์ ํํด ์ฃผ์ธ์.
๋์์ธ ํ ํฐ ์ปค์คํฐ๋ง์ด์ง
๋์์ธ ํ ํฐ์ ๋์์ธ ํคํธ์ ์ง์ญ ๋ณ์ ์ปฌ๋ ์ ์ ์ ์๋ผ ์๊ณ , ์์ ํ๋ ํธ, breakpoints, shape, spacing ํ ํฐ์ ํฌํจํด์. ํ์ดํฌ๊ทธ๋ํผ์ ๊ทธ๋ฆผ์ ๊ด๋ จ ํ ํฐ์ ์ง์ญ ์คํ์ผ ์ปฌ๋ ์ ์์ ์ฐพ์ ์ ์์ด์.
๊ธฐ์กด ํ ํฐ ์์ ํ๊ธฐ
๋์์ธ ํคํธ๋ Material UI React ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ๋ณธ ํ ๋ง์ ๋งคํ๋๋ ๋์์ธ ํ ํฐ์ผ๋ก ๊ฐ๋ ์ฐจ ์์ด์.
๊ธฐ์กด ํ ํฐ์ ์ปค์คํฐ๋ง์ด์ฆํ๋ ค๋ฉด ์๋์ฒ๋ผ ํํฐ ์์ด์ฝ์ ํด๋ฆญํด์ ์ง์ญ ๋ณ์ ๋ชจ๋ฌ์ ์ด์ด ์ฃผ์ธ์. ์ปฌ๋ ์ ์ ์๋ ๋ณ์๋ค(ํ๋ ํธ, breakpoints, shape, spacing ๋ฑ) ์ค ์ํ๋ ๋๋ก ์กฐ์ ํ๋ฉด ๋ผ์.
๊ทธ๋ฐ ๋ค์ Material UI Sync ํ๋ฌ๊ทธ์ธ์ ์ด๊ณ Generate theme๋ฅผ ํด๋ฆญํด ์ฃผ์ธ์.
์์ ๋ ํ ํฐ์ด ๋ด๊ธด ํ ๋ง๊ฐ ์์ฑ๋์ด ํ๋ฌ๊ทธ์ธ์ Theme ํญ์ ํ์๋ผ์.
Storybook ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํญ์ผ๋ก ๊ฐ๋ฉด ์์ฑ๋ ํ ๋ง์ ์ปค์คํฐ๋ง์ด์ฆ๋ ํ ํฐ์ ๋ฏธ๋ฆฌ ๋ณผ ์๋ ์์ด์.
์ ํ ํฐ ์ถ๊ฐํ๊ธฐ
๊ธฐ์กด ์ง์ญ ๋ณ์ ์ปฌ๋ ์ ์ ์ ๋ณ์๋ฅผ ์ถ๊ฐํ๊ฑฐ๋, ์ง์ญ ์คํ์ผ ์ปฌ๋ ์ ์ ์ elevationยทtypography ์คํ์ผ์ ์ถ๊ฐํด์ ์์ ๋ง์ ํ ํฐ์ผ๋ก ๊ธฐ์กด ํ ํฐ ์งํฉ์ ํ์ฅํ ์ ์์ด์. ์ปค์คํ ํ ํฐ์ ์ถ๊ฐํ ๋ค Regenerate theme๋ฅผ ํด๋ฆญํ๋ฉด ๊ทธ ํ ํฐ๋ค์ด ํ ๋ง์ ํฌํจ๋ผ์.
์ปดํฌ๋ํธ ์ปค์คํฐ๋ง์ด์ง
:::warning ์ด ๊ธฐ๋ฅ์ ์คํ์ ์ด๋ฉฐ Button, Switch, Typography ์ปดํฌ๋ํธ๋ก ์ ํ๋ผ์. :::
Sync ํ๋ฌ๊ทธ์ธ์ ์ปค์คํฐ๋ง์ด์ฆ๋ ์ปดํฌ๋ํธ์ ๋ํ ํ ๋ง ์คํ์ผ๋ ์์ฑํ ์ ์์ด์, Figma ์์์ ์ปดํฌ๋ํธ์ ๋๋์ ์์ ํ ๋ฐ๊พธ๊ณ ์์ ๋ง์ ๋์์ธ ์์คํ ์ ๋ง๋ค ์ ์๊ฒ ํด ์ค์.
์์๋ก, iOS์ ๋๋์ ์ฌํํ๋๋ก Switch ์ปดํฌ๋ํธ์ checked ์ํ, medium ํฌ๊ธฐ, primary ์์์ ์ปค์คํฐ๋ง์ด์ฆํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๊ฒ์.
:::warning Sync๊ฐ ์ปค์คํ ์ปดํฌ๋ํธ ์คํ์ผ์ ์ฌ๋ฐ๋ฅด๊ฒ ์ถ์ถํ๊ณ ํ ๋ง๋ฅผ ์์ฑํ๋ ค๋ฉด, ๋์์ธ ํคํธ์ ์ปดํฌ๋ํธ ๋ ์ด์ด ๊ณ์ธต๊ณผ ๋ ์ด์ด ์ด๋ฆ์ด ๋ณํ์ง ์์์ผ ํด์. :::
Sync ํ๋ฌ๊ทธ์ธ์ ์ปค์คํฐ๋ง์ด์ฆ๋ Switch์ ๋ํด ๋ค์ ํ ๋ง ์ฝ๋๋ฅผ ์์ฑํด์.
{
components: {
MuiSwitch: {
styleOverrides: {
root: {
'&.MuiSwitch-sizeMedium:has(.MuiSwitch-colorPrimary)': {
'&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))':
{
width: '40px',
height: '21px',
padding: '0',
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
padding: '0',
'& .MuiSwitch-thumb': {
width: '17px',
height: '17px',
background: '#FAFAFA',
},
'& + .MuiSwitch-track': {
width: '38px',
height: '21px',
background: 'var(--mui-palette-success-light)',
opacity: '1',
},
},
},
},
},
},
},
},
}
์์ฑ๋ ํ ๋ง๋ ์์์ ์ ์ํ ํน์ Switch ๊ตฌ์ฑ์ ํด๋นํ๋ ํด๋์ค๋ฅผ ๋์์ผ๋ก ํด์. ๊ทธ๋์ Material UI ์ปดํฌ๋ํธ์ props์ ์ํ๊ฐ ์ปค์คํฐ๋ง์ด์ฆ๋ Figma ์ปดํฌ๋ํธ์ ์ผ์นํ ๋๋ง ์คํ์ผ์ด ์ ์ฉ๋ผ์.
๋ค๋ฅธ ์ํ๋ฅผ ์ปค์คํฐ๋ง์ด์ฆํ๋ ค๋ฉด ๋ค์ ๋จ๊ณ์ ๋ฐ๋ผ Figma์ ๊ฐ variant์ ์ํ๋ ๋์์ธ ๋ณ๊ฒฝ์ ์ ์ฉํด์ผ ํด์.
- ๋จ์ผ "base" variant๋ฅผ ์ปค์คํฐ๋ง์ด์ฆํด์ โ ์๋ฅผ ๋ค์ด checked ์ํ, medium ํฌ๊ธฐ, primary ์์์ Switch ์ปดํฌ๋ํธ์.
- ์ด variant๋ฅผ ๋ณต์ ํ๊ณ , ์ปค์คํฐ๋ง์ด์ฆํ๋ ค๋ ๋ค์ variant๋ฅผ ๋์์ผ๋ก ์ด๋ฆ์ ๋ฐ๊ฟ์ โ ์๋ฅผ ๋ค์ด
Checked=True, Size=Medium, Color=Primary, State=Enabled์ ๋ณต์ ๋ณธ์Checked=False, Size=Medium, Color=Primary, State=Enabled๋ก ๋ฐ๊ฟ์. - ๊ฐ์ variant์ ์ด์ ๋ฒ์ ์ ์ญ์ ํด์.
- variant ๊ทธ๋ฆฌ๋์ ์ฌ๋ฐ๋ฅธ ์นธ์ผ๋ก ์ ๋ฒ์ ์ ์ด๋ํด์.
- variant์ ํ์ ๋ ์ด์ด์ ํ์ํ ์คํ์ผ ์กฐ์ ์ ํด์.
์ปค์คํฐ๋ง์ด์ฆํ๋ ค๋ ๊ฐ variant์ ๋ํด ์ด ๊ณผ์ ์ ๋ฐ๋ณตํด์. ๊ทธ ๋ชจ์ต์ ์์๋ ๋ค์๊ณผ ๊ฐ์์.
์ฌ๊ธฐ์ Sync๋ฅผ ์คํํ๋ฉด ์ ํ ๋ง๋ฅผ ์์ฑํ ์ ์์ด์ โ ์ ์์์์ ์์ฑ๋๋ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์์.
{
components: {
MuiSwitch: {
styleOverrides: {
root: {
'&.MuiSwitch-sizeMedium:has(.MuiSwitch-colorPrimary)': {
width: '40px',
height: '21px',
padding: '0',
'& .MuiSwitch-switchBase': {
padding: '0',
'& .MuiSwitch-thumb': {
width: '17px',
height: '17px',
background: '#FAFAFA',
},
'& + .MuiSwitch-track': {
width: '38px',
height: '21px',
borderRadius: '100px',
opacity: '1',
},
},
'&:not(:has(.Mui-checked)):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(3px) translateY(2px)',
'& + .MuiSwitch-track': {
background: '#BDBDBD',
},
},
},
'&:not(:has(.Mui-checked)):has(.Mui-disabled):not(:has(.Mui-focusVisible))': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(3px) translateY(2px)',
'& + .MuiSwitch-track': {
background: 'rgba(229, 229, 229, 0.99)',
},
},
},
'&:not(:has(.Mui-checked)):not(:has(.Mui-disabled)):has(.Mui-focusVisible)': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(3px) translateY(2px)',
'& + .MuiSwitch-track': {
border: '1px solid #000',
background: '#BDBDBD',
},
},
},
'&:has(.Mui-checked):has(.Mui-disabled):not(:has(.Mui-focusVisible))': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
'& + .MuiSwitch-track': {
background: 'rgba(187, 231, 188, 0.99)',
},
},
},
'&:not(:has(.Mui-checked)):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible)):hover': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(3px) translateY(2px)',
'& + .MuiSwitch-track': {
background: '#616161',
},
},
},
'&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
'& + .MuiSwitch-track': {
background: 'var(--mui-palette-success-light)',
},
},
},
'&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible)):hover': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
'& + .MuiSwitch-track': {
background: 'var(--mui-palette-success-dark)',
},
},
},
'&:has(.Mui-checked):not(:has(.Mui-disabled)):has(.Mui-focusVisible)': {
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
'& + .MuiSwitch-track': {
border: '1px solid #000',
background: 'var(--mui-palette-success-light)',
},
},
},
},
},
},
},
},
}
:::info
์์ฑ๋ ํ
๋ง์๋ ํน์ ํ์ ํด๋์ค๋ฅผ ๋์์ผ๋ก ํ๋ CSS has() ์ ํ์๊ฐ ํฌํจ๋ ์ ์์ด์. ์ด ์ ํ์๋ ๋ธ๋ผ์ฐ์ ์ง์์ด ์ ํ์ ์ด์๊ธฐ ๋๋ฌธ์ ๋ฌธ์์ ๋ค๋ฅธ ํ
๋ง ๊ด๋ จ ์์์์๋ ์ฌ์ฉ๋์ง ์์์ด์. ์ง๊ธ์ ๋ชจ๋ ์ต์ ๋ธ๋ผ์ฐ์ ์์ ์ง์๋ผ์.
:::
์ปดํฌ๋ํธ์ Material UI ๋ฒ์ ์ ํ ์คํธํ๋ ค๋ฉด Storybook ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ํ์ธํ ์๋ ์์ด์.
์์ฑ๋ ํ ๋ง ์ฌ์ฉํ๊ธฐ
Sync๊ฐ ์์ฑํ ํ ๋ง๋ฅผ ์ฝ๋๋ฒ ์ด์ค์ ์ถ๊ฐํ๋ ์์๋ ๋ค์๊ณผ ๊ฐ์์.
import { createTheme, ThemeProvider } from '@mui/material/styles';
const theme = createTheme({
cssVariables: true,
shape: {
borderRadiusRound: 999,
},
components: {
MuiSwitch: {
styleOverrides: {
root: {
'&.MuiSwitch-sizeMedium:has(.MuiSwitch-colorPrimary)': {
'&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))':
{
width: '40px',
height: '21px',
padding: '0',
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
padding: '0',
'& .MuiSwitch-thumb': {
width: '17px',
height: '17px',
background: '#FAFAFA',
},
'& + .MuiSwitch-track': {
width: '38px',
height: '21px',
background: 'var(--mui-palette-success-light)',
borderRadius: 'var(--mui-shape-borderRadiusRound)',
opacity: '1',
},
},
},
},
},
},
},
},
});
export default function MyApp(props) {
const { Component, pageProps } = props;
return (
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
);
}
ํผ๋๋ฐฑ๊ณผ ๋ฒ๊ทธ ์ ๊ณ
ํผ๋๋ฐฑ์ด ์๋ค๋ฉด ์ฌ๊ธฐ๋ก ๋ค๋ ค์ฃผ์ธ์.