mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import { 2 type StyleProp, 3 StyleSheet, 4 type TextStyle, 5 View, 6 type ViewStyle, 7} from 'react-native' 8 9import {choose} from '#/lib/functions' 10import {colors} from '#/lib/styles' 11import {useTheme} from '#/lib/ThemeContext' 12import {type TypographyVariant} from '#/lib/ThemeContext' 13import {Text} from '../text/Text' 14import {Button, type ButtonType} from './Button' 15 16/** 17 * @deprecated use Toggle from `#/components/form/Toggle.tsx` instead 18 */ 19export function ToggleButton({ 20 testID, 21 type = 'default-light', 22 label, 23 isSelected, 24 style, 25 labelType, 26 onPress, 27}: { 28 testID?: string 29 type?: ButtonType 30 label: string 31 isSelected: boolean 32 style?: StyleProp<ViewStyle> 33 labelType?: TypographyVariant 34 onPress?: () => void 35}) { 36 const theme = useTheme() 37 const circleStyle = choose<TextStyle, Record<ButtonType, TextStyle>>(type, { 38 primary: { 39 borderColor: theme.palette.primary.text, 40 }, 41 secondary: { 42 borderColor: theme.palette.secondary.text, 43 }, 44 inverted: { 45 borderColor: theme.palette.inverted.text, 46 }, 47 'primary-outline': { 48 borderColor: theme.palette.primary.border, 49 }, 50 'secondary-outline': { 51 borderColor: theme.palette.secondary.border, 52 }, 53 'primary-light': { 54 borderColor: theme.palette.primary.border, 55 }, 56 'secondary-light': { 57 borderColor: theme.palette.secondary.border, 58 }, 59 default: { 60 borderColor: theme.palette.default.border, 61 }, 62 'default-light': { 63 borderColor: theme.palette.default.border, 64 }, 65 }) 66 const circleFillStyle = choose<TextStyle, Record<ButtonType, TextStyle>>( 67 type, 68 { 69 primary: { 70 backgroundColor: theme.palette.primary.text, 71 opacity: isSelected ? 1 : 0.33, 72 }, 73 secondary: { 74 backgroundColor: theme.palette.secondary.text, 75 opacity: isSelected ? 1 : 0.33, 76 }, 77 inverted: { 78 backgroundColor: theme.palette.inverted.text, 79 opacity: isSelected ? 1 : 0.33, 80 }, 81 'primary-outline': { 82 backgroundColor: theme.palette.primary.background, 83 opacity: isSelected ? 1 : 0.5, 84 }, 85 'secondary-outline': { 86 backgroundColor: theme.palette.secondary.background, 87 opacity: isSelected ? 1 : 0.5, 88 }, 89 'primary-light': { 90 backgroundColor: theme.palette.primary.background, 91 opacity: isSelected ? 1 : 0.5, 92 }, 93 'secondary-light': { 94 backgroundColor: theme.palette.secondary.background, 95 opacity: isSelected ? 1 : 0.5, 96 }, 97 default: { 98 backgroundColor: isSelected 99 ? theme.palette.primary.background 100 : colors.gray3, 101 }, 102 'default-light': { 103 backgroundColor: isSelected 104 ? theme.palette.primary.background 105 : colors.gray3, 106 }, 107 }, 108 ) 109 const labelStyle = choose<TextStyle, Record<ButtonType, TextStyle>>(type, { 110 primary: { 111 color: theme.palette.primary.text, 112 fontWeight: theme.palette.primary.isLowContrast ? '600' : undefined, 113 }, 114 secondary: { 115 color: theme.palette.secondary.text, 116 fontWeight: theme.palette.secondary.isLowContrast ? '600' : undefined, 117 }, 118 inverted: { 119 color: theme.palette.inverted.text, 120 fontWeight: theme.palette.inverted.isLowContrast ? '600' : undefined, 121 }, 122 'primary-outline': { 123 color: theme.palette.primary.textInverted, 124 fontWeight: theme.palette.primary.isLowContrast ? '600' : undefined, 125 }, 126 'secondary-outline': { 127 color: theme.palette.secondary.textInverted, 128 fontWeight: theme.palette.secondary.isLowContrast ? '600' : undefined, 129 }, 130 'primary-light': { 131 color: theme.palette.primary.textInverted, 132 fontWeight: theme.palette.primary.isLowContrast ? '600' : undefined, 133 }, 134 'secondary-light': { 135 color: theme.palette.secondary.textInverted, 136 fontWeight: theme.palette.secondary.isLowContrast ? '600' : undefined, 137 }, 138 default: { 139 color: theme.palette.default.text, 140 fontWeight: theme.palette.default.isLowContrast ? '600' : undefined, 141 }, 142 'default-light': { 143 color: theme.palette.default.text, 144 fontWeight: theme.palette.default.isLowContrast ? '600' : undefined, 145 }, 146 }) 147 return ( 148 <Button testID={testID} type={type} onPress={onPress} style={style}> 149 <View style={styles.outer}> 150 <View style={[circleStyle, styles.circle]}> 151 <View 152 style={[ 153 circleFillStyle, 154 styles.circleFill, 155 isSelected ? styles.circleFillSelected : undefined, 156 ]} 157 /> 158 </View> 159 {label === '' ? null : ( 160 <Text type={labelType || 'button'} style={[labelStyle, styles.label]}> 161 {label} 162 </Text> 163 )} 164 </View> 165 </Button> 166 ) 167} 168 169const styles = StyleSheet.create({ 170 outer: { 171 flexDirection: 'row', 172 alignItems: 'center', 173 gap: 10, 174 }, 175 circle: { 176 width: 42, 177 height: 26, 178 borderRadius: 15, 179 padding: 3, 180 borderWidth: 2, 181 }, 182 circleFill: { 183 width: 16, 184 height: 16, 185 borderRadius: 10, 186 }, 187 circleFillSelected: { 188 marginLeft: 16, 189 }, 190 label: { 191 flex: 1, 192 }, 193})