1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 |
|
6 | var _class, _temp2;
|
7 |
|
8 | import React from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import Button from '../button';
|
11 | import { func, obj } from '../util';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var 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 |
|
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);
|
90 | Reset.displayName = 'Reset';
|
91 |
|
92 |
|
93 | export default Reset; |
\ | No newline at end of file |