forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.tsx
138 lines (136 loc) · 3.94 KB
/
command.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
import {
Activity,
Airplay,
AlarmClockIcon,
AlertCircle,
AlignRight,
Baby,
BadgeAlert,
Calendar,
Database,
Ear,
Fan,
GalleryHorizontal,
Lamp,
Table,
} from 'lucide-react-native';
import React from 'react';
import { Alert, Pressable, Text, View } from 'react-native';
import { buttonTextVariants, buttonVariants } from '~/components/ui/button';
import {
Command,
CommandContent,
CommandInput,
CommandList,
CommandListHeader,
CommandListHeaderProps,
CommandListItem,
CommandListItemProps,
CommandTrigger,
} from '~/components/ui/command';
import { cn } from '~/lib/utils';
export default function CommandScreen() {
const renderSectionHeader = React.useCallback(
(props: CommandListHeaderProps) => {
return <CommandListHeader>{props.item}</CommandListHeader>;
},
[]
);
const renderItem = React.useCallback(
({ index, item }: CommandListItemProps<(typeof data)[number]>) => {
if (typeof item === 'string') return null;
return (
<CommandListItem index={index}>
{({ pressed }) => {
const Icon = item.icon;
return (
<>
<Icon
className={cn(pressed && 'opacity-70', 'text-foreground')}
size={21}
/>
<Text
className={cn(
pressed && 'opacity-70',
'text-foreground font-semibold text-lg'
)}
>
{item.title}
</Text>
</>
);
}}
</CommandListItem>
);
},
[]
);
return (
<View className='flex-1 justify-center items-center'>
<Command
data={data}
filterFn={(search, item) => {
return item.title.toLowerCase().includes(search.toLowerCase());
}}
onItemSelected={(item) => {
Alert.alert(item.title);
}}
>
<CommandTrigger className={buttonVariants()}>
{({ pressed }) => (
<Text
className={buttonTextVariants({
className: pressed ? 'opacity-70' : '',
})}
>
Open Command
</Text>
)}
</CommandTrigger>
<CommandContent>
<CommandInput />
<CommandList
renderSectionHeader={renderSectionHeader}
renderItem={renderItem}
ListEmptyComponent={() => {
return (
<Pressable className='bg-background items-center p-6 rounded-b-2xl'>
<Text className='text-foreground text-lg font-semibold'>
No Results...
</Text>
</Pressable>
);
}}
/>
</CommandContent>
</Command>
</View>
);
}
const data = [
'HTML Basics',
{ title: 'Introduction to HTML', id: 'htmlIntro', icon: Calendar },
{ title: 'HTML Tags and Elements', id: 'htmlTags', icon: GalleryHorizontal },
'CSS Fundamentals',
{ title: 'CSS Selectors', id: 'cssSelectors', icon: Activity },
{ title: 'Box Model', id: 'boxModel', icon: Airplay },
'JavaScript Essentials',
{
title: 'Variables and Data Types',
id: 'jsVariables',
icon: AlarmClockIcon,
},
{ title: 'Functions and Scope', id: 'jsFunctions', icon: AlertCircle },
'React Framework',
{ title: 'React Components', id: 'reactComponents', icon: AlignRight },
{ title: 'State and Props', id: 'reactStateProps', icon: Baby },
'Responsive Web Design',
{ title: 'Media Queries', id: 'mediaQueries', icon: BadgeAlert },
{ title: 'Flexbox and Grid', id: 'flexboxGrid', icon: Database },
'Backend Development',
{ title: 'Node.js Basics', id: 'nodeBasics', icon: Fan },
{ title: 'RESTful APIs', id: 'restAPIs', icon: Table },
'Version Control (Git)',
{ title: 'Git Workflow', id: 'gitWorkflow', icon: Lamp },
{ title: 'Branches and Merging', id: 'gitBranches', icon: Ear },
];