spec
React + Next.js
Mobx
TypeScript
PostCSS + tailwindcss
// _app.tsx
import { ThemeProvider } from 'styled-components';
import { theme } from '@/styles/theme';
import '@/styles/globals.css';
โ Next.js ์ _app
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
/* globals.css */
@tailwind base; /* normalize */
@tailwind components; /* layout */
@tailwind utilities; /* classes */
โ tailwindcss ๊ธฐ๋ณธ์ ์ผ๋ก ๋ด๊ณ ์๋ ๋ด์ฉ
cdnjs > tailwindcss
@tailwind
Directives
Tailwind ์ปค์คํ ๐จ
F12 ๊ฐ๋ฐ์ ๋๊ตฌ์์ Tailwind ํด๋์ค๋ฅผ ํ์ธํ๋ฉด globals.css ๊ฒฝ๋ก์ธ ๊ฒ์ ํ์ธํ ์ ์๋ค.๐
const Circle = styled.div`
width: 100px; height: 100px; border-radius: 50%;
background: ${props => props.color || 'black'}; // props ์ ์ฉ
`;
<Circle color="blue" />
const BigCircle = styled(Circle)`
transform: scale(1.5);
`;
<BigCircle />
TypeScript | styled-components
Before you can effectively start to use TypeScript you will have to do a little bit of configuration.
TypeScript๋ฅผ ํจ๊ณผ์ ์ผ๋ก ์ฌ์ฉํ๊ธฐ ์ ์ ์ฝ๊ฐ์ ๊ตฌ์ฑ์ ์ํํด์ผ ํ๋ค.
// styled.d.ts
import 'styled-components';
declare module 'styled-components' {
export interface DefaultTheme {
colors: {
primary: string;
};
}
}
// theme.ts
import { DefaultTheme } from 'styled-components';
const colors = {
primary: 'rgb(252 178 43)',
};
export const theme: DefaultTheme = {
colors,
};
// [component].tsx
const Input = styled.input`
caret-color: ${({ theme }) => theme.colors.primary};
`;
styled-components ๋ฅผ ํตํด ๋ถ์ฌํ style์ด ๋ณ๋ ํด๋์ค๋ฅผ ํตํด ์ ์ฉ๋๋ค.๐