UNPKG

2.51 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
4import _inherits from 'babel-runtime/helpers/inherits';
5
6var _class, _temp2;
7
8import React from 'react';
9import PropTypes from 'prop-types';
10import Button from '../button';
11import { func, obj } from '../util';
12
13/**
14 * Form.Reset
15 * @description 继承 Button API
16 * @order 3
17 */
18var Reset = (_temp2 = _class = function (_React$Component) {
19 _inherits(Reset, _React$Component);
20
21 function Reset() {
22 var _temp, _this, _ret;
23
24 _classCallCheck(this, Reset);
25
26 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
27 args[_key] = arguments[_key];
28 }
29
30 return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function () {
31 var _this$props = _this.props,
32 names = _this$props.names,
33 toDefault = _this$props.toDefault,
34 onClick = _this$props.onClick;
35
36 var field = _this.context._formField || _this.props.field;
37
38 if (!field) {
39 onClick();
40 return;
41 }
42
43 if (toDefault) {
44 field.resetToDefault(names);
45 } else {
46 field.reset(names);
47 }
48
49 onClick();
50 }, _temp), _possibleConstructorReturn(_this, _ret);
51 }
52
53 Reset.prototype.render = function render() {
54 var children = this.props.children;
55
56
57 return React.createElement(
58 Button,
59 _extends({}, obj.pickOthers(Reset.propTypes, this.props), {
60 onClick: this.handleClick
61 }),
62 children
63 );
64 };
65
66 return Reset;
67}(React.Component), _class.propTypes = {
68 /**
69 * 自定义重置的字段
70 */
71 names: PropTypes.array,
72 /**
73 * 点击提交后触发
74 */
75 onClick: PropTypes.func,
76 /**
77 * 返回默认值
78 */
79 toDefault: PropTypes.bool,
80 /**
81 * 自定义 field (在 Form 内不需要设置)
82 */
83 field: PropTypes.object,
84 children: PropTypes.node
85}, _class.defaultProps = {
86 onClick: func.noop
87}, _class.contextTypes = {
88 _formField: PropTypes.object
89}, _temp2);
90Reset.displayName = 'Reset';
91
92
93export default Reset;
\No newline at end of file