반응형
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- redux-toolkit
- 폼
- HTML
- component
- 알고리즘
- next
- eslint
- js
- form
- Javasript
- javascript
- algorithm
- 상호 평가
- Prettier
- solution
- Challenge
- javscript
- MaterialUI
- array
- 리액트
- split
- Weekly Challenge
- nextjs
- programmers
- level1
- React
- Weekly
- Collapse
- From
- 직업군 추천하기
Archives
- Today
- Total
기록
Simple Collapse 본문
소스코드
import { useState } from 'react';
import styled from 'styled-components';
const StyledCollapse = styled.div`
.content{
background: blue;
color: white;
max-height: 0;
bottom: 0;
overflow: hidden;
-webkit-transition: max-height 0.2s cubic-bezier(0.215, 0.61, 0.355, 1);
transition: max-height 0.2s cubic-bezier(0.215, 0.61, 0.355, 1);
}
.content.on {
max-height: 500px;
-webkit-transition: max-height 1s cubic-bezier(0.215, 0.61, 0.355, 1);
transition: max-height 1s cubic-bezier(0.215, 0.61, 0.355, 1);
}
.arrow {
background: red;
svg {
transform: rotate(${props => props.rotate ? 180 : 0}deg);
transition: transform 0.3s;
}
}
`
const App = () => {
const [isRotate, setIsRotate] = useState(false);
const handleCollapse = () => {
if (document.getElementsByClassName('content')[0].classList.contains('on')) {
setIsRotate(false);
return document.getElementsByClassName('content')[0].classList.remove('on');
}
setIsRotate(true);
document.getElementsByClassName('content')[0].classList.add('on');
}
return (
<StyledCollapse rotate={isRotate}>
<div className='content'>
<p>test</p>
</div>
<div onClick={handleCollapse} className='arrow'>
<svg xmlns="http://www.w3.org/2000/svg" width="29" height="15" fill="none" viewBox="0 0 29 15">
<path
stroke="#797979"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="4.5"
d="M26.717 2.5l-12 10-12-10"
/>
</svg>
</div>
</StyledCollapse>
);
}
export default App;
동작
반응형
'React' 카테고리의 다른 글
React Antd CollapseForm 검색 컴포넌트(1) (0) | 2021.07.28 |
---|---|
useState, useEffect (0) | 2021.06.03 |
state, props (0) | 2021.06.03 |
함수 컴포넌트, 클래스 컴포넌트 (0) | 2021.06.03 |
React 시작하기 (0) | 2021.06.02 |
Comments