UNPKG

@progress/kendo-react-barcodes

Version:

React Barcodes provide a set of React components to build beautiful and customizable barcodes. KendoReact Barcodes package

9 lines (8 loc) 3.34 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),d=require("prop-types"),v=require("./store/store.js"),f=require("./store/reducer.js"),O=require("./utils/common.js"),w=require("./BarcodeContext.js"),a=require("@progress/kendo-react-common"),l=require("./package-metadata.js");function C(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const r in n)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>n[r]})}}return e.default=n,Object.freeze(e)}const o=C(b),i=class i extends o.Component{constructor(e){super(e),this.barcodeInstance=null,this.surface=null,this._element=null,this.observersStore={},this.showLicenseWatermark=!1,this.onWindowResize=()=>{this.barcodeInstance!==null&&(this.barcodeInstance.redraw(),this.trigger("render",{sender:this}))},this.showLicenseWatermark=!a.validatePackage(l.packageMetadata,{component:"Barcode"}),this.licenseMessage=a.getLicenseMessage(l.packageMetadata),this.observersStore=v.createStore(f.observersReducer),this.contextValue={observersStore:this.observersStore}}get element(){return this._element}componentDidMount(){this.instantiateCoreBarcode(),window.addEventListener("resize",this.onWindowResize),this.trigger("render",{sender:this})}componentDidUpdate(e){const{children:r,deriveOptionsFromParent:t,getTarget:s,barcodeConstructor:I,className:y,renderAs:h,...p}=this.props,{children:P,deriveOptionsFromParent:S,getTarget:k,barcodeConstructor:M,className:q,renderAs:u,...g}=e;if(this.barcodeInstance!==null){const m=O.isOptionsChanged(g,p);(h||"svg")!==(u||"svg")?(this.barcodeInstance!==null&&(this.barcodeInstance.destroy(),this.barcodeInstance=null),this.instantiateCoreBarcode()):m&&this.refresh(),this.trigger("render",{sender:this})}}componentWillUnmount(){this.barcodeInstance!==null&&(this.barcodeInstance.destroy(),this.barcodeInstance=null),window.removeEventListener("resize",this.onWindowResize)}render(){const{style:e={},className:r,children:t}=this.props;return o.createElement(w.BarcodeContext.Provider,{value:this.contextValue},o.createElement("div",{style:e,ref:s=>{this._element=s},className:r},t,this.showLicenseWatermark&&o.createElement(a.WatermarkOverlay,{message:this.licenseMessage})))}instantiateCoreBarcode(){const{barcodeConstructor:e}=this.props,r=this.getBarcodeOptions();this.barcodeInstance=new e(this.element,r,t=>{if(process.env.NODE_ENV!=="production")throw t;console.warn(t)})}refresh(){if(this.barcodeInstance!==null){const e=this.getBarcodeOptions();this.barcodeInstance.setOptions(e)}}getBarcodeOptions(){const{renderAs:e,deriveOptionsFromParent:r}=this.props;let t={renderAs:e};return r&&(t=r(t)),t}trigger(e,r){const t=this.observersStore.getState();for(let s=0;s<t.length;s++)t[s].trigger(e,r)}};i.propTypes={dir:d.string,renderAs:d.oneOf(["svg","canvas"])},i.defaultProps={renderAs:"svg"};let c=i;exports.BaseBarcode=c;