Skip to content

Commit a025118

Browse files
authored
Change card layout depending on cover aspect ratio (#2828)
1 parent 71688a8 commit a025118

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.changeset/shy-books-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Change card layout depending on cover aspect ratio

packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export async function RecordCard(
2828
: null;
2929
const target = targetRef ? await context.resolveContentRef(targetRef) : null;
3030

31+
const coverIsLandscape =
32+
cover?.file?.dimensions &&
33+
cover.file?.dimensions?.width / cover.file?.dimensions?.height > 1;
34+
3135
const body = (
3236
<div
3337
className={tcls(
@@ -42,17 +46,21 @@ export async function RecordCard(
4246
'rounded-[7px]',
4347
'straight-corners:rounded-none',
4448
'overflow-hidden',
45-
'[&_.heading]:flip-heading-hash',
49+
'[&_.heading>div:first-child]:hidden',
50+
'[&_.heading>div]:text-[.8em]',
51+
'md:[&_.heading>div]:text-[1em]',
4652
'[&_.blocks:first-child_.heading:first-child_div]:mt-0', // Remove margin on first heading in card
4753

48-
cover
49-
? [
50-
// On mobile, the cover is displayed on the left with 40% of the width
54+
// On mobile, check if we can display the cover responsively or not:
55+
// - If the file has a landscape aspect ratio, we display it normally
56+
// - If the file is square or portrait, we display it left with 40% of the card width
57+
coverIsLandscape
58+
? 'grid-rows-[auto,1fr]'
59+
: [
5160
'grid-cols-[40%,_1fr]',
5261
'min-[432px]:grid-cols-none',
5362
'min-[432px]:grid-rows-[auto,1fr]',
54-
]
55-
: null,
63+
],
5664
)}
5765
>
5866
{cover ? (
@@ -74,8 +82,9 @@ export async function RecordCard(
7482
'w-full',
7583
'h-full',
7684
'object-cover',
77-
'min-[432px]:h-auto',
78-
'min-[432px]:aspect-video',
85+
coverIsLandscape
86+
? ['h-auto', 'aspect-video']
87+
: ['min-[432px]:h-auto', 'min-[432px]:aspect-video'],
7988
)}
8089
priority={isOffscreen ? 'lazy' : 'high'}
8190
preload

0 commit comments

Comments
 (0)