- Improve intro sections of API reference to utilize divided columns - Improve the content of the intro sections - Add a new Workflows section to explain the workflows badge and how to use it - Fixes to headings and add anchor for copying the link to a section - Fixes responsiveness of intro sections on mobile devices - Other: fix loading not showing when a sidebar category is opened. Closes DOCS-932, DOCS-934, DOCS-937 Preview: https://api-reference-v2-git-docs-api-ref-intro-fixes-medusajs.vercel.app/v2/api/store
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
"use client"
|
|
|
|
import clsx from "clsx"
|
|
import { useActiveOnScroll, useSidebar } from "docs-ui"
|
|
import { useRouter } from "next/navigation"
|
|
import { useEffect, useRef } from "react"
|
|
|
|
export type SectionProps = {
|
|
checkActiveOnScroll?: boolean
|
|
} & React.AllHTMLAttributes<HTMLDivElement>
|
|
|
|
const Section = ({
|
|
children,
|
|
className,
|
|
checkActiveOnScroll = false,
|
|
}: SectionProps) => {
|
|
const sectionRef = useRef<HTMLDivElement>(null)
|
|
const { activeItemId } = useActiveOnScroll({
|
|
rootElm: sectionRef.current || undefined,
|
|
enable: checkActiveOnScroll,
|
|
useDefaultIfNoActive: false,
|
|
maxLevel: 2,
|
|
})
|
|
const { setActivePath } = useSidebar()
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
if ("scrollRestoration" in history) {
|
|
// disable scroll on refresh
|
|
history.scrollRestoration = "manual"
|
|
}
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (activeItemId.length) {
|
|
router.push(`#${activeItemId}`, {
|
|
scroll: false,
|
|
})
|
|
setActivePath(activeItemId)
|
|
}
|
|
}, [activeItemId])
|
|
|
|
return (
|
|
<div
|
|
ref={sectionRef}
|
|
className={clsx("[&_ul]:list-disc [&_ul]:px-1", "[&_h2]:pt-7", className)}
|
|
>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Section
|