-
Notifications
You must be signed in to change notification settings - Fork 52
/
App.tsx
308 lines (300 loc) · 11.5 KB
/
App.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* eslint-disable prettier/prettier */
import { CircleUser, CreditCard, Settings } from 'lucide-react-native';
import { useState } from 'react';
import { Alert, ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { Avatar, AvatarFallback, AvatarImage } from './components/Avatar';
import { Badge } from './components/Badge';
import { Button } from './components/Button';
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from './components/Card';
import { Checkbox } from './components/Checkbox';
import { Dialog, DialogContent, DialogTrigger } from './components/Dialog';
import {
DropDown,
DropDownContent,
DropDownItem,
DropDownItemSeparator,
DropDownLabel,
DropDownTrigger,
} from './components/DropDown';
import { Input } from './components/Input';
import { Progress } from './components/Progress';
import {
RadioGroup,
RadioGroupItem,
RadioGroupLabel,
} from './components/RadioGroup';
import { ISelectedValue, Select } from './components/Select';
import { Skeleton } from './components/Skeleton';
import { Switch } from './components/Switch';
import { Tabs, TabsContent, TabsList, TabsTrigger } from './components/Tabs';
import { ToastProvider, ToastVariant, useToast } from './components/Toast';
import './styles/globals.css';
export default function App() {
const [inputText, onChangeText] = useState('');
const [isEnabled, setIsEnabled] = useState(false);
const [selectedOption, setSelectedOption] = useState<ISelectedValue>();
return (
<ToastProvider position="top">
<ScrollView className="bg-background flex-1 py-16 px-10">
<Text className="mb-2 text-3xl underline text-primary">
nativecn-ui
</Text>
<View className="flex gap-3 mb-8">
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Avatar</Text>
<View className="flex justify-center items-center flex-row gap-4">
<Avatar className="h-14 w-14">
<AvatarImage
source={{
uri: 'https://pbs.twimg.com/profile_images/1745949238519803904/ZHwM5B07_400x400.jpg',
}}
/>
<AvatarFallback>CG</AvatarFallback>
</Avatar>
<Avatar className="h-14 w-14">
<AvatarImage
source={{
uri: 'https://pbs.twimg.com/profile_images/1603610343905058816/PsPEWMOJ_400x400.jpg',
}}
/>
<AvatarFallback>SS</AvatarFallback>
</Avatar>
</View>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Badge</Text>
<View className="flex flex-row gap-2">
<Badge label="Badge" />
<Badge label="Badge" variant="secondary" />
<Badge label="Badge" variant="destructive" />
<Badge label="Badge" className="bg-amber-400 dark:bg-amber-600" />
<Badge label="Badge" variant="success" />
</View>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Button</Text>
<View className="flex flex-row gap-3">
<Button label="Button" onPress={() => Alert.alert('Pressed 1')} />
<Button
label="Button"
variant="secondary"
onPress={() => Alert.alert('Pressed 2')}
/>
<Button
label="Button"
variant="destructive"
onPress={() => Alert.alert('Pressed 3')}
/>
</View>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Card</Text>
<Card>
<CardHeader>
<CardTitle>Accelerate UI</CardTitle>
<CardDescription>
Enter a new development experience
</CardDescription>
</CardHeader>
<CardContent>
<Text className="text-base text-primary">
Sleek, easy to use components to build your next app faster.
</Text>
</CardContent>
<CardFooter>
<Text className="text-sm text-muted-foreground">
Inspired by shadcn/ui
</Text>
</CardFooter>
</Card>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Checkbox</Text>
<Checkbox label="Accept T&C" />
</View>
{/* DropDown ComponentView */}
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">DropDown</Text>
<Text className="text-primary text-base">
Displays a menu to the user - such as a set of actions of
functions - triggered by a button
</Text>
<View className="rounded-xl border border-border z-50">
<DropDown>
<DropDownTrigger>
<Button label="Open Dropdown" />
</DropDownTrigger>
<DropDownContent>
<DropDownLabel labelTitle="My Account" />
<DropDownItemSeparator />
<DropDownItem>
<TouchableOpacity className="flex flex-row gap-2 items-center">
<CircleUser size={18} color="#fff" />
<Text className="text-primary text-xl">Profile</Text>
</TouchableOpacity>
</DropDownItem>
<DropDownItem>
<TouchableOpacity className="flex flex-row gap-2 items-center">
<Settings size={18} color="#fff" />
<Text className="text-primary text-xl">Settings</Text>
</TouchableOpacity>
</DropDownItem>
<DropDownItem>
<TouchableOpacity className="flex flex-row gap-2 items-center">
<CreditCard size={18} color="#fff" />
<Text className="text-primary text-xl">Billing</Text>
</TouchableOpacity>
</DropDownItem>
<DropDownLabel labelTitle="Team" />
<DropDownItemSeparator />
<DropDownItem>
<TouchableOpacity className="flex flex-row gap-2 items-center">
<CreditCard size={18} color="#fff" />
<Text className="text-primary text-xl">Billing</Text>
</TouchableOpacity>
</DropDownItem>
</DropDownContent>
</DropDown>
</View>
</View>
{/* Dialog ComponentView */}
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Dialog</Text>
<Dialog>
<DialogTrigger>
<Button label="Open Dialog" />
</DialogTrigger>
<DialogContent>
<View className="flex gap-4">
<Text className="font-semibold text-xl text-primary">
Dialog Content
</Text>
<Text className="text-primary">
Tap outside the dialog to close it.
</Text>
</View>
</DialogContent>
</Dialog>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Input</Text>
<View>
<Input
placeholder="Email"
value={inputText}
onChangeText={onChangeText}
/>
</View>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">
Radio Group
</Text>
<RadioGroup defaultValue="dark">
<RadioGroupItem value="light" label="Light" />
<RadioGroupItem value="dark" label="Dark" />
<View className="flex flex-row items-center gap-2">
<RadioGroupItem value="system" />
<RadioGroupLabel value="system">
<AvatarImage
className="h-8 w-8 rounded-full"
source={{
uri: 'https://avatars.githubusercontent.com/u/75042455?s=200&v=4',
}}
/>
</RadioGroupLabel>
</View>
</RadioGroup>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Skeleton</Text>
<View className="flex">
<Skeleton className="w-48 h-4 mb-1" />
<Skeleton className="w-60 h-4 mb-1" />
<Skeleton className="w-56 h-4 mb-1" />
<Skeleton className="w-36 h-4" />
</View>
</View>
<View className="flex gap-2">
<Text className="font-semibold text-xl text-primary">Switch</Text>
<View className="flex">
<Switch onValueChange={setIsEnabled} value={isEnabled} />
</View>
</View>
<View className="flex gap-2 mt-1">
<Text className="font-semibold text-xl text-primary">Tabs</Text>
<Tabs defaultValue="account">
<TabsList>
<TabsTrigger value="account" title="Account" />
<TabsTrigger value="password" title="Password" />
</TabsList>
<TabsContent value="account">
<Text className="text-primary">
Make changes to your account here.
</Text>
</TabsContent>
<TabsContent value="password">
<Text className="text-primary">Change your password here.</Text>
</TabsContent>
</Tabs>
</View>
<View>
<Text className="font-semibold text-xl dark:text-white">Toast</Text>
<View className="flex mx-auto">
<ExampleToast />
</View>
</View>
<View className="gap-2 mb-2">
<Text className="font-semibold text-xl text-primary">Progress</Text>
<View>
<Progress value={50} className="mb-2" />
</View>
</View>
{/* Select Component */}
<View className="gap-4 mb-40">
<Text className="font-semibold text-xl text-primary">Select</Text>
<Select
label="Choose an option"
options={[
{ id: 1, name: 'Option 1' },
{ id: 2, name: 'Option 2' },
]}
labelKey="name"
valueKey="id"
selectedValue={selectedOption}
onSelect={value => setSelectedOption(value)}
/>
</View>
</View>
</ScrollView>
</ToastProvider>
);
}
function ExampleToast() {
const { toast } = useToast();
const variants: ToastVariant[] = [
'default',
'success',
'destructive',
'info',
];
return (
<Button
label="Toast"
onPress={() => {
variants.forEach((variant, index) => {
setTimeout(() => {
toast(`${variant} toast`, variant, 3000, 'bottom', true);
}, index * 1000);
});
}}
/>
);
}