UNPKG

@arche-mc2/arche-controls

Version:

We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get

70 lines 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var typestyle_1 = require("typestyle"); var react_pdf_1 = require("react-pdf"); var theming_1 = require("../../../Common/theming"); var LoadingIndicator_1 = require("../LoadingIndicator"); var FullWidth = typestyle_1.style({ width: '100%', flexDirection: 'column', }); var UpPDFViewer = (function (_super) { tslib_1.__extends(UpPDFViewer, _super); function UpPDFViewer(props, context) { var _this = _super.call(this, props, context) || this; _this.onLoadSuccess = function (data) { _this.setState({ pagesNumber: data.numPages }); if (_this.props.onLoadSuccess) { _this.props.onLoadSuccess(); } }; _this.setDivSize = function () { if (_this.props.width) { _this.setState({ wrapperWidth: _this.props.width }); } else if (_this.pdfWrapper != null) { _this.setState({ wrapperWidth: _this.pdfWrapper.getBoundingClientRect().width }); } }; _this.displayAllPages = function (numPages) { var pages = []; for (var page = 1; page <= numPages; page++) { pages.push(React.createElement(react_pdf_1.Page, { key: page, pageNumber: page, scale: _this.props.scale, width: _this.state.wrapperWidth ? _this.state.wrapperWidth : '100%' })); } return pages; }; _this.state = {}; return _this; } UpPDFViewer.prototype.componentDidMount = function () { this.setDivSize(); }; UpPDFViewer.prototype.componentWillUnmount = function () { }; UpPDFViewer.prototype.render = function () { var _this = this; var _a = this.props, isProcessingPrint = _a.isProcessingPrint, base64PDFOrUrl = _a.base64PDFOrUrl; if (isProcessingPrint === true) { return (React.createElement(LoadingIndicator_1.default, { message: "Chargement en cours...", isLoading: isProcessingPrint })); } return (React.createElement("div", { ref: function (ref) { _this.pdfWrapper = ref; _this.setDivSize(); }, className: this.props.className }, React.createElement(react_pdf_1.Document, { file: base64PDFOrUrl, loading: React.createElement("div", { style: { margin: 'auto' } }, React.createElement(LoadingIndicator_1.default, { message: "Chargement en cours...", isLoading: true })), onLoadSuccess: this.onLoadSuccess, noData: '' }, this.props.showAllPages && this.state.pagesNumber && this.displayAllPages(this.state.pagesNumber), !this.props.showAllPages && React.createElement(react_pdf_1.Page, { width: this.state.wrapperWidth ? this.state.wrapperWidth : '100%', pageNumber: 1, scale: this.props.scale }), this.props.children))); }; UpPDFViewer.defaultProps = { scale: 1.1, className: FullWidth }; return UpPDFViewer; }(React.PureComponent)); exports.UpPDFViewer = UpPDFViewer; exports.default = theming_1.withTheme(UpPDFViewer); //# sourceMappingURL=UpPDFViewer.js.map