search.js
2.78 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var React = _interopRequireWildcard(require("react"));
var _CloseCircleFilled = _interopRequireDefault(require("@ant-design/icons/CloseCircleFilled"));
var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons/SearchOutlined"));
var _input = _interopRequireDefault(require("../input"));
var Search = /*#__PURE__*/function (_React$Component) {
(0, _inherits2["default"])(Search, _React$Component);
var _super = (0, _createSuper2["default"])(Search);
function Search() {
var _this;
(0, _classCallCheck2["default"])(this, Search);
_this = _super.apply(this, arguments);
_this.handleChange = function (e) {
var onChange = _this.props.onChange;
if (onChange) {
onChange(e);
}
};
_this.handleClear = function (e) {
e.preventDefault();
var _this$props = _this.props,
handleClear = _this$props.handleClear,
disabled = _this$props.disabled;
if (!disabled && handleClear) {
handleClear(e);
}
};
return _this;
}
(0, _createClass2["default"])(Search, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
placeholder = _this$props2.placeholder,
value = _this$props2.value,
prefixCls = _this$props2.prefixCls,
disabled = _this$props2.disabled;
var icon = value && value.length > 0 ? /*#__PURE__*/React.createElement("a", {
className: "".concat(prefixCls, "-action"),
onClick: this.handleClear
}, /*#__PURE__*/React.createElement(_CloseCircleFilled["default"], null)) : /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-action")
}, /*#__PURE__*/React.createElement(_SearchOutlined["default"], null));
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_input["default"], {
placeholder: placeholder,
className: prefixCls,
value: value,
onChange: this.handleChange,
disabled: disabled
}), icon);
}
}]);
return Search;
}(React.Component);
exports["default"] = Search;
Search.defaultProps = {
placeholder: ''
};