-
Notifications
You must be signed in to change notification settings - Fork 3k
/
FormHelpMessage.js
56 lines (47 loc) · 1.6 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
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';
const propTypes = {
/** Error or hint text. Ignored when children is not empty */
message: PropTypes.string,
/** 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: [],
};
const FormHelpMessage = (props) => {
if (_.isEmpty(props.message) && _.isEmpty(props.children)) {
return null;
}
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, styles.ml2]}>
{props.children || (
<Text style={[props.isError ? styles.formError : styles.formHelp, styles.mb0]}>
{props.message}
</Text>
)}
</View>
</View>
);
};
FormHelpMessage.propTypes = propTypes;
FormHelpMessage.defaultProps = defaultProps;
FormHelpMessage.displayName = 'FormHelpMessage';
export default FormHelpMessage;