Skip to content

Commit b485582

Browse files
authored
docs: fix scroll + divider issues (#9663)
1 parent 34621f5 commit b485582

File tree

8 files changed

+73
-28
lines changed

8 files changed

+73
-28
lines changed

www/apps/api-reference/components/Section/Container/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const SectionContainer = forwardRef<HTMLDivElement, SectionContainerProps>(
1919
ref={ref}
2020
>
2121
{children}
22-
{!noDivider && <SectionDivider className="-left-1.5 lg:!-left-full" />}
22+
{!noDivider && (
23+
<SectionDivider className="-left-[16px] lg:!-left-1/4" />
24+
)}
2325
</div>
2426
)
2527
}

www/apps/api-reference/components/Tags/Operation/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const TagOperation = ({
134134
}
135135
/>
136136
</div>
137-
<SectionDivider />
137+
<SectionDivider className="-left-[16px] lg:!-left-1/4" />
138138
</div>
139139
)
140140
}

www/apps/api-reference/components/Tags/Section/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
123123
<DividedLayout
124124
ref={ref}
125125
mainContent={
126-
<SectionContainer>
126+
<SectionContainer noDivider={true}>
127127
<h2>{tag.name}</h2>
128128
{tag.description && (
129129
<Section>
@@ -154,6 +154,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
154154
vertical
155155
question="Was this section helpful?"
156156
/>
157+
<SectionDivider className="-left-[16px] lg:!-left-[30%]" />
157158
</SectionContainer>
158159
}
159160
codeContent={<></>}
@@ -166,7 +167,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
166167
<TagPaths tag={tag} />
167168
</LoadingProvider>
168169
)}
169-
{!loadPaths && <SectionDivider />}
170+
{!loadPaths && <SectionDivider className="lg:!-left-1" />}
170171
</div>
171172
)
172173
}

www/apps/api-reference/layouts/Divided/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ const DividedLayout = forwardRef<HTMLDivElement, DividedLayoutProps>(
3939
>
4040
{mainContent}
4141
</div>
42-
<div
43-
className={clsx(
44-
"w-full flex-shrink-0 flex-grow-0 lg:w-[calc(50%-32px)] lg:basis-[calc(50%-32px)] lg:pr-1.5",
45-
"mt-2 lg:mt-0",
46-
codeContentClassName
47-
)}
48-
>
49-
{codeContent}
50-
</div>
42+
{codeContent && (
43+
<div
44+
className={clsx(
45+
"w-full flex-shrink-0 flex-grow-0 lg:w-[calc(50%-32px)] lg:basis-[calc(50%-32px)] lg:pr-1.5",
46+
"mt-2 lg:mt-0",
47+
codeContentClassName
48+
)}
49+
>
50+
{codeContent}
51+
</div>
52+
)}
5153
</div>
5254
)
5355
}

www/packages/docs-ui/src/components/Heading/H2/index.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
"use client"
2+
13
import clsx from "clsx"
2-
import React from "react"
3-
import { Link } from "@/components"
4+
import React, { useMemo } from "react"
5+
import { CopyButton, Link } from "@/components"
6+
import { useIsBrowser } from "../../../providers"
47

58
type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
69
id?: string
710
passRef?: React.RefObject<HTMLHeadingElement>
811
}
912

1013
export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
14+
const { isBrowser } = useIsBrowser()
15+
const copyText = useMemo(() => {
16+
const url = `#${props.id}`
17+
if (!isBrowser) {
18+
return url
19+
}
20+
21+
const hashIndex = window.location.href.indexOf("#")
22+
return (
23+
window.location.href.substring(
24+
0,
25+
hashIndex !== -1 ? hashIndex : window.location.href.length
26+
) + url
27+
)
28+
}, [props.id, isBrowser])
1129
return (
1230
<h2
1331
className={clsx(
@@ -20,12 +38,14 @@ export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
2038
>
2139
{children}
2240
{props.id && (
23-
<Link
24-
href={`#${props.id}`}
41+
<CopyButton
42+
text={copyText}
2543
className="opacity-0 group-hover/h2:opacity-100 transition-opacity ml-docs_0.5 inline-block"
2644
>
27-
#
28-
</Link>
45+
<Link href={`#${props.id}`} scroll={false}>
46+
#
47+
</Link>
48+
</CopyButton>
2949
)}
3050
</h2>
3151
)

www/packages/docs-ui/src/components/Heading/H3/index.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1+
"use client"
2+
13
import clsx from "clsx"
2-
import React from "react"
3-
import { Link } from "@/components"
4+
import React, { useMemo } from "react"
5+
import { CopyButton, Link } from "@/components"
6+
import { useIsBrowser } from "../../../providers"
47

58
type H3Props = React.HTMLAttributes<HTMLHeadingElement> & {
69
id?: string
710
}
811

912
export const H3 = ({ className, children, ...props }: H3Props) => {
13+
const { isBrowser } = useIsBrowser()
14+
const copyText = useMemo(() => {
15+
const url = `#${props.id}`
16+
if (!isBrowser) {
17+
return url
18+
}
19+
20+
const hashIndex = window.location.href.indexOf("#")
21+
return (
22+
window.location.href.substring(
23+
0,
24+
hashIndex !== -1 ? hashIndex : window.location.href.length
25+
) + url
26+
)
27+
}, [props.id, isBrowser])
1028
return (
1129
<h3
1230
className={clsx(
@@ -18,12 +36,14 @@ export const H3 = ({ className, children, ...props }: H3Props) => {
1836
>
1937
{children}
2038
{props.id && (
21-
<Link
22-
href={`#${props.id}`}
39+
<CopyButton
40+
text={copyText}
2341
className="opacity-0 group-hover/h3:opacity-100 transition-opacity ml-docs_0.5 inline-block"
2442
>
25-
#
26-
</Link>
43+
<Link href={`#${props.id}`} scroll={false}>
44+
#
45+
</Link>
46+
</CopyButton>
2747
)}
2848
</h3>
2949
)

www/packages/docs-ui/src/hooks/use-page-scroll-manager/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const usePageScrollManager = () => {
3636

3737
targetElm?.scrollIntoView()
3838
}
39-
}, [pathname, scrollableElement])
39+
}, [pathname, scrollableElement, checkedPageReload])
4040

4141
useEffect(() => {
4242
if (!scrollableElement || checkedPageReload) {
@@ -71,5 +71,5 @@ export const usePageScrollManager = () => {
7171
)
7272
}
7373
})
74-
}, [scrollableElement])
74+
}, [scrollableElement, checkedPageReload])
7575
}

www/packages/docs-ui/src/layouts/main-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const MainContentLayout = ({
3838
"relative max-w-full",
3939
"h-full flex-1",
4040
"flex flex-col",
41-
"gap-docs_0.5 lg:pt-docs_0.25 lg:mr-docs_0.25",
41+
"gap-docs_0.5 lg:pt-docs_0.25 lg:mr-docs_0.25 scroll-m-docs_0.25",
4242
!desktopSidebarOpen && "lg:ml-docs_0.25",
4343
mainWrapperClasses
4444
)}

0 commit comments

Comments
 (0)