Skip to content

Commit 611e286

Browse files
authored
Remove padding on first Heading in Columns (#3479)
1 parent 2a3bb0e commit 611e286

File tree

10 files changed

+28
-25
lines changed

10 files changed

+28
-25
lines changed

.changeset/tall-schools-visit.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+
Remove padding on first Heading in Columns

packages/gitbook/src/components/DocumentView/Columns/Columns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function Columns(props: BlockProps<DocumentBlockColumns>) {
1818
document={document}
1919
ancestorBlocks={[...ancestorBlocks, block, columnBlock]}
2020
context={context}
21-
style="w-full space-y-4 *:max-w-full"
21+
style="group/column w-full space-y-4 *:max-w-full"
2222
/>
2323
</Column>
2424
);

packages/gitbook/src/components/DocumentView/Heading.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,29 @@ export function Heading(props: BlockProps<DocumentBlockHeading>) {
2424
className={tcls(
2525
textStyle.textSize,
2626
'heading',
27-
'grid',
27+
'flex',
28+
'items-baseline',
2829
'scroll-m-12',
2930
hashLinkButtonWrapperStyles,
30-
style
31+
style,
32+
textStyle.marginTop
3133
)}
3234
>
3335
<HashLinkButton
3436
id={id}
3537
block={block}
36-
className={tcls('-ml-6', textStyle.anchorButtonMarginTop)}
38+
className={tcls('-ml-6', 'pr-2')}
3739
iconClassName={tcls('size-4')}
3840
label="Direct link to heading"
3941
/>
4042

4143
<div
4244
className={tcls(
43-
'grid-area-1-1',
45+
'flex-1',
4446
'z-[1]',
4547
'justify-self-start',
4648
getTextAlignment(block.data.align),
47-
textStyle.lineHeight,
48-
textStyle.marginTop
49+
textStyle.lineHeight
4950
)}
5051
>
5152
<Inlines {...rest} context={context} nodes={block.nodes} ancestorInlines={[]} />

packages/gitbook/src/components/DocumentView/Hint.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
5252
{hasHeading ? (
5353
<Block
5454
style={tcls(
55-
'flip-heading-hash p-4 pl-3 text-[1em] *:mt-0',
55+
'flip-heading-hash !py-4 items-start px-4 pl-3 text-[1em] *:flex-none',
5656
hasHeading ? hintStyle.header : null
5757
)}
5858
ancestorBlocks={[...ancestorBlocks, block]}

packages/gitbook/src/components/DocumentView/ListItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export function ListItem(props: BlockProps<DocumentBlockListItem>) {
3535
// flip heading hash icon if list item is a heading
3636
'flip-heading-hash',
3737
// remove margin-top for the first heading in a list
38-
'[&:is(h2)>div]:mt-0',
39-
'[&:is(h3)>div]:mt-0',
40-
'[&:is(h4)>div]:mt-0',
38+
'[&:is(h2)]:pt-0',
39+
'[&:is(h3)]:pt-0',
40+
'[&:is(h4)]:pt-0',
4141
// Override the "mx-auto" class from UnwrappedBlocks
4242
'mx-0'
4343
)}

packages/gitbook/src/components/DocumentView/OpenAPI/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function getOpenAPIContext(args: {
6161
style={tcls([
6262
headingProps.deprecated ? 'line-through' : undefined,
6363
headingProps.deprecated || !!headingProps.stability
64-
? '[&>div]:mt-0'
64+
? '[&>div]:pt-0'
6565
: undefined,
6666
])}
6767
block={{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function RecordCard(
5858
'[&_.heading>div:first-child]:hidden',
5959
'[&_.heading>div]:text-[.8em]',
6060
'md:[&_.heading>div]:text-[1em]',
61-
'[&_.blocks:first-child_.heading:first-child_div]:mt-0', // Remove margin on first heading in card
61+
'[&_.blocks:first-child_.heading]:pt-0', // Remove padding-top on first heading in card
6262

6363
// On mobile, check if we can display the cover responsively or not:
6464
// - If the file has a landscape aspect ratio, we display it normally

packages/gitbook/src/components/DocumentView/spacing.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export function getBlockTextStyle(block: DocumentBlock): {
1010
lineHeight: string;
1111
/** Tailwind class for the margin top (mt-*) */
1212
marginTop?: string;
13-
/** Tailwind class for the margin top to apply on the anchor link button */
14-
anchorButtonMarginTop?: string;
1513
} {
1614
switch (block.type) {
1715
case 'paragraph':
@@ -23,22 +21,19 @@ export function getBlockTextStyle(block: DocumentBlock): {
2321
return {
2422
textSize: 'text-3xl font-semibold',
2523
lineHeight: 'leading-tight',
26-
marginTop: 'mt-[1em]',
27-
anchorButtonMarginTop: 'mt-[1.05em]',
24+
marginTop: 'column-first-of-type:pt-0 pt-[1em]',
2825
};
2926
case 'heading-2':
3027
return {
3128
textSize: 'text-2xl font-semibold',
3229
lineHeight: 'leading-snug',
33-
marginTop: 'mt-[0.75em]',
34-
anchorButtonMarginTop: 'mt-[0.9em]',
30+
marginTop: 'column-first-of-type:pt-0 pt-[0.75em]',
3531
};
3632
case 'heading-3':
3733
return {
3834
textSize: 'text-xl font-semibold',
3935
lineHeight: 'leading-snug',
40-
marginTop: 'mt-[0.5em]',
41-
anchorButtonMarginTop: 'mt-[0.65em]',
36+
marginTop: 'column-first-of-type:pt-0 pt-[0.5em]',
4237
};
4338
case 'divider':
4439
return {

packages/gitbook/src/components/RootLayout/globals.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@
5454
}
5555

5656
.flip-heading-hash {
57-
@apply [&:is(h1,h2,h3,h4)]:content-start;
58-
@apply [&:is(h1,h2,h3,h4)]:[grid-auto-columns:auto_1fr];
59-
@apply [&:is(h1,h2,h3,h4)>div:first-child]:[grid-area:1/2];
60-
@apply [&:is(h1,h2,h3,h4)>div:first-child]:ml-1;
57+
@apply [&:is(h1,h2,h3,h4)]:flex-row-reverse;
58+
@apply [&:is(h1,h2,h3,h4)]:[justify-content:start];
59+
@apply [&:is(h1,h2,h3,h4)>div:first-child]:ml-2;
6160
}
6261
}
6362

packages/gitbook/tailwind.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ const config: Config = {
516516
'html:not(.announcement-hidden):has(#announcement-banner) &'
517517
);
518518

519+
// Variant to target first-of-type in a column
520+
addVariant('column-first-of-type', ':merge(.group\\/column) > &:first-of-type'); // optional for group-based variants
521+
519522
const customisationVariants = {
520523
// Sidebar styles
521524
sidebar: ['sidebar-default', 'sidebar-filled'],

0 commit comments

Comments
 (0)