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
|
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import React from 'react'
import {Pressable, StyleProp, StyleSheet, ViewStyle} from 'react-native'
import {Text} from '../text/Text'
interface SelectableBtnProps {
testID?: string
selected: boolean
label: string
left?: boolean
right?: boolean
onSelect: () => void
accessibilityHint?: string
style?: StyleProp<ViewStyle>
}
export function SelectableBtn({
testID,
selected,
label,
left,
right,
onSelect,
accessibilityHint,
style,
}: SelectableBtnProps) {
const pal = usePalette('default')
const palPrimary = usePalette('inverted')
const needsWidthStyles = !style || !('width' in style || 'flex' in style)
const {isMobile} = useWebMediaQueries()
return (
<Pressable
testID={testID}
style={[
styles.btn,
needsWidthStyles && {
flex: isMobile ? 1 : undefined,
width: !isMobile ? 100 : undefined,
},
left && styles.btnLeft,
right && styles.btnRight,
pal.border,
selected ? palPrimary.view : pal.view,
style,
]}
onPress={onSelect}
accessibilityRole="button"
accessibilityLabel={label}
accessibilityHint={accessibilityHint}>
<Text style={selected ? palPrimary.text : pal.text}>{label}</Text>
</Pressable>
)
}
const styles = StyleSheet.create({
btn: {
flexDirection: 'row',
justifyContent: 'center',
flexGrow: 1,
borderWidth: 1,
borderLeftWidth: 0,
paddingHorizontal: 10,
paddingVertical: 10,
},
btnLeft: {
borderTopLeftRadius: 8,
borderBottomLeftRadius: 8,
borderLeftWidth: 1,
},
btnRight: {
borderTopRightRadius: 8,
borderBottomRightRadius: 8,
},
})
|