|
| 1 | +import { StyleSheet, Text, View, TextInput, TouchableOpacity, Keyboard, TouchableWithoutFeedback } from 'react-native' |
| 2 | +import React, { useState } from 'react' |
| 3 | +import DropDownPicker from 'react-native-dropdown-picker' |
| 4 | +import { Colors } from '../config/Colors' |
| 5 | + |
| 6 | +const UserForm = () => { |
| 7 | + const [question, setQuestion] = useState('') |
| 8 | + const [open, setOpen] = useState(false) |
| 9 | + const [topic, setTopic] = useState("PA1") |
| 10 | + const [items, setItems] = useState([ |
| 11 | + { label: 'PA1', value: 'PA1' }, |
| 12 | + { label: 'PA2', value: 'PA2' }, |
| 13 | + { label: 'PA3', value: 'PA3' }, |
| 14 | + { label: 'PA4', value: 'PA4' }, |
| 15 | + { label: 'PA5', value: 'PA5' } |
| 16 | + ]) |
| 17 | + |
| 18 | + const handleSubmit = () => { |
| 19 | + console.log("Topic:", topic, "Question:", question) |
| 20 | + } |
| 21 | + |
| 22 | + return ( |
| 23 | + <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}> |
| 24 | + <View style={styles.container}> |
| 25 | + <Text style={styles.header}>Ask a Question</Text> |
| 26 | + |
| 27 | + <Text style={styles.label}>Topic</Text> |
| 28 | + <DropDownPicker |
| 29 | + open={open} |
| 30 | + value={topic} |
| 31 | + items={items} |
| 32 | + setOpen={setOpen} |
| 33 | + setValue={setTopic} |
| 34 | + setItems={setItems} |
| 35 | + placeholder="Select a topic" |
| 36 | + containerStyle={styles.dropdownContainer} |
| 37 | + style={styles.dropdown} |
| 38 | + dropDownContainerStyle={styles.dropdownContainerStyle} |
| 39 | + /> |
| 40 | + |
| 41 | + <Text style={styles.label}>Question</Text> |
| 42 | + <TextInput |
| 43 | + style={[styles.input, styles.textArea]} |
| 44 | + placeholder="Enter your question" |
| 45 | + value={question} |
| 46 | + onChangeText={setQuestion} |
| 47 | + multiline |
| 48 | + returnKeyType="done" |
| 49 | + onSubmitEditing={() => Keyboard.dismiss()} |
| 50 | + /> |
| 51 | + |
| 52 | + <TouchableOpacity style={styles.submitButton} onPress={handleSubmit}> |
| 53 | + <Text style={styles.submitButtonText}>Submit</Text> |
| 54 | + </TouchableOpacity> |
| 55 | + </View> |
| 56 | + </TouchableWithoutFeedback> |
| 57 | + ) |
| 58 | +} |
| 59 | + |
| 60 | +export default UserForm |
| 61 | + |
| 62 | +const styles = StyleSheet.create({ |
| 63 | + container: { |
| 64 | + flex: 1, |
| 65 | + backgroundColor: Colors.Background, |
| 66 | + padding: 20, |
| 67 | + justifyContent: 'center', |
| 68 | + }, |
| 69 | + header: { |
| 70 | + fontSize: 28, |
| 71 | + fontWeight: 'bold', |
| 72 | + color: Colors.Primary, |
| 73 | + marginBottom: 20, |
| 74 | + textAlign: 'center', |
| 75 | + }, |
| 76 | + label: { |
| 77 | + fontSize: 16, |
| 78 | + fontWeight: '600', |
| 79 | + color: Colors.Primary, |
| 80 | + marginBottom: 8, |
| 81 | + }, |
| 82 | + dropdownContainer: { |
| 83 | + height: 50, |
| 84 | + marginBottom: 20, |
| 85 | + }, |
| 86 | + dropdown: { |
| 87 | + backgroundColor: '#fff', |
| 88 | + borderColor: Colors.Primary, |
| 89 | + }, |
| 90 | + dropdownContainerStyle: { |
| 91 | + backgroundColor: '#fafafa', |
| 92 | + }, |
| 93 | + input: { |
| 94 | + borderWidth: 1, |
| 95 | + borderColor: Colors.Primary, |
| 96 | + padding: 10, |
| 97 | + borderRadius: 8, |
| 98 | + backgroundColor: '#fff', |
| 99 | + marginBottom: 20, |
| 100 | + }, |
| 101 | + textArea: { |
| 102 | + height: 100, |
| 103 | + textAlignVertical: 'top', |
| 104 | + }, |
| 105 | + submitButton: { |
| 106 | + backgroundColor: Colors.Blue, |
| 107 | + padding: 15, |
| 108 | + borderRadius: 8, |
| 109 | + alignItems: 'center', |
| 110 | + }, |
| 111 | + submitButtonText: { |
| 112 | + color: '#fff', |
| 113 | + fontSize: 16, |
| 114 | + fontWeight: '600', |
| 115 | + }, |
| 116 | +}) |
0 commit comments