Skip to content

Commit 2bfae38

Browse files
committed
fix: add sticky component
1 parent 89f4e5c commit 2bfae38

File tree

11 files changed

+119
-14
lines changed

11 files changed

+119
-14
lines changed

next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const withMDX = createMDX({
6666
],
6767
],
6868
rehypePlugins: [rehypeHighlight, rehypeHighlightLines, [rehypeToc, {
69+
// position: 'beforebegin', // "beforebegin" | "afterbegin" | "beforeend" | "afterend"
6970
headings: ["h2", "h3", "h4", "h5", "h6"]
7071
}]],
7172
},

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"react-dom": "^19.0.0",
4040
"react-scroll": "^1.9.3",
4141
"react-slick": "^0.30.3",
42+
"react-stickynode": "^5.0.2",
4243
"read-yaml-file": "^2.1.0",
4344
"rehype-highlight": "^7.0.2",
4445
"rehype-highlight-code-lines": "^1.1.3",
@@ -62,6 +63,7 @@
6263
"@types/react": "^19",
6364
"@types/react-dom": "^19",
6465
"@types/react-slick": "^0.23.13",
66+
"@types/react-stickynode": "^4.0.3",
6567
"eslint": "^9",
6668
"eslint-config-next": "15.1.7",
6769
"typescript": "^5"

src/app/[locale]/blog/[name]/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default async function BlogsDetail({
1616
const t = await getI18n();
1717

1818
return (
19-
<Box sx={{ marginRight: '300px', paddingBlock: 3 }}>
19+
<Box sx={{ paddingBlock: 3 }}>
2020
<Container
2121
sx={{ minHeight: "var(--container-min-height)"}}
2222
className="markdown-body"

src/app/[locale]/docs/[version]/[category]/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default async function DocsLayout({
6565
</Box>
6666
</Stack>
6767
) : null}
68-
<Box sx={{ marginInline: menu.length ? "300px" : 0 }}>
68+
<Box sx={{ marginLeft: menu.length ? "300px" : 0 }}>
6969
<Container
7070
sx={{ minHeight: "var(--container-min-height)", paddingBlock: 3}}
7171
className="markdown-body"

src/app/[locale]/global.css

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,34 @@
2525
}
2626

2727
/* markdown navigation */
28-
29-
.toc {
30-
border-left: 1px solid var(--css-palette-divider);
31-
position: fixed;
32-
width: 300px;
33-
right: 0;
28+
@media screen and (min-width: 0) {
29+
.markdown-body > *:not(.sticky-outer-wrapper) {
30+
margin-right: auto;
31+
}
32+
.markdown-body .toc {
33+
position: static;
34+
display: none;
35+
}
36+
}
37+
38+
@media screen and (min-width: 980px) {
39+
.markdown-body > *:not(.sticky-outer-wrapper) {
40+
margin-right: 300px;
41+
}
42+
.markdown-body .toc {
43+
position: absolute;
44+
right: 0;
45+
top: 0;
46+
width: 280px;
47+
display: block;
48+
border-left: 1px solid var(--css-palette-divider);
49+
}
50+
}
51+
52+
.markdown-body .toc {
3453
font-size: 13px;
3554
}
55+
3656
.toc .toc-level {
3757
margin: 0;
3858
padding-left: 20px;

src/app/[locale]/layout.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ export default async function RootLayout({
7171
color="inherit"
7272
size="large"
7373
href="/blog"
74-
sx={{ paddingInline: 2 }}
74+
sx={{
75+
paddingInline: 2,
76+
overflow: "hidden",
77+
textOverflow: "ellipsis",
78+
whiteSpace: "nowrap",
79+
}}
7580
>
7681
{t("navigation.blogs")}
7782
</Button>
@@ -82,7 +87,12 @@ export default async function RootLayout({
8287
href="https://console.kubeblocks.io"
8388
target="_blank"
8489
endIcon={<LaunchOutlined />}
85-
sx={{ paddingInline: 2 }}
90+
sx={{
91+
paddingInline: 2,
92+
overflow: "hidden",
93+
textOverflow: "ellipsis",
94+
whiteSpace: "nowrap",
95+
}}
8696
>
8797
Kubeblocks Cloud
8898
</Button>

src/app/[locale]/nav-databases.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export default function DatabasesNav() {
8383
paddingInline: 2,
8484
bgcolor: open ? theme.palette.action.hover : "transparent",
8585
"&:hover": { bgcolor: theme.palette.action.hover },
86+
overflow: 'hidden',
87+
textOverflow: 'ellipsis',
88+
whiteSpace: 'nowrap'
8689
}}
8790
endIcon={
8891
<ExpandMore
@@ -99,13 +102,13 @@ export default function DatabasesNav() {
99102
</Button>
100103
}
101104
onChange={(v) => setOpen(v)}
102-
sx={{ width: 760 }}
105+
sx={{ maxWidth: 760 }}
103106
placement="bottom-start"
104107
>
105108
<Box p={1.5}>
106109
<Grid container spacing={1}>
107110
{databases.map((item, index) => (
108-
<Grid size={4} key={index}>
111+
<Grid size={{ lg: 4, md: 4, sm: 6, xs: 6 }} key={index}>
109112
<MenuItem
110113
dense
111114
component={Link}

src/app/[locale]/nav-document.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export default function DocumentationNav() {
5858
paddingInline: 2,
5959
bgcolor: open ? theme.palette.action.hover : "transparent",
6060
"&:hover": { bgcolor: theme.palette.action.hover },
61+
overflow: 'hidden',
62+
textOverflow: 'ellipsis',
63+
whiteSpace: 'nowrap'
6164
}}
6265
endIcon={
6366
<ExpandMore

src/components/Sticky.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use client";
2+
3+
import StickyNode from 'react-stickynode';
4+
5+
export default function Sticky(props: StickyNode.Props) {
6+
return <StickyNode {...props} />
7+
}

src/mdx-components.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@ import type { MDXComponents } from "mdx/types";
1414
import { JSX } from "react";
1515
import NoteBox from "./components/NoteBox";
1616
import { Link } from "./components/Link";
17+
import Sticky from "./components/Sticky";
1718

1819
export function useMDXComponents(components: MDXComponents): MDXComponents {
1920
return {
21+
nav: (props: JSX.IntrinsicElements["nav"]) => {
22+
if (props.className === "toc") {
23+
return (
24+
<Sticky enabled={true} top={80} >
25+
<nav {...props} />
26+
</Sticky>
27+
);
28+
} else {
29+
return <nav {...props} />;
30+
}
31+
},
2032
a: (props: JSX.IntrinsicElements["a"]) => {
2133
const target = props.href?.match(/^http/) ? "_blank" : "_self";
2234
const url = props.href?.replace(/\.md/, "");

0 commit comments

Comments
 (0)