all files / src/ActionBar/ SearchBar.jsx

85.19% Statements 46/54
53.33% Branches 16/30
66.67% Functions 8/12
88.89% Lines 32/36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98                                                                                                                                   
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _react = require('react');
 
var _react2 = _interopRequireDefault(_react);
 
var _propTypes = require('prop-types');
 
var _propTypes2 = _interopRequireDefault(_propTypes);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); Iif (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
function _possibleConstructorReturn(self, call) { Iif (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
 
function _inherits(subClass, superClass) { Iif (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Grid Component for uxcore
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * @author zhouquan.yezq
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Copyright 2014-2015, UXCore Team, Alinw.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * All rights reserved.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */
 
var SearchBar = function (_React$Component) {
  _inherits(SearchBar, _React$Component);
 
  function SearchBar(props) {
    _classCallCheck(this, SearchBar);
 
    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
 
    _this.state = {
      searchTxt: ''
    };
    _this.onKeyDown = _this.onKeyDown.bind(_this);
    _this.handleChange = _this.handleChange.bind(_this);
    _this.doSearch = _this.doSearch.bind(_this);
    return _this;
  }
 
  SearchBar.prototype.onKeyDown = function onKeyDown(e) {
    if (e.keyCode === 13) {
      this.doSearch();
    }
  };
 
  SearchBar.prototype.doSearch = function doSearch() {
    this.props.onSearch(this.state.searchTxt);
  };
 
  SearchBar.prototype.handleChange = function handleChange(e) {
    this.setState({
      searchTxt: e.target.value
    });
  };
 
  SearchBar.prototype.render = function render() {
    var me = this;
    var placeholder = me.props.placeholder;
 
    return _react2['default'].createElement(
      'div',
      { className: this.props.prefixCls },
      _react2['default'].createElement('input', {
        type: 'text',
        className: 'kuma-input',
        placeholder: placeholder,
        value: this.state.value,
        onKeyDown: this.onKeyDown,
        onChange: this.handleChange
      }),
      _react2['default'].createElement('i', { className: 'kuma-icon kuma-icon-search', onClick: this.doSearch })
    );
  };
 
  return SearchBar;
}(_react2['default'].Component);
 
SearchBar.propTypes = {
  onSearch: _propTypes2['default'].func,
  prefixCls: _propTypes2['default'].string
};
 
SearchBar.defaultProps = {
  prefixCls: 'kuma-uxtable-searchbar',
  onSearch: function onSearch() {}
};
 
exports['default'] = SearchBar;
module.exports = exports['default'];