UNPKG

antd-meck

Version:

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

77 lines (67 loc) 3.29 kB
import _extends from 'babel-runtime/helpers/extends'; import _defineProperty from 'babel-runtime/helpers/defineProperty'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; }return t; }; import * as React from 'react'; import classNames from 'classnames'; import Input from './Input'; import Icon from '../icon'; import Button from '../button'; var Search = function (_React$Component) { _inherits(Search, _React$Component); function Search() { _classCallCheck(this, Search); var _this = _possibleConstructorReturn(this, (Search.__proto__ || Object.getPrototypeOf(Search)).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: 'render', value: function render() { var _classNames; var _a = this.props, className = _a.className, prefixCls = _a.prefixCls, inputPrefixCls = _a.inputPrefixCls, size = _a.size, enterButton = _a.enterButton, suffix = _a.suffix, others = __rest(_a, ["className", "prefixCls", "inputPrefixCls", "size", "enterButton", "suffix"]); delete others.onSearch; var buttonOrIcon = enterButton ? React.createElement( Button, { className: prefixCls + '-button', type: 'primary', size: size, onClick: this.onSearch, key: 'enterButton' }, enterButton === true ? React.createElement(Icon, { type: 'search' }) : enterButton ) : React.createElement(Icon, { className: prefixCls + '-icon', type: 'search', key: 'searchIcon' }); var searchSuffix = suffix ? [suffix, buttonOrIcon] : buttonOrIcon; var inputClassName = classNames(prefixCls, className, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-enter-button', !!enterButton), _defineProperty(_classNames, prefixCls + '-' + size, !!size), _classNames)); return React.createElement(Input, _extends({ onPressEnter: this.onSearch }, others, { size: size, className: inputClassName, prefixCls: inputPrefixCls, suffix: searchSuffix, ref: this.saveInput })); } }]); return Search; }(React.Component); export default Search; Search.defaultProps = { inputPrefixCls: 'ant-input', prefixCls: 'ant-input-search', enterButton: false };