diff --git a/docs/data/joy/pages.ts b/docs/data/joy/pages.ts index 67c3ecf29bbd3f..779d77047412b4 100644 --- a/docs/data/joy/pages.ts +++ b/docs/data/joy/pages.ts @@ -1,7 +1,6 @@ const pages = [ { pathname: '/joy-ui/getting-started', - scopePathnames: ['/joy-ui/main-features'], icon: 'DescriptionIcon', children: [ { pathname: '/joy-ui/getting-started/overview' }, diff --git a/docs/data/material/pages.ts b/docs/data/material/pages.ts index 67821005ecafaf..cbc6ed28604d4c 100644 --- a/docs/data/material/pages.ts +++ b/docs/data/material/pages.ts @@ -21,12 +21,6 @@ const pages: MuiPage[] = [ }, { pathname: '/material-ui/react-', - scopePathnames: [ - '/material-ui/icons', - '/material-ui/material-icons', - '/material-ui/about-the-lab', - '/material-ui/transitions', - ], title: 'Components', icon: 'ToggleOnIcon', children: [ @@ -165,7 +159,7 @@ const pages: MuiPage[] = [ icon: 'CreateIcon', children: [ { - pathname: '/material-ui/customization', + pathname: '/material-ui/customization/theme', subheader: '/material-ui/customization/theme', children: [ { pathname: '/material-ui/customization/theming' }, @@ -263,7 +257,7 @@ const pages: MuiPage[] = [ title: 'Migrating to Grid v2', }, { - pathname: '/material-ui/migration', + pathname: '/material-ui/migration/v5', subheader: 'Upgrade to v5', children: [ { @@ -289,7 +283,7 @@ const pages: MuiPage[] = [ ], }, { - pathname: '/material-ui/migration', + pathname: '/material-ui/migration/earlier', subheader: 'Earlier versions', children: [ { pathname: '/material-ui/migration/migration-v3', title: 'Migration from v3 to v4' }, diff --git a/docs/data/system/pages.ts b/docs/data/system/pages.ts index a2936405ac5688..8f0a87315323ab 100644 --- a/docs/data/system/pages.ts +++ b/docs/data/system/pages.ts @@ -14,21 +14,6 @@ const pages = [ }, { pathname: '/style-utilities', - scopePathnames: [ - '/system/properties', - '/system/borders', - '/system/display', - '/system/flexbox', - '/system/grid', - '/system/palette', - '/system/positions', - '/system/shadows', - '/system/sizing', - '/system/spacing', - '/system/screen-readers', - '/system/typography', - '/system/styled', - ], icon: 'BuildIcon', children: [ { pathname: '/system/properties' }, diff --git a/docs/pages/_app.js b/docs/pages/_app.js index a16b6291a22945..67c6f73c9454b4 100644 --- a/docs/pages/_app.js +++ b/docs/pages/_app.js @@ -4,7 +4,7 @@ import * as React from 'react'; import { loadCSS } from 'fg-loadcss/src/loadCSS'; import NextHead from 'next/head'; import PropTypes from 'prop-types'; -import pages from 'docs/src/pages'; +import generalPages from 'docs/src/pages'; import basePages from 'docs/data/base/pages'; import materialPages from 'docs/data/material/pages'; import joyPages from 'docs/data/joy/pages'; @@ -142,18 +142,22 @@ function AppWrapper(props) { } }, []); - let productPages = pages; - if (product === 'base') { - productPages = basePages; - } else if (product === 'material-ui') { - productPages = materialPages; - } else if (product === 'joy-ui') { - productPages = joyPages; - } else if (product === 'system') { - productPages = systemPages; - } + const pageContextValue = React.useMemo(() => { + let pages = generalPages; + if (product === 'base') { + pages = basePages; + } else if (product === 'material-ui') { + pages = materialPages; + } else if (product === 'joy-ui') { + pages = joyPages; + } else if (product === 'system') { + pages = systemPages; + } + + const { activePage, activePageParents } = findActivePage(pages, router.pathname); - const activePage = findActivePage(productPages, router.pathname); + return { activePage, activePageParents, pages }; + }, [product, router.pathname]); let fonts = []; if (asPathWithoutLang.match(/onepirate/)) { @@ -162,11 +166,6 @@ function AppWrapper(props) { ]; } - const pageContextValue = React.useMemo( - () => ({ activePage, pages: productPages }), - [activePage, productPages], - ); - return ( diff --git a/docs/src/MuiPage.ts b/docs/src/MuiPage.ts index 6d8e5ca5268244..4724f8f1d32772 100644 --- a/docs/src/MuiPage.ts +++ b/docs/src/MuiPage.ts @@ -15,6 +15,7 @@ export interface MuiPage { /** * In case the children have pathnames out of pathname value, use this field to scope other pathnames. * Pathname can be partial, e.g. '/components/' will cover '/components/button/' and '/components/link/'. + * @deprecated Dead code, to remove. */ scopePathnames?: string[]; /** @@ -24,9 +25,12 @@ export interface MuiPage { */ inSideNav?: boolean; /** - * Props spread to the Link component + * Props spread to the Link component. */ linkProps?: Record; + /** + * Subheader to display before navigation links. + */ subheader?: string; /** * Overrides the default page title. diff --git a/docs/src/modules/components/AppNavDrawer.js b/docs/src/modules/components/AppNavDrawer.js index 9b5c301ac037f5..c95e1f495b1517 100644 --- a/docs/src/modules/components/AppNavDrawer.js +++ b/docs/src/modules/components/AppNavDrawer.js @@ -208,7 +208,7 @@ function renderNavItems(options) { * @param {import('docs/src/pages').MuiPage} context.page */ function reduceChildRoutes(context) { - const { onClose, activePage, items, depth, t } = context; + const { onClose, activePageParents, items, depth, t } = context; let { page } = context; if (page.inSideNav === false) { return items; @@ -217,10 +217,9 @@ function reduceChildRoutes(context) { const title = pageToTitleI18n(page, t); if (page.children && page.children.length >= 1) { - const topLevel = activePage - ? activePage.pathname.indexOf(`${page.pathname}`) === 0 || - page.scopePathnames?.some((pathname) => activePage.pathname.includes(pathname)) - : false; + const topLevel = + activePageParents.map((parentPage) => parentPage.pathname).indexOf(page.pathname) !== -1; + let firstChild = page.children[0]; if (firstChild.subheader && firstChild.children) { @@ -247,7 +246,7 @@ function reduceChildRoutes(context) { {renderNavItems({ onClose, pages: page.children, - activePage, + activePageParents, depth: subheader ? depth : depth + 1, t, })} @@ -283,7 +282,7 @@ const iOS = typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigato export default function AppNavDrawer(props) { const { className, disablePermanent, mobileOpen, onClose, onOpen } = props; - const { activePage, pages } = React.useContext(PageContext); + const { activePageParents, pages } = React.useContext(PageContext); const router = useRouter(); const [anchorEl, setAnchorEl] = React.useState(null); const userLanguage = useUserLanguage(); @@ -294,7 +293,7 @@ export default function AppNavDrawer(props) { const drawer = React.useMemo(() => { const { canonicalAs } = pathnameToLanguage(router.asPath); - const navItems = renderNavItems({ onClose, pages, activePage, depth: 0, t }); + const navItems = renderNavItems({ onClose, pages, activePageParents, depth: 0, t }); const renderVersionSelector = (versions, sx) => { if (!versions?.length) { @@ -528,7 +527,7 @@ export default function AppNavDrawer(props) { {navItems} ); - }, [activePage, pages, onClose, languagePrefix, t, anchorEl, setAnchorEl, router.asPath]); + }, [activePageParents, pages, onClose, languagePrefix, t, anchorEl, setAnchorEl, router.asPath]); return (