๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

React

[ React / antd ] react ant-design theme ๋ณ€๊ฒฝ ( custom theme )

React์—์„œ antd๋ฅผ ์‚ฌ์šฉ์ค‘์—, custom theme๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜๋‹ค.

antd์˜ ๊ณต์‹ ํŽ˜์ด์ง€(https://ant.design/docs/react/customize-theme)์—์„œ customize์— ๋Œ€ํ•ด ์นœ์ ˆํ•˜๊ฒŒ ์„ค๋ช…์„ ์จ ์ฃผ์—ˆ์ง€๋งŒ, ๋‚œ ์™œ์ด๋ ‡๊ฒŒ ์ฝ๊ธฐ๊ฐ€ ์–ด๋ ค์šด๊ฑด์ง€..ใ… ใ… ใ… ใ… ...

 

 

 

 

* LinkedIn ๊ธ€์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ž‘์„ฑ.

 

 

 


 

 

 

1.  Create React App ์„ ํ†ตํ•ด ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ.

npx create-react-app <App Name>

 

 

 

 

 

2. antd ํŒจํ‚ค์ง€ ์„ค์น˜

// 1) npm install antd ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ „์ฒด ํŒจํ‚ค์ง€ ์„ค์น˜
npm install antd

// 2) npm install less -g ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ less ์ „์—ญ ์„ค์น˜.
npm install -g less

 

 

 

 

 

3. antd/dist ํด๋”๋กœ ์ด๋™.

cd ./node_module/antd/dist

 

 

 

 

 

4. antd/dist ํด๋” ์•ˆ์— ์ƒˆ๋กœ์šด less ํŒŒ์ผ ์ƒ์„ฑ.

// ์›ํ•˜๋Š” ํŒŒ์ผ๋ช…์œผ๋กœ less ํŒŒ์ผ ์ƒ์„ฑ.
touch my-theme.less

 

 

 

 

 

5. ์ƒ์„ฑํ•œ less ํŒŒ์ผ ์—ด๊ธฐ.

โญ๏ธ antd deault ์†์„ฑ ๊ฐ’ ํ™•์ธ โญ๏ธ

// my-theme.less
@import "./antd.less";

// custom ํ•˜๊ณ ์‹ถ์€ ๊ธฐ๋ณธ ๋ณ€์ˆ˜์— ์›ํ•˜๋Š” ๊ฐ’์„ ์ž…๋ ฅ. 
@primary-color: #ff4acd;
@link-color: #ff4acd;

 

 

 

 

6. lessc --js my-theme.less custom-antd.css ์‹คํ–‰

์‹คํ–‰ํ•˜๋ฉด custom-antd.css ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค. 

// ./node_module/antd/dist ๋ฃจํŠธ์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด ์‹คํ–‰.

lessc --js my-theme.less custom-antd.css

 

 

 

 

 

7. ./node_module/antd/dist ํด๋” ์•ˆ์— ์ƒ์„ฑ๋œ custom-antd.css ํŒŒ์ผ ์ ์šฉ.

์ƒ์„ฑ๋œ custom-antd.css ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜์—ฌ src/ ๋ฃจํŠธ ์•ˆ์—๋‹ค ๋ถ™์—ฌ๋„ฃ๊ณ , (ex: src/๋ฃจํŠธ ๋ฐ”๋กœ ์•ˆ์— ๋„ฃ๊ฑฐ๋‚˜, src/assests/style ๋“ฑ๊ณผ ๊ฐ™์ด css ํŒŒ์ผ๋“ค์ด ๋“ค์–ด์žˆ๋Š” ํด๋”๊ฐ€ ๋”ฐ๋กœ ์žˆ๋‹ค๋ฉด ๋ณธ์ธ์˜ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ์— ๋งž์ถฐ์„œ ์•Œ์•„์„œ ๋„ฃ์–ด์ฃผ๊ณ  import ํ•ด์ฃผ๋ฉด ๋จ. )

app์˜ ์ตœ์ƒ์œ„ ํŒŒ์ผ, antd.css๊ฐ€ ์žˆ๋˜ ๊ณณ์— antd.css๋ฅผ ์ง€์šฐ๊ณ  custom-antd.cssํŒŒ์ผ์„  import ์‹œํ‚จ๋‹ค. 

// index.js or app.js ํŒŒ์ผ์˜ antd.css ํŒŒ์ผ์„
// ์ƒˆ๋กœ ์ƒ์„ฑํ•œ custom-antd.css ๋กœ ๋ณ€๊ฒฝ.

//import "antd/dist/antd.css"
import "antd/dist/custom-antd.css"

 

 

 

 

 

 

ํ•˜๊ณ  ์•ฑ์„ ์ข…๋ฃŒํ•˜๊ณ  ์žฌ์‹œ์ž‘ ํ•˜๋‹ˆ ์ปค์Šคํ…€ ํ…Œ๋งˆ๊ฐ€ ์ž˜ ์ ์šฉ๋œ๋‹ค!!!!! ๐Ÿ‘