-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu.tsx
56 lines (51 loc) · 1.41 KB
/
menu.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
import { UseSelectReturnValue } from "downshift";
import { ReactElement } from "react";
import { DropdownOption } from "./box";
const Option = (props: {
select: UseSelectReturnValue<string>;
option: DropdownOption;
index: number;
}): ReactElement => {
const { select, option, index } = props;
const isSelected = select.selectedItem === option.value;
const isHighlighted = select.highlightedIndex === index;
return (
<li
className={[
"px-18 select-none",
option.isHeading ? "text-15 text-A0A uppercase" : "",
option.isHeading && index !== 0 ? "mt-18" : "",
isSelected ? "bg-718" : "",
isHighlighted && !isSelected ? "bg-4A5" : "",
].join(" ")}
{...select.getItemProps({ item: option.value, index })}
>
{option.label}
</li>
);
};
export const DropdownMenu = (props: {
select: UseSelectReturnValue<string>;
options: DropdownOption[];
}): ReactElement => {
const { select, options } = props;
return (
<ul
{...select.getMenuProps()}
className={[
"bg-2D3 text-FFF shadow-A0A text-18 leading-36",
"absolute left-0 top-0 z-1 w-320 py-9",
!select.isOpen ? "hidden" : "",
].join(" ")}
>
{options.map((option, index) => (
<Option
key={`${option.value}${index}`}
select={select}
option={option}
index={index}
/>
))}
</ul>
);
};