mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-27 18:50:59 +08:00
41 lines
951 B
TypeScript
41 lines
951 B
TypeScript
import React, { PropTypes } from 'react';
|
|
import createDOMForm from 'rc-form/lib/createDOMForm';
|
|
import Form from './Form';
|
|
import FormItem from './FormItem';
|
|
import ValueMixin from './ValueMixin';
|
|
import assign from 'object-assign';
|
|
import { FIELD_META_PROP } from './constants';
|
|
|
|
Form.create = (o = {}) => {
|
|
const options = assign({}, o, {
|
|
fieldNameProp: 'id',
|
|
fieldMetaProp: FIELD_META_PROP,
|
|
});
|
|
const formWrapper = createDOMForm(options);
|
|
|
|
/* eslint-disable react/prefer-es6-class */
|
|
return (Component) => formWrapper(React.createClass({
|
|
propTypes: {
|
|
form: PropTypes.object.isRequired,
|
|
},
|
|
childContextTypes: {
|
|
form: PropTypes.object.isRequired,
|
|
},
|
|
getChildContext() {
|
|
return {
|
|
form: this.props.form,
|
|
};
|
|
},
|
|
render() {
|
|
return <Component {...this.props} />;
|
|
},
|
|
}));
|
|
};
|
|
|
|
Form.Item = FormItem;
|
|
|
|
// @Deprecated
|
|
Form.ValueMixin = ValueMixin;
|
|
|
|
export default Form;
|