Skip to content

Commit 685317f

Browse files
authored
Fix full-width for code-blocks and embeds (GitbookIO#2272)
1 parent 0c22486 commit 685317f

File tree

7 files changed

+31
-44
lines changed

7 files changed

+31
-44
lines changed

e2e/pages.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ const testCases: TestsCase[] = [
212212
url: 'blocks/lists',
213213
fullPage: true,
214214
},
215+
{
216+
name: 'Code',
217+
url: 'blocks/code',
218+
fullPage: true,
219+
},
215220
{
216221
name: 'Cards',
217222
url: 'blocks/cards',
@@ -224,6 +229,7 @@ const testCases: TestsCase[] = [
224229
{
225230
name: 'Embeds',
226231
url: 'blocks/embeds',
232+
fullPage: true,
227233
},
228234
{
229235
name: 'Annotations',
@@ -511,7 +517,7 @@ for (const testCase of testCases) {
511517
}
512518
if (testEntry.screenshot !== false) {
513519
await argosScreenshot(page, `${testCase.name} - ${testEntry.name}`, {
514-
viewports: ['macbook-13', 'iphone-x', 'ipad-2'],
520+
viewports: ['macbook-16', 'macbook-13', 'iphone-x', 'ipad-2'],
515521
argosCSS: `
516522
/* Hide Intercom */
517523
.intercom-lightweight-app {

src/components/DocumentView/Blocks.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ export function Blocks<T extends DocumentBlock, Tag extends React.ElementType =
3434
<Block
3535
key={node.key}
3636
block={node}
37-
style={['max-w-3xl', 'w-full', 'mx-auto', 'decoration-primary/6', blockStyle]}
37+
style={[
38+
node.data && 'fullWidth' in node.data && node.data.fullWidth
39+
? 'max-w-screen-xl'
40+
: 'max-w-3xl',
41+
'w-full',
42+
'mx-auto',
43+
'decoration-primary/6',
44+
blockStyle,
45+
]}
3846
{...contextProps}
3947
/>
4048
))}

src/components/DocumentView/CodeBlock/CodeBlock.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ export async function CodeBlock(props: BlockProps<DocumentBlockCode>) {
2222
const withLineNumbers = !!block.data.lineNumbers && block.nodes.length > 1;
2323
const withWrap = block.data.overflow === 'wrap';
2424
const title = block.data.title;
25-
const fullWidth = block.data.fullWidth;
26-
27-
const fullWidthStyle = fullWidth ? 'max-w-4xl' : 'max-w-3xl';
2825
const titleRoundingStyle = [
2926
'rounded-md',
3027
'straight-corners:rounded-sm',
3128
title ? 'rounded-ss-none' : null,
3229
];
3330

3431
return (
35-
<div className={tcls('group/codeblock', 'grid', 'grid-flow-col', fullWidthStyle, style)}>
32+
<div className={tcls('group/codeblock', 'grid', 'grid-flow-col', style)}>
3633
<div
3734
className={tcls(
3835
'flex',

src/components/DocumentView/Embed.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { DocumentBlockEmbed } from '@gitbook/api';
2+
import Script from 'next/script';
3+
24

35
import { Card } from '@/components/primitives';
46
import { api } from '@/lib/api';
5-
import { getNodeFragmentByName, isNodeEmpty } from '@/lib/document';
6-
import { ClassValue, tcls } from '@/lib/tailwind';
7+
import { tcls } from '@/lib/tailwind';
78

89
import { BlockProps } from './Block';
910
import { Caption } from './Caption';
10-
import { Inlines } from './Inlines';
1111

1212
export async function Embed(props: BlockProps<DocumentBlockEmbed>) {
1313
const { block } = props;
@@ -17,11 +17,15 @@ export async function Embed(props: BlockProps<DocumentBlockEmbed>) {
1717
return (
1818
<Caption {...props}>
1919
{embed.type === 'rich' ? (
20-
<div
21-
dangerouslySetInnerHTML={{
22-
__html: embed.html,
23-
}}
24-
/>
20+
<>
21+
<div
22+
dangerouslySetInnerHTML={{
23+
__html: embed.html,
24+
}}
25+
/>
26+
{/* We load the iframely script to resize the embed iframes dynamically */}
27+
<Script src="https://cdn.iframe.ly/embed.js" defer async />
28+
</>
2529
) : (
2630
<Card
2731
leadingIcon={

src/components/DocumentView/Images.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export function Images(props: BlockProps<DocumentBlockImages>) {
3131
align === 'right' && 'justify-end',
3232
align === 'left' && 'justify-start',
3333
isMultipleImages && ['grid', 'grid-flow-col', 'max-w-none'],
34-
block.data.fullWidth ? 'max-w-screen-2xl' : null,
3534
)}
3635
>
3736
{block.nodes.map((node: any, i: number) => (

src/components/DocumentView/Table/ViewCards.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ export function ViewCards(props: TableViewProps<DocumentTableViewCards>) {
1212
<div
1313
className={tcls(
1414
style,
15-
'max-w-full',
16-
'md:max-w-3xl',
1715
'inline-grid',
1816
'gap-4',
1917
'grid-cols-1',
2018
'min-[432px]:grid-cols-2',
2119
view.cardSize === 'large' ? 'md:grid-cols-2' : 'md:grid-cols-3',
22-
block.data.fullWidth ? ['max-w-full', 'large:flex-column'] : null,
20+
block.data.fullWidth ? 'large:flex-column' : null,
2321
)}
2422
>
2523
{records.map((record) => {

src/components/DocumentView/Table/ViewGrid.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,15 @@ export function ViewGrid(props: TableViewProps<DocumentTableViewGrid>) {
1414
const tableWrapper = columnsOverThreshold
1515
? [
1616
// has over X columns
17-
'w-full',
1817
'overflow-x-auto',
1918
'overflow-y-hidden',
2019
'mx-auto',
2120
'rounded-md',
2221
'border',
2322
'border-dark/3',
2423
'dark:border-light/2',
25-
block.data.fullWidth
26-
? [
27-
// has over X columns, and is full width
28-
'max-w-full',
29-
]
30-
: [
31-
// NOT full width, but has over X columns
32-
'max-w-4xl',
33-
],
3424
]
35-
: [
36-
'w-full',
37-
'overflow-x-auto',
38-
'overflow-y-hidden',
39-
'mx-auto',
40-
// has under X columns
41-
block.data.fullWidth
42-
? [
43-
// has under X columns, and is full width
44-
'max-w-full',
45-
]
46-
: [
47-
// NOT full width, but has under X columns
48-
'max-w-3xl',
49-
],
50-
];
25+
: ['overflow-x-auto', 'overflow-y-hidden', 'mx-auto'];
5126

5227
const tableTR = columnsOverThreshold
5328
? ['[&>*+*]:border-l', '[&>*]:px-4']

0 commit comments

Comments
 (0)