forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigation-menu.tsx
191 lines (184 loc) · 6.77 KB
/
navigation-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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { useNavigation } from 'expo-router';
import { Sparkles } from '~/components/Icons';
import * as React from 'react';
import { Platform, Pressable, StyleSheet, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
navigationMenuTriggerStyle,
} from '~/components/ui/navigation-menu';
import { TextRef } from '~/components/primitives/types';
import { cn } from '~/lib/utils';
import { Text } from '~/components/ui/typography';
export default function MenubarScreen() {
const insets = useSafeAreaInsets();
const contentInsets = {
top: insets.top,
bottom: insets.bottom,
left: 12,
right: 12,
};
const [value, setValue] = React.useState<string>();
const navigation = useNavigation();
function closeAll() {
setValue('');
}
React.useEffect(() => {
const sub = navigation.addListener('blur', () => {
closeAll();
});
return sub;
}, []);
return (
<View className='flex-1 items-center px-6 py-3 gap-12'>
{Platform.OS !== 'web' && !!value && (
<Pressable
onPress={() => {
setValue('');
}}
style={StyleSheet.absoluteFill}
/>
)}
<NavigationMenu value={value} onValueChange={setValue}>
<NavigationMenuList>
<NavigationMenuItem value='getting-started'>
<NavigationMenuTrigger>
<Text>Getting started</Text>
</NavigationMenuTrigger>
<NavigationMenuContent insets={contentInsets}>
<View
role='list'
className='web:grid gap-3 p-6 md:w-[400px] lg:w-[500px] web:lg:grid-cols-[.75fr_1fr]'
>
<View role='listitem' className='web:row-span-3'>
<NavigationMenuLink asChild>
<View className='flex web:select-none flex-col justify-end rounded-md web:bg-gradient-to-b web:from-muted/50 web:to-muted native:border native:border-border p-6 web:no-underline web:outline-none web:focus:shadow-md web:focus:shadow-foreground/5'>
<Sparkles size={16} className='text-foreground' />
<Text className='mb-2 mt-4 text-lg native:text-2xl font-medium'>
react-native-reusables
</Text>
<Text className='text-sm native:text-base leading-tight text-muted-foreground'>
Universal components that you can copy and paste into
your apps. Accessible. Customizable. Open Source.
</Text>
</View>
</NavigationMenuLink>
</View>
<ListItem href='/docs' title='Introduction'>
<Text>
Re-usable components built using Radix UI on the web and
Tailwind CSS.
</Text>
</ListItem>
<ListItem href='/docs/installation' title='Installation'>
<Text>
How to install dependencies and structure your app.
</Text>
</ListItem>
<ListItem href='/docs/primitives/typography' title='Typography'>
<Text>Styles for headings, paragraphs, lists...etc</Text>
</ListItem>
</View>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem value='components'>
<NavigationMenuTrigger>
<Text className='text-foreground '>Components</Text>
</NavigationMenuTrigger>
<NavigationMenuContent insets={contentInsets}>
<View
role='list'
className='web:grid w-[400px] gap-3 p-4 md:w-[500px] web:md:grid-cols-2 lg:w-[600px] '
>
{components.map((component) => (
<ListItem
key={component.title}
title={component.title}
href={component.href}
>
{component.description}
</ListItem>
))}
</View>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem value='documentation'>
<NavigationMenuLink
onPress={closeAll}
className={navigationMenuTriggerStyle()}
>
<Text>Documentation</Text>
</NavigationMenuLink>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
</View>
);
}
const components: { title: string; href: string; description: string }[] = [
{
title: 'Alert Dialog',
href: '/alert-dialog/alert-dialog-universal',
description:
'A modal dialog that interrupts the user with important content and expects a response.',
},
{
title: 'Hover Card',
href: '/hover-card/hover-card-universal',
description:
'For sighted users to preview content available behind a link.',
},
{
title: 'Progress',
href: '/progress/progress-universal',
description:
'Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.',
},
{
title: 'Scroll-area',
href: '/scroll-area/scroll-area-universal',
description: 'Visually or semantically separates content.',
},
{
title: 'Tabs',
href: '/tabs/tabs-universal',
description:
'A set of layered sections of content—known as tab panels—that are displayed one at a time.',
},
{
title: 'Tooltip',
href: '/tooltip/tooltip-universal',
description:
'A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.',
},
];
const ListItem = React.forwardRef<
TextRef,
React.ComponentPropsWithoutRef<typeof Text> & { title: string; href: string }
>(({ className, title, children, ...props }, ref) => {
return (
<View role='listitem'>
<NavigationMenuLink
ref={ref}
className={cn(
'web:block web:select-none gap-1 rounded-md p-3 leading-none no-underline text-foreground web:outline-none web:transition-colors web:hover:bg-accent active:bg-accent web:hover:text-accent-foreground web:focus:bg-accent web:focus:text-accent-foreground',
className
)}
{...props}
>
<Text className='text-sm native:text-base font-medium text-foreground leading-none'>
{title}
</Text>
<Text className='line-clamp-2 text-sm native:text-base leading-snug text-muted-foreground'>
{children}
</Text>
</NavigationMenuLink>
</View>
);
});
ListItem.displayName = 'ListItem';