UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

124 lines (94 loc) 5.82 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _searchBar = require('antd-mobile/lib/search-bar'); var _searchBar2 = _interopRequireDefault(_searchBar); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/search-bar/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _FunctionUtil = require('../../utils/FunctionUtil'); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!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) { if (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 } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var YYSearchBar = function (_React$Component) { _inherits(YYSearchBar, _React$Component); function YYSearchBar() { var _ref; var _temp, _this, _ret; _classCallCheck(this, YYSearchBar); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYSearchBar.__proto__ || Object.getPrototypeOf(YYSearchBar)).call.apply(_ref, [this].concat(args))), _this), _this.state = { value: _this.props.value }, _this.onSubmit = function (val) { if ((0, _FunctionUtil.isFunction)(_this.props.onSubmit)) _this.props.onSubmit(_this.state.value); }, _this.onChange = function (val) { _this.setState({ value: val }, function () { if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) _this.props.onChange(val); }); }, _this.onFocus = function () { if ((0, _FunctionUtil.isFunction)(_this.props.onFocus)) _this.props.onFocus(); }, _this.onBlur = function () { if ((0, _FunctionUtil.isFunction)(_this.props.onBlur)) _this.props.onBlur(); }, _this.onCancel = function (val) { _this.setState({ value: '' }, function () { if ((0, _FunctionUtil.isFunction)(_this.props.onCancel)) _this.props.onCancel(val, _this.state.value); }); }, _this.onClear = function (val) { _this.setState({ value: '' }); if ((0, _FunctionUtil.isFunction)(_this.props.onClear)) _this.props.onClear(val); }, _this.focus = function () { _this.SearchBar.focus(); }, _this.getValue = function () { return _this.state.value; }, _this.setValue = function (value) { _this.setState({ value: value }); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(YYSearchBar, [{ key: 'render', value: function render() { var _this2 = this; var _props = this.props, visible = _props.visible, showCancelButton = _props.showCancelButton, restProps = _objectWithoutProperties(_props, ['visible', 'showCancelButton']); var wrapClz = (0, _classnames2.default)('yy-search-bar', !visible && 'hidden', this.props.className); return _react2.default.createElement(_searchBar2.default, _extends({}, restProps, { className: wrapClz, value: this.state.value, ref: function ref(_ref2) { return _this2.SearchBar = _ref2; }, onSubmit: this.onSubmit, onChange: this.onChange, onFocus: this.onFocus, onBlur: this.onBlur, onCancel: this.onCancel, onClear: this.onClear, showCancelButton: showCancelButton })); } }]); return YYSearchBar; }(_react2.default.Component); ; YYSearchBar.defaultProps = { visible: true }; exports.default = YYSearchBar;