mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 05:56:47 +01:00
29 lines
719 B
TypeScript
29 lines
719 B
TypeScript
import { useMemo } from 'react';
|
|
|
|
interface Props {
|
|
body: string;
|
|
contentType: string;
|
|
url: string;
|
|
}
|
|
|
|
export function Webview({ body, url, contentType }: Props) {
|
|
const contentForIframe: string | undefined = useMemo(() => {
|
|
if (!contentType.includes('html')) return;
|
|
if (body.includes('<head>')) {
|
|
return body.replace(/<head>/gi, `<head><base href="${url}"/>`);
|
|
}
|
|
return body;
|
|
}, [url, body, contentType]);
|
|
|
|
return (
|
|
<div className="h-full pb-3">
|
|
<iframe
|
|
title="Response preview"
|
|
srcDoc={contentForIframe}
|
|
sandbox="allow-scripts allow-same-origin"
|
|
className="h-full w-full rounded border border-highlightSecondary"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|