mantine ์ปดํฌ๋ํธ๋ฅผ ํ์ฉํ๊ณ ๊ฐ ์ปดํฌ๋ํธ์ docs props๋ฅผ ์ฐธ๊ณ ํ์ฌ style props๋ก ํด๊ฒฐํ๋ค.
๋ํ props
import { Box } from '@mantine/core';
// margin-top: theme.spacing.xs
<Box mt="xs" />
// margin-top: theme.spacing.md * -1
<Box mt="-md" />
// margin-top: auto
<Box mt="auto" />
// margin-top: 1rem
<Box mt={16} />
// margin-top: 5rem
<Box mt="5rem" />
// color: theme.colors.blue[theme.fn.primaryShade()]
<Box c="blue" />
// background: theme.colors.orange[1]
<Box bg="orange.1" />
// color: theme.colorScheme === 'dark' ? theme.colors.dark[2] : theme.colors.gray[6]
<Box c="dimmed" />
// background: #EDFEFF
<Box bg="#EDFEFF" />
// background: rgba(0, 34, 45, 0.6)
<Box bg="rgba(0, 34, 45, 0.6)" />
props์ {}
๋ก ๊ฐ์ธ์ฃผ๋ฉด px๊ธฐ์ค ๊ฐ์ด rem์ผ๋ก ๋ณํ๋๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ํ์ฉํ๋ค.
// X
<Box w="1rem" />
<Box w="16px" />
// O
<Box w={16} />
props color๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ useMantineTheme()
๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ๋ค.
const TempLoader = () => {
const theme = useMantineTheme();
const { colorScheme } = useMantineColorScheme();
const dark = colorScheme === 'dark';
return (
<Conatiner>
<Loader color={dark ? theme.colors.gray[0] : theme.colors.dark[8]} />
</Conatiner>
);
};
style props๋ก ์งํํ ์ ์๋ ์คํ์ผ์ styled
ํจ์๋ฅผ ์ฌ์ฉํ๋ค.
<MantineProvider />
๋ก theme์ ์ ๋ฌํ๊ณ ์๊ธฐ๋๋ฌธ์ styled ์ปดํฌ๋ํธ์์ ์ ๊ทผํ ์ ์๋ค.
// example
const Temp = styled(Container)`
// ...
background-color: `${(({theme}) => theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.colors.gray[0])}`;
`
styled ์ปดํฌ๋ํธ ๋ด๋ถ์์๋ rem()
ํจ์๊ฐ ์๋ px to rem(vscode extention)์ ํ์ฉํ์ฌ px์ rem์ผ๋ก ๋ณํํ๋ค.
styled ์ปดํฌ๋ํธ์์๋ css variable์ ํ์ฉํ๋ค.
// example
const Temp = styled(Container)`
// ...
padding: var(--mantine-spacing-md);
`
mantine์ ์ค์ฒฉ๋ ์ปดํฌ๋ํธ(nested elements, ex: Modal
, Slide
๋ฑ)์ docs์ ์๋ props๋ฅผ ๊ผญ ์ดํด๋ณด๊ณ ์ฌ์ฉํ๋ค. static selector๋ก ์ปดํฌ๋ํธ Styles API์ ์ ๊ทผํ ์ ์๋ค.
Mantine UI์ ์๋ ์์ ์ฝ๋๋ฅผ ํ์ฉํ๊ณ ์ ํ ๊ฒฝ์ฐ, ์ ์ปจ๋ฒค์ ์ ๋ง์กฑํ๋๋ก ๋ณํํ๋ค.
์ปดํฌ๋ํธ์ props๋ก ํด๊ฒฐ ๊ฐ๋ฅํ ๊ฒฝ์ฐ useMantineColorScheme()
ํจ์๋ฅผ ํธ์ถํ์ฌ ๋ค์๊ณผ ๊ฐ์ด ์กฐ๊ฑด๋ถ ์ฒ๋ฆฌํ๋ค.
// example
const Temp = () => {
const { colorScheme } = useMantineColorScheme()
const dark = colorScheme === 'dark'
return (
<Container>
<Button color={dark ? 'gray' : 'black'} />
</Container>
)
}
props๋ก ํด๊ฒฐ์ด ์ด๋ ค์ด ๊ฒฝ์ฐ (ex: backgroundColor, ์ปฌ๋ฌ๋ฅผ theme.colors์ key๋ง ํ์ฉํ๋ ์ปดํฌ๋ํธ ๋ฑ)
// example
const Temp = styled(Container)`
// ...
background-color: `${({theme}) => theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.colors.gray[0])}`;
`
๋ผ์ฐํ ์์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ๋ค.
import { Link } from 'react-router-dom';
import { Button } from '@mantine/core';
const Temp = () => (
<Button component={Link} to="/react-router">
React router link
</Button>
);