Skip to content

Commit

Permalink
🐛 Fix sidebar sticky when navbar not hide
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Sep 12, 2023
1 parent 47b53ea commit 4fb373e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
14 changes: 13 additions & 1 deletion packages/theme-nonepress/src/theme/Page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";

import "./styles.css";
import clsx from "clsx";

import type { Props } from "@theme/Page";
import Sidebar from "@theme/Sidebar";
import TOC from "@theme/TOC";
Expand All @@ -9,14 +11,24 @@ export default function Page({
children,
hideSidebar = false,
hideTableOfContents = false,
reduceContentWidth = true,
}: Props): JSX.Element {
const shouldReduceContent = !hideTableOfContents && reduceContentWidth;

return (
<div className="page">
{/* sidebar */}
{!hideSidebar && <Sidebar className="page-sidebar" />}
{/* main */}
<main className="page-main">
<div className="page-content">{children}</div>
<div
className={clsx(
"page-content",
shouldReduceContent && "page-content-narrow",
)}
>
{children}
</div>
{/* TOC */}
{!hideTableOfContents && <TOC className="page-toc" />}
</main>
Expand Down
6 changes: 5 additions & 1 deletion packages/theme-nonepress/src/theme/Page/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
}

&-content {
@apply grow w-full lg:max-w-[calc(100%-256px)] mx-auto;
@apply grow w-full mx-auto;

&-narrow {
@apply lg:max-w-[calc(100%-256px)];
}
}

&-toc {
Expand Down
8 changes: 1 addition & 7 deletions packages/theme-nonepress/src/theme/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ export default function Sidebar({ className }: Props): JSX.Element | null {
}

return (
<div
className={clsx(
"sidebar",
hideOnScroll && "sidebar-with-hideable-navbar",
className,
)}
>
<div className={clsx("sidebar", className)}>
{hideOnScroll && (
<Logo
className="sidebar-brand"
Expand Down
8 changes: 4 additions & 4 deletions packages/theme-nonepress/src/theme/Sidebar/styles.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.sidebar {
@apply flex flex-col h-full max-h-screen;
@apply flex flex-col h-full max-h-screen -mt-16;

&-with-hideable-navbar {
@apply -mt-16;
&:not(:has(> &-brand)) {
@apply pt-16;
}

&-brand {
@apply flex items-center px-4 sm:px-6 md:px-8 py-4;
@apply flex items-center h-16 px-4 sm:px-6 md:px-8 py-4;

&-logo {
@apply h-auto w-auto;
Expand Down
1 change: 1 addition & 0 deletions packages/theme-nonepress/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,7 @@ declare module "@theme/Page" {
children?: ReactNode;
hideSidebar?: boolean;
hideTableOfContents?: boolean;
reduceContentWidth?: boolean;
}

export default function Page(props: Props): JSX.Element;
Expand Down
1 change: 1 addition & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const config = {
},
navbar: {
title: "NonePress",
hideOnScroll: true,
logo: {
alt: "NonePress",
src: "img/logo.svg",
Expand Down

0 comments on commit 4fb373e

Please sign in to comment.