docs: fix scroll + divider issues (#9663)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-10-21 09:54:05 +03:00
1 parent 34621f53a3
commit b4855825be
8 files changed
+60 -15

No files matched your search

@@ -19,7 +19,9 @@ const SectionContainer = forwardRef<HTMLDivElement, SectionContainerProps>(
ref={ref} ref={ref}
> >
{children} {children}
{!noDivider && <SectionDivider className="-left-1.5 lg:!-left-full" />} {!noDivider && (
<SectionDivider className="-left-[16px] lg:!-left-1/4" />
)}
</div> </div>
) )
} }
@@ -134,7 +134,7 @@ const TagOperation = ({
} }
/> />
</div> </div>
<SectionDivider /> <SectionDivider className="-left-[16px] lg:!-left-1/4" />
</div> </div>
) )
} }
@@ -123,7 +123,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
<DividedLayout <DividedLayout
ref={ref} ref={ref}
mainContent={ mainContent={
<SectionContainer> <SectionContainer noDivider={true}>
<h2>{tag.name}</h2> <h2>{tag.name}</h2>
{tag.description && ( {tag.description && (
<Section> <Section>
@@ -154,6 +154,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
vertical vertical
question="Was this section helpful?" question="Was this section helpful?"
/> />
<SectionDivider className="-left-[16px] lg:!-left-[30%]" />
</SectionContainer> </SectionContainer>
} }
codeContent={<></>} codeContent={<></>}
@@ -166,7 +167,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
<TagPaths tag={tag} /> <TagPaths tag={tag} />
</LoadingProvider> </LoadingProvider>
)} )}
{!loadPaths && <SectionDivider />} {!loadPaths && <SectionDivider className="lg:!-left-1" />}
</div> </div>
) )
} }
@@ -39,6 +39,7 @@ const DividedLayout = forwardRef<HTMLDivElement, DividedLayoutProps>(
> >
{mainContent} {mainContent}
</div> </div>
{codeContent && (
<div <div
className={clsx( className={clsx(
"w-full flex-shrink-0 flex-grow-0 lg:w-[calc(50%-32px)] lg:basis-[calc(50%-32px)] lg:pr-1.5", "w-full flex-shrink-0 flex-grow-0 lg:w-[calc(50%-32px)] lg:basis-[calc(50%-32px)] lg:pr-1.5",
@@ -48,6 +49,7 @@ const DividedLayout = forwardRef<HTMLDivElement, DividedLayoutProps>(
> >
{codeContent} {codeContent}
</div> </div>
)}
</div> </div>
) )
} }
@@ -1,6 +1,9 @@
"use client"
import clsx from "clsx" import clsx from "clsx"
import React from "react" import React, { useMemo } from "react"
import { Link } from "@/components" import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"
type H2Props = React.HTMLAttributes<HTMLHeadingElement> & { type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
id?: string id?: string
@@ -8,6 +11,21 @@ type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
} }
export const H2 = ({ className, children, passRef, ...props }: H2Props) => { export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
const { isBrowser } = useIsBrowser()
const copyText = useMemo(() => {
const url = `#${props.id}`
if (!isBrowser) {
return url
}
const hashIndex = window.location.href.indexOf("#")
return (
window.location.href.substring(
0,
hashIndex !== -1 ? hashIndex : window.location.href.length
) + url
)
}, [props.id, isBrowser])
return ( return (
<h2 <h2
className={clsx( className={clsx(
@@ -20,12 +38,14 @@ export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
> >
{children} {children}
{props.id && ( {props.id && (
<Link <CopyButton
href={`#${props.id}`} text={copyText}
className="opacity-0 group-hover/h2:opacity-100 transition-opacity ml-docs_0.5 inline-block" className="opacity-0 group-hover/h2:opacity-100 transition-opacity ml-docs_0.5 inline-block"
> >
<Link href={`#${props.id}`} scroll={false}>
# #
</Link> </Link>
</CopyButton>
)} )}
</h2> </h2>
) )
@@ -1,12 +1,30 @@
"use client"
import clsx from "clsx" import clsx from "clsx"
import React from "react" import React, { useMemo } from "react"
import { Link } from "@/components" import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"
type H3Props = React.HTMLAttributes<HTMLHeadingElement> & { type H3Props = React.HTMLAttributes<HTMLHeadingElement> & {
id?: string id?: string
} }
export const H3 = ({ className, children, ...props }: H3Props) => { export const H3 = ({ className, children, ...props }: H3Props) => {
const { isBrowser } = useIsBrowser()
const copyText = useMemo(() => {
const url = `#${props.id}`
if (!isBrowser) {
return url
}
const hashIndex = window.location.href.indexOf("#")
return (
window.location.href.substring(
0,
hashIndex !== -1 ? hashIndex : window.location.href.length
) + url
)
}, [props.id, isBrowser])
return ( return (
<h3 <h3
className={clsx( className={clsx(
@@ -18,12 +36,14 @@ export const H3 = ({ className, children, ...props }: H3Props) => {
> >
{children} {children}
{props.id && ( {props.id && (
<Link <CopyButton
href={`#${props.id}`} text={copyText}
className="opacity-0 group-hover/h3:opacity-100 transition-opacity ml-docs_0.5 inline-block" className="opacity-0 group-hover/h3:opacity-100 transition-opacity ml-docs_0.5 inline-block"
> >
<Link href={`#${props.id}`} scroll={false}>
# #
</Link> </Link>
</CopyButton>
)} )}
</h3> </h3>
) )
@@ -36,7 +36,7 @@ export const usePageScrollManager = () => {
targetElm?.scrollIntoView() targetElm?.scrollIntoView()
} }
}, [pathname, scrollableElement]) }, [pathname, scrollableElement, checkedPageReload])
useEffect(() => { useEffect(() => {
if (!scrollableElement || checkedPageReload) { if (!scrollableElement || checkedPageReload) {
@@ -71,5 +71,5 @@ export const usePageScrollManager = () => {
) )
} }
}) })
}, [scrollableElement]) }, [scrollableElement, checkedPageReload])
} }
@@ -38,7 +38,7 @@ export const MainContentLayout = ({
"relative max-w-full", "relative max-w-full",
"h-full flex-1", "h-full flex-1",
"flex flex-col", "flex flex-col",
"gap-docs_0.5 lg:pt-docs_0.25 lg:mr-docs_0.25", "gap-docs_0.5 lg:pt-docs_0.25 lg:mr-docs_0.25 scroll-m-docs_0.25",
!desktopSidebarOpen && "lg:ml-docs_0.25", !desktopSidebarOpen && "lg:ml-docs_0.25",
mainWrapperClasses mainWrapperClasses
)} )}