Skip to content

Commit 1138d59

Browse files
Add sidebar new background styles (#2645)
Co-authored-by: Zeno Kapitein <[email protected]>
1 parent 8276ba0 commit 1138d59

File tree

17 files changed

+404
-290
lines changed

17 files changed

+404
-290
lines changed

.changeset/dull-parents-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': minor
3+
---
4+
5+
Add support for sidebar background styles

packages/gitbook/e2e/pages.spec.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ const allThemePresets: CustomizationHeaderPreset[] = [
6060
CustomizationHeaderPreset.Custom,
6161
];
6262

63+
const allSidebarBackgroundStyles: CustomizationSidebarBackgroundStyle[] = [
64+
CustomizationSidebarBackgroundStyle.Default,
65+
CustomizationSidebarBackgroundStyle.Filled,
66+
];
67+
6368
async function waitForCookiesDialog(page: Page) {
6469
const dialog = page.getByRole('dialog', { name: 'Cookies' });
6570
const accept = dialog.getByRole('button', { name: 'Accept' });
@@ -545,40 +550,47 @@ const testCases: TestsCase[] = [
545550
}),
546551
run: waitForCookiesDialog,
547552
},
548-
...allThemePresets.flatMap((preset) => ({
549-
name: `With tint - Preset ${preset} - Theme ${theme}`,
550-
url: getCustomizationURL({
551-
styling: {
552-
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
553-
},
554-
header: {
555-
preset,
556-
...(preset === CustomizationHeaderPreset.Custom
557-
? {
558-
backgroundColor: { light: '#C62C68', dark: '#EF96B8' },
559-
linkColor: { light: '#4DDE98', dark: '#0C693D' },
560-
}
561-
: {}),
562-
links: [
563-
{
564-
title: 'Secondary button',
565-
to: { kind: 'url', url: 'https://www.gitbook.com' },
566-
style: 'button-secondary',
567-
},
568-
{
569-
title: 'Primary button',
570-
to: { kind: 'url', url: 'https://www.gitbook.com' },
571-
style: 'button-primary',
553+
// Theme-specific tests
554+
...allThemePresets.flatMap((preset) => [
555+
...allSidebarBackgroundStyles.flatMap((sidebarStyle) => ({
556+
name: `With tint - Preset ${preset} - Sidebar ${sidebarStyle} - Theme ${theme}`,
557+
url: getCustomizationURL({
558+
styling: {
559+
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
560+
sidebar: {
561+
background: sidebarStyle,
562+
list: CustomizationSidebarListStyle.Default,
572563
},
573-
],
574-
},
575-
themes: {
576-
default: theme,
577-
toggeable: false,
578-
},
579-
}),
580-
run: waitForCookiesDialog,
581-
})),
564+
},
565+
header: {
566+
preset,
567+
...(preset === CustomizationHeaderPreset.Custom
568+
? {
569+
backgroundColor: { light: '#C62C68', dark: '#EF96B8' },
570+
linkColor: { light: '#4DDE98', dark: '#0C693D' },
571+
}
572+
: {}),
573+
links: [
574+
{
575+
title: 'Secondary button',
576+
to: { kind: 'url', url: 'https://www.gitbook.com' },
577+
style: 'button-secondary',
578+
},
579+
{
580+
title: 'Primary button',
581+
to: { kind: 'url', url: 'https://www.gitbook.com' },
582+
style: 'button-primary',
583+
},
584+
],
585+
},
586+
themes: {
587+
default: theme,
588+
toggeable: false,
589+
},
590+
}),
591+
run: waitForCookiesDialog,
592+
})),
593+
]),
582594
{
583595
name: `With tint - Legacy background match - Theme ${theme}`,
584596
url: getCustomizationURL({

packages/gitbook/src/components/Header/CompactHeader.tsx

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './Header';
2-
export * from './CompactHeader';
2+
export * from './HeaderLogo';

packages/gitbook/src/components/PageAside/PageAside.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function getTopOffset(props: { sectionsHeader: boolean; topHeader: boolean }) {
2626
if (props.sectionsHeader && props.topHeader) {
2727
return 'lg:max-h-[calc(100vh_-_8rem)] top-32 page-api-block:xl:max-2xl:top-32';
2828
}
29-
if (props.sectionsHeader || props.topHeader) {
30-
return 'lg:max-h-[calc(100vh_-_4rem)] top-16 page-api-block:xl:max-2xl:top-16';
29+
if (props.topHeader) {
30+
return 'lg:max-h-[calc(100vh_-_6rem)] top-24 page-api-block:xl:max-2xl:top-24';
3131
}
3232
return 'lg:max-h-screen top-0 page-api-block:xl:max-2xl:top-0';
3333
}
@@ -76,7 +76,7 @@ export async function PageAside(props: {
7676
'grow-0',
7777
'shrink-0',
7878
'sticky',
79-
'py-8',
79+
withHeaderOffset.topHeader ? 'py-4' : 'py-8',
8080
'break-anywhere', // To prevent long words in headings from breaking the layout
8181
'lg:h-full',
8282
'h-[100vh]',
@@ -117,7 +117,7 @@ export async function PageAside(props: {
117117
'flex-1',
118118
'flex',
119119
'flex-col',
120-
'gap-4',
120+
'gap-6',
121121
'[&::-webkit-scrollbar]:bg-transparent',
122122
'[&::-webkit-scrollbar-thumb]:bg-transparent',
123123

packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
CustomizationHeaderPreset,
44
CustomizationIconsStyle,
55
CustomizationSettings,
6+
CustomizationSidebarBackgroundStyle,
7+
CustomizationSidebarListStyle,
68
CustomizationTint,
79
SiteCustomizationSettings,
810
} from '@gitbook/api';
@@ -36,8 +38,8 @@ export async function CustomizationRootLayout(props: {
3638

3739
const headerTheme = generateHeaderTheme(customization);
3840
const language = getSpaceLanguage(customization);
39-
4041
const tintColor = getTintColor(customization);
42+
const sidebarStyles = getSidebarStyles(customization);
4143

4244
return (
4345
<html
@@ -51,6 +53,8 @@ export async function CustomizationRootLayout(props: {
5153
? ' straight-corners'
5254
: '',
5355
tintColor ? ' tint' : 'no-tint',
56+
sidebarStyles.background && ' sidebar-' + sidebarStyles.background,
57+
sidebarStyles.list && ' sidebar-list-' + sidebarStyles.list,
5458
)}
5559
>
5660
<head>
@@ -185,7 +189,7 @@ export async function CustomizationRootLayout(props: {
185189
* Get the tint color from the customization settings.
186190
* If the tint color is not set or it is a space customization, it will return the default color.
187191
*/
188-
export function getTintColor(
192+
function getTintColor(
189193
customization: CustomizationSettings | SiteCustomizationSettings,
190194
): CustomizationTint['color'] | undefined {
191195
if ('tint' in customization.styling && customization.styling.tint) {
@@ -196,6 +200,26 @@ export function getTintColor(
196200
}
197201
}
198202

203+
/**
204+
* Get the sidebar styles from the customization settings.
205+
* If it is a space customization, it will return the default styles.
206+
*/
207+
function getSidebarStyles(
208+
customization: CustomizationSettings | SiteCustomizationSettings,
209+
): SiteCustomizationSettings['styling']['sidebar'] {
210+
if ('sidebar' in customization.styling) {
211+
return {
212+
background: customization.styling.sidebar.background,
213+
list: customization.styling.sidebar.list,
214+
};
215+
}
216+
217+
return {
218+
background: CustomizationSidebarBackgroundStyle.Default,
219+
list: CustomizationSidebarListStyle.Default,
220+
};
221+
}
222+
199223
type ColorInput = string | Record<string, string>;
200224
function generateColorVariable(name: string, color: ColorInput) {
201225
const shades: Record<string, string> = typeof color === 'string' ? shadesOfColor(color) : color;

packages/gitbook/src/components/Search/SearchButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export function SearchButton(props: { children?: React.ReactNode; style?: ClassV
4747
'py-2',
4848
'gap-2',
4949

50-
'bg-light',
51-
'dark:bg-dark',
50+
'bg-light-1',
51+
'dark:bg-dark-1',
5252

5353
'ring-1',
5454
'ring-dark/1',

packages/gitbook/src/components/SiteSectionTabs/SiteSectionTabs.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function SiteSectionTabs(props: {
6262
<nav
6363
aria-label="Sections"
6464
ref={navRef}
65-
className="flex flex-nowrap items-center mb-px max-w-screen-2xl mx-auto page-full-width:max-w-full"
65+
className="flex flex-nowrap items-center max-w-screen-2xl mx-auto page-full-width:max-w-full"
6666
style={
6767
{
6868
'--tab-opacity': `${opacity}`,
@@ -121,6 +121,7 @@ export function SiteSectionTabs(props: {
121121
'after:translate-x-[var(--tab-start)]',
122122
'after:will-change-transform',
123123
'after:h-0.5',
124+
'after:mb-px',
124125
'after:w-[100px]',
125126
'after:bg-primary',
126127
'dark:after:bg-primary-400',

0 commit comments

Comments
 (0)