-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathFormAlertWithSubmitButton.js
77 lines (64 loc) · 2.19 KB
/
FormAlertWithSubmitButton.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import Button from './Button';
import FormAlertWrapper from './FormAlertWrapper';
const propTypes = {
/** Text for the button */
buttonText: PropTypes.string.isRequired,
/** Styles for container element */
containerStyles: PropTypes.arrayOf(PropTypes.object),
/** Whether to show the alert text */
isAlertVisible: PropTypes.bool.isRequired,
/** Whether the button is disabled */
isDisabled: PropTypes.bool,
/** Is the button in a loading state */
isLoading: PropTypes.bool,
/** Whether message is in html format */
isMessageHtml: PropTypes.bool,
/** Error message to display above button */
message: PropTypes.string,
/** Callback fired when the "fix the errors" link is pressed */
onFixTheErrorsPressed: PropTypes.func,
/** Submit function */
onSubmit: PropTypes.func.isRequired,
};
const defaultProps = {
message: '',
isDisabled: false,
isMessageHtml: false,
containerStyles: [],
isLoading: false,
onFixTheErrorsPressed: () => {},
};
const FormAlertWithSubmitButton = props => (
<FormAlertWrapper
containerStyles={[styles.mh5, styles.mb5, styles.flex1, styles.justifyContentEnd, ...props.containerStyles]}
isAlertVisible={props.isAlertVisible}
isMessageHtml={props.isMessageHtml}
message={props.message}
onFixTheErrorsPressed={props.onFixTheErrorsPressed}
>
{isOffline => (isOffline ? (
<Button
success
isDisabled
text={props.buttonText}
style={[styles.mb3]}
/>
) : (
<Button
success
pressOnEnter
text={props.buttonText}
onPress={props.onSubmit}
isDisabled={props.isDisabled}
isLoading={props.isLoading}
/>
))}
</FormAlertWrapper>
);
FormAlertWithSubmitButton.propTypes = propTypes;
FormAlertWithSubmitButton.defaultProps = defaultProps;
FormAlertWithSubmitButton.displayName = 'FormAlertWithSubmitButton';
export default FormAlertWithSubmitButton;