forked from Nutlope/twitterbio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropDown.tsx
77 lines (71 loc) · 2.57 KB
/
DropDown.tsx
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Menu, Transition } from "@headlessui/react";
import {
CheckIcon,
ChevronDownIcon,
ChevronUpIcon,
} from "@heroicons/react/20/solid";
import { Fragment } from "react";
function classNames(...classes: string[]) {
return classes.filter(Boolean).join(" ");
}
export type VibeType = "Professional" | "Casual" | "Funny";
interface DropDownProps {
vibe: VibeType;
setVibe: (vibe: VibeType) => void;
}
let vibes: VibeType[] = ["Professional", "Casual", "Funny"];
export default function DropDown({ vibe, setVibe }: DropDownProps) {
return (
<Menu as="div" className="relative block text-left w-full">
<div>
<Menu.Button className="inline-flex w-full justify-between items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-black">
{vibe}
<ChevronUpIcon
className="-mr-1 ml-2 h-5 w-5 ui-open:hidden"
aria-hidden="true"
/>
<ChevronDownIcon
className="-mr-1 ml-2 h-5 w-5 hidden ui-open:block"
aria-hidden="true"
/>
</Menu.Button>
</div>
<Transition
as={Fragment}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items
className="absolute left-0 z-10 mt-2 w-full origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
key={vibe}
>
<div className="">
{vibes.map((vibeItem) => (
<Menu.Item key={vibeItem}>
{({ active }) => (
<button
onClick={() => setVibe(vibeItem)}
className={classNames(
active ? "bg-gray-100 text-gray-900" : "text-gray-700",
vibe === vibeItem ? "bg-gray-200" : "",
"px-4 py-2 text-sm w-full text-left flex items-center space-x-2 justify-between"
)}
>
<span>{vibeItem}</span>
{vibe === vibeItem ? (
<CheckIcon className="w-4 h-4 text-bold" />
) : null}
</button>
)}
</Menu.Item>
))}
</div>
</Menu.Items>
</Transition>
</Menu>
);
}