UNPKG

react-application-core

Version:

A react-based application core for the business applications.

118 lines 4.71 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, 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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Barcode = void 0; var React = require("react"); var JsBarcode = require("jsbarcode"); var R = require("ramda"); var generic_component_1 = require("../base/generic.component"); var util_1 = require("../../util"); var barcode_support_1 = require("./barcode.support"); var definition_1 = require("../../definition"); var Barcode = /** @class */ (function (_super) { __extends(Barcode, _super); function Barcode() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.uuid = util_1.UuidUtils.uuid(true); return _this; } /** * @stable [03.11.2020] * @param prevProps * @param prevState */ Barcode.prototype.componentDidUpdate = function (prevProps, prevState) { if (!R.equals(this.originalProps, prevProps)) { this.refresh(); } }; /** * @stable [03.11.2020] */ Barcode.prototype.componentDidMount = function () { this.refresh(); }; /** * @stable [17.12.2020] */ Barcode.prototype.render = function () { var _this = this; var footer = this.originalProps.footer; return (React.createElement(React.Fragment, null, this.validFormats .map(function (format, index) { return (React.createElement("div", { key: index, className: definition_1.BarcodeClassesEnum.BARCODE }, _this.originalChildren, React.createElement("svg", { id: _this.toId(format), className: definition_1.BarcodeClassesEnum.DATA }), util_1.NvlUtils.nvl(util_1.CalcUtils.calc(footer, format), format))); }))); }; /** * @stable [11.06.2018] */ Barcode.prototype.refresh = function () { var _this = this; var _a = this.originalProps, barcode = _a.barcode, fontSize = _a.fontSize, height = _a.height; var options = util_1.FilterUtils.defValuesFilter({ height: height, fontSize: fontSize, }); this.validFormats.forEach(function (format) { var barcodeInstance = JsBarcode("#" + _this.toId(format)); switch (format) { case definition_1.BarcodeFormatsEnum.CODE128: barcodeInstance.CODE128(barcode, options).render(); break; case definition_1.BarcodeFormatsEnum.CODE39: barcodeInstance.CODE39(barcode, options).render(); break; case definition_1.BarcodeFormatsEnum.EAN8: barcodeInstance.EAN8(barcode, options).render(); break; case definition_1.BarcodeFormatsEnum.EAN13: barcodeInstance.EAN13(barcode, options).render(); break; case definition_1.BarcodeFormatsEnum.UPC: barcodeInstance.UPC(barcode, options).render(); break; } }); }; /** * @stable [03.11.2020] * @param format * @private */ Barcode.prototype.toId = function (format) { return this.uuid + "-" + format; }; Object.defineProperty(Barcode.prototype, "validFormats", { /** * @stable [10.04.2019] * @returns {BarcodeFormatsEnum[]} */ get: function () { var props = this.props; var barcodeFormats = barcode_support_1.getBarcodeApplicableFormats(props.barcode, props.format); return barcodeFormats.filter(function (format) { return props.filter(format, barcodeFormats); }); }, enumerable: false, configurable: true }); Barcode.defaultProps = { format: definition_1.BARCODE_APPLICABLE_FORMATS, filter: function () { return true; }, }; return Barcode; }(generic_component_1.GenericComponent)); exports.Barcode = Barcode; //# sourceMappingURL=barcode.component.js.map