728x90
import React, { useState } from "react";
import styled from "styled-components";
import { AiOutlineDown } from "react-icons/ai";
import { AiOutlineUp } from "react-icons/ai";
const Dropdown = () => {
const List = [
{ name: '토마토' },
{ name: '고구마' },
{ name: '감자' },
{ name: '오이*극혐' },
{ name: '구황작물조아' },
]
//드롭여부 확인
const [isActive, setIsActive] = useState(false);
const [category, setCategory] = useState("")
const [search, setSearch] = useState("")
return (
<div>
<DropWrap>
<button className="dropbtn" onClick={() => setIsActive(!isActive)}>
{category ? <p>{category}</p> : <p>카테고리</p>}
{isActive ? <AiOutlineUp size="20" /> : <AiOutlineDown size="20" />}
</button>
{isActive && (
<CategoryWrap>
<input
className="category"
placeholder="검색어를 입력하세요"
onChange={(e) => {
setSearch(e.target.value);
}}
></input>
{List.filter((d) => {
if (search === "") {
return d
} else if (d.name.toLowerCase().includes(search.toLowerCase())) {
return d;
}
}).map(d => {
return (
<div
className="category"
onClick={() => {
setCategory(d.name);
setIsActive(false);
}}
key={d.name}
s
>
{d.name}
</div>
);
})}
</CategoryWrap>
)}
</DropWrap>
</div>
);
};
const DropWrap = styled.div`
position: relative;
width: 400px;
margin: 30px auto;
.dropbtn {
display: flex;
justify-content: space-between;
background-color: #ffffff;
align-items: center;
border-radius: 4px;
padding: 15px;
border: 1px solid #ceced9;
width: 400px;
height: 43px;
cursor: pointer;
}
`;
const CategoryWrap = styled.div`
position: absolute;
margin-top: 10px;
width: 400px;
border: 1px solid #ceced9;
border-radius: 4px;
transition: all 1s;
.category {
padding: 15px;
border: none;
border-bottom: 1px solid gray;
width: 370px;
:focus {
outline: none;
}
}
`;
const Line = styled.hr`
width: 88%;
margin: auto;
border: 0.5px solid #e4e2eb;
`;
export default Dropdown;
728x90
'FE' 카테고리의 다른 글
TS & RN - props 타입 선언법 (0) | 2022.07.06 |
---|---|
TS - defaultProps 사용법 (0) | 2022.05.12 |
REACT - 회원가입 유효성 검사 & 비밀번호 토글 기능 (0) | 2022.04.25 |
CSS - slide animation 참고 사이트 (0) | 2022.03.26 |
React - 환경변수 설정 !(configureStore) (0) | 2022.03.26 |