rewrite ErrorMessage with ALF
This commit is contained in:
@@ -1,21 +1,12 @@
|
|||||||
import {
|
import {type StyleProp, View, type ViewStyle} from 'react-native'
|
||||||
type StyleProp,
|
import {useLingui} from '@lingui/react/macro'
|
||||||
StyleSheet,
|
|
||||||
TouchableOpacity,
|
|
||||||
View,
|
|
||||||
type ViewStyle,
|
|
||||||
} from 'react-native'
|
|
||||||
import {
|
|
||||||
FontAwesomeIcon,
|
|
||||||
type FontAwesomeIconStyle,
|
|
||||||
} from '@fortawesome/react-native-fontawesome'
|
|
||||||
import {msg} from '@lingui/core/macro'
|
|
||||||
import {useLingui} from '@lingui/react'
|
|
||||||
|
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
import {atoms as a, useGutters, useTheme, utils} from '#/alf'
|
||||||
import {useTheme} from '#/lib/ThemeContext'
|
import {Button} from '#/components/Button'
|
||||||
|
import {ArrowRotateClockwise_Stroke2_Corner0_Rounded as ArrowRotateIcon} from '#/components/icons/ArrowRotate'
|
||||||
|
import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning'
|
||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
import {Text} from '../text/Text'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function ErrorMessage({
|
export function ErrorMessage({
|
||||||
message,
|
message,
|
||||||
@@ -28,72 +19,51 @@ export function ErrorMessage({
|
|||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
onPressTryAgain?: () => void
|
onPressTryAgain?: () => void
|
||||||
}) {
|
}) {
|
||||||
const theme = useTheme()
|
const {t: l} = useLingui()
|
||||||
const pal = usePalette('error')
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const gutter = useGutters(['base'])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout.Center>
|
<Layout.Center>
|
||||||
<View testID="errorMessageView" style={[styles.outer, pal.view, style]}>
|
<View
|
||||||
<View
|
testID="errorMessageView"
|
||||||
style={[
|
style={[
|
||||||
styles.errorIcon,
|
a.flex_row,
|
||||||
{backgroundColor: theme.palette.error.icon},
|
a.align_center,
|
||||||
]}>
|
gutter,
|
||||||
<FontAwesomeIcon
|
a.py_sm,
|
||||||
icon="exclamation"
|
{backgroundColor: t.palette.pink},
|
||||||
style={pal.text as FontAwesomeIconStyle}
|
a.gap_md,
|
||||||
size={16}
|
style,
|
||||||
/>
|
]}>
|
||||||
</View>
|
<WarningIcon size="md" fill={t.palette.white} />
|
||||||
<Text
|
<Text
|
||||||
type="sm-medium"
|
style={[
|
||||||
style={[styles.message, pal.text]}
|
a.flex_1,
|
||||||
|
a.font_medium,
|
||||||
|
a.leading_snug,
|
||||||
|
a.text_md,
|
||||||
|
{color: t.palette.white},
|
||||||
|
]}
|
||||||
numberOfLines={numberOfLines}>
|
numberOfLines={numberOfLines}>
|
||||||
{message}
|
{message}
|
||||||
</Text>
|
</Text>
|
||||||
{onPressTryAgain && (
|
{onPressTryAgain && (
|
||||||
<TouchableOpacity
|
<Button
|
||||||
testID="errorMessageTryAgainButton"
|
testID="errorMessageTryAgainButton"
|
||||||
style={styles.btn}
|
|
||||||
onPress={onPressTryAgain}
|
onPress={onPressTryAgain}
|
||||||
accessibilityRole="button"
|
label={l`Retry`}
|
||||||
accessibilityLabel={_(msg`Retry`)}
|
accessibilityHint={l`Retries the last action, which errored out`}
|
||||||
accessibilityHint={_(
|
size="small"
|
||||||
msg`Retries the last action, which errored out`,
|
shape="round"
|
||||||
)}>
|
variant="ghost"
|
||||||
<FontAwesomeIcon
|
hoverStyle={{
|
||||||
icon="arrows-rotate"
|
backgroundColor: utils.alpha(t.palette.white, 0.2),
|
||||||
style={{color: theme.palette.error.icon}}
|
}}>
|
||||||
size={18}
|
<ArrowRotateIcon size="md" fill={t.palette.white} />
|
||||||
/>
|
</Button>
|
||||||
</TouchableOpacity>
|
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</Layout.Center>
|
</Layout.Center>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
outer: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
paddingVertical: 8,
|
|
||||||
paddingHorizontal: 8,
|
|
||||||
},
|
|
||||||
errorIcon: {
|
|
||||||
borderRadius: 12,
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginRight: 8,
|
|
||||||
},
|
|
||||||
message: {
|
|
||||||
flex: 1,
|
|
||||||
paddingRight: 10,
|
|
||||||
},
|
|
||||||
btn: {
|
|
||||||
paddingHorizontal: 4,
|
|
||||||
paddingVertical: 4,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user