这是indexloc提供的服务,不要输入任何密码
Skip to content

docs: Fix gap on open mobile nav with banner #507

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

Merged
merged 6 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions docs/nextra-theme-docs/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useMemo } from "react";
import React, { useState, useEffect, useMemo, useCallback } from "react";
import cn from "classnames";
import Slugger from "github-slugger";
import { useRouter } from "next/router";
Expand Down Expand Up @@ -157,6 +157,23 @@ export default function Sidebar({
.map((child) => child.props.children),
[headings]
);
const [hasScrolled, setHasScrolled] = useState(false);

const onScroll = useCallback(() => {
setHasScrolled(window.pageYOffset > 1);
}, []);

useEffect(() => {
if (typeof window !== "undefined") {
requestIdleCallback(onScroll);
window.addEventListener("scroll", onScroll);
}
return () => {
if (typeof window !== "undefined") {
window.removeEventListener("scroll", onScroll);
}
};
}, [onScroll]);

const { menu } = useMenuContext();
useEffect(() => {
Expand All @@ -175,8 +192,8 @@ export default function Sidebar({
mdShow ? "md:block" : ""
)}
style={{
top: "4rem",
height: "calc(100vh - 4rem)",
top: hasScrolled ? "4rem" : "6rem",
height: hasScrolled ? "calc(100vh - 4rem)" : "calc(100vh - 6rem)",
}}
>
<div className="w-full h-full p-4 pb-40 overflow-y-auto border-gray-200 sidebar dark:border-gray-900 md:pb-16">
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import Prism from "prism-react-renderer/prism";
(typeof global !== "undefined" ? global : window).Prism = Prism;
require("prismjs/components/prism-docker");

// Shim requestIdleCallback in Safari
if (typeof window !== "undefined" && !("requestIdleCallback" in window)) {
window.requestIdleCallback = (fn) => setTimeout(fn, 1);
window.cancelIdleCallback = (e) => clearTimeout(e);
}

export default function Nextra({ Component, pageProps }) {
return (
<>
Expand Down