|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { Text, TouchableOpacity, View } from 'react-native' |
| 3 | +import { TextInput } from 'rn-base-component' |
| 4 | +import { demoStyles } from './styles' |
| 5 | + |
| 6 | +export const IconsAndComponents = () => { |
| 7 | + const [searchText, setSearchText] = useState('') |
| 8 | + const [phoneNumber, setPhoneNumber] = useState('') |
| 9 | + const [isPasswordVisible, setIsPasswordVisible] = useState(false) |
| 10 | + |
| 11 | + const SearchIcon = () => ( |
| 12 | + <View style={{ paddingHorizontal: 8 }}> |
| 13 | + <Text style={{ fontSize: 16 }}>🔍</Text> |
| 14 | + </View> |
| 15 | + ) |
| 16 | + |
| 17 | + const PhoneIcon = () => ( |
| 18 | + <View style={{ paddingHorizontal: 8 }}> |
| 19 | + <Text style={{ fontSize: 16 }}>📞</Text> |
| 20 | + </View> |
| 21 | + ) |
| 22 | + |
| 23 | + const EyeIcon = ({ visible }: { visible: boolean }) => ( |
| 24 | + <TouchableOpacity |
| 25 | + onPress={() => setIsPasswordVisible(!visible)} |
| 26 | + style={{ paddingHorizontal: 8 }} |
| 27 | + > |
| 28 | + <Text style={{ fontSize: 16 }}>{visible ? '👁️' : '🙈'}</Text> |
| 29 | + </TouchableOpacity> |
| 30 | + ) |
| 31 | + |
| 32 | + const ClearButton = ({ onClear }: { onClear: () => void }) => ( |
| 33 | + <TouchableOpacity onPress={onClear} style={{ paddingHorizontal: 8 }}> |
| 34 | + <Text style={{ fontSize: 16 }}>❌</Text> |
| 35 | + </TouchableOpacity> |
| 36 | + ) |
| 37 | + |
| 38 | + const UnitLabel = ({ unit }: { unit: string }) => ( |
| 39 | + <View style={{ paddingHorizontal: 8, backgroundColor: '#f0f0f0', borderRadius: 4, paddingVertical: 2 }}> |
| 40 | + <Text style={{ fontSize: 12, color: '#666' }}>{unit}</Text> |
| 41 | + </View> |
| 42 | + ) |
| 43 | + |
| 44 | + return ( |
| 45 | + <View style={demoStyles.section}> |
| 46 | + <Text style={demoStyles.sectionTitle}>🎨 Icons and Components</Text> |
| 47 | + <Text style={demoStyles.sectionDescription}> |
| 48 | + TextInput with left and right components for enhanced UX |
| 49 | + </Text> |
| 50 | + |
| 51 | + <View style={demoStyles.example}> |
| 52 | + <Text style={demoStyles.exampleTitle}>Search Input with Icon</Text> |
| 53 | + <TextInput |
| 54 | + label="Search" |
| 55 | + placeholder="Search for something..." |
| 56 | + value={searchText} |
| 57 | + onChangeText={setSearchText} |
| 58 | + leftComponent={<SearchIcon />} |
| 59 | + rightComponent={ |
| 60 | + searchText ? <ClearButton onClear={() => setSearchText('')} /> : undefined |
| 61 | + } |
| 62 | + /> |
| 63 | + </View> |
| 64 | + |
| 65 | + <View style={demoStyles.example}> |
| 66 | + <Text style={demoStyles.exampleTitle}>Phone Number Input</Text> |
| 67 | + <TextInput |
| 68 | + label="Phone Number" |
| 69 | + placeholder="(123) 456-7890" |
| 70 | + value={phoneNumber} |
| 71 | + onChangeText={setPhoneNumber} |
| 72 | + keyboardType="phone-pad" |
| 73 | + leftComponent={<PhoneIcon />} |
| 74 | + /> |
| 75 | + </View> |
| 76 | + |
| 77 | + <View style={demoStyles.example}> |
| 78 | + <Text style={demoStyles.exampleTitle}>Password with Visibility Toggle</Text> |
| 79 | + <TextInput |
| 80 | + label="Password" |
| 81 | + placeholder="Enter your password" |
| 82 | + secureTextEntry={!isPasswordVisible} |
| 83 | + rightComponent={<EyeIcon visible={isPasswordVisible} />} |
| 84 | + /> |
| 85 | + </View> |
| 86 | + |
| 87 | + <View style={demoStyles.example}> |
| 88 | + <Text style={demoStyles.exampleTitle}>Weight Input with Unit</Text> |
| 89 | + <TextInput |
| 90 | + label="Weight" |
| 91 | + placeholder="Enter weight" |
| 92 | + keyboardType="numeric" |
| 93 | + rightComponent={<UnitLabel unit="kg" />} |
| 94 | + /> |
| 95 | + </View> |
| 96 | + |
| 97 | + <View style={demoStyles.example}> |
| 98 | + <Text style={demoStyles.exampleTitle}>Price Input with Currency</Text> |
| 99 | + <TextInput |
| 100 | + label="Price" |
| 101 | + placeholder="0.00" |
| 102 | + keyboardType="numeric" |
| 103 | + leftComponent={<UnitLabel unit="$" />} |
| 104 | + /> |
| 105 | + </View> |
| 106 | + |
| 107 | + <View style={demoStyles.example}> |
| 108 | + <Text style={demoStyles.exampleTitle}>Complex Example - Email with Actions</Text> |
| 109 | + <TextInput |
| 110 | + label="Email Address" |
| 111 | + placeholder="your@email.com" |
| 112 | + keyboardType="email-address" |
| 113 | + autoCapitalize="none" |
| 114 | + leftComponent={ |
| 115 | + <View style={{ paddingHorizontal: 8 }}> |
| 116 | + <Text style={{ fontSize: 16 }}>✉️</Text> |
| 117 | + </View> |
| 118 | + } |
| 119 | + rightComponent={ |
| 120 | + <View style={{ flexDirection: 'row' }}> |
| 121 | + <TouchableOpacity style={{ paddingHorizontal: 8 }}> |
| 122 | + <Text style={{ fontSize: 16 }}>📎</Text> |
| 123 | + </TouchableOpacity> |
| 124 | + <TouchableOpacity style={{ paddingHorizontal: 8 }}> |
| 125 | + <Text style={{ fontSize: 16 }}>⚙️</Text> |
| 126 | + </TouchableOpacity> |
| 127 | + </View> |
| 128 | + } |
| 129 | + /> |
| 130 | + </View> |
| 131 | + </View> |
| 132 | + ) |
| 133 | +} |
0 commit comments