Styled Components

λ…Έλ§ˆλ“œμ½”λ” - React JS λ§ˆμŠ€ν„° 클래슀arrow-up-right https://styled-components.com/arrow-up-right

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