From ff9e5a5228eb7ab292d238ac6c2af304b3ec8ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 30 Sep 2024 17:34:31 +0200 Subject: [PATCH 1/2] Show caption for file blocks --- packages/gitbook/e2e/pages.spec.ts | 5 + .../src/components/DocumentView/Caption.tsx | 3 +- .../src/components/DocumentView/File.tsx | 112 ++++++++---------- 3 files changed, 58 insertions(+), 62 deletions(-) diff --git a/packages/gitbook/e2e/pages.spec.ts b/packages/gitbook/e2e/pages.spec.ts index 3b3539ee6..1d58656be 100644 --- a/packages/gitbook/e2e/pages.spec.ts +++ b/packages/gitbook/e2e/pages.spec.ts @@ -371,6 +371,11 @@ const testCases: TestsCase[] = [ name: 'Math', url: 'blocks/math', }, + { + name: 'Files', + url: 'blocks/files', + fullPage: true, + }, { name: 'Embeds', url: 'blocks/embeds', diff --git a/packages/gitbook/src/components/DocumentView/Caption.tsx b/packages/gitbook/src/components/DocumentView/Caption.tsx index ecd530039..ff762883b 100644 --- a/packages/gitbook/src/components/DocumentView/Caption.tsx +++ b/packages/gitbook/src/components/DocumentView/Caption.tsx @@ -1,6 +1,7 @@ import { DocumentBlockDrawing, DocumentBlockEmbed, + DocumentBlockFile, DocumentBlockImage, JSONDocument, } from '@gitbook/api'; @@ -21,7 +22,7 @@ export function Caption( style?: ClassValue; fit?: boolean; wrapperStyle?: ClassValue; - block: DocumentBlockImage | DocumentBlockDrawing | DocumentBlockEmbed; + block: DocumentBlockImage | DocumentBlockDrawing | DocumentBlockEmbed | DocumentBlockFile; } & DocumentContextProps, ) { const { diff --git a/packages/gitbook/src/components/DocumentView/File.tsx b/packages/gitbook/src/components/DocumentView/File.tsx index 4a9845308..7ae0b2e10 100644 --- a/packages/gitbook/src/components/DocumentView/File.tsx +++ b/packages/gitbook/src/components/DocumentView/File.tsx @@ -4,10 +4,11 @@ import { getSimplifiedContentType } from '@/lib/files'; import { tcls } from '@/lib/tailwind'; import { BlockProps } from './Block'; +import { Caption } from './Caption'; import { FileIcon } from './FileIcon'; export async function File(props: BlockProps) { - const { block, context, style } = props; + const { block, context } = props; const contentRef = await context.resolveContentRef(block.data.ref); const file = contentRef?.file; @@ -19,76 +20,65 @@ export async function File(props: BlockProps) { const contentType = getSimplifiedContentType(file.contentType); return ( - -
+ -
- -
- {getHumanFileSize(file.size)} +
+ +
+
+ {getHumanFileSize(file.size)} +
+
+
+
{file.name}
+
+ {contentType} +
-
-
-
{file.name}
-
{contentType}
-
-
+ + ); } From 82b21727b9e77b857e81799c7e1f838afa3a7945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 30 Sep 2024 17:35:00 +0200 Subject: [PATCH 2/2] Changeset --- .changeset/nine-maps-judge.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nine-maps-judge.md diff --git a/.changeset/nine-maps-judge.md b/.changeset/nine-maps-judge.md new file mode 100644 index 000000000..83f87acea --- /dev/null +++ b/.changeset/nine-maps-judge.md @@ -0,0 +1,5 @@ +--- +'gitbook': minor +--- + +Show the caption for file blocks