๐Ÿง react-prototype

Bora Imยท2022๋…„ 6์›” 17์ผ
0

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

// 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 ๊ฒฝ๋กœ์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.๐Ÿ˜‰

styled-components ์‚ฌ์šฉ๋ฒ•

  1. ํƒœ๊ทธ๋ช…
const Circle = styled.div`
  width: 100px; height: 100px; border-radius: 50%;
  background: ${props => props.color || 'black'}; // props ์ ์šฉ
`;
<Circle color="blue" />
  1. ์ปดํฌ๋„ŒํŠธ๋ช…
const BigCircle = styled(Circle)`
  transform: scale(1.5);
`;
<BigCircle />

styled-components X TypeScript

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์ด ๋ณ„๋„ ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ์ ์šฉ๋œ๋‹ค.๐Ÿ™„

0๊ฐœ์˜ ๋Œ“๊ธ€