-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from DyadStablecoin/feature/dropdown
Feature/dropdown
- Loading branch information
Showing
2 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,73 @@ | ||
import { Select } from "@chakra-ui/react"; | ||
import { animated, useSpring } from "react-spring"; | ||
import { useRef, useEffect, useState } from "react"; | ||
import classNames from "classnames"; | ||
import Icon from "./Icon"; | ||
import { COLORS } from "../consts/colors"; | ||
import { DownOutlined } from "@ant-design/icons"; | ||
|
||
export default function Dropdown({ options, onChange }) { | ||
const [selectedOption, setSelectedOption] = useState(); | ||
const [isShowingOptions, setIsShowingOptions] = useState(false); | ||
const [style, animate] = useSpring(() => ({ height: "0px" }), []); | ||
const ref = useRef(null); | ||
|
||
useEffect(() => { | ||
animate({ | ||
height: (isShowingOptions ? ref.current.offsetHeight : 0) + "px", | ||
}); | ||
}, [animate, ref, isShowingOptions]); | ||
|
||
return ( | ||
<Select onChange={(event) => onChange(event.target.value)}> | ||
{options.map((option) => ( | ||
<option key={option} value={option} style={{ color: "black" }}> | ||
{option} | ||
</option> | ||
))} | ||
</Select> | ||
<div className="w-full"> | ||
<> | ||
<div className={"w-max justify-start flex gap-4 items-center"}> | ||
<a | ||
className={"cursor-pointer text-white"} | ||
onClick={() => setIsShowingOptions(!isShowingOptions)} | ||
> | ||
{selectedOption ? selectedOption : `Select an Option`} | ||
</a> | ||
<div | ||
className={classNames( | ||
"transition-all duration-150 w-min h-min", | ||
isShowingOptions ? "rotate-0" : "rotate-180" | ||
)} | ||
> | ||
<Icon onClick={() => setIsShowingOptions(!isShowingOptions)}> | ||
<DownOutlined | ||
style={{ fontSize: "0.9rem", color: COLORS.Purple }} | ||
/> | ||
</Icon> | ||
</div> | ||
</div> | ||
</> | ||
|
||
{isShowingOptions && ( | ||
<animated.div | ||
className="absolute overflow-hidden min-w-[6.5rem] z-50 bg-black border border-white w-max" | ||
style={{ | ||
...style, | ||
}} | ||
> | ||
<div ref={ref} className="flex flex-col w-full"> | ||
{options.map((option) => { | ||
return ( | ||
<a | ||
key={option} | ||
className="px-4 py-2 text-sm text-white transition-all bg-black cursor-pointer hover:text-black hover:bg-white" | ||
onClick={() => { | ||
setIsShowingOptions(false); | ||
setSelectedOption(option); | ||
onChange(option); | ||
}} | ||
> | ||
{option} | ||
</a> | ||
); | ||
})} | ||
</div> | ||
</animated.div> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115b3f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
frontend – ./
frontend-woad-pi.vercel.app
frontend-dyad.vercel.app
frontend-git-main-dyad.vercel.app
dyadstable.xyz
www.dyadstable.xyz