@afzalimdad9/react-file-preview
Version:
The url previewer is built using native html elements for previewing url of files of the following type
29 lines • 1.23 kB
JavaScript
import { __makeTemplateObject } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import styled from 'styled-components';
var Iframe = styled.iframe(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background-color: white;\n width: 100%;\n height: 100%;\n"], ["\n background-color: white;\n width: 100%;\n height: 100%;\n"])));
export default function HTMLViewer(_a) {
var src = _a.src, onLoad = _a.onLoad, onError = _a.onError;
var _b = useState(''), data = _b[0], setData = _b[1];
useEffect(function () {
var req = new XMLHttpRequest();
req.open('GET', src, true);
req.onload = function (e) {
if (req.status >= 300) {
onError(e);
}
else {
setData(req.response);
onLoad(true);
}
};
req.send();
return function () {
req.abort();
};
}, [src, onLoad, onError]);
return _jsx(Iframe, { src: "data:text/html; charset=utf-8,".concat(encodeURIComponent(data)), sandbox: '' });
}
var templateObject_1;
//# sourceMappingURL=html-viewer.js.map