styled component는 패키지 다운부터 받고 import를 해와야 사용이 가능함
yarn add styled-components
1. 꾸미고자하는 컴포넌트를 styled component 방식대로 만들고
2. 그 안에 style 코드를 작성하고
3. 이렇게 만들어진 컴포넌트를 실제 html 태그처럼 사용하면 된다
import React from "react";
import { css, styled } from "styled-components";
function ButtonArea() {
return (
<>
<h2>01.Button</h2>
<div>
<StButton
backgroundColor="#55efc4"
color="#000000"
size="large"
outline={true}
>
테스트
</StButton>
<StButton backgroundColor="#55efc4" color="#000000" size="medium">
테스트
</StButton>
<StButton backgroundColor="#55efc4" color="#000000" size="small">
테스트
</StButton>
</div>
<div>
<StButton
backgroundColor="#c49ae6"
color="#d63031"
size="large"
outline={true}
>
테스트
</StButton>
<StButton backgroundColor="#c49ae6" color="#d63031" size="medium">
테스트
</StButton>
<StButton backgroundColor="#c49ae6" color="#d63031" size="small">
테스트
</StButton>
</div>
</>
);
}
export default ButtonArea;
const StButton = styled.button`
border: none;
cursor: pointer;
border-radius: 8px;
background-color: ${({ backgroundColor }) => backgroundColor};
color: ${({ color }) => color};
font-weight: 0;
${({ size }) => {
switch (size) {
case "large":
return css`
height: 50px;
width: 200px;
`;
case "medium":
return css`
height: 45px;
width: 130px;
`;
case "small":
return css`
height: 40px;
width: 100px;
`;
default:
break;
}
}}
${({ outline, backgroundColor }) => {
if (outline) {
return css`
border: 3px solid ${backgroundColor};
background-color: #fff;
font-weight: 600;
`;
}
}}
margin: 5px;
`;

'TIL' 카테고리의 다른 글
| 6월 29일 TIL react ) 스크롤 올려주는 top 버튼 만들기 (0) | 2023.06.29 |
|---|---|
| 6월 26일 TIL 리액트로 모달창 만들기 (0) | 2023.06.26 |
| 6월 22일 TIL - redux로 todolist 만들기 (3) - 라우팅 사용해서 todo list 세부페이지 뜨게하기 (0) | 2023.06.22 |
| 6월 21일 TIL - redux로 todolist 만들기 (2) - 추가, 삭제 (0) | 2023.06.22 |
| 6월 20일 TIL - redux로 todolist 만들기 (1) (0) | 2023.06.20 |