File size: 3,668 Bytes
7c41b6a b924fc9 7c41b6a b924fc9 |
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 |
import streamlit as st
import random
from typing import List, Dict
# Sample React Native and TypeScript components
samples: List[Dict[str, str]] = [
{
"name": "Basic Button",
"emoji": "π",
"code": """
import React from 'react';
import { Button } from 'react-native';
interface ButtonProps {
title: string;
onPress: () => void;
}
const BasicButton: React.FC<ButtonProps> = ({ title, onPress }) => (
<Button title={title} onPress={onPress} />
);
export default BasicButton;
"""
},
{
"name": "Text Input",
"emoji": "π",
"code": """
import React, { useState } from 'react';
import { TextInput, StyleSheet } from 'react-native';
interface TextInputProps {
placeholder: string;
}
const CustomTextInput: React.FC<TextInputProps> = ({ placeholder }) => {
const [text, setText] = useState('');
return (
<TextInput
style={styles.input}
onChangeText={setText}
value={text}
placeholder={placeholder}
/>
);
};
const styles = StyleSheet.create({
input: {
height: 40,
borderColor: 'gray',
borderWidth: 1,
padding: 10,
},
});
export default CustomTextInput;
"""
},
{
"name": "List View",
"emoji": "π",
"code": """
import React from 'react';
import { FlatList, Text, View, StyleSheet } from 'react-native';
interface Item {
id: string;
title: string;
}
interface ListViewProps {
data: Item[];
}
const ListView: React.FC<ListViewProps> = ({ data }) => (
<FlatList
data={data}
renderItem={({ item }) => (
<View style={styles.item}>
<Text>{item.title}</Text>
</View>
)}
keyExtractor={item => item.id}
/>
);
const styles = StyleSheet.create({
item: {
padding: 20,
borderBottomWidth: 1,
borderBottomColor: '#ccc',
},
});
export default ListView;
"""
},
]
def main():
st.title("React Native and TypeScript Mobile UI Generator π±")
st.sidebar.header("UI Components π§©")
selected_component = st.sidebar.selectbox(
"Choose a component:",
[f"{sample['emoji']} {sample['name']}" for sample in samples]
)
selected_index = [f"{sample['emoji']} {sample['name']}" for sample in samples].index(selected_component)
st.header(f"{samples[selected_index]['emoji']} {samples[selected_index]['name']}")
st.code(samples[selected_index]['code'], language='typescript')
st.subheader("Component Preview π")
st.warning("This is a placeholder for the component preview. In a full implementation, this would render a visual representation of the component.")
st.subheader("Customization Options π οΈ")
# Allow customization options
if "Basic Button" in selected_component:
button_label = st.text_input("Button Label", "Click Me")
if st.button(f"Generate {button_label}"):
st.success(f'Generated button with label "{button_label}"')
elif "Text Input" in selected_component:
placeholder = st.text_input("Placeholder", "Enter text...")
if st.button("Generate Text Input"):
st.success(f'Generated Text Input with placeholder "{placeholder}"')
elif "List View" in selected_component:
num_items = st.slider("Number of List Items", 1, 10, 5)
list_items = [f"Item {i}" for i in range(1, num_items + 1)]
if st.button("Generate List View"):
st.success(f"Generated List View with {num_items} items: {', '.join(list_items)}")
st.info("This is a basic implementation. Add more customization options as needed.")
if __name__ == "__main__":
main()
|