-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChip.tsx
More file actions
61 lines (56 loc) · 1.55 KB
/
Chip.tsx
File metadata and controls
61 lines (56 loc) · 1.55 KB
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
import React, { useState } from 'react'
import {
LayoutChangeEvent,
StyleProp,
StyleSheet,
Text,
TextStyle,
TouchableOpacity,
View,
ViewStyle,
} from 'react-native'
import { fontSize, theme } from '../styles'
import appTextStyle from '../styles/text'
type Props = {
text?: string
textStyle?: StyleProp<TextStyle>
containerStyle?: StyleProp<ViewStyle>
onPress?: () => void
disabled?: boolean
}
const Chip = ({ text, textStyle, containerStyle, onPress, disabled }: Props) => {
const [borderRadius, setBorderRadius] = useState(theme.margin.common)
return (
<TouchableOpacity onPress={disabled ? undefined : onPress} activeOpacity={0.5} disabled={disabled}>
<View
onLayout={(event: LayoutChangeEvent) => setBorderRadius(event.nativeEvent.layout.height / 2)}
style={[styles.chipContainer, { borderRadius }, containerStyle]}
>
<View style={styles.chipTextContainer}>
<Text style={[styles.chipText, textStyle]}>{text}</Text>
</View>
</View>
</TouchableOpacity>
)
}
const styles = StyleSheet.create({
chipTextContainer: {
flexDirection: 'row',
justifyContent: 'center',
},
chipText: {
...appTextStyle.body,
color: theme.color.white,
lineHeight: theme.margin.common,
fontSize: fontSize.medium,
},
chipContainer: {
backgroundColor: theme.color.accentLime400,
paddingHorizontal: theme.margin.common,
paddingVertical: theme.margin.half,
borderRadius: theme.margin.common,
minWidth: 44,
justifyContent: 'center',
},
})
export default Chip