search.js
2.18 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
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import * as React from 'react';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import SearchOutlined from '@ant-design/icons/SearchOutlined';
import Input from '../input';
var Search = /*#__PURE__*/function (_React$Component) {
_inherits(Search, _React$Component);
var _super = _createSuper(Search);
function Search() {
var _this;
_classCallCheck(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;
}
_createClass(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, null)) : /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-action")
}, /*#__PURE__*/React.createElement(SearchOutlined, null));
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Input, {
placeholder: placeholder,
className: prefixCls,
value: value,
onChange: this.handleChange,
disabled: disabled
}), icon);
}
}]);
return Search;
}(React.Component);
export { Search as default };
Search.defaultProps = {
placeholder: ''
};