Skip to content

Commit

Permalink
chore: add list markup for sidebar navigation sections children
Browse files Browse the repository at this point in the history
Closes: INSTUI-4244
  • Loading branch information
ToMESSKa authored and HerrTopi committed Dec 13, 2024
1 parent c51a9b8 commit e1142e4
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions packages/__docs__/src/Nav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ class Nav extends Component<NavProps, NavState> {
}: {
id: string
title: string
children: React.ReactNode[]
children: React.ReactNode
variant?: 'section' | 'category'
}): React.ReactNode {
if (children.length === 0) {
if (
React.isValidElement(children) &&
React.Children.count(children.props.children) === 0
) {
return
}

Expand Down Expand Up @@ -201,6 +204,7 @@ class Nav extends Component<NavProps, NavState> {

return (
<View
as="li"
display="block"
key={docId}
margin="xx-small none xx-small"
Expand Down Expand Up @@ -229,7 +233,7 @@ class Nav extends Component<NavProps, NavState> {
renderSectionChildren(
sectionId: string,
markExpanded: (sectionId: string) => void
): React.ReactNode[] {
): React.ReactNode {
const children: Record<
string,
{ id: string; section?: boolean; order?: string }
Expand All @@ -249,33 +253,37 @@ class Nav extends Component<NavProps, NavState> {
}
)

return Object.keys(children)
.sort((a, b) => {
const orderA = children[a].order ? children[a].order : ''
const orderB = children[b].order ? children[b].order : ''
const idA = `${orderA}${a.toUpperCase()}`
const idB = `${orderB}${b.toUpperCase()}`
if (idA < idB) {
return -1
}
if (idA > idB) {
return 1
}
return 0
})
.map((id) => {
if (children[id].section) {
return this.renderSectionLink(
children[id].id,
() => {
markExpanded(sectionId)
},
'category'
)
} else {
return this.renderDocLink(id)
}
})
return (
<ul style={{ paddingLeft: '0px', margin: '0px' }}>
{Object.keys(children)
.sort((a, b) => {
const orderA = children[a].order ? children[a].order : ''
const orderB = children[b].order ? children[b].order : ''
const idA = `${orderA}${a.toUpperCase()}`
const idB = `${orderB}${b.toUpperCase()}`
if (idA < idB) {
return -1
}
if (idA > idB) {
return 1
}
return 0
})
.map((id) => {
if (children[id].section) {
return this.renderSectionLink(
children[id].id,
() => {
markExpanded(sectionId)
},
'category'
)
} else {
return this.renderDocLink(id)
}
})}
</ul>
)
}

renderSectionLink(
Expand Down

0 comments on commit e1142e4

Please sign in to comment.