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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
from typing import List, Dict
|
4 |
+
|
5 |
+
# Sample React Native and TypeScript components
|
6 |
+
samples: List[Dict[str, str]] = [
|
7 |
+
{
|
8 |
+
"name": "Basic Button",
|
9 |
+
"emoji": "π",
|
10 |
+
"code": """
|
11 |
+
import React from 'react';
|
12 |
+
import { Button } from 'react-native';
|
13 |
+
|
14 |
+
interface ButtonProps {
|
15 |
+
title: string;
|
16 |
+
onPress: () => void;
|
17 |
+
}
|
18 |
+
|
19 |
+
const BasicButton: React.FC<ButtonProps> = ({ title, onPress }) => (
|
20 |
+
<Button title={title} onPress={onPress} />
|
21 |
+
);
|
22 |
+
|
23 |
+
export default BasicButton;
|
24 |
+
"""
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"name": "Text Input",
|
28 |
+
"emoji": "π",
|
29 |
+
"code": """
|
30 |
+
import React, { useState } from 'react';
|
31 |
+
import { TextInput, StyleSheet } from 'react-native';
|
32 |
+
|
33 |
+
interface TextInputProps {
|
34 |
+
placeholder: string;
|
35 |
+
}
|
36 |
+
|
37 |
+
const CustomTextInput: React.FC<TextInputProps> = ({ placeholder }) => {
|
38 |
+
const [text, setText] = useState('');
|
39 |
+
|
40 |
+
return (
|
41 |
+
<TextInput
|
42 |
+
style={styles.input}
|
43 |
+
onChangeText={setText}
|
44 |
+
value={text}
|
45 |
+
placeholder={placeholder}
|
46 |
+
/>
|
47 |
+
);
|
48 |
+
};
|
49 |
+
|
50 |
+
const styles = StyleSheet.create({
|
51 |
+
input: {
|
52 |
+
height: 40,
|
53 |
+
borderColor: 'gray',
|
54 |
+
borderWidth: 1,
|
55 |
+
padding: 10,
|
56 |
+
},
|
57 |
+
});
|
58 |
+
|
59 |
+
export default CustomTextInput;
|
60 |
+
"""
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"name": "List View",
|
64 |
+
"emoji": "π",
|
65 |
+
"code": """
|
66 |
+
import React from 'react';
|
67 |
+
import { FlatList, Text, View, StyleSheet } from 'react-native';
|
68 |
+
|
69 |
+
interface Item {
|
70 |
+
id: string;
|
71 |
+
title: string;
|
72 |
+
}
|
73 |
+
|
74 |
+
interface ListViewProps {
|
75 |
+
data: Item[];
|
76 |
+
}
|
77 |
+
|
78 |
+
const ListView: React.FC<ListViewProps> = ({ data }) => (
|
79 |
+
<FlatList
|
80 |
+
data={data}
|
81 |
+
renderItem={({ item }) => (
|
82 |
+
<View style={styles.item}>
|
83 |
+
<Text>{item.title}</Text>
|
84 |
+
</View>
|
85 |
+
)}
|
86 |
+
keyExtractor={item => item.id}
|
87 |
+
/>
|
88 |
+
);
|
89 |
+
|
90 |
+
const styles = StyleSheet.create({
|
91 |
+
item: {
|
92 |
+
padding: 20,
|
93 |
+
borderBottomWidth: 1,
|
94 |
+
borderBottomColor: '#ccc',
|
95 |
+
},
|
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(
|
522 |
+
"Choose a component:",
|
523 |
+
[f"{sample['emoji']} {sample['name']}" for sample in samples]
|
524 |
+
)
|
525 |
+
|
526 |
+
selected_index = [f"{sample['emoji']} {sample['name']}" for sample in samples].index(selected_component)
|
527 |
+
|
528 |
+
st.header(f"{samples[selected_index]['emoji']} {samples[selected_index]['name']}")
|
529 |
+
|
530 |
+
st.code(samples[selected_index]['code'], language='typescript')
|
531 |
+
|
532 |
+
st.subheader("Component Preview π")
|
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
|