Files
medusa-store/www/apps/api-reference/providers/page-title.tsx
Shahed Nasser 4d632e7a5d docs: added tests for components in api-reference project (#14428)
* add tests (WIP)

* added test for h2

* finished adding tests

* fixes

* fixes

* fixes
2026-01-05 10:56:56 +02:00

49 lines
1.3 KiB
TypeScript

"use client"
import React from "react"
import { createContext, useEffect } from "react"
import { useSidebar } from "docs-ui"
import { useArea } from "./area"
import { Sidebar } from "types"
const PageTitleContext = createContext(null)
type PageTitleProviderProps = {
children: React.ReactNode
}
const PageTitleProvider = ({ children }: PageTitleProviderProps) => {
const { activePath, activeItem } = useSidebar()
const { displayedArea } = useArea()
useEffect(() => {
const titleSuffix = `Medusa ${displayedArea} API Reference`
if (!activePath?.length) {
document.title = titleSuffix
} else {
if (activeItem?.path === activePath) {
document.title = `${activeItem?.title} - ${titleSuffix}`
} else {
// find the child that matches the active path
const item = activeItem?.children?.find(
(i) => i.type === "link" && i.path === activePath
) as Sidebar.SidebarItemLink
if (item) {
document.title = `${item.title} - ${titleSuffix}`
} else {
document.title = titleSuffix
}
}
}
}, [activePath, displayedArea, activeItem])
return (
<PageTitleContext.Provider value={null}>
{children}
</PageTitleContext.Provider>
)
}
export default PageTitleProvider