- 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
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
"use client"
|
|
|
|
import { useScrollController, useSidebar, H2 as UiH2 } from "docs-ui"
|
|
import { useEffect, useMemo, useRef, useState } from "react"
|
|
import getSectionId from "../../../utils/get-section-id"
|
|
|
|
type H2Props = React.HTMLAttributes<HTMLHeadingElement>
|
|
|
|
const H2 = ({ children, ...props }: H2Props) => {
|
|
const headingRef = useRef<HTMLHeadingElement>(null)
|
|
const { activePath, addItems } = useSidebar()
|
|
const { scrollableElement, scrollToElement } = useScrollController()
|
|
const [scrolledFirstTime, setScrolledFirstTime] = useState(false)
|
|
|
|
const id = useMemo(() => getSectionId([children as string]), [children])
|
|
|
|
useEffect(() => {
|
|
if (!scrollableElement || !headingRef.current || scrolledFirstTime) {
|
|
return
|
|
}
|
|
|
|
if (id === (activePath || location.hash.replace("#", ""))) {
|
|
scrollToElement(
|
|
(headingRef.current.offsetParent as HTMLElement) || headingRef.current
|
|
)
|
|
}
|
|
setScrolledFirstTime(scrolledFirstTime)
|
|
}, [scrollableElement, headingRef, id])
|
|
|
|
useEffect(() => {
|
|
addItems([
|
|
{
|
|
type: "link",
|
|
path: `${id}`,
|
|
title: children as string,
|
|
loaded: true,
|
|
},
|
|
])
|
|
}, [id])
|
|
|
|
return (
|
|
<UiH2 {...props} id={id} passRef={headingRef}>
|
|
{children}
|
|
</UiH2>
|
|
)
|
|
}
|
|
|
|
export default H2
|