๐ก Component Driven Development์ ์ฝ์
๐ก ๋ถํ ๋จ์๋ก UI๋ฅผ ๋ง๋ค์ด๋๊ฐ๋ ๊ฐ๋ฐ ์งํ ๊ฐ๋ฅ
๐ก ์ฌ์ฌ์ฉํ ์ ์๋ ์ปดํฌ๋ํธ ๊ฐ๋ฐ ๊ฐ๋ฅ
๐ CSS
์๊ท๋ชจ ํ๋ก์ ํธ์ ์ฆ๊ฐ, ํ๋ก์ ํธ ๋ณต์ก์ฑ์ ์ฌํ, ๋ค์ํ ๋๋ฐ์ด์ค์ ๋ฑ์ฅ์ผ๋ก
CSS์ ์์
์ ํจ์จ์ ์ผ๋ก ํ๊ธฐ์ํ ๊ตฌ์กฐํ๋ CSS ํ์์ฑ ๋๋
๐ CSS ์ ์ฒ๋ฆฌ๊ธฐ
CSS์ ๋จ์ ์ ํ๋ก๊ทธ๋๋ฐ ๊ฐ๋
(๋ณ์, ํจ์, ์์ ๋ฑ)์ ํ์ฉํ์ฌ ํด๊ฒฐ
์๋ฒ์ ์ธ์ํ๊ฒ ํ๊ธฐ ์ํด Compiler๋ฅผ ์ฌ์ฉ, ์ฉ๋์ด ๋งค์ฐ ์ฆ๊ฐํ๋ ๋จ์
๐ CSS ๋ฐฉ๋ฒ๋ก
-์ฝ๋์ ์ฌ์ฌ์ฉ์ฑ
-์ฌ์ด ์ ์ง๋ณด์
-ํ์ฅ ๊ฐ๋ฅ
-ํด๋์ค๋ช
์ผ๋ก ์๋ฏธ ์์ธก ๊ฐ๋ฅ
//block__element--modifier
.header__navi--text{
color: red;
}
//block : ์ ์ฒด๋ฅผ ๊ฐ์ธ๋ ์์
//element : ๋ธ๋ญ์ด ํฌํจํ๋ ์์์ค ํ ์กฐ๊ฐ
//modifier: ๋ธ๋ญ ๋๋ ์์์ ์์ฑ
โ ์ธ์ด ๋ก์ง์์ ์ง์ ํ ์บก์ํ(๊ฐ์ฒด์ ์์ฑ๊ณผ ํ์๋ฅผ ํ๋๋ก ๋ฌถ๊ณ // ์ค์ ๊ตฌํ ๋ด์ฉ ์ผ๋ถ๋ฅผ ์ธ๋ถ์ ๊ฐ์ถ์ด ์๋ํจ)๊ฐ ๋์ง ์์
๐ก CSS๋ฅผ ์ปดํฌ๋ํธ์ ์์ญ์ผ๋ก ๋ถ๋ฌ ๋ค์
npm install --save styled-components
//package.json
{
"resolutions": {
"styled-components": "^5"
}
}
๐ ์ปดํฌ๋ํธ ๋ง๋ค๊ธฐ
import styled from "styled-components";
const A = styled.button`
background-color:#ccc;
color: #000;
`;
export default function App(){
return <A>a</A>
}
๐ ์ปดํฌ๋ํธ ํ์ฅ
import styled from "styled-components";
const A = styled.button`
background-color:#ccc;
color: #000;
`;
const Aa = styled(A)`
padding: 10px;
`;
export default function App(){
return (
<>
<A>a</A>
<Aa>aa</Aa>
</>
)
}
๐ ์ ์ญ ์คํ์ผ
//GlobalStyle.js
import { createGlobalStyle } from "styled-components";
const GlobalStyle = createGlobalStyle`
button{
padding: 5px;
color: blue;
}
`;
export default GlobalStyle;
//App.js
import styled from "styled-components";
import GlobalStyle from "./GlobalStyle";
const Btn1 = styled.button`
background : ${(props) => (props.color ? props.color : "white")};
`;
//const Btn1 = styled.button`
//background : ${(props) => props.color || "white"};
//`;
export default function App() {
return (
<>
<GlobalStyle />//์ ์ญ ์คํ์ผ ์ ์ฉ
<Btn1>aa</Btn1>
<Btn1 color="orange">Button1</Btn1>
</>
);
}