mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Pressable, ViewStyle, StyleProp, StyleSheet} from 'react-native'
3import {Text} from '../text/Text'
4import {usePalette} from 'lib/hooks/usePalette'
5import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
6
7interface SelectableBtnProps {
8 testID?: string
9 selected: boolean
10 label: string
11 left?: boolean
12 right?: boolean
13 onSelect: () => void
14 accessibilityHint?: string
15 style?: StyleProp<ViewStyle>
16}
17
18export function SelectableBtn({
19 testID,
20 selected,
21 label,
22 left,
23 right,
24 onSelect,
25 accessibilityHint,
26 style,
27}: SelectableBtnProps) {
28 const pal = usePalette('default')
29 const palPrimary = usePalette('inverted')
30 const needsWidthStyles = !style || !('width' in style || 'flex' in style)
31 const {isMobile} = useWebMediaQueries()
32 return (
33 <Pressable
34 testID={testID}
35 style={[
36 styles.btn,
37 needsWidthStyles && {
38 flex: isMobile ? 1 : undefined,
39 width: !isMobile ? 100 : undefined,
40 },
41 left && styles.btnLeft,
42 right && styles.btnRight,
43 pal.border,
44 selected ? palPrimary.view : pal.view,
45 style,
46 ]}
47 onPress={onSelect}
48 accessibilityRole="button"
49 accessibilityLabel={label}
50 accessibilityHint={accessibilityHint}>
51 <Text style={selected ? palPrimary.text : pal.text}>{label}</Text>
52 </Pressable>
53 )
54}
55
56const styles = StyleSheet.create({
57 btn: {
58 flexDirection: 'row',
59 justifyContent: 'center',
60 flexGrow: 1,
61 borderWidth: 1,
62 borderLeftWidth: 0,
63 paddingHorizontal: 10,
64 paddingVertical: 10,
65 },
66 btnLeft: {
67 borderTopLeftRadius: 8,
68 borderBottomLeftRadius: 8,
69 borderLeftWidth: 1,
70 },
71 btnRight: {
72 borderTopRightRadius: 8,
73 borderBottomRightRadius: 8,
74 },
75})