-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathFormHelpMessage.tsx
55 lines (45 loc) · 1.82 KB
/
FormHelpMessage.tsx
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
import isEmpty from 'lodash/isEmpty';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Localize from '@libs/Localize';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';
type FormHelpMessageProps = {
/** Error or hint text. Ignored when children is not empty */
message?: Localize.MaybePhraseKey;
/** Children to render next to dot indicator */
children?: React.ReactNode;
/** Indicates whether to show error or hint */
isError?: boolean;
/** Container style props */
style?: StyleProp<ViewStyle>;
/** Whether to show dot indicator */
shouldShowRedDotIndicator?: boolean;
};
function FormHelpMessage({message = '', children, isError = true, style, shouldShowRedDotIndicator = true}: FormHelpMessageProps) {
const theme = useTheme();
const styles = useThemeStyles();
if (isEmpty(message) && isEmpty(children)) {
return null;
}
const translatedMessage = Localize.translateIfPhraseKey(message);
return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mt2, styles.mb1, style]}>
{isError && shouldShowRedDotIndicator && (
<Icon
src={Expensicons.DotIndicator}
fill={theme.danger}
/>
)}
<View style={[styles.flex1, isError && shouldShowRedDotIndicator ? styles.ml2 : {}]}>
{children ?? <Text style={[isError ? styles.formError : styles.formHelp, styles.mb0]}>{translatedMessage}</Text>}
</View>
</View>
);
}
FormHelpMessage.displayName = 'FormHelpMessage';
export default FormHelpMessage;