UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

180 lines (152 loc) 5.15 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { cloneElement, Component } from 'react'; import classNames from 'classnames'; import Input from './Input'; import Button from '../button'; import { Size } from '../_util/enum'; import { getPrefixCls as _getPrefixCls } from '../configure'; var Search = /*#__PURE__*/ function (_Component) { _inherits(Search, _Component); var _super = _createSuper(Search); function Search() { var _this; _classCallCheck(this, Search); _this = _super.apply(this, arguments); _this.onSearch = function () { var onSearch = _this.props.onSearch; if (onSearch) { onSearch(_this.input.input.value); } _this.input.focus(); }; _this.saveInput = function (node) { _this.input = node; }; return _this; } _createClass(Search, [{ key: "focus", value: function focus() { this.input.focus(); } }, { key: "blur", value: function blur() { this.input.blur(); } }, { key: "getPrefixCls", value: function getPrefixCls() { var prefixCls = this.props.prefixCls; return _getPrefixCls('input-search', prefixCls); } }, { key: "getButtonOrIcon", value: function getButtonOrIcon() { var _this$props = this.props, enterButton = _this$props.enterButton, size = _this$props.size; if (!enterButton) { return React.createElement(Button, { type: "primary", size: size, shape: "circle", icon: "search" }); } var enterButtonAsElement = enterButton; if (enterButtonAsElement.type === Button || enterButtonAsElement.type === 'button') { return cloneElement(enterButtonAsElement, enterButtonAsElement.type === Button ? { className: "".concat(this.getPrefixCls(), "-button"), size: size, onClick: this.onSearch } : { onClick: this.onSearch }); } if (enterButton === true) { return React.createElement(Button, { type: "primary", size: size, shape: "circle", onClick: this.onSearch, icon: "search" }); } return React.createElement(Button, { type: "primary", size: size, onClick: this.onSearch, key: "enterButton" }, enterButton); } }, { key: "render", value: function render() { var _classNames; var _this$props2 = this.props, className = _this$props2.className, inputPrefixCls = _this$props2.inputPrefixCls, size = _this$props2.size, suffix = _this$props2.suffix, enterButton = _this$props2.enterButton, others = _objectWithoutProperties(_this$props2, ["className", "inputPrefixCls", "size", "suffix", "enterButton"]); var prefixCls = this.getPrefixCls(); delete others.onSearch; delete others.prefixCls; var buttonOrIcon = this.getButtonOrIcon(); var searchSuffix = suffix ? [suffix, buttonOrIcon] : buttonOrIcon; var inputClassName = classNames(prefixCls, className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-enter-button"), !!enterButton), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(size), !!size), _classNames)); return React.createElement(Input, _extends({ onPressEnter: this.onSearch }, others, { size: size, className: inputClassName, prefixCls: _getPrefixCls('input', inputPrefixCls), suffix: searchSuffix, ref: this.saveInput })); } }]); return Search; }(Component); export { Search as default }; Search.displayName = 'Search'; Search.defaultProps = { enterButton: false, size: Size.small }; //# sourceMappingURL=Search.js.map