From 34de3d0c7bd78ecbfe76b316dad853a406896c59 Mon Sep 17 00:00:00 2001 From: Rhino-ty Date: Tue, 25 Apr 2023 16:03:57 +0900 Subject: [PATCH] =?UTF-8?q?#46=20-=20feat:=20=EB=93=9C=EB=A1=AD=EB=8B=A4?= =?UTF-8?q?=EC=9A=B4=20UI=20props=EB=A1=9C=20=EB=8C=80=EC=B2=B4=20?= =?UTF-8?q?=ED=9B=84=20=EC=9E=84=EC=8B=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 전에 만들었던 signup/dropdown.tsx 참고, label, list, selected, onSelectedChange --- src/components/ui/dropDownUI.tsx | 128 ++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/src/components/ui/dropDownUI.tsx b/src/components/ui/dropDownUI.tsx index f9e19fd3..c6758719 100644 --- a/src/components/ui/dropDownUI.tsx +++ b/src/components/ui/dropDownUI.tsx @@ -1,3 +1,127 @@ -export default function DropDownUI() { - return <>; +import React, { useState, useCallback } from "react"; +import styled from "styled-components"; + +interface StyledInputProps { + isActive: boolean; } + +interface DropDownProps { + label: string; + list: string[]; + selected: string; + onSelectedChange: (selected: string) => void; +} + +export default function DropDown({ label, list, selected, onSelectedChange }: DropDownProps) { + const [isActive, setIsActive] = useState(false); + + const onActiveToggle = useCallback(() => { + setIsActive((prev) => !prev); + }, []); + + const handleSelectItem: React.MouseEventHandler = useCallback( + (e) => { + const target = e.target as HTMLLIElement; + const selectedNation = target.innerText; + onSelectedChange(selectedNation); + setIsActive(false); + }, + [onSelectedChange] + ); + + return ( + + {label} + + + {selected} + + + + {list.map((item) => ( + + {item} + + ))} + + + + ); +} +const S = { + Container: styled.div` + display: flex; + flex-direction: column; + `, + Label: styled.label` + margin-bottom: 8px; + font-size: 16px; + font-weight: 600; + color: #1f1f33; + `, + DropdownContainer: styled.div` + position: relative; + width: 100%; + &:hover { + cursor: pointer; + } + `, + DropdownBody: styled.div` + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; + height: 50px; + padding: 12px 16px; + background-color: #f8f8fa; + border: 1px solid #dcdce0; + border-radius: 8px; + `, + Selected: styled.div` + font-size: 16px; + color: #1f1f33; + `, + Caret: styled.div` + width: 0; + height: 0; + margin-left: 8px; + border-top: 6px solid #1f1f33; + border-right: 6px solid transparent; + border-left: 6px solid transparent; + `, + DropdownMenu: styled.ul` + position: absolute; + top: 100%; + left: 0; + z-index: 1; + width: 100%; + max-height: 200px; + padding: 8px 0; + background-color: #ffffff; + border: 1px solid #dcdce0; + border-radius: 8px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); + overflow-y: auto; + display: ${(props) => (props.isActive ? "block" : "none")}; + width: 452px; + height: 208px; + border: 1px solid #dcdce0; + border-radius: 8px; + padding-top: 21px; + `, + DropdownItemContainer: styled.li` + display: flex; + align-items: center; + padding-top: 0px; + padding-bottom: 12px; + padding-left: 16px; + &:hover { + background-color: #f8f8fa; + cursor: pointer; + } + `, + Item: styled.div` + font-size: 16px; + color: #1f1f33; + `, +};