mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at rnw 85 lines 1.9 kB view raw
1import React from 'react' 2import { 3 StyleSheet, 4 TouchableOpacity, 5 StyleProp, 6 View, 7 ViewStyle, 8} from 'react-native' 9import { 10 FontAwesomeIcon, 11 FontAwesomeIconStyle, 12} from '@fortawesome/react-native-fontawesome' 13import {Text} from '../text/Text' 14import {useTheme} from 'lib/ThemeContext' 15import {usePalette} from 'lib/hooks/usePalette' 16 17export function ErrorMessage({ 18 message, 19 numberOfLines, 20 style, 21 onPressTryAgain, 22}: { 23 message: string 24 numberOfLines?: number 25 style?: StyleProp<ViewStyle> 26 onPressTryAgain?: () => void 27}) { 28 const theme = useTheme() 29 const pal = usePalette('error') 30 return ( 31 <View testID="errorMessageView" style={[styles.outer, pal.view, style]}> 32 <View 33 style={[styles.errorIcon, {backgroundColor: theme.palette.error.icon}]}> 34 <FontAwesomeIcon 35 icon="exclamation" 36 style={pal.text as FontAwesomeIconStyle} 37 size={16} 38 /> 39 </View> 40 <Text 41 type="sm" 42 style={[styles.message, pal.text]} 43 numberOfLines={numberOfLines}> 44 {message} 45 </Text> 46 {onPressTryAgain && ( 47 <TouchableOpacity 48 testID="errorMessageTryAgainButton" 49 style={styles.btn} 50 onPress={onPressTryAgain}> 51 <FontAwesomeIcon 52 icon="arrows-rotate" 53 style={{color: theme.palette.error.icon}} 54 size={18} 55 /> 56 </TouchableOpacity> 57 )} 58 </View> 59 ) 60} 61 62const styles = StyleSheet.create({ 63 outer: { 64 flexDirection: 'row', 65 alignItems: 'center', 66 paddingVertical: 8, 67 paddingHorizontal: 8, 68 }, 69 errorIcon: { 70 borderRadius: 12, 71 width: 24, 72 height: 24, 73 alignItems: 'center', 74 justifyContent: 'center', 75 marginRight: 8, 76 }, 77 message: { 78 flex: 1, 79 paddingRight: 10, 80 }, 81 btn: { 82 paddingHorizontal: 4, 83 paddingVertical: 4, 84 }, 85})