Skip to content

Commit 03fdf82

Browse files
authored
feat: embed pdfs (#48)
1 parent 0798c28 commit 03fdf82

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

packages/web/src/components/embed/embed.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { EmbedImage } from "./variants/embed-image";
55
import { EmbedMarkdown } from "./variants/embed-markdown";
66
import { EmbedText } from "./variants/embed-text";
77
import { EmbedVideo } from "./variants/embed-video";
8+
import { EmbedDocument } from "./variants/embed-document";
89

910
interface EmbedProps {
1011
data: Embeddable;
@@ -18,6 +19,11 @@ export const Embed: FC<EmbedProps> = ({ data }) => {
1819
const isImage = EmbedImage.embeddable(data);
1920
const isVideo = EmbedVideo.embeddable(data);
2021
const isMarkdown = EmbedMarkdown.embeddable(data);
22+
const isDocument = EmbedDocument.embeddable(data);
23+
24+
if (isDocument) {
25+
return <EmbedDocument file={data} />;
26+
}
2127

2228
if (isMarkdown) {
2329
return <EmbedMarkdown data={data} />;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import clsx from "clsx";
2+
import { BASE_EMBED_CLASSES, MAX_HEIGHT } from "../embed";
3+
import type { Embeddable } from "../embeddable";
4+
5+
export const EmbedDocument = ({ file }: { file: Embeddable }) => {
6+
const classes = clsx("outline-none h-[70vh] p-4", BASE_EMBED_CLASSES, MAX_HEIGHT);
7+
8+
return (
9+
<object data={file.paths.direct} type="application/pdf" aria-label={file.displayName} className={classes}>
10+
This browser does not support PDFs. You can download the file{" "}
11+
<a className="text-primary" href={file.paths.direct} target="_blank" rel="noreferrer">
12+
here
13+
</a>
14+
.
15+
</object>
16+
);
17+
};
18+
19+
EmbedDocument.embeddable = (data: Embeddable) => {
20+
switch (data.type) {
21+
case "application/pdf": {
22+
return true;
23+
}
24+
default: {
25+
return false;
26+
}
27+
}
28+
};

0 commit comments

Comments
 (0)