* upgrade primer/react * upgrade * using deprecated * remove lib" * Upgrade primer/react: Upgrade Label (#28502) update Label to primer/react 35.2.2 * fix merge conflicts * primer/react v35: update ActionList (#28467) * Update to v35 ActionList for LearningTrack * Update to v35 ActionList for ArticleList * Update to v35 ActionList for ProductArticleList * Update to v35 ActionList for TableOfContents * Update to v35 ActionList for ProductCollapsibleSection * Update to v35 ActionList for RestCollapsibleSection * Update to v35 ActionList for SidebarHomepage * Update to v35 ActionList for MiniTocs * Update to v35 ActionList for Search * Extra div for rendering test * One less div for rendering test * All the style updates for v35 ActionList * Works without setting as an li which is already the default (didn't before for some reason) * Use deprecated ItemInput for now * Picker update for primer/react (#28485) * update picker * inline picker for mobile * set width to auto * Update components/ui/Picker/Picker.tsx Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> * update * Update Picker.tsx * update onselect * checking language code * move language cookie setting to language picker Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> * Resolve package merge conflicts * fresh npm install * Primer update UnderlineNav (#28582) * update underlinenav for primer/react update * update tests * update switches test * update one last label * update header test" * remove href in underlinenav * update rendering tests * update cursor * primer/react v35: update DropDownMenu to ActionMenu (#28576) * Update to v35 ActionMenu for ArticleCards * Update to v35 ActionMenu for Search * Set button to inline-block * Put the props on the overlay * Update test for ActionMenu markup * update package * update package lock * primer/react v35: CodeLanguagePicker update from SelectMenu to ActionMenu (#28625) * Use octicon for menu down arrow * Update to v35 ActionMenu for CodeLanguagePicker * update to SubNav Co-authored-by: Grace Park <gracepark@github.com> * update package-lock Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
123 lines
4.2 KiB
TypeScript
123 lines
4.2 KiB
TypeScript
import cx from 'classnames'
|
|
import { useState, SyntheticEvent } from 'react'
|
|
import { ChevronDownIcon } from '@primer/octicons-react'
|
|
import { ActionList } from '@primer/react'
|
|
|
|
import { Link } from 'components/Link'
|
|
import { ProductTreeNode } from 'components/context/MainContext'
|
|
import { EventType, sendEvent } from 'components/lib/events'
|
|
import styles from './SidebarProduct.module.scss'
|
|
|
|
type SectionProps = {
|
|
routePath: string
|
|
page: ProductTreeNode
|
|
title: string
|
|
defaultOpen: boolean
|
|
}
|
|
export const ProductCollapsibleSection = (props: SectionProps) => {
|
|
const { routePath, defaultOpen, title, page } = props
|
|
const [isOpen, setIsOpen] = useState(defaultOpen)
|
|
|
|
const onToggle = (e: SyntheticEvent) => {
|
|
const newIsOpen = (e.target as HTMLDetailsElement).open
|
|
setIsOpen(newIsOpen)
|
|
sendEvent({
|
|
type: EventType.navigate,
|
|
navigate_label: `details ${newIsOpen ? 'open' : 'close'}: ${title}`,
|
|
})
|
|
}
|
|
|
|
// The lowest level page link displayed in the tree
|
|
const renderTerminalPageLink = (page: ProductTreeNode) => {
|
|
const title = page.renderedShortTitle || page.renderedFullTitle
|
|
|
|
const isCurrent = routePath === page.href
|
|
return (
|
|
<ActionList.Item
|
|
key={page.href}
|
|
data-testid="sidebar-article"
|
|
data-is-current-page={isCurrent}
|
|
className={cx(
|
|
'width-full position-relative',
|
|
styles.sidebarArticle,
|
|
isCurrent && ['text-bold', styles.sidebarArticleActive]
|
|
)}
|
|
sx={{
|
|
padding: '2px 0',
|
|
':hover': {
|
|
borderRadius: 0,
|
|
},
|
|
}}
|
|
>
|
|
<Link
|
|
href={page.href}
|
|
className={cx(
|
|
'd-block pl-6 pr-5 py-1 no-underline width-full',
|
|
isCurrent ? 'color-fg-accent' : 'color-fg-default'
|
|
)}
|
|
>
|
|
{title}
|
|
</Link>
|
|
</ActionList.Item>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<details open={defaultOpen} onToggle={onToggle} className="details-reset">
|
|
<summary className="outline-none">
|
|
<div className="d-flex flex-justify-between">
|
|
<div className="pl-4 pr-1 py-2 f5 d-block flex-auto mr-3 color-fg-default no-underline text-bold">
|
|
{title}
|
|
</div>
|
|
<span style={{ marginTop: 7 }} className="flex-shrink-0 pr-3">
|
|
<ChevronDownIcon className={cx('opacity-60', isOpen && 'rotate-180')} />
|
|
</span>
|
|
</div>
|
|
</summary>
|
|
|
|
{
|
|
<>
|
|
{/* <!-- some pages have nested child pages (formerly known as a mapTopic) --> */}
|
|
{page.childPages[0]?.page.documentType === 'mapTopic' ? (
|
|
<ul className="list-style-none position-relative">
|
|
{page.childPages.map((childPage, i) => {
|
|
const childTitle = childPage.renderedShortTitle || childPage.renderedFullTitle
|
|
|
|
const isActive = routePath.includes(childPage.href)
|
|
const isCurrent = routePath === childPage.href
|
|
|
|
return (
|
|
<li key={childPage.href + i} data-is-current-page={isCurrent}>
|
|
<details
|
|
open={isActive}
|
|
onToggle={(e) => e.stopPropagation()}
|
|
className="details-reset"
|
|
>
|
|
<summary>
|
|
<div className={cx('pl-4 pr-5 py-2 no-underline')}>{childTitle}</div>
|
|
</summary>
|
|
<div data-testid="sidebar-article-group" className="pb-0">
|
|
<ActionList variant="full" className="my-2">
|
|
{childPage.childPages.map((cp) => {
|
|
return renderTerminalPageLink(cp)
|
|
})}
|
|
</ActionList>
|
|
</div>
|
|
</details>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
) : page.childPages[0]?.page.documentType === 'article' ? (
|
|
<div data-testid="sidebar-article-group" className="pb-0">
|
|
<ActionList variant="full" className="my-2">
|
|
{page.childPages.map(renderTerminalPageLink)}
|
|
</ActionList>
|
|
</div>
|
|
) : null}
|
|
</>
|
|
}
|
|
</details>
|
|
)
|
|
}
|