* start SidebarNav, enable dark mode * wip: sidebarnav, fix primer components theme rendering * feat: ProductSiteTree, useFeatureFlag * feat: add new product site tree (untested) * wire up HomepageVersionPicker, run lint * fix: remove re-render logic, fix homepage version picker to be natural width * fix: support css + primer/components color modes * fix: rename categoryId -> productId * feat: ProductSiteTree and AllArticlesProduct * fix: cleanup warnings * fix: use next links on ProductSiteTreeNew * fix: use next Link on AllArticlesProduct * fix: add tooltip to ScrollButton, remove stylesheet dependency * feat: ProductArticlesList component * fix: convert color_mode value from cookie when necessary * remove comments * replace liquid with jsx Co-authored-by: Rachael Sewell <rachmari@github.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import Link from 'next/link'
|
|
|
|
import { useState } from 'react'
|
|
import { ChevronUpIcon } from '@primer/octicons-react'
|
|
import { SiteTreePage, useMainContext } from 'components/context/MainContext'
|
|
|
|
const maxArticles = 10
|
|
|
|
export const ProductArticlesList = () => {
|
|
const { productSiteTreeNew } = useMainContext()
|
|
|
|
if (!productSiteTreeNew) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div className="d-flex gutter flex-wrap">
|
|
{productSiteTreeNew.childPages.map((childPage) => {
|
|
if (childPage.page.documentType === 'article') {
|
|
return null
|
|
}
|
|
|
|
return <ArticleList key={childPage.href} page={childPage} />
|
|
})}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const ArticleList = ({ page }: { page: SiteTreePage }) => {
|
|
const [isShowingMore, setIsShowingMore] = useState(false)
|
|
|
|
return (
|
|
<div className="col-12 col-lg-4 mb-6 height-full">
|
|
<h4 className="mb-3">
|
|
<Link href={page.href}>
|
|
<a>{page.page.title}</a>
|
|
</Link>
|
|
</h4>
|
|
|
|
<ul className="list-style-none">
|
|
{page.childPages.map((grandchildPage) => {
|
|
if (page.childPages[0].page.documentType === 'mapTopic' && grandchildPage.page.hidden) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<li className="mb-3 { page.childPages.length > maxArticles ? d-none : null }">
|
|
<Link href={grandchildPage.href}>
|
|
<a>{grandchildPage.page.title}</a>
|
|
</Link>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
{!isShowingMore && page.childPages.length > maxArticles && (
|
|
<button onClick={() => setIsShowingMore(true)} className="btn-link Link--secondary">
|
|
Show {page.childPages.length - maxArticles} more{' '}
|
|
<ChevronUpIcon className="v-align-text-bottom" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|