Skip to content

Commit

Permalink
docs: fix scroll + divider issues (#9663)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Oct 21, 2024
1 parent 34621f5 commit b485582
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const SectionContainer = forwardRef<HTMLDivElement, SectionContainerProps>(
ref={ref}
>
{children}
{!noDivider && <SectionDivider className="-left-1.5 lg:!-left-full" />}
{!noDivider && (
<SectionDivider className="-left-[16px] lg:!-left-1/4" />
)}
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion www/apps/api-reference/components/Tags/Operation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const TagOperation = ({
}
/>
</div>
<SectionDivider />
<SectionDivider className="-left-[16px] lg:!-left-1/4" />
</div>
)
}
Expand Down
5 changes: 3 additions & 2 deletions www/apps/api-reference/components/Tags/Section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
<DividedLayout
ref={ref}
mainContent={
<SectionContainer>
<SectionContainer noDivider={true}>
<h2>{tag.name}</h2>
{tag.description && (
<Section>
Expand Down Expand Up @@ -154,6 +154,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
vertical
question="Was this section helpful?"
/>
<SectionDivider className="-left-[16px] lg:!-left-[30%]" />
</SectionContainer>
}
codeContent={<></>}
Expand All @@ -166,7 +167,7 @@ const TagSection = ({ tag }: TagSectionProps) => {
<TagPaths tag={tag} />
</LoadingProvider>
)}
{!loadPaths && <SectionDivider />}
{!loadPaths && <SectionDivider className="lg:!-left-1" />}
</div>
)
}
Expand Down
20 changes: 11 additions & 9 deletions www/apps/api-reference/layouts/Divided/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ const DividedLayout = forwardRef<HTMLDivElement, DividedLayoutProps>(
>
{mainContent}
</div>
<div
className={clsx(
"w-full flex-shrink-0 flex-grow-0 lg:w-[calc(50%-32px)] lg:basis-[calc(50%-32px)] lg:pr-1.5",
"mt-2 lg:mt-0",
codeContentClassName
)}
>
{codeContent}
</div>
{codeContent && (
<div
className={clsx(
"w-full flex-shrink-0 flex-grow-0 lg:w-[calc(50%-32px)] lg:basis-[calc(50%-32px)] lg:pr-1.5",
"mt-2 lg:mt-0",
codeContentClassName
)}
>
{codeContent}
</div>
)}
</div>
)
}
Expand Down
32 changes: 26 additions & 6 deletions www/packages/docs-ui/src/components/Heading/H2/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
"use client"

import clsx from "clsx"
import React from "react"
import { Link } from "@/components"
import React, { useMemo } from "react"
import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"

type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
id?: string
passRef?: React.RefObject<HTMLHeadingElement>
}

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 (
<h2
className={clsx(
Expand All @@ -20,12 +38,14 @@ export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
>
{children}
{props.id && (
<Link
href={`#${props.id}`}
<CopyButton
text={copyText}
className="opacity-0 group-hover/h2:opacity-100 transition-opacity ml-docs_0.5 inline-block"
>
#
</Link>
<Link href={`#${props.id}`} scroll={false}>
#
</Link>
</CopyButton>
)}
</h2>
)
Expand Down
32 changes: 26 additions & 6 deletions www/packages/docs-ui/src/components/Heading/H3/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
"use client"

import clsx from "clsx"
import React from "react"
import { Link } from "@/components"
import React, { useMemo } from "react"
import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"

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

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 (
<h3
className={clsx(
Expand All @@ -18,12 +36,14 @@ export const H3 = ({ className, children, ...props }: H3Props) => {
>
{children}
{props.id && (
<Link
href={`#${props.id}`}
<CopyButton
text={copyText}
className="opacity-0 group-hover/h3:opacity-100 transition-opacity ml-docs_0.5 inline-block"
>
#
</Link>
<Link href={`#${props.id}`} scroll={false}>
#
</Link>
</CopyButton>
)}
</h3>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const usePageScrollManager = () => {

targetElm?.scrollIntoView()
}
}, [pathname, scrollableElement])
}, [pathname, scrollableElement, checkedPageReload])

useEffect(() => {
if (!scrollableElement || checkedPageReload) {
Expand Down Expand Up @@ -71,5 +71,5 @@ export const usePageScrollManager = () => {
)
}
})
}, [scrollableElement])
}, [scrollableElement, checkedPageReload])
}
2 changes: 1 addition & 1 deletion www/packages/docs-ui/src/layouts/main-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const MainContentLayout = ({
"relative max-w-full",
"h-full flex-1",
"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",
mainWrapperClasses
)}
Expand Down

0 comments on commit b485582

Please sign in to comment.