@up-group-ui/react-controls
Version:
Up shared react controls
69 lines • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpPDFViewer = void 0;
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var typestyle_1 = require("typestyle");
var react_pdf_1 = require("react-pdf");
var theming_1 = require("../../../Common/theming");
var LoadingIndicator_1 = (0, tslib_1.__importDefault)(require("../LoadingIndicator"));
var FullWidth = (0, typestyle_1.style)({
width: '100%',
flexDirection: 'column',
});
var UpPDFViewer = (function (_super) {
(0, 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((0, jsx_runtime_1.jsx)(react_pdf_1.Page, { pageNumber: page, scale: _this.props.scale, width: _this.state.wrapperWidth ? _this.state.wrapperWidth : '100%' }, page));
}
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 (0, jsx_runtime_1.jsx)(LoadingIndicator_1.default, { message: "Chargement en cours...", isLoading: isProcessingPrint }, void 0);
}
return ((0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ ref: function (ref) {
_this.pdfWrapper = ref;
_this.setDivSize();
}, className: this.props.className }, { children: (0, jsx_runtime_1.jsxs)(react_pdf_1.Document, (0, tslib_1.__assign)({ file: base64PDFOrUrl, loading: (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ style: { margin: 'auto' } }, { children: (0, jsx_runtime_1.jsx)(LoadingIndicator_1.default, { message: 'Chargement en cours...', isLoading: true }, void 0) }), void 0), onLoadSuccess: this.onLoadSuccess, noData: '' }, { children: [this.props.showAllPages && this.state.pagesNumber && this.displayAllPages(this.state.pagesNumber), !this.props.showAllPages && ((0, jsx_runtime_1.jsx)(react_pdf_1.Page, { width: this.state.wrapperWidth ? this.state.wrapperWidth : '100%', pageNumber: 1, scale: this.props.scale }, void 0)), this.props.children] }), void 0) }), void 0));
};
UpPDFViewer.defaultProps = {
scale: 1.1,
className: FullWidth,
};
return UpPDFViewer;
}(react_1.default.PureComponent));
exports.UpPDFViewer = UpPDFViewer;
exports.default = (0, theming_1.withTheme)(UpPDFViewer);
//# sourceMappingURL=UpPDFViewer.js.map