Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 80 additions & 35 deletions src/components/LibraryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import { trackEvent, useTrackedImpression } from '~/utils/analytics'
import {
getLibraryLayoutVersion,
getLibraryTabLinkOptions,

Check warning on line 42 in src/components/LibraryLayout.tsx

View workflow job for this annotation

GitHub Actions / PR

eslint(no-unused-vars)

Identifier 'getLibraryTabLinkOptions' is imported but never used.
getMenuGroupInitialOpenState,
isChartsCatalogTarget,
} from './library-layout-navigation'
Expand Down Expand Up @@ -830,6 +830,10 @@
d.routeId.startsWith('/_library/charts/catalog'),
)

const isThemeEditor = matches.some((d) =>
d.routeId.startsWith('/_library/highlight/$version/theme-editor'),
)

const isNpmStats = matches.some((d) => d.pathname.includes('/docs/npm-stats'))

const [mobileMenuOpen, setMobileMenuOpen] = React.useState(false)
Expand Down Expand Up @@ -860,30 +864,58 @@
const tabbedMenuConfig = React.useMemo(() => {
const tabs = getTabbedMenuConfig(menuConfig)

return libraryId === 'charts'
? tabs.map((tab) =>
tab.id === 'examples'
? {
...tab,
firstItem: {
label: 'Examples',
to: '/charts/catalog',
tab: 'examples',
},
}
: tab,
)
: tabs
if (libraryId === 'charts') {
return tabs.map((tab) =>
tab.id === 'examples'
? {
...tab,
firstItem: {
label: 'Examples',
to: '/charts/catalog',
tab: 'examples',
},
}
: tab,
)
}

if (libraryId === 'highlight') {
return [
...tabs,
{
id: 'theme-editor' as const,
label: 'Theme Editor',
groups: [],
firstItem: {
label: 'Theme Editor',
to: '/highlight/$version/theme-editor',
tab: 'theme-editor' as const,
},
},
]
}

return tabs
}, [libraryId, menuConfig])

const activeTabId = React.useMemo(() => {
if (isThemeEditor) {
return 'theme-editor' as const
}

return getActiveDocsNavTabId({
isExample,
menuConfig,
pathname: lastMatch.pathname,
relativePathname,
})
}, [isExample, lastMatch.pathname, menuConfig, relativePathname])
}, [
isExample,
isThemeEditor,
lastMatch.pathname,
menuConfig,
relativePathname,
])

const visibleMenuConfig = React.useMemo(() => {
return (
Expand Down Expand Up @@ -1187,23 +1219,29 @@
return null
}

const linkOptions = getLibraryTabLinkOptions({
libraryId,
version,
to: target.to,
})
const isCustomToolRoute =
target.to === '/charts/catalog' ||
target.to === '/highlight/$version/theme-editor'
const linkParams =
!target.to.startsWith('/') ||
target.to.includes('/$libraryId') ||
target.to.includes('/$version')
? ({ libraryId, version } as never)
: undefined
const isActive = tab.id === activeTabId

return (
<li key={tab.id}>
<Link
from={linkOptions.from as never}
to={linkOptions.to as never}
params={linkOptions.params as never}
onClick={closeMobileMenu}
preload={
isChartsCatalogTarget(target.to) ? false : 'intent'
from={
isCustomToolRoute
? undefined
: '/$libraryId/$version/docs'
}
to={target.to}
params={linkParams}
onClick={closeMobileMenu}
preload={isCustomToolRoute ? false : 'intent'}
aria-current={isActive ? 'page' : undefined}
className={twMerge(
'relative block whitespace-nowrap pb-2 font-semibold',
Expand Down Expand Up @@ -1374,19 +1412,25 @@
return null
}

const linkOptions = getLibraryTabLinkOptions({
libraryId,
version,
to: target.to,
})
const isCustomToolRoute =
target.to === '/charts/catalog' ||
target.to === '/highlight/$version/theme-editor'
const linkParams =
!target.to.startsWith('/') ||
target.to.includes('/$libraryId') ||
target.to.includes('/$version')
? ({ libraryId, version } as never)
: undefined

return (
<Link
key={tab.id}
from={linkOptions.from as never}
to={linkOptions.to as never}
params={linkOptions.params as never}
preload={isChartsCatalogTarget(target.to) ? false : 'intent'}
from={
isCustomToolRoute ? undefined : '/$libraryId/$version/docs'
}
to={target.to}
params={linkParams}
preload={isCustomToolRoute ? false : 'intent'}
activeOptions={{
exact: true,
includeHash: false,
Expand Down Expand Up @@ -1487,6 +1531,7 @@
!isLandingPage &&
!isExample &&
!isNpmStats &&
!isThemeEditor &&
!isFullWidth &&
'mx-auto w-[900px]',
)}
Expand Down
Loading
Loading