-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (65 loc) · 2.08 KB
/
index.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
import { formFieldContextTypes, formPropTypes } from './propTypes';
import { BASE_GRID_HEIGHT } from './constants/layout';
import DateField from './formFields/DateField';
import React from 'react';
import SelectField from './formFields/SelectField';
import SelectOption from './formFields/SelectOption';
import Separator from './components/separators/Separator';
import TextInputField from './formFields/TextInputField';
import TimeRangeField from './formFields/TimeRangeField';
import {
View,
} from 'react-native';
import _ from 'lodash/lang';
const propTypes = {
...formPropTypes,
};
const defaultProps = {};
const childContextTypes = {
...formFieldContextTypes,
};
export default class EasyForm extends React.Component {
constructor(props) {
super(props);
this.state = {
formData: props.formData || {},
};
}
getChildContext = () => ({
formData: this.state.formData,
handleValueChange: this.handleFormFieldValueChange,
labelContainerStyle: this.props.labelContainerStyle,
labelTextStyle: this.props.labelTextStyle,
inputContainerStyle: this.props.inputContainerStyle,
inputTextStyle: this.props.inputTextStyle,
theme: this.props.theme,
baseGridHeight: this.props.baseGridHeight || BASE_GRID_HEIGHT,
})
componentWillReceiveProps(nextProps) {
if (!_.isEqual(nextProps.formData, this.props.formData)) {
this.setState({ formData: nextProps.formData });
}
}
handleFormFieldValueChange = (fieldName, value) => {
this.setState(
(previousState) => ({ formData: { ...previousState.formData, [fieldName]: value } }),
() => { this.props.onFormDataChange(this.state.formData); }
);
}
render() {
return (
<View>
{this.props.children}
</View>
);
}
}
EasyForm.propTypes = propTypes;
EasyForm.defaultProps = defaultProps;
EasyForm.childContextTypes = childContextTypes;
EasyForm.SelectField = SelectField;
EasyForm.SelectOption = SelectOption;
EasyForm.TimeRangeField = TimeRangeField;
EasyForm.DateField = DateField;
EasyForm.TextInputField = TextInputField;
EasyForm.Separator = Separator;