@jdcfe/yep-react
Version:
一套移动端的React组件库
108 lines (97 loc) • 4.44 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import * as React from 'react';
import classNames from 'classnames';
import SearchOutlined from '@jdcfe/icons-react/SearchOutlined';
import CloseCircleOutlined from '@jdcfe/icons-react/CloseCircleOutlined';
var SearchBar = /*#__PURE__*/function (_React$PureComponent) {
_inherits(SearchBar, _React$PureComponent);
var _super = _createSuper(SearchBar);
function SearchBar(props) {
var _this;
_classCallCheck(this, SearchBar);
_this = _super.call(this, props);
_this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this));
_this.handleClear = _this.handleClear.bind(_assertThisInitialized(_this));
_this.handleSearchFn = _this.handleSearchFn.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(SearchBar, [{
key: "handleClear",
value: function handleClear() {
var onChange = this.props.onChange;
onChange && onChange('');
}
}, {
key: "handleChange",
value: function handleChange(e) {
var value = e.target.value;
var onChange = this.props.onChange;
onChange && onChange(value);
}
}, {
key: "handleSearchFn",
value: function handleSearchFn(value) {
var onSearch = this.props.onSearch;
onSearch && onSearch(value);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
className = _this$props.className,
prefixCls = _this$props.prefixCls,
disabled = _this$props.disabled,
placeholder = _this$props.placeholder,
readOnly = _this$props.readOnly,
maxLength = _this$props.maxLength,
clearable = _this$props.clearable,
value = _this$props.value,
type = _this$props.type,
style = _this$props.style;
var inputProps = {
value: value,
type: type,
disabled: disabled,
placeholder: placeholder,
readOnly: readOnly,
maxLength: maxLength
};
var inputCls = classNames("".concat(prefixCls), className);
return /*#__PURE__*/React.createElement("div", {
className: "yep-search-bar-bj"
}, /*#__PURE__*/React.createElement("div", {
className: classNames('Yep-search-bar-wrapper', className),
style: style
}, /*#__PURE__*/React.createElement(SearchOutlined, {
className: "Yep-icon-lego_sousuo Yep-icon-xxs"
}), /*#__PURE__*/React.createElement("input", _extends({
className: inputCls
}, inputProps, {
onChange: this.handleChange
})), (value || value === 0 || Number.isNaN(value)) && clearable && /*#__PURE__*/React.createElement(CloseCircleOutlined, {
className: "Yep-search-bar__clear Yep-icon-xxs",
onClick: this.handleClear
})), (value || value === 0 || Number.isNaN(value)) && clearable && /*#__PURE__*/React.createElement("span", {
className: "yep-search-bar-cancel",
onClick: this.handleSearchFn
}, "\u641C\u7D22"));
}
}]);
return SearchBar;
}(React.PureComponent);
SearchBar.defaultProps = {
prefixCls: 'Yep-search-bar',
style: {},
type: 'text',
value: '',
readOnly: false
};
export default SearchBar;