styled.
+ html태그
const Circle = styled.div`
//css 정의
`;
const Circle = styled.div`
background = ${props=>props.color || 'black'};
`;
function App(){
return <Circle color="blue"/>;
}
css
함수를 사용해서 여러개의 CSS 속성을 묶어서 정의.const Circle = styled.div`
background =
${ (props) =>
props.primary &&
css`
color : white;
background : navy;
`
}
`;
styled(컴포넌트이름)
const Button = styled.button`
color : red;
font-size:1em;
`
//Button 컴포넌트를 갖다 쓸 새로운 component
const TomatoButton = styled(Button)`
color : tomato,
border-color : tomato;
`
const Box = styled.div`
background-color : red;
`;
function App(){
return(
<Box as="span"></Box>
);
}
const Input = styled.input.attrs({required:true})`
background-color : blue;
`;
import {keyframes} from "styled-components";
const rotateAnimation = keyframes`
//animation 정의 - from {} to {} 설정
`;
const StyledBox = styled.div`
animation : ${rotateAnimation} 1s linear infinite;
`;
Component 안에 있는 "다른 요소" target 할 때
&
를 통해 자신이 포함된 상위 선택자를 지정할 수 있다.
const Box = styled.div`
background-color : black;
${Emoji} {
&:active {
transform: translateX(60px);
}
}
`;
function App(){
return(
<Box>
<Emoji>👴</Emoji>
</Box>
);
}