-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchips.js
93 lines (87 loc) · 2.57 KB
/
chips.js
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
/**
* @author Alexis Valenciano <[email protected]>
*/
import React from "react";
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
const Chips = (props) => {
const { value, onPress, chipStyle,type,selected,chipCloseStyle,valueStyleSelected,chipStyleSelected,valueStyle} = props;
const returnStyles=()=>{
if(type=='removable'){
return removableStyles
}
return selectableStyles
}
const returnRemovable=()=>{
if(type=='removable'){
return(
<Text style={[returnStyles().chipCloseBtnTxt,chipCloseStyle]}>x</Text>
)
}
}
if (type=='selectable') {
return (<TouchableOpacity onPress={onPress}>
<View style={selected?[{flexDirection:'row'},returnStyles().chipSelected, chipStyle,chipStyleSelected]:[{flexDirection:'row'},returnStyles().chip, chipStyle]}>
<Text style={selected?[{ paddingHorizontal: 5 },returnStyles().valueStyleSelected,valueStyle,valueStyleSelected]:[{ paddingHorizontal: 5 },returnStyles().valueStyle,valueStyle]}>{value}</Text>
{returnRemovable()}
</View>
</TouchableOpacity>)
} else {
return ( //Basic
<View style={[{flexDirection:'row'},returnStyles().chip, chipStyle]}>
<Text style={[{ paddingHorizontal: 5 },returnStyles().valueStyle,valueStyle]}>{value}</Text>
{returnRemovable()}
</View>
)
}
}
const removableStyles = StyleSheet.create({
chip: {
backgroundColor:'#2196F3',
borderColor: '#2196F3',
borderWidth: 1,
margin: 5,
padding:6,
borderRadius: 20,
alignItems: 'center',
justifyContent: 'center'
},
chipCloseBtnTxt: {
fontSize:20,
color: '#FFF'
},
valueStyle:{
color:'#FFF',
fontSize:20
}
})
const selectableStyles = StyleSheet.create({
chip: {
backgroundColor:'#FFF',
borderColor: '#2196F3',
borderWidth: 1,
margin: 5,
padding:6,
borderRadius: 20,
alignItems: 'center',
justifyContent: 'center'
},
valueStyle:{
color:'#2196F3',
fontSize:20
},
chipSelected: {
backgroundColor:'#2196F3',
borderColor: '#2196F3',
borderWidth: 1,
margin: 5,
padding:6,
borderRadius: 20,
alignItems: 'center',
justifyContent: 'center'
},
valueStyleSelected:{
color:'#FFF',
fontSize:20
}
})
export default Chips;