11import { useRouter } from 'next/router'
22import cx from 'classnames'
33
4+ import { ActionList } from '@primer/components'
45import { Link } from 'components/Link'
56import { BumpLink } from 'components/ui/BumpLink'
67import type { TocItem } from 'components/context/ProductLandingContext'
@@ -16,47 +17,57 @@ export const TableOfContents = (props: Props) => {
1617 return (
1718 < ul
1819 data-testid = "table-of-contents"
19- className = { cx ( variant === 'compact' ? 'list-style-inside pl-2' : 'list-style-none' ) }
20+ className = { cx ( variant === 'compact' ? 'list-style-outside pl-2' : 'list-style-none' ) }
2021 >
21- { ( items || [ ] ) . map ( ( item ) => {
22- if ( ! item ) {
23- return null
24- }
25-
26- const { fullPath : href , title, intro, childTocItems } = item
27- const isActive = router . pathname === href
28- return variant === 'compact' ? (
29- < li key = { href } className = "f4 my-1" >
30- < Link href = { href } > { title } </ Link >
31- { ( childTocItems || [ ] ) . length > 0 && (
32- < ul
33- className = { cx (
34- variant === 'compact' ? 'list-style-circle pl-5 my-3' : 'list-style-none'
35- ) }
36- >
37- { ( childTocItems || [ ] ) . map ( ( childItem ) => {
38- if ( ! childItem ) {
39- return null
40- }
41- return (
42- < li key = { childItem . fullPath } className = "f4 mt-1" >
43- < Link href = { childItem . fullPath } > { childItem . title } </ Link >
22+ < ActionList
23+ items =
24+ { ( items || [ ] ) . filter ( item => typeof item !== 'undefined' ) . map ( ( item ) => {
25+ const { fullPath : href , title, intro, childTocItems } = item
26+ const isActive = router . pathname === href
27+ return ( variant === 'compact' ) ? {
28+ key : href ,
29+ text : title ,
30+ renderItem : ( ) => (
31+ < ActionList . Item >
32+ < li key = { href } className = "f4 d-list-item width-full" >
33+ < Link className = "d-block width-full" href = { href } > { title } </ Link >
34+ { ( childTocItems || [ ] ) . length > 0 && (
35+ < ul
36+ className = { cx (
37+ variant === 'compact' ? 'list-style-circle pl-5 my-3' : 'list-style-none'
38+ ) }
39+ >
40+ { ( childTocItems || [ ] ) . map ( ( childItem ) => {
41+ if ( ! childItem ) {
42+ return null
43+ }
44+ return (
45+ < li key = { childItem . fullPath } className = "f4 d-block width-full" >
46+ < Link className = "d-block width-full" href = { childItem . fullPath } > { childItem . title } </ Link >
47+ </ li >
48+ )
49+ } ) }
50+ </ ul >
51+ ) }
4452 </ li >
45- )
46- } ) }
47- </ ul >
48- ) }
49- </ li >
50- ) : (
51- < li key = { href } className = { cx ( 'mb-3 border-bottom pb-2' , isActive && 'color-fg-muted' ) } >
52- < BumpLink as = { Link } href = { href } title = { < h2 className = "h4" > { title } </ h2 > } >
53- { intro && (
54- < p className = "f4 color-fg-muted" dangerouslySetInnerHTML = { { __html : intro } } />
55- ) }
56- </ BumpLink >
57- </ li >
58- )
59- } ) }
53+ </ ActionList . Item >
54+ )
55+ } : {
56+ key : href ,
57+ title : title ,
58+ renderItem : ( ) => (
59+ < ActionList . Item className = { cx ( 'border-bottom' ) } >
60+ < li key = { href } className = { cx ( 'mt-2' , isActive && 'color-fg-muted' ) } >
61+ < BumpLink as = { Link } href = { href } title = { < h2 className = "py-1 h4" > { title } </ h2 > } >
62+ { intro && (
63+ < p className = "f4 color-fg-muted" dangerouslySetInnerHTML = { { __html : intro } } />
64+ ) }
65+ </ BumpLink >
66+ </ li >
67+ </ ActionList . Item >
68+ )
69+ }
70+ } ) } />
6071 </ ul >
6172 )
6273}
0 commit comments