-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
FormHelpMessage.js
59 lines (50 loc) · 1.83 KB
/
FormHelpMessage.js
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
56
57
58
59
import React from 'react';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';
import colors from '../styles/colors';
import styles from '../styles/styles';
import stylePropTypes from '../styles/stylePropTypes';
import * as Localize from '../libs/Localize';
const propTypes = {
/** Error or hint text. Ignored when children is not empty */
message: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object]))]),
/** Children to render next to dot indicator */
children: PropTypes.node,
/** Indicates whether to show error or hint */
isError: PropTypes.bool,
/** Container style props */
style: stylePropTypes,
};
const defaultProps = {
message: '',
children: null,
isError: true,
style: [],
};
function FormHelpMessage(props) {
if (_.isEmpty(props.message) && _.isEmpty(props.children)) {
return null;
}
const translatedMessage = Localize.translateIfPhraseKey(props.message);
return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mt2, styles.mb1, ...props.style]}>
{props.isError && (
<Icon
src={Expensicons.DotIndicator}
fill={colors.red}
/>
)}
<View style={[styles.flex1, props.isError && styles.ml2]}>
{props.children || <Text style={[props.isError ? styles.formError : styles.formHelp, styles.mb0]}>{translatedMessage}</Text>}
</View>
</View>
);
}
FormHelpMessage.propTypes = propTypes;
FormHelpMessage.defaultProps = defaultProps;
FormHelpMessage.displayName = 'FormHelpMessage';
export default FormHelpMessage;