|
| 1 | +import React, {useCallback, useRef, useState} from 'react'; |
| 2 | +import {Alert} from 'react-native'; |
| 3 | +import {Colors, View, Text, Switch, SearchInput, SearchInputRef, Button, Icon, Assets} from 'react-native-ui-lib'; |
| 4 | + |
| 5 | +const SearchInputScreen = () => { |
| 6 | + const [showCancelBtn, setShowCancelBtn] = useState(false); |
| 7 | + const [showLoader, setShowLoader] = useState(false); |
| 8 | + const [showCustomRightElement, setShowCustomRightElement] = useState(false); |
| 9 | + const searchInput = useRef<SearchInputRef>(); |
| 10 | + |
| 11 | + const onChangeText = (text: string) => { |
| 12 | + console.log('UILIB text: ', text); |
| 13 | + }; |
| 14 | + |
| 15 | + const onDismiss = useCallback(() => { |
| 16 | + Alert.alert('Cancel was pressed'); |
| 17 | + }, []); |
| 18 | + |
| 19 | + const customRightElement = ( |
| 20 | + <View center marginH-s2> |
| 21 | + <Icon source={Assets.icons.demo.check}/> |
| 22 | + </View> |
| 23 | + ); |
| 24 | + |
| 25 | + return ( |
| 26 | + <View style={{marginVertical: 5}}> |
| 27 | + <Text center h3 $textDefault margin-5> |
| 28 | + SearchInput |
| 29 | + </Text> |
| 30 | + |
| 31 | + <View> |
| 32 | + <SearchInput |
| 33 | + showLoader={showLoader} |
| 34 | + ref={searchInput} |
| 35 | + testID={'searchInput'} |
| 36 | + value="" |
| 37 | + placeholder="Search" |
| 38 | + onDismiss={showCancelBtn ? onDismiss : undefined} |
| 39 | + cancelButtonProps={{label: 'Cancel'}} |
| 40 | + customRightElement={showCustomRightElement ? customRightElement : undefined} |
| 41 | + /> |
| 42 | + <View marginV-s2> |
| 43 | + <SearchInput |
| 44 | + showLoader={showLoader} |
| 45 | + invertColors |
| 46 | + value={''} |
| 47 | + placeholder="Search with inverted colors" |
| 48 | + style={{backgroundColor: Colors.$backgroundNeutralHeavy}} |
| 49 | + onDismiss={showCancelBtn ? onDismiss : undefined} |
| 50 | + cancelButtonProps={{label: 'Cancel'}} |
| 51 | + onChangeText={onChangeText} |
| 52 | + customRightElement={showCustomRightElement ? customRightElement : undefined} |
| 53 | + /> |
| 54 | + </View> |
| 55 | + <SearchInput |
| 56 | + showLoader={showLoader} |
| 57 | + value={''} |
| 58 | + placeholder="Search with custom colors" |
| 59 | + onDismiss={showCancelBtn ? onDismiss : undefined} |
| 60 | + cancelButtonProps={{label: 'Cancel'}} |
| 61 | + onChangeText={onChangeText} |
| 62 | + style={{backgroundColor: Colors.purple20}} |
| 63 | + placeholderTextColor={Colors.white} |
| 64 | + containerStyle={{color: Colors.white}} |
| 65 | + customRightElement={showCustomRightElement ? customRightElement : undefined} |
| 66 | + /> |
| 67 | + </View> |
| 68 | + |
| 69 | + <View marginV-s2> |
| 70 | + <Text center h3 $textDefault margin-5> |
| 71 | + Search Input Presets: |
| 72 | + </Text> |
| 73 | + <View margin-s2> |
| 74 | + <Text marginL-s3 marginV-s2> |
| 75 | + Default: |
| 76 | + </Text> |
| 77 | + <SearchInput |
| 78 | + showLoader={showLoader} |
| 79 | + testID={'searchInput'} |
| 80 | + value="" |
| 81 | + placeholder="Search" |
| 82 | + onDismiss={showCancelBtn ? onDismiss : undefined} |
| 83 | + cancelButtonProps={{label: 'Cancel'}} |
| 84 | + customRightElement={showCustomRightElement ? customRightElement : undefined} |
| 85 | + /> |
| 86 | + </View> |
| 87 | + <Text marginL-s3 marginV-s2> |
| 88 | + Prominent: |
| 89 | + </Text> |
| 90 | + <SearchInput |
| 91 | + showLoader={showLoader} |
| 92 | + testID={'searchInput'} |
| 93 | + value="" |
| 94 | + placeholder="Search" |
| 95 | + onDismiss={showCancelBtn ? onDismiss : undefined} |
| 96 | + cancelButtonProps={{label: 'Cancel'}} |
| 97 | + preset={'prominent'} |
| 98 | + customRightElement={showCustomRightElement ? customRightElement : undefined} |
| 99 | + /> |
| 100 | + </View> |
| 101 | + |
| 102 | + <View marginT-s8 marginH-s3> |
| 103 | + <Text bodyBold>Settings:</Text> |
| 104 | + <View row marginV-s2> |
| 105 | + <Switch |
| 106 | + value={showCancelBtn} |
| 107 | + onValueChange={value => setShowCancelBtn(value)} |
| 108 | + onColor={Colors.$iconSuccessLight} |
| 109 | + /> |
| 110 | + <Text marginL-s4>Toggle cancel button</Text> |
| 111 | + </View> |
| 112 | + <View row marginV-s2> |
| 113 | + <Switch |
| 114 | + value={showCustomRightElement} |
| 115 | + onValueChange={value => setShowCustomRightElement(value)} |
| 116 | + onColor={Colors.$iconSuccessLight} |
| 117 | + /> |
| 118 | + <Text marginL-s4>Toggle Custom right element</Text> |
| 119 | + </View> |
| 120 | + <View row marginV-s2> |
| 121 | + <Switch value={showLoader} onValueChange={value => setShowLoader(value)} onColor={Colors.$iconSuccessLight}/> |
| 122 | + <Text marginL-s4>Toggle loader</Text> |
| 123 | + </View> |
| 124 | + <View padding-10 marginV-s1> |
| 125 | + <Text>Actions: on the first example</Text> |
| 126 | + <View row spread marginV-s1> |
| 127 | + <Button size={Button.sizes.small} label={'Blur'} onPress={() => searchInput?.current?.blur()}/> |
| 128 | + <Button size={Button.sizes.small} label={'Focus'} onPress={() => searchInput?.current?.focus()}/> |
| 129 | + <Button size={Button.sizes.small} label={'Clear'} onPress={() => searchInput?.current?.clear()}/> |
| 130 | + </View> |
| 131 | + </View> |
| 132 | + </View> |
| 133 | + </View> |
| 134 | + ); |
| 135 | +}; |
| 136 | + |
| 137 | +export default SearchInputScreen; |
0 commit comments