|
| 1 | +import React, {Component} from 'react'; |
| 2 | +import {StyleSheet, ScrollView} from 'react-native'; |
| 3 | +import {View, Colors, Text, Typography, ChipsInput, ChipsInputChipProps} from 'react-native-ui-lib'; // eslint-disable-line |
| 4 | + |
| 5 | +interface State { |
| 6 | + chips: Array<ChipsInputChipProps>; |
| 7 | + namesChips: Array<ChipsInputChipProps>; |
| 8 | + nonRemovalChips: Array<ChipsInputChipProps>; |
| 9 | + customChips: Array<string>; |
| 10 | + tags: Array<string | any>; |
| 11 | + tags2: Array<string>; |
| 12 | + tags3: Array<string>; |
| 13 | +} |
| 14 | + |
| 15 | +export default class ChipsInputScreen extends Component<{}, State> { |
| 16 | + // @ts-ignore |
| 17 | + customChipsInput = React.createRef<ChipsInput>(); |
| 18 | + |
| 19 | + constructor(props: any) { |
| 20 | + super(props); |
| 21 | + |
| 22 | + this.state = { |
| 23 | + chips: [{label: 'Falcon 9'}, {label: 'Enterprise'}, {label: 'Challenger', borderRadius: 0}, {label: 'Coca Cola', invalid: true}], |
| 24 | + namesChips: [{label: 'Amit'}, {label: 'Ethan', invalid: true}], |
| 25 | + nonRemovalChips: [{label: 'Non'}, {label: 'Removable'}, {label: 'Tags'}], |
| 26 | + customChips: ['Chips', 'Input'], |
| 27 | + tags: [{label: 'Amit'}, {label: 'Ethan', invalid: true}], |
| 28 | + tags2: ['Non', 'Removable', 'Tags'], |
| 29 | + tags3: ['Change', 'Typography'] |
| 30 | + }; |
| 31 | + } |
| 32 | + |
| 33 | + onTagPress = (tagIndex: number, markedTagIndex: number) => { |
| 34 | + this.customChipsInput.current?.markTagIndex(tagIndex === markedTagIndex ? undefined : tagIndex); |
| 35 | + }; |
| 36 | + |
| 37 | + renderCustomTag(tag: any, _: number, shouldMarkToRemove: boolean) { |
| 38 | + return ( |
| 39 | + <View style={[styles.customTag, shouldMarkToRemove && {backgroundColor: Colors.purple70}]}> |
| 40 | + <Text white>{tag.label}</Text> |
| 41 | + </View> |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + renderLeftElement = () => { |
| 46 | + return ( |
| 47 | + <View center height={40} marginR-s2 style={{alignItems: 'flex-start'}}> |
| 48 | + <Text grey30 text70M> |
| 49 | + To: |
| 50 | + </Text> |
| 51 | + </View> |
| 52 | + ); |
| 53 | + }; |
| 54 | + |
| 55 | + renderSearchTypeInput = () => { |
| 56 | + return ( |
| 57 | + <> |
| 58 | + <Text marginB-10 text60>Search Type</Text> |
| 59 | + <View bg-grey60> |
| 60 | + <ChipsInput |
| 61 | + placeholder={'Enter Tags'} |
| 62 | + chips={this.state.chips} |
| 63 | + leftElement={this.renderLeftElement()} |
| 64 | + hideUnderline |
| 65 | + maxHeight={100} |
| 66 | + /> |
| 67 | + </View> |
| 68 | + </> |
| 69 | + ); |
| 70 | + }; |
| 71 | + |
| 72 | + renderFormTypeInput = () => { |
| 73 | + return ( |
| 74 | + <View marginT-40> |
| 75 | + <Text marginB-10 text60>Form Type</Text> |
| 76 | + <ChipsInput |
| 77 | + placeholder={'Enter Tags'} |
| 78 | + title={'Mendy'} |
| 79 | + chips={this.state.chips} |
| 80 | + maxLength={4} |
| 81 | + /> |
| 82 | + </View> |
| 83 | + ); |
| 84 | + }; |
| 85 | + |
| 86 | + onCreateTag = (value: string) => { |
| 87 | + return {label: value}; |
| 88 | + } |
| 89 | + |
| 90 | + render() { |
| 91 | + return ( |
| 92 | + <ScrollView keyboardShouldPersistTaps="never"> |
| 93 | + <View style={styles.container}> |
| 94 | + <Text text40 marginB-20> |
| 95 | + ChipsInput |
| 96 | + </Text> |
| 97 | + |
| 98 | + |
| 99 | + {this.renderSearchTypeInput()} |
| 100 | + |
| 101 | + {this.renderFormTypeInput()} |
| 102 | + |
| 103 | + <ChipsInput |
| 104 | + containerStyle={styles.bottomMargin} |
| 105 | + placeholder="Enter Tags" |
| 106 | + chips={this.state.namesChips} |
| 107 | + validationErrorMessage="error validation message" |
| 108 | + /> |
| 109 | + |
| 110 | + <ChipsInput |
| 111 | + containerStyle={styles.bottomMargin} |
| 112 | + placeholder="Editing disabled" |
| 113 | + chips={this.state.nonRemovalChips} |
| 114 | + disableTagRemoval |
| 115 | + disableTagAdding |
| 116 | + /> |
| 117 | + |
| 118 | + <Text text50 marginV-20>Old Usage</Text> |
| 119 | + <ChipsInput |
| 120 | + containerStyle={styles.bottomMargin} |
| 121 | + placeholder="Enter Tags" |
| 122 | + tags={this.state.tags} |
| 123 | + validationErrorMessage="error validation message" |
| 124 | + /> |
| 125 | + |
| 126 | + <ChipsInput |
| 127 | + containerStyle={styles.bottomMargin} |
| 128 | + placeholder="Editing disabled" |
| 129 | + tags={this.state.tags2} |
| 130 | + disableTagRemoval |
| 131 | + disableTagAdding |
| 132 | + /> |
| 133 | + <ChipsInput |
| 134 | + ref={this.customChipsInput} |
| 135 | + containerStyle={styles.bottomMargin} |
| 136 | + placeholder="With custom tags" |
| 137 | + tags={this.state.tags} |
| 138 | + renderTag={this.renderCustomTag} |
| 139 | + onCreateTag={this.onCreateTag} |
| 140 | + onTagPress={this.onTagPress} |
| 141 | + inputStyle={styles.customInput} |
| 142 | + /> |
| 143 | + <ChipsInput |
| 144 | + text60 |
| 145 | + containerStyle={styles.bottomMargin} |
| 146 | + placeholder="Enter Tags" |
| 147 | + tags={this.state.tags3} |
| 148 | + /> |
| 149 | + |
| 150 | + </View> |
| 151 | + </ScrollView> |
| 152 | + ); |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +const styles = StyleSheet.create({ |
| 157 | + container: { |
| 158 | + flex: 1, |
| 159 | + padding: 15 |
| 160 | + }, |
| 161 | + customInput: { |
| 162 | + ...Typography.text60, |
| 163 | + color: Colors.blue30 |
| 164 | + }, |
| 165 | + bottomMargin: { |
| 166 | + marginBottom: 25 |
| 167 | + }, |
| 168 | + customTag: { |
| 169 | + backgroundColor: Colors.purple30, |
| 170 | + paddingVertical: 2, |
| 171 | + paddingHorizontal: 8, |
| 172 | + borderRadius: 3, |
| 173 | + marginRight: 10, |
| 174 | + marginBottom: 10 |
| 175 | + } |
| 176 | +}); |
0 commit comments