2016-07-07 20:25:03 +08:00
|
|
|
import * as React from 'react';
|
2015-11-24 20:03:57 +08:00
|
|
|
import classNames from 'classnames';
|
2016-06-16 22:06:06 +08:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2016-07-07 12:06:05 +08:00
|
|
|
import omit from 'object.omit';
|
2016-07-29 13:59:37 +08:00
|
|
|
import warning from 'warning';
|
2015-10-09 13:53:04 +08:00
|
|
|
|
2016-03-14 12:52:06 +08:00
|
|
|
export default class Form extends React.Component {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-form',
|
|
|
|
onSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
},
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
prefixCls: React.PropTypes.string,
|
2016-08-04 17:45:15 +08:00
|
|
|
vertical: React.PropTypes.bool,
|
2016-03-29 14:01:10 +08:00
|
|
|
horizontal: React.PropTypes.bool,
|
|
|
|
inline: React.PropTypes.bool,
|
|
|
|
children: React.PropTypes.any,
|
|
|
|
onSubmit: React.PropTypes.func,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2016-07-29 13:59:37 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2016-08-02 09:24:15 +08:00
|
|
|
warning(!props.form, 'It is unnecessary to pass `form` to `Form` after antd@1.7.0.');
|
2016-07-29 13:59:37 +08:00
|
|
|
}
|
|
|
|
|
2016-06-12 10:15:59 +08:00
|
|
|
shouldComponentUpdate(...args) {
|
|
|
|
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
|
|
|
|
}
|
|
|
|
|
2015-10-09 13:53:04 +08:00
|
|
|
render() {
|
2016-08-04 17:45:15 +08:00
|
|
|
const { prefixCls, className, inline, horizontal, vertical } = this.props;
|
2015-12-25 14:30:28 +08:00
|
|
|
const formClassName = classNames({
|
2016-08-10 14:38:35 +08:00
|
|
|
[`${prefixCls}`]: true,
|
2016-07-07 12:06:05 +08:00
|
|
|
[`${prefixCls}-horizontal`]: horizontal,
|
2016-08-04 17:45:15 +08:00
|
|
|
[`${prefixCls}-vertical`]: vertical,
|
2016-07-07 12:06:05 +08:00
|
|
|
[`${prefixCls}-inline`]: inline,
|
2016-03-30 10:58:37 +08:00
|
|
|
[className]: !!className,
|
2015-12-25 14:30:28 +08:00
|
|
|
});
|
2015-10-09 13:53:04 +08:00
|
|
|
|
2016-07-07 12:06:05 +08:00
|
|
|
const formProps = omit(this.props, [
|
|
|
|
'prefixCls',
|
|
|
|
'className',
|
|
|
|
'inline',
|
|
|
|
'horizontal',
|
2016-08-04 17:45:15 +08:00
|
|
|
'vertical',
|
2016-07-07 12:06:05 +08:00
|
|
|
'form',
|
|
|
|
]);
|
|
|
|
|
|
|
|
return <form {...formProps} className={formClassName} />;
|
2015-10-09 13:53:04 +08:00
|
|
|
}
|
|
|
|
}
|