UNPKG

ukelli-ui

Version:

Base on React's UI lib. Make frontend's dev simpler and faster.

65 lines (64 loc) 2.89 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /* eslint-disable consistent-return */ import React from 'react'; import { Call } from 'basic-helper'; import FormFilterHelper from './form-filter'; /** * 查询条件生成器 * * @export * @class ConditionGenerator * @extends {FormFilterHelper} */ var ConditionGenerator = /** @class */ (function (_super) { __extends(ConditionGenerator, _super); function ConditionGenerator() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.titleDisplayFilter = function (config) { var type = config.type, title = config.title, _title = config._title; return ('input,password'.split(',').indexOf(type) === -1) && (title || _title); }; return _this; } ConditionGenerator.prototype.render = function () { var _this = this; var _a = this.props, conditionConfig = _a.conditionConfig, className = _a.className, children = _a.children, onSubmit = _a.onSubmit; var Wrapper = onSubmit ? 'form' : 'div'; return (React.createElement(Wrapper, { className: className, onSubmit: function (e) { e.preventDefault(); Call(onSubmit, _this.value); } }, conditionConfig.map(function (condition, idx) { if (!condition || typeof condition === 'string') return; var _con = _this.wrapConditionTitle(condition); var ref = _con.ref, _a = _con.refs, refs = _a === void 0 ? [] : _a, _b = _con.refu, refu = _b === void 0 ? [] : _b; var itemKey = ref || refs[0] || JSON.stringify(refu); var showTitle = _this.titleDisplayFilter(_con); var titleDOM = showTitle && (React.createElement("span", { className: "title" }, _con.tipsDOM, _con._title)); return (React.createElement("span", { key: itemKey, className: "item " + _con.type + (_con.className ? " " + _con.className : '') }, titleDOM, _this.greneratFormDOM(_con))); }), children)); }; ConditionGenerator.defaultProps = { className: "condition-group" }; return ConditionGenerator; }(FormFilterHelper)); export default ConditionGenerator;