Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position the variant picker in the ToC #2632

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
34f8630
New styling and placement for the variant picker
valentin0h Dec 16, 2024
d2fb275
top padding
valentin0h Dec 16, 2024
67b9e41
Bump API version
valentin0h Dec 13, 2024
949987d
Remove compact header
valentin0h Dec 18, 2024
d3eef16
add background test
valentin0h Dec 18, 2024
1b4d94d
less drastic offset
valentin0h Dec 18, 2024
02b4d2c
First pass
zenoachtig Jan 2, 2025
fab72d4
Redo positioning and filled bg
zenoachtig Jan 3, 2025
9c5df67
Fix default list style
zenoachtig Jan 3, 2025
04e977d
Add `sidebar-list-line` and `sidebar-list-pill` styles
zenoachtig Jan 3, 2025
7051e2a
Merge branch 'main' into rnd-5808-sidebar-new-style-settings-gbo
zenoachtig Jan 3, 2025
51719db
Lint
zenoachtig Jan 3, 2025
be7d604
Restyle page aside to use sidebar list styles
zenoachtig Jan 6, 2025
4a7f6a1
Improve padding
zenoachtig Jan 6, 2025
0cf933c
Fix border when there is no page index
zenoachtig Jan 6, 2025
816da18
Accessible styling
zenoachtig Jan 6, 2025
b64a176
Alignment and overflow fixes
zenoachtig Jan 6, 2025
958a7e9
Merge branch 'main' into rnd-5808-sidebar-new-style-settings-gbo
zenoachtig Jan 7, 2025
7104adc
Update TableOfContents.tsx
zenoachtig Jan 7, 2025
5643970
Merge branch 'rnd-5808-sidebar-new-style-settings-gbo' into style-pag…
zenoachtig Jan 7, 2025
0e24084
Better styling for fixed API block aside nav
zenoachtig Jan 7, 2025
9cab85c
Remove comments
zenoachtig Jan 7, 2025
c7f55a5
Fix padding of feedback container
zenoachtig Jan 7, 2025
15b67b0
Merge branch 'style-page-aside' into variant-dropdown-styling
zenoachtig Jan 7, 2025
e3bff9c
Restyle variant selector
zenoachtig Jan 7, 2025
93e1326
If `no-toc`, put variant selector in header
zenoachtig Jan 7, 2025
c0a6afc
Update Header.tsx
zenoachtig Jan 7, 2025
626a6bf
Update Header.tsx
zenoachtig Jan 7, 2025
57c3b0d
Add search box for sidebar-only themes
zenoachtig Jan 8, 2025
c2b7bf4
Merge branch 'main' into variant-dropdown-styling
zenoachtig Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/gitbook/src/components/Header/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export function DropdownChevron() {
'opacity-6',
'size-3',
'ms-1',
'transition-transform',
'group-hover/dropdown:rotate-180',
'transition-all',
'group-hover/dropdown:opacity-11',
'group-focus-within/dropdown:rotate-180',
)}
/>
);
Expand Down
34 changes: 10 additions & 24 deletions packages/gitbook/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ export function Header(props: {
'gap-4',
'lg:gap-8',
'flex',
'h-16',
'items-center',
'justify-between',
'w-full',
'py-3',
'min-h-16',
'sm:h-16',
'page-no-toc:max-[400px]:flex-wrap',
CONTAINER_STYLE,
)}
>
Expand All @@ -93,31 +96,14 @@ export function Header(props: {
)}
/>
<HeaderLogo site={site} space={space} customization={customization} />
{!hasSiteSections && isMultiVariants ? (
<div className="z-20 shrink hidden sm:block">
<SpacesDropdown
className={tcls(
!isCustomizationDefault &&
withTopHeader && [
'bg-header-link/2',
'dark:bg-header-link/2',
'text-header-link/8',
'dark:text-header-link/8',
'ring-1',
'ring-header-link/4',
'dark:ring-header-link/4',
'contrast-more:bg-header-background',
'contrast-more:text-header-link',
'contrast-more:ring-header-link',
],
)}
space={space}
spaces={spaces}
/>
</div>
) : null}
</div>

{isMultiVariants && (
<div className="hidden page-no-toc:flex">
<SpacesDropdown space={space} spaces={spaces} />
</div>
)}

{customization.header.links.length > 0 && (
<HeaderLinks>
{customization.header.links.map((link, index) => {
Expand Down
45 changes: 37 additions & 8 deletions packages/gitbook/src/components/Header/SpacesDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function SpacesDropdown(props: { space: Space; spaces: Space[]; className

return (
<Dropdown
className={tcls(
'group-hover/dropdown:invisible', // Prevent hover from opening the dropdown, as it's annoying in this context
'group-focus-within/dropdown:group-hover/dropdown:visible', // When the dropdown is already open, it should remain visible when hovered
)}
button={(buttonProps) => (
<div
{...buttonProps}
Expand All @@ -18,29 +22,54 @@ export function SpacesDropdown(props: { space: Space; spaces: Space[]; className
'flex',
'flex-row',
'items-center',
'rounded-2xl',
'transition-all',
'hover:cursor-pointer',

'px-3',
'py-2',
'gap-2',

'rounded-md',
'straight-corners:rounded-none',

'hover:cursor-pointer',
'bg-dark/1',
'dark:bg-light/1',
'bg-light',
'group-hover/dropdown:bg-light-1',
'group-focus-within/dropdown:bg-light-1',
'dark:bg-dark-1',
'dark:group-hover/dropdown:bg-dark-3',
'dark:group-focus-within/dropdown:bg-dark-3',

'text-sm',
'text-dark-4',
'group-hover/dropdown:text-dark',
'group-focus-within/dropdown:text-dark',
'dark:text-light-4',
'dark:group-hover/dropdown:text-light',
'dark:group-focus-within/dropdown:text-light',

'ring-1',
'ring-dark/2',
'group-hover/dropdown:ring-dark/4',
'group-focus-within/dropdown:ring-dark/4',
'dark:ring-light/2',
'dark:group-hover/dropdown:ring-light/4',
'dark:group-focus-within/dropdown:ring-light/4',

'contrast-more:bg-light',
'dark:contrast-more:bg-dark',
'contrast-more:ring-1',
'contrast-more:group-hover/dropdown:ring-2',
'contrast-more:ring-dark',
'contrast-more:group-hover/dropdown:ring-dark',
'contrast-more:group-focus-within/dropdown:ring-dark',
'dark:contrast-more:ring-light',
'dark:contrast-more:bg-dark',
'dark:contrast-more:group-hover/dropdown:ring-light',
'dark:contrast-more:group-focus-within/dropdown:ring-light',

'px-3',
'py-1',
className,
)}
>
<span className="line-clamp-2">{space.title}</span>
<span className={tcls('line-clamp-2', 'grow')}>{space.title}</span>
<DropdownChevron />
</div>
)}
Expand Down
27 changes: 0 additions & 27 deletions packages/gitbook/src/components/PageAside/AnimatedLine.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client';

import { Transition, motion, useReducedMotion } from 'framer-motion';
import React from 'react';

import { ClassValue, tcls } from '@/lib/tailwind';

export function AsideSectionHighlight({
transition,
className,
}: {
transition?: Transition;
className?: ClassValue;
}) {
const prefersReducedMotion = useReducedMotion();

return (
<motion.div
layout
layoutId="sections-line"
className={tcls([
'border-primary',
'sidebar-list-line:border-l-2',

'dark:border-primary-400',
'inset-0',
'pointer-events-none',
'absolute',
'z-0',
'sidebar-list-line:-left-px',

'rounded-md',
'straight-corners:rounded-none',
'sidebar-list-line:rounded-l-none',

'sidebar-list-pill:bg-primary/3',
'dark:sidebar-list-pill:bg-primary-400/3',

'contrast-more:border',
'contrast-more:bg-primary/3',
'dark:contrast-more:bg-primary-400/3',
className,
])}
transition={prefersReducedMotion ? { duration: 0 } : transition}
/>
);
}
83 changes: 58 additions & 25 deletions packages/gitbook/src/components/PageAside/PageAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ import { Ad } from '../Ads';
import { PageFeedbackForm } from '../PageFeedback';

function getTopOffset(props: { sectionsHeader: boolean; topHeader: boolean }) {
if (props.sectionsHeader && props.topHeader) {
return 'lg:max-h-[calc(100vh_-_8rem)] top-32 page-api-block:xl:max-2xl:top-32';
if (props.topHeader && props.sectionsHeader) {
return 'lg:top-[6.75rem] lg:max-h-[calc(100vh_-_6.75rem)]';
}

if (props.topHeader) {
return 'lg:max-h-[calc(100vh_-_6rem)] top-24 page-api-block:xl:max-2xl:top-24';
return 'lg:top-16 lg:max-h-[calc(100vh_-_3rem)]';
}
return 'lg:max-h-screen top-0 page-api-block:xl:max-2xl:top-0';

return 'lg:top-0 lg:max-h-screen';
}

/**
Expand Down Expand Up @@ -76,40 +78,61 @@ export async function PageAside(props: {
'grow-0',
'shrink-0',
'sticky',
withHeaderOffset.topHeader ? 'py-4' : 'py-8',
'break-anywhere', // To prevent long words in headings from breaking the layout
'lg:h-full',
'h-[100vh]',
'page-api-block:xl:max-2xl:z-[1]',

'text-dark/7',
'dark:text-light/7',
'contrast-more:text-dark',
'contrast-more:dark:text-light',

// When in api page mode, we display it as an overlay on non-large resolutions
'page-api-block:xl:max-2xl:backdrop-blur-md',
'page-api-block:xl:max-2xl:z-10',
'page-api-block:xl:max-2xl:fixed',
'page-api-block:xl:max-2xl:right-8',
'page-api-block:xl:max-2xl:w-56',
'page-api-block:xl:max-2xl:bg-light-2/9',
'page-api-block:xl:max-2xl:rounded',
'page-api-block:xl:max-2xl:bg-light-2',
'page-api-block:xl:max-2xl:bg-opacity-9',
'page-api-block:xl:max-2xl:contrast-more:bg-opacity-11',
'page-api-block:xl:max-2xl:backdrop-blur-lg',
'page-api-block:xl:max-2xl:border',
'page-api-block:xl:max-2xl:border-dark/2',
'page-api-block:xl:max-2xl:dark:border-light/2',
'page-api-block:xl:max-2xl:hover:shadow-lg',
'page-api-block:xl:max-2xl:hover:shadow-dark/2',
'page-api-block:xl:max-2xl:rounded-md',
'page-api-block:xl:max-2xl:h-auto',
'page-api-block:xl:max-2xl:py-0',
'page-api-block:xl:max-2xl:mt-3',
'page-api-block:xl:max-2xl:my-8',
'dark:page-api-block:xl:max-2xl:bg-dark-2/8',

topOffset,
)}
>
<div
className={tcls(
'hidden',
'page-api-block:xl:max-2xl:flex',
'text-xs',
'tracking-wide',
'font-semibold',
'uppercase',

'flex-row',
'items-center',
'gap-3',
'text-sm',
'font-semibold',
'px-2',
'py-2',
'gap-2',
'p-2',
)}
>
<Icon icon="bars" className={tcls('size-3')} />
<Icon icon="block-quote" className={tcls('size-3')} />
{t(language, 'on_this_page')}
<Icon
icon="chevron-down"
className={tcls(
'size-3',
'opacity-6',
'ml-auto',
'page-api-block:xl:max-2xl:group-hover/aside:hidden',
)}
/>
</div>
<div
className={tcls(
Expand All @@ -118,9 +141,11 @@ export async function PageAside(props: {
'flex',
'flex-col',
'gap-6',
'py-8',
'[&::-webkit-scrollbar]:bg-transparent',
'[&::-webkit-scrollbar-thumb]:bg-transparent',

'page-api-block:xl:max-2xl:py-0',
// Hide it for api page, until hovered
'page-api-block:xl:max-2xl:hidden',
'page-api-block:xl:max-2xl:group-hover/aside:flex',
Expand All @@ -132,7 +157,19 @@ export async function PageAside(props: {
</React.Suspense>
) : null}
<div
className={tcls('flex', 'flex-col', 'gap-3', 'page-api-block:xl:max-2xl:px-3')}
className={tcls(
'flex',
'flex-col',
'gap-3',
'sidebar-list-default:px-3',
'border-t',
'first:border-none',
'border-dark/2',
'dark:border-light/2',
'py-4',
'first:pt-0',
'page-api-block:xl:max-2xl:px-3',
)}
>
{withPageFeedback ? (
<React.Suspense fallback={null}>
Expand All @@ -148,10 +185,8 @@ export async function PageAside(props: {
'flex-row',
'items-center',
'text-sm',
'text-dark/6',
'hover:text-primary',
'py-2',
'dark:text-light/5',
)}
>
<Icon
Expand All @@ -175,10 +210,8 @@ export async function PageAside(props: {
'flex-row',
'items-center',
'text-sm',
'text-dark/6',
'hover:text-primary',
'py-2',
'dark:text-light/5',
)}
>
<Icon icon="file-pdf" className={tcls('size-4', 'mr-1.5')} />
Expand All @@ -196,7 +229,7 @@ export async function PageAside(props: {
spaceId={space.id}
siteAdsStatus={site?.ads && site.ads.status ? site.ads.status : undefined}
ignore={process.env.NODE_ENV !== 'production'}
style={tcls('mt-4')}
style={tcls(site?.ads && site.ads.status === SiteAdsStatus.Live && ['mt-4'])}
/>
</aside>
);
Expand Down
Loading
Loading