1- import { View , StyleSheet , TouchableOpacity } from 'react-native' ;
2- import { Card , Input , ListItem , Text } from '@rneui/themed' ;
1+ import { View , StyleSheet } from 'react-native' ;
2+ import { Input , ListItem } from '@rneui/themed' ;
33import React , { useState } from 'react' ;
4- import { router } from 'expo-router ' ;
4+ import { IconNode } from '@rneui/base ' ;
55
66export interface AutocompleteWidgetProps {
7- origValue : string ;
8- label ?: string ;
97 data : any [ ] ;
108 onChange : ( value : string ) => void ;
11- // origOnChange: (value: string) => void;
12- icon ?: string ;
13- style ?: object ;
14- menuStyle ?: object ;
15- right ?: object ;
16- left ?: object ;
9+ placeholder ?: string ;
10+ onPress : ( id : string ) => void ;
11+ leftIcon ?: IconNode ;
1712}
1813
19- export const Autocomplete : React . FC < AutocompleteWidgetProps > = ( {
20- origValue,
21- label,
22- data,
23- onChange,
24- // origOnChange,
25- icon,
26- style,
27- menuStyle,
28- right,
29- left
30- } ) => {
31- const [ value , setValue ] = useState ( origValue ) ;
14+ export const Autocomplete : React . FC < AutocompleteWidgetProps > = ( { data, onChange, placeholder, onPress, leftIcon } ) => {
15+ const [ value , setValue ] = useState ( '' ) ;
3216 const [ menuVisible , setMenuVisible ] = useState ( false ) ;
33- const [ filteredData , setFilteredData ] = useState < any [ ] > ( [ ] ) ;
3417
35- const filterData = ( text : string ) => {
36- return data . filter ( ( val : any ) => val ?. toLowerCase ( ) ?. indexOf ( text ?. toLowerCase ( ) ) > - 1 ) ;
37- } ;
3818 return (
39- < View style = { { flexDirection : 'column' , flex : 1 , flexGrow : 1 } } >
40- < View style = { { flexDirection : 'row' , flex : 0 } } >
19+ < View style = { styles . container } >
20+ < View style = { styles . inputContainer } >
4121 < Input
4222 onFocus = { ( ) => {
43- if ( value . length === 0 ) {
23+ if ( value ? .length === 0 ) {
4424 setMenuVisible ( true ) ;
4525 }
4626 } }
27+ leftIcon = { leftIcon }
28+ placeholder = { placeholder }
4729 onBlur = { ( ) => setMenuVisible ( false ) }
48- label = { label }
49- // right={right}
50- // left={left}
51- // style={styles.input}
30+ underlineColorAndroid = { 'transparent' }
31+ inputContainerStyle = { { borderBottomWidth : 0 } }
5232 onChangeText = { ( text ) => {
53- // origOnChange(text);
5433 onChange ( text ) ;
55- // if (text && text.length > 0) {
56- // setFilteredData(filterData(text));
57- // } else if (text && text.length === 0) {
58- // setFilteredData(data);
59- // }
6034 setMenuVisible ( true ) ;
6135 setValue ( text ) ;
6236 } }
63- // value={value}
37+ containerStyle = { {
38+ borderColor : 'black' ,
39+ borderWidth : 1 ,
40+ borderRadius : 4 ,
41+ height : 48 ,
42+ backgroundColor : 'white'
43+ } }
6444 />
6545 </ View >
6646 { menuVisible && (
67- < View
68- style = { {
69- flex : 2 ,
70- flexGrow : 1 ,
71- flexDirection : 'column'
72- } } >
47+ < View style = { styles . menuContainer } >
7348 { data . map ( ( val , index ) => (
74- < TouchableOpacity
49+ < ListItem
50+ bottomDivider
7551 key = { index }
7652 onPress = { ( ) => {
77- router . push ( {
78- pathname : 'views/todos/edit/[id]' ,
79- params : { id : val . id }
80- } ) ;
81- } } >
82- < Card style = { { display : 'flex' , width : '100%' } } >
83- { val . listName && < Text style = { { fontSize : 18 } } > { val . listName } </ Text > }
53+ setMenuVisible ( false ) ;
54+ onPress ( val . id ) ;
55+ } }
56+ style = { { paddingBottom : 8 } } >
57+ < ListItem . Content >
58+ { val . listName && (
59+ < ListItem . Title style = { { fontSize : 18 , color : 'black' } } > { val . listName } </ ListItem . Title >
60+ ) }
8461 { val . todoName && (
85- < Text style = { { fontSize : 14 } } >
62+ < ListItem . Subtitle style = { { fontSize : 14 , color : 'grey' } } >
8663 { '\u2022' } { val . todoName }
87- </ Text >
64+ </ ListItem . Subtitle >
8865 ) }
89- </ Card >
90- </ TouchableOpacity >
91- // <ListItem
92- // // key={i}
93- // style={[{ width: '100%' }]}
94- // // icon={icon}
95- // onPress={() => {
96- // setValue(val);
97- // setMenuVisible(false);
98- // }}
99- // // title={datum}
100- // >
101- // <ListItem.Content>
102- // <ListItem.Title>{val}</ListItem.Title>
103- // </ListItem.Content>
104- // </ListItem>
66+ </ ListItem . Content >
67+ < ListItem . Chevron />
68+ </ ListItem >
10569 ) ) }
10670 </ View >
10771 ) }
@@ -110,12 +74,20 @@ export const Autocomplete: React.FC<AutocompleteWidgetProps> = ({
11074} ;
11175
11276const styles = StyleSheet . create ( {
113- input : {
114- flexDirection : 'row ' ,
77+ container : {
78+ flexDirection : 'column ' ,
11579 flex : 1 ,
11680 flexGrow : 1 ,
117- width : '100%' ,
118- alignItems : 'center' ,
119- justifyContent : 'flex-start'
81+ marginHorizontal : 8
82+ } ,
83+ inputContainer : {
84+ flexDirection : 'row' ,
85+ flex : 0 ,
86+ marginVertical : 8
87+ } ,
88+ menuContainer : {
89+ flex : 2 ,
90+ flexGrow : 1 ,
91+ flexDirection : 'column'
12092 }
12193} ) ;
0 commit comments