-
Notifications
You must be signed in to change notification settings - Fork 734
/
Copy pathSearchInputScreen.tsx
137 lines (128 loc) · 4.76 KB
/
SearchInputScreen.tsx
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
import React, {useCallback, useRef, useState} from 'react';
import {Alert} from 'react-native';
import {Colors, View, Text, Switch, SearchInput, SearchInputRef, Button, Icon, Assets} from 'react-native-ui-lib';
const SearchInputScreen = () => {
const [showCancelBtn, setShowCancelBtn] = useState(false);
const [showLoader, setShowLoader] = useState(false);
const [showCustomRightElement, setShowCustomRightElement] = useState(false);
const searchInput = useRef<SearchInputRef>();
const onChangeText = (text: string) => {
console.log('UILIB text: ', text);
};
const onDismiss = useCallback(() => {
Alert.alert('Cancel was pressed');
}, []);
const customRightElement = (
<View center marginH-s2>
<Icon source={Assets.icons.demo.check}/>
</View>
);
return (
<View style={{marginVertical: 5}}>
<Text center h3 $textDefault margin-5>
SearchInput
</Text>
<View>
<SearchInput
showLoader={showLoader}
ref={searchInput}
testID={'searchInput'}
value=""
placeholder="Search"
onDismiss={showCancelBtn ? onDismiss : undefined}
cancelButtonProps={{label: 'Cancel'}}
customRightElement={showCustomRightElement ? customRightElement : undefined}
/>
<View marginV-s2>
<SearchInput
showLoader={showLoader}
invertColors
value={''}
placeholder="Search with inverted colors"
style={{backgroundColor: Colors.$backgroundNeutralHeavy}}
onDismiss={showCancelBtn ? onDismiss : undefined}
cancelButtonProps={{label: 'Cancel'}}
onChangeText={onChangeText}
customRightElement={showCustomRightElement ? customRightElement : undefined}
/>
</View>
<SearchInput
showLoader={showLoader}
value={''}
placeholder="Search with custom colors"
onDismiss={showCancelBtn ? onDismiss : undefined}
cancelButtonProps={{label: 'Cancel'}}
onChangeText={onChangeText}
style={{backgroundColor: Colors.purple20}}
placeholderTextColor={Colors.white}
containerStyle={{color: Colors.white}}
customRightElement={showCustomRightElement ? customRightElement : undefined}
/>
</View>
<View marginV-s2>
<Text center h3 $textDefault margin-5>
Search Input Presets:
</Text>
<View margin-s2>
<Text marginL-s3 marginV-s2>
Default:
</Text>
<SearchInput
showLoader={showLoader}
testID={'searchInput'}
value=""
placeholder="Search"
onDismiss={showCancelBtn ? onDismiss : undefined}
cancelButtonProps={{label: 'Cancel'}}
customRightElement={showCustomRightElement ? customRightElement : undefined}
/>
</View>
<Text marginL-s3 marginV-s2>
Prominent:
</Text>
<SearchInput
showLoader={showLoader}
testID={'searchInput'}
value=""
placeholder="Search"
onDismiss={showCancelBtn ? onDismiss : undefined}
cancelButtonProps={{label: 'Cancel'}}
preset={SearchInput.presets.PROMINENT}
customRightElement={showCustomRightElement ? customRightElement : undefined}
/>
</View>
<View marginT-s8 marginH-s3>
<Text bodyBold>Settings:</Text>
<View row marginV-s2>
<Switch
value={showCancelBtn}
onValueChange={value => setShowCancelBtn(value)}
onColor={Colors.$iconSuccessLight}
/>
<Text marginL-s4>Toggle cancel button</Text>
</View>
<View row marginV-s2>
<Switch
value={showCustomRightElement}
onValueChange={value => setShowCustomRightElement(value)}
onColor={Colors.$iconSuccessLight}
/>
<Text marginL-s4>Toggle Custom right element</Text>
</View>
<View row marginV-s2>
<Switch value={showLoader} onValueChange={value => setShowLoader(value)} onColor={Colors.$iconSuccessLight}/>
<Text marginL-s4>Toggle loader</Text>
</View>
<View padding-10 marginV-s1>
<Text>Actions: on the first example</Text>
<View row spread marginV-s1>
<Button size={Button.sizes.small} label={'Blur'} onPress={() => searchInput?.current?.blur()}/>
<Button size={Button.sizes.small} label={'Focus'} onPress={() => searchInput?.current?.focus()}/>
<Button size={Button.sizes.small} label={'Clear'} onPress={() => searchInput?.current?.clear()}/>
</View>
</View>
</View>
</View>
);
};
export default SearchInputScreen;