Styled Components
๋ ธ๋ง๋์ฝ๋ - React JS ๋ง์คํฐ ํด๋์ค https://styled-components.com/
Install
CRAํ์npm i styled-components
Using
1. import
import styled from "styled-components";2. Create styled components
๋ฐฑํฑ์ฌ์ด์๋css๊ฐ ๋ค์ด๊ฐvscode ์ต์คํ ์ ์ค์นํ๋ฉด ์๋์์ฑ
ํด๋์ค ๋ค์์ ๋๋คํ๊ฒ ์ง์ ๋จ
const Father = styled.div`
display: flex;
`;
const Btn = styled.button`
color: white;
background-color: tomato;
border: 0;
border-radius: 15px;
`;
}3. Adapting and Extending
adapting(modify)
props์ฌ์ฉ ๊ฐ๋ฅ
extending
styled(๊ธฐ์กด์ปดํฌ๋ํธ)๊ธฐ์กด ์ปดํฌ๋ํธ์ ๋ชจ๋ ์์ฑ์ ์๋ก์ด ์์ฑ์ ๋ ํด์ค
4. 'As' and Attrs
as๋ผ๋ props๋ฅผ ์ด์ฉํ๋ฉด ์ ์๋ ์คํ์ผ์ ๊ทธ๋๋ก ๊ฐ์ง๊ณ ๊ฐ๋ ํ๊ทธ๋ค์์ ๋ฐ๊ฟ ์ ์์
attrs๋ฅผ ์ด์ฉํ๋ฉด html์ ์์ฑ์ ๋ฏธ๋ฆฌ ์ค์ ํ ์ ์์์ฌ๋ฌ๊ฐ์ ๋์ผํ ์ค์ ์ด ํ์ํ ๊ฒฝ์ฐ ์ ์ฉ
5. Animations and Pseudo Selectors
animations
keyframes๋ผ๋ ํฌํผ ํจ์๋ฅผ ์ถ๊ฐ๋ฐ์์ animation์ ์ ์ธํ๊ณ
styled-components์์์ ์ฌ์ฉ
seudo Selectors
styled-components๊ฐ ์๋๋๋ผ๋ ์ปดํฌ๋ํธ ๋ด์์ ํ์ ํ๊ทธ์ ๋ํ ํ๊ฒ ์ ํ ๊ฐ๋ฅ์ถ์ฝ์ด
&case1
styled-components๋ด์์ ํ์ ์ปดํฌ๋ํธ์ ๋ํ ํ๊ฒ ์ ํ ๊ฐ๋ฅ(๋ณ์๋ช ์ฒ๋ผ ์ฌ์ฉ)case2
Themes
๋ชจ๋ ์์์ ๊ฐ์ง๊ณ ์๋ object
index.js์์ ์ค์ ํ๊ณ App.js์์
props๋ก ๊ฐ์ ธ๋ค ์์์ ์ฟจํจ๐คฉ
Last updated