UNPKG

choerodon-ui

Version:

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

143 lines (117 loc) 4 kB
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"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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, { Component } from 'react'; import PropTypes from 'prop-types'; import Icon from '../../icon'; import Input from '../../input'; import Button from '../../button'; import { saveRef } from './util'; var FilterInput = /*#__PURE__*/ function (_Component) { _inherits(FilterInput, _Component); var _super = _createSuper(FilterInput); function FilterInput(props) { var _this; _classCallCheck(this, FilterInput); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "componentWillReceiveProps", function (nextProps) { if ('filterValue' in nextProps) { var value = nextProps.filterValue; _this.setState({ value: value }); } }); _defineProperty(_assertThisInitialized(_this), "handleChange", function (event, input) { var onChange = _this.props.onChange; onChange(event.target.value); _this.setState({ value: event.target.value }); }); _defineProperty(_assertThisInitialized(_this), "clearInputValue", function () { var onChange = _this.props.onChange; onChange(''); }); _defineProperty(_assertThisInitialized(_this), "focus", function () { _this.filterInputRef.focus(); }); _defineProperty(_assertThisInitialized(_this), "blur", function () { _this.filterInputRef.blur(); }); var _value = props.filterValue || ''; _this.state = { value: _value }; return _this; } _createClass(FilterInput, [{ key: "render", value: function render() { var _this$props = this.props, prefixCls = _this$props.prefixCls, placeholder = _this$props.placeholder; var value = this.state.value; var suffix = value && React.createElement(Button, { size: "small", onClick: this.clearInputValue, shape: "circle", icon: "close" }); return React.createElement("div", { className: "".concat(prefixCls, "-filter") }, React.createElement("span", { className: "".concat(prefixCls, "-filter-input") }, React.createElement(Input, { value: value, placeholder: placeholder, prefix: React.createElement(Icon, { type: "search" }), suffix: suffix, onChange: this.handleChange, onKeyDown: this.props.onKeyDown, ref: saveRef(this, 'filterInputRef') }))); } }]); return FilterInput; }(Component); _defineProperty(FilterInput, "propTypes", { prefixCls: PropTypes.string, placeholder: PropTypes.string, onChange: PropTypes.func, onKeyDown: PropTypes.func }); export default FilterInput; //# sourceMappingURL=FilterInput.js.map