awacke1 commited on
Commit
b924fc9
Β·
verified Β·
1 Parent(s): 7c41b6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -417
app.py CHANGED
@@ -96,426 +96,12 @@ const styles = StyleSheet.create({
96
  });
97
 
98
  export default ListView;
99
- """
100
- },
101
- {
102
- "name": "Toggle Switch",
103
- "emoji": "πŸ”›",
104
- "code": """
105
- import React, { useState } from 'react';
106
- import { Switch, View, Text, StyleSheet } from 'react-native';
107
-
108
- interface ToggleSwitchProps {
109
- label: string;
110
- }
111
-
112
- const ToggleSwitch: React.FC<ToggleSwitchProps> = ({ label }) => {
113
- const [isEnabled, setIsEnabled] = useState(false);
114
- const toggleSwitch = () => setIsEnabled(previousState => !previousState);
115
-
116
- return (
117
- <View style={styles.container}>
118
- <Text>{label}</Text>
119
- <Switch
120
- trackColor={{ false: "#767577", true: "#81b0ff" }}
121
- thumbColor={isEnabled ? "#f5dd4b" : "#f4f3f4"}
122
- onValueChange={toggleSwitch}
123
- value={isEnabled}
124
- />
125
- </View>
126
- );
127
- };
128
-
129
- const styles = StyleSheet.create({
130
- container: {
131
- flexDirection: 'row',
132
- justifyContent: 'space-between',
133
- alignItems: 'center',
134
- padding: 10,
135
- },
136
- });
137
-
138
- export default ToggleSwitch;
139
- """
140
- },
141
- {
142
- "name": "Card Component",
143
- "emoji": "πŸƒ",
144
- "code": """
145
- import React from 'react';
146
- import { View, Text, StyleSheet } from 'react-native';
147
-
148
- interface CardProps {
149
- title: string;
150
- content: string;
151
- }
152
-
153
- const Card: React.FC<CardProps> = ({ title, content }) => (
154
- <View style={styles.card}>
155
- <Text style={styles.title}>{title}</Text>
156
- <Text style={styles.content}>{content}</Text>
157
- </View>
158
- );
159
-
160
- const styles = StyleSheet.create({
161
- card: {
162
- backgroundColor: 'white',
163
- borderRadius: 8,
164
- padding: 16,
165
- margin: 8,
166
- shadowColor: "#000",
167
- shadowOffset: {
168
- width: 0,
169
- height: 2,
170
- },
171
- shadowOpacity: 0.25,
172
- shadowRadius: 3.84,
173
- elevation: 5,
174
- },
175
- title: {
176
- fontSize: 18,
177
- fontWeight: 'bold',
178
- marginBottom: 8,
179
- },
180
- content: {
181
- fontSize: 14,
182
- },
183
- });
184
-
185
- export default Card;
186
- """
187
- },
188
- {
189
- "name": "Modal Dialog",
190
- "emoji": "πŸ’¬",
191
- "code": """
192
- import React, { useState } from 'react';
193
- import { Modal, View, Text, Pressable, StyleSheet } from 'react-native';
194
-
195
- interface ModalDialogProps {
196
- title: string;
197
- content: string;
198
- }
199
-
200
- const ModalDialog: React.FC<ModalDialogProps> = ({ title, content }) => {
201
- const [modalVisible, setModalVisible] = useState(false);
202
-
203
- return (
204
- <View>
205
- <Modal
206
- animationType="slide"
207
- transparent={true}
208
- visible={modalVisible}
209
- onRequestClose={() => setModalVisible(!modalVisible)}
210
- >
211
- <View style={styles.centeredView}>
212
- <View style={styles.modalView}>
213
- <Text style={styles.modalText}>{title}</Text>
214
- <Text>{content}</Text>
215
- <Pressable
216
- style={[styles.button, styles.buttonClose]}
217
- onPress={() => setModalVisible(!modalVisible)}
218
- >
219
- <Text style={styles.textStyle}>Close</Text>
220
- </Pressable>
221
- </View>
222
- </View>
223
- </Modal>
224
- <Pressable
225
- style={[styles.button, styles.buttonOpen]}
226
- onPress={() => setModalVisible(true)}
227
- >
228
- <Text style={styles.textStyle}>Show Modal</Text>
229
- </Pressable>
230
- </View>
231
- );
232
- };
233
-
234
- const styles = StyleSheet.create({
235
- centeredView: {
236
- flex: 1,
237
- justifyContent: "center",
238
- alignItems: "center",
239
- marginTop: 22
240
- },
241
- modalView: {
242
- margin: 20,
243
- backgroundColor: "white",
244
- borderRadius: 20,
245
- padding: 35,
246
- alignItems: "center",
247
- shadowColor: "#000",
248
- shadowOffset: {
249
- width: 0,
250
- height: 2
251
- },
252
- shadowOpacity: 0.25,
253
- shadowRadius: 4,
254
- elevation: 5
255
- },
256
- button: {
257
- borderRadius: 20,
258
- padding: 10,
259
- elevation: 2
260
- },
261
- buttonOpen: {
262
- backgroundColor: "#F194FF",
263
- },
264
- buttonClose: {
265
- backgroundColor: "#2196F3",
266
- },
267
- textStyle: {
268
- color: "white",
269
- fontWeight: "bold",
270
- textAlign: "center"
271
- },
272
- modalText: {
273
- marginBottom: 15,
274
- textAlign: "center"
275
- }
276
- });
277
-
278
- export default ModalDialog;
279
- """
280
- },
281
- {
282
- "name": "Navigation Menu",
283
- "emoji": "🧭",
284
- "code": """
285
- import React from 'react';
286
- import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
287
-
288
- interface MenuItem {
289
- label: string;
290
- onPress: () => void;
291
- }
292
-
293
- interface NavigationMenuProps {
294
- items: MenuItem[];
295
- }
296
-
297
- const NavigationMenu: React.FC<NavigationMenuProps> = ({ items }) => (
298
- <View style={styles.container}>
299
- {items.map((item, index) => (
300
- <TouchableOpacity key={index} style={styles.menuItem} onPress={item.onPress}>
301
- <Text style={styles.menuText}>{item.label}</Text>
302
- </TouchableOpacity>
303
- ))}
304
- </View>
305
- );
306
-
307
- const styles = StyleSheet.create({
308
- container: {
309
- flexDirection: 'row',
310
- justifyContent: 'space-around',
311
- alignItems: 'center',
312
- backgroundColor: '#f0f0f0',
313
- height: 60,
314
- },
315
- menuItem: {
316
- padding: 10,
317
- },
318
- menuText: {
319
- fontSize: 16,
320
- },
321
- });
322
-
323
- export default NavigationMenu;
324
- """
325
- },
326
- {
327
- "name": "Image Carousel",
328
- "emoji": "πŸ–ΌοΈ",
329
- "code": """
330
- import React, { useState } from 'react';
331
- import { View, Image, StyleSheet, Dimensions } from 'react-native';
332
- import Carousel from 'react-native-snap-carousel';
333
-
334
- interface CarouselItem {
335
- id: string;
336
- imageUrl: string;
337
- }
338
-
339
- interface ImageCarouselProps {
340
- data: CarouselItem[];
341
- }
342
-
343
- const ImageCarousel: React.FC<ImageCarouselProps> = ({ data }) => {
344
- const [activeIndex, setActiveIndex] = useState(0);
345
- const windowWidth = Dimensions.get('window').width;
346
-
347
- const renderItem = ({ item }: { item: CarouselItem }) => (
348
- <View style={styles.slide}>
349
- <Image
350
- source={{ uri: item.imageUrl }}
351
- style={styles.image}
352
- />
353
- </View>
354
- );
355
-
356
- return (
357
- <Carousel
358
- data={data}
359
- renderItem={renderItem}
360
- sliderWidth={windowWidth}
361
- itemWidth={windowWidth - 60}
362
- onSnapToItem={index => setActiveIndex(index)}
363
- />
364
- );
365
- };
366
-
367
- const styles = StyleSheet.create({
368
- slide: {
369
- width: '100%',
370
- height: 200,
371
- justifyContent: 'center',
372
- alignItems: 'center',
373
- },
374
- image: {
375
- width: '100%',
376
- height: '100%',
377
- resizeMode: 'cover',
378
- borderRadius: 8,
379
- },
380
- });
381
-
382
- export default ImageCarousel;
383
- """
384
- },
385
- {
386
- "name": "Form Validation",
387
- "emoji": "βœ…",
388
- "code": """
389
- import React, { useState } from 'react';
390
- import { View, TextInput, Text, TouchableOpacity, StyleSheet } from 'react-native';
391
-
392
- interface FormData {
393
- email: string;
394
- password: string;
395
- }
396
-
397
- const FormValidation: React.FC = () => {
398
- const [formData, setFormData] = useState<FormData>({ email: '', password: '' });
399
- const [errors, setErrors] = useState<Partial<FormData>>({});
400
-
401
- const validateForm = (): boolean => {
402
- let newErrors: Partial<FormData> = {};
403
- if (!formData.email) newErrors.email = 'Email is required';
404
- if (!formData.password) newErrors.password = 'Password is required';
405
- setErrors(newErrors);
406
- return Object.keys(newErrors).length === 0;
407
- };
408
-
409
- const handleSubmit = () => {
410
- if (validateForm()) {
411
- console.log('Form submitted:', formData);
412
- } else {
413
- console.log('Form has errors');
414
- }
415
- };
416
-
417
- return (
418
- <View style={styles.container}>
419
- <TextInput
420
- style={styles.input}
421
- placeholder="Email"
422
- value={formData.email}
423
- onChangeText={(text) => setFormData({ ...formData, email: text })}
424
- />
425
- {errors.email && <Text style={styles.errorText}>{errors.email}</Text>}
426
- <TextInput
427
- style={styles.input}
428
- placeholder="Password"
429
- secureTextEntry
430
- value={formData.password}
431
- onChangeText={(text) => setFormData({ ...formData, password: text })}
432
- />
433
- {errors.password && <Text style={styles.errorText}>{errors.password}</Text>}
434
- <TouchableOpacity style={styles.button} onPress={handleSubmit}>
435
- <Text style={styles.buttonText}>Submit</Text>
436
- </TouchableOpacity>
437
- </View>
438
- );
439
- };
440
-
441
- const styles = StyleSheet.create({
442
- container: {
443
- padding: 20,
444
- },
445
- input: {
446
- height: 40,
447
- borderColor: 'gray',
448
- borderWidth: 1,
449
- marginBottom: 10,
450
- paddingHorizontal: 10,
451
- },
452
- errorText: {
453
- color: 'red',
454
- marginBottom: 10,
455
- },
456
- button: {
457
- backgroundColor: 'blue',
458
- padding: 10,
459
- borderRadius: 5,
460
- },
461
- buttonText: {
462
- color: 'white',
463
- textAlign: 'center',
464
- },
465
- });
466
-
467
- export default FormValidation;
468
- """
469
- },
470
- {
471
- "name": "Custom Hook",
472
- "emoji": "🎣",
473
- "code": """
474
- import { useState, useEffect } from 'react';
475
-
476
- interface UseFetchResult<T> {
477
- data: T | null;
478
- loading: boolean;
479
- error: Error | null;
480
- }
481
-
482
- function useFetch<T>(url: string): UseFetchResult<T> {
483
- const [data, setData] = useState<T | null>(null);
484
- const [loading, setLoading] = useState<boolean>(true);
485
- const [error, setError] = useState<Error | null>(null);
486
-
487
- useEffect(() => {
488
- const fetchData = async () => {
489
- try {
490
- const response = await fetch(url);
491
- if (!response.ok) {
492
- throw new Error(`HTTP error! status: ${response.status}`);
493
- }
494
- const result = await response.json();
495
- setData(result);
496
- } catch (e) {
497
- setError(e instanceof Error ? e : new Error('An unknown error occurred'));
498
- } finally {
499
- setLoading(false);
500
- }
501
- };
502
-
503
- fetchData();
504
- }, [url]);
505
-
506
- return { data, loading, error };
507
- }
508
-
509
- export default useFetch;
510
-
511
- // Usage example:
512
- // const { data, loading, error } = useFetch<YourDataType>('https://api.example.com/data');
513
  """
514
  },
515
  ]
516
 
517
  def main():
518
- st.title("React and TypeScript Mobile UI Generator πŸ“±")
519
 
520
  st.sidebar.header("UI Components 🧩")
521
  selected_component = st.sidebar.selectbox(
@@ -533,6 +119,25 @@ def main():
533
  st.warning("This is a placeholder for the component preview. In a full implementation, this would render a visual representation of the component.")
534
 
535
  st.subheader("Customization Options πŸ› οΈ")
536
- st.info("Here you can add customization options for the selected component. For example, color pickers, sliders for sizes, text inputs for labels, etc.")
537
 
538
- if st.button("Generate Component
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  });
97
 
98
  export default ListView;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  """
100
  },
101
  ]
102
 
103
  def main():
104
+ st.title("React Native and TypeScript Mobile UI Generator πŸ“±")
105
 
106
  st.sidebar.header("UI Components 🧩")
107
  selected_component = st.sidebar.selectbox(
 
119
  st.warning("This is a placeholder for the component preview. In a full implementation, this would render a visual representation of the component.")
120
 
121
  st.subheader("Customization Options πŸ› οΈ")
 
122
 
123
+ # Allow customization options
124
+ if "Basic Button" in selected_component:
125
+ button_label = st.text_input("Button Label", "Click Me")
126
+ if st.button(f"Generate {button_label}"):
127
+ st.success(f'Generated button with label "{button_label}"')
128
+
129
+ elif "Text Input" in selected_component:
130
+ placeholder = st.text_input("Placeholder", "Enter text...")
131
+ if st.button("Generate Text Input"):
132
+ st.success(f'Generated Text Input with placeholder "{placeholder}"')
133
+
134
+ elif "List View" in selected_component:
135
+ num_items = st.slider("Number of List Items", 1, 10, 5)
136
+ list_items = [f"Item {i}" for i in range(1, num_items + 1)]
137
+ if st.button("Generate List View"):
138
+ st.success(f"Generated List View with {num_items} items: {', '.join(list_items)}")
139
+
140
+ st.info("This is a basic implementation. Add more customization options as needed.")
141
+
142
+ if __name__ == "__main__":
143
+ main()