-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMenu.tsx
More file actions
76 lines (70 loc) · 2.08 KB
/
Menu.tsx
File metadata and controls
76 lines (70 loc) · 2.08 KB
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
import React from "react";
import { View, TouchableOpacity } from "react-native";
import { BrandText } from "./BrandText";
import { PrimaryBox } from "./boxes/PrimaryBox";
import { useDropdowns } from "@/hooks/useDropdowns";
import { neutral33 } from "@/utils/style/colors";
import { fontRegular13 } from "@/utils/style/fonts";
import { layout } from "@/utils/style/layout";
const DEFAULT_WIDTH = 164;
interface MenuProps {
component: React.ReactNode;
items: {
label: string;
onPress: () => void;
disabled?: boolean;
}[];
width?: number;
}
export const Menu: React.FC<MenuProps> = ({
items,
component,
width = DEFAULT_WIDTH,
}) => {
const [isDropdownOpen, setDropdownState, dropdownRef] = useDropdowns();
return (
<View style={{ position: "relative" }}>
<TouchableOpacity onPress={() => setDropdownState(!isDropdownOpen)}>
{component}
</TouchableOpacity>
{isDropdownOpen && (
<View ref={dropdownRef} collapsable={false}>
<PrimaryBox
style={{
position: "absolute",
right: 0,
bottom: -20,
width,
paddingHorizontal: layout.spacing_x1_5,
}}
>
{items.map((item, index) => (
<TouchableOpacity
disabled={item.disabled}
key={item.label}
onPress={() => {
setDropdownState(false);
item.onPress();
}}
activeOpacity={0.7}
style={[
{ paddingVertical: layout.spacing_x1_5, width: "100%" },
index !== items.length - 1 && {
borderBottomWidth: 1,
borderColor: neutral33,
},
]}
>
<BrandText
style={[fontRegular13, item.disabled && { opacity: 0.5 }]}
>
{item.label}
</BrandText>
</TouchableOpacity>
))}
</PrimaryBox>
</View>
)}
</View>
);
};