Files
unicorn-utterances/src/utils/markdown/iframes/iframe-placeholder.tsx
Corbin Crutchley d701825d0b Merge branch 'partial-uwu' into uwu-search-page
# Conflicts:
#	astro.config.ts
#	package-lock.json
#	package.json
#	src/types/plausible.d.ts
#	src/utils/debounce.ts
2023-07-26 17:44:00 -07:00

77 lines
1.9 KiB
TypeScript

/** @jsxRuntime automatic */
import { Element } from "hast";
import { GetPictureResult } from "@astrojs/image/dist/lib/get-picture";
import { fromHtml } from "hast-util-from-html";
import fs from "fs/promises";
const launch = await fs.readFile("src/icons/launch.svg", "utf8");
const play = await fs.readFile("src/icons/play.svg", "utf8");
export interface IFramePlaceholderProps {
width: string;
height: string;
src: string;
pageTitle: string;
pageIcon: GetPictureResult;
}
/** @jsxImportSource hastscript */
export function IFramePlaceholder({
height,
width,
...props
}: IFramePlaceholderProps): Element {
return (
<div class="embed">
<div class="embed__header">
<div class="embed__header__favicon">
<picture>
{props.pageIcon.sources.map((source) => (
<source {...source} />
))}
<img
{...(props.pageIcon.image as any)}
alt=""
loading="lazy"
decoding="async"
data-nozoom="true"
/>
</picture>
</div>
<div class="embed__header__info">
<p>
<span class="visually-hidden">An embedded webpage:</span>
{props.pageTitle}
</p>
<a
href={props.src}
rel="nofollow noopener noreferrer"
target="_blank"
>
{props.src}
</a>
</div>
<a
href={props.src}
class="button regular primary text-style-button-regular"
rel="nofollow noopener noreferrer"
target="_blank"
>
<div class="buttonIcon">{fromHtml(launch)}</div>
<div class="innerText">New tab</div>
</a>
</div>
<div
class="embed__placeholder"
data-iframeurl={props.src}
style={`height: ${Number(height) ? `${height}px` : height};`}
>
<button class="button regular primary-emphasized text-style-button-regular">
<div class="buttonIcon">{fromHtml(play)}</div>
<div class="innerText">Run</div>
</button>
</div>
</div>
) as never;
}