|
1 | 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 |
| 2 | +import {View, Text, Card, TextField, Button, Colors, ChipsInput} from 'react-native-ui-lib'; //eslint-disable-line |
| 3 | +import _ from 'lodash'; |
4 | 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); |
| 5 | +export default class ChipsInputScreen extends Component { |
| 6 | + state = { |
| 7 | + chips: [{label: 'one'}, {label: 'two'}], |
| 8 | + chips2: [] |
35 | 9 | };
|
36 | 10 |
|
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 = () => { |
| 11 | + render() { |
46 | 12 | return (
|
47 |
| - <View center height={40} marginR-s2 style={{alignItems: 'flex-start'}}> |
48 |
| - <Text grey30 text70M> |
49 |
| - To: |
| 13 | + <View flex padding-20> |
| 14 | + <Text h1 marginB-s4> |
| 15 | + ChipsInput |
50 | 16 | </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 | 17 | <ChipsInput
|
77 |
| - placeholder={'Enter Tags'} |
78 |
| - title={'Mendy'} |
| 18 | + placeholder="Enter chips" |
| 19 | + defaultChipProps={{ |
| 20 | + backgroundColor: Colors.$backgroundPrimaryHeavy, |
| 21 | + labelStyle: {color: Colors.$textDefaultLight}, |
| 22 | + containerStyle: {borderWidth: 0}, |
| 23 | + dismissColor: Colors.$iconDefaultLight |
| 24 | + }} |
| 25 | + invalidChipProps={{ |
| 26 | + dismissColor: Colors.$iconDanger, |
| 27 | + labelStyle: {color: Colors.$textDanger}, |
| 28 | + backgroundColor: Colors.$backgroundDefault, |
| 29 | + containerStyle: {borderColor: Colors.$outlineDanger} |
| 30 | + }} |
79 | 31 | chips={this.state.chips}
|
80 |
| - maxLength={4} |
| 32 | + leadingAccessory={<Text>TO: </Text>} |
| 33 | + onChange={newChips => { |
| 34 | + _.flow(newChips => _.groupBy(newChips, 'label'), |
| 35 | + newChips => |
| 36 | + _.forEach(newChips, group => { |
| 37 | + if (group.length === 1) { |
| 38 | + delete group[0].invalid; |
| 39 | + } else { |
| 40 | + group[group.length - 1].invalid = true; |
| 41 | + } |
| 42 | + }), |
| 43 | + _.values, |
| 44 | + _.flatten)(newChips); |
| 45 | + |
| 46 | + this.setState({chips: newChips}); |
| 47 | + }} |
81 | 48 | />
|
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 | 49 |
|
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> |
| 50 | + <ChipsInput |
| 51 | + label="Max 3 chips" |
| 52 | + placeholder="Enter chips..." |
| 53 | + chips={this.state.chips2} |
| 54 | + onChange={newChips => this.setState({chips2: newChips})} |
| 55 | + maxChips={3} |
| 56 | + /> |
| 57 | + </View> |
152 | 58 | );
|
153 | 59 | }
|
154 | 60 | }
|
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