UNPKG

2.83 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2import _createClass from "@babel/runtime/helpers/createClass";
3import _inherits from "@babel/runtime/helpers/inherits";
4import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
7function _createSuper(Derived) {
8 function isNativeReflectConstruct() {
9 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
10 if (Reflect.construct.sham) return false;
11 if (typeof Proxy === "function") return true;
12
13 try {
14 Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
15 return true;
16 } catch (e) {
17 return false;
18 }
19 }
20
21 return function () {
22 var Super = _getPrototypeOf(Derived),
23 result;
24
25 if (isNativeReflectConstruct()) {
26 var NewTarget = _getPrototypeOf(this).constructor;
27
28 result = Reflect.construct(Super, arguments, NewTarget);
29 } else {
30 result = Super.apply(this, arguments);
31 }
32
33 return _possibleConstructorReturn(this, result);
34 };
35}
36
37import React, { Component } from 'react';
38import Icon from '../icon';
39import Input from '../input';
40
41var Search =
42/*#__PURE__*/
43function (_Component) {
44 _inherits(Search, _Component);
45
46 var _super = _createSuper(Search);
47
48 function Search() {
49 var _this;
50
51 _classCallCheck(this, Search);
52
53 _this = _super.apply(this, arguments);
54
55 _this.handleChange = function (e) {
56 var onChange = _this.props.onChange;
57
58 if (onChange) {
59 onChange(e);
60 }
61 };
62
63 _this.handleClear = function (e) {
64 e.preventDefault();
65 var handleClear = _this.props.handleClear;
66
67 if (handleClear) {
68 handleClear(e);
69 }
70 };
71
72 return _this;
73 }
74
75 _createClass(Search, [{
76 key: "render",
77 value: function render() {
78 var _this$props = this.props,
79 placeholder = _this$props.placeholder,
80 value = _this$props.value,
81 prefixCls = _this$props.prefixCls;
82 var icon = value && value.length > 0 ? React.createElement("a", {
83 href: "#",
84 className: "".concat(prefixCls, "-action"),
85 onClick: this.handleClear
86 }, React.createElement(Icon, {
87 type: "cross-circle"
88 })) : React.createElement("span", {
89 className: "".concat(prefixCls, "-action")
90 }, React.createElement(Icon, {
91 type: "search"
92 }));
93 return React.createElement("div", null, React.createElement(Input, {
94 placeholder: placeholder,
95 className: prefixCls,
96 value: value,
97 onChange: this.handleChange
98 }), icon);
99 }
100 }]);
101
102 return Search;
103}(Component);
104
105export { Search as default };
106Search.defaultProps = {
107 placeholder: ''
108};
109//# sourceMappingURL=search.js.map