UNPKG

quesbook-component

Version:
189 lines (166 loc) 9.35 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _QbDropDownItem = require('./QbDropDownItem'); var _QbDropDownItem2 = _interopRequireDefault(_QbDropDownItem); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } /** * Created by az on 2017/7/17. */ /*eslint-disable*/ var QbDropDown = function (_Component) { _inherits(QbDropDown, _Component); function QbDropDown(props) { _classCallCheck(this, QbDropDown); var _this = _possibleConstructorReturn(this, (QbDropDown.__proto__ || Object.getPrototypeOf(QbDropDown)).call(this, props)); _this.state = { selectedObj: { label: props ? props.defaultData.label : '', value: props ? props.defaultData.value : '' }, keyword: '' }; return _this; } _createClass(QbDropDown, [{ key: 'componentDidUpdate', value: function componentDidUpdate() { var onChange = this.props.onChange; onChange(this.state.selectedObj); } }, { key: 'renderInputComp', value: function renderInputComp() { var _this2 = this; var _props = this.props, compClass = _props.compClass, compStyle = _props.compStyle, inputType = _props.inputType, btnStyle = _props.btnStyle, size = _props.size, inputClassName = _props.inputClassName, dropdownStyle = _props.dropdownStyle, content = _props.content; var children = void 0; if (inputType === 'button') { children = content.map(function (data, index) { return _react2.default.createElement(_QbDropDownItem2.default, { label: data.label, key: index, value: data.value, onClick: function onClick(data) { return _this2.setState({ selectedObj: data }); } }); }); } else if (inputType === 'input') { var filterArray = content.filter(function (data) { if (data.label.indexOf(_this2.state.keyword) !== -1) { return true; } else { return false; } }); children = filterArray.map(function (data, index) { return _react2.default.createElement(_QbDropDownItem2.default, { label: data.label, key: index, value: data.value, onClick: function onClick(data) { return _this2.setState({ selectedObj: data }); } }); }); } switch (inputType) { case 'button': var btnClass = "btn " + (inputClassName ? inputClassName : 'btn-secondary'); var finalStyle = eval("style.button." + (size ? size : "default")); return _react2.default.createElement( 'div', { className: compClass + ' btn-group', style: _extends({ height: finalStyle.height }, compStyle) }, _react2.default.createElement( 'button', { type: 'button', className: btnClass, style: _extends({}, btnStyle, style.button.publicStyle, { height: finalStyle.height, borderRight: 0, fontSize: finalStyle.fontSize }) }, this.state.selectedObj.label ), _react2.default.createElement( 'button', { type: 'button', style: _extends({}, style.button.publicStyle, { borderLeft: 0 }), className: 'btn btn-secondary dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': 'true', 'aria-expanded': 'false' }, _react2.default.createElement( 'span', { className: 'sr-only' }, 'Toggle Dropdown' ) ), _react2.default.createElement( 'div', { className: 'dropdown-menu', style: dropdownStyle }, children ) ); case 'input': return _react2.default.createElement( 'div', { className: compClass, style: _extends({}, style.inputStyle, compStyle) }, _react2.default.createElement('input', { type: 'text', 'data-toggle': 'dropdown', className: 'form-control', onChange: function onChange(e) { return _this2.setState({ keyword: e.target.value }); } }), _react2.default.createElement( 'div', { className: 'dropdown-menu dropdown-menu-right', style: dropdownStyle }, children ) ); } } }, { key: 'render', value: function render() { return this.renderInputComp(); } }]); return QbDropDown; }(_react.Component); var style = { button: { publicStyle: { border: '1px solid #cccccc', lineHeight: 1 }, small: { height: 30, fontSize: 16, margin: '7px 20px' }, default: { height: 38, fontSize: 21, margin: '9px 26px' }, large: { height: 52, fontSize: 25, margin: '13px 36px' }, blockLarge: { height: 52, fontSize: 25, margin: '13px 62px' } }, inputStyle: { position: 'relative' } }; exports.default = QbDropDown; //# sourceMappingURL=QbDropDown.js.map