Skip to content

Commit cbd2513

Browse files
committed
feat(wip): Update sidebar nav to be more explorable
1 parent 7987cf6 commit cbd2513

File tree

3 files changed

+76
-16
lines changed

3 files changed

+76
-16
lines changed

src/components/dynamicNav.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,35 @@ type ChildrenProps = {
100100
showDepth?: number;
101101
};
102102

103-
export function Children({tree, path, exclude = [], showDepth = 0}: ChildrenProps) {
104-
return <Fragment>{renderChildren(tree, exclude, path, showDepth)}</Fragment>;
103+
function TopLevelChildren({tree, path, exclude = [], showDepth = 0}: ChildrenProps) {
104+
return sortPages(
105+
tree.filter(
106+
({name, node}) =>
107+
node &&
108+
!!node.context.title &&
109+
name !== '' &&
110+
exclude.indexOf(node.path) === -1 &&
111+
!node.context.sidebar_hidden
112+
),
113+
({node}) => node!
114+
).map(({node, children: nodeChildren}) => {
115+
// will not be null because of the filter above
116+
if (!node) {
117+
return null;
118+
}
119+
return (
120+
<SidebarLink
121+
to={node.path}
122+
key={node.path}
123+
title={node.context.sidebar_title || node.context.title!}
124+
collapsed={false}
125+
path={path}
126+
showChevron={false}
127+
>
128+
{renderChildren(nodeChildren, exclude, path, showDepth, 1)}
129+
</SidebarLink>
130+
);
131+
});
105132
}
106133

107134
type Props = {
@@ -184,12 +211,12 @@ export function DynamicNav({
184211
<li className="mb-3" data-sidebar-branch>
185212
{header}
186213
{(!collapse || isActive) && entity.children && (
187-
<ul data-sidebar-tree className="pl-3">
214+
<ul data-sidebar-tree data-sidebar-tree-root>
188215
{prependLinks &&
189216
prependLinks.map(link => (
190217
<SidebarLink to={link[0]} key={link[0]} title={link[1]} path={linkPath} />
191218
))}
192-
<Children
219+
<TopLevelChildren
193220
tree={entity.children}
194221
exclude={exclude}
195222
showDepth={showDepth}

src/components/sidebar/style.module.scss

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
border-top: 1px solid var(--border-color);
7070
}
7171

72+
[data-sidebar-tree-root] > li > [data-sidebar-link] {
73+
font-weight: 500;
74+
}
75+
7276
.toc {
7377
font-size: 0.875rem;
7478
flex: 1;
@@ -89,7 +93,19 @@
8993
padding-left: 0;
9094
}
9195

92-
:global(.toc-item) :global(.toc-item) {
96+
[data-sidebar-tree-root] {
97+
margin-bottom: 1rem;
98+
}
99+
100+
[data-sidebar-tree-root] > [data-sidebar-branch-has-subtree='true']:not(:first-child) {
101+
margin-top: 1rem;
102+
}
103+
104+
[data-sidebar-tree-root] > [data-sidebar-branch-has-subtree='true']:not(:last-child) {
105+
margin-bottom: 1rem;
106+
}
107+
108+
:global(.toc-item) :global(.toc-item) :global(.toc-item) {
93109
padding-left: 0.75rem;
94110
}
95111

@@ -100,23 +116,24 @@
100116
[data-sidebar-link] {
101117
position: relative;
102118
line-height: 1.5;
103-
border-radius: 4px;
104-
padding: 0.5rem;
119+
border-radius: 0;
120+
padding: 0.1rem 0rem;
121+
margin: 0.4rem 0;
105122
opacity: 0.8;
106123
text-decoration: none;
107124
transition: var(--transition-time) ease-out;
125+
border-left: 3px solid transparent;
108126

109127
&:hover {
110128
opacity: 1;
111-
text-decoration: none;
112-
color: var(--sidebar-item-color);
113-
background-color: var(--sidebar-item-bg-hover);
129+
color: var(--accent-purple);
114130
}
115131

116132
&:global(.active) {
117133
opacity: 1;
118-
color: var(--white);
119-
background-color: var(--accent-purple);
134+
color: var(--accent-purple);
135+
border-left-color: var(--accent-purple);
136+
padding-left: 0.3rem;
120137
}
121138
}
122139
}
@@ -128,7 +145,7 @@
128145
&.active {
129146
background-color: var(--brandDecoration);
130147

131-
strong {
148+
strong {
132149
color: #fff;
133150
}
134151
}

src/components/sidebarLink.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ interface SidebarLinkProps {
2727
* Indicates that the links are currently hidden. Overriden by isActive
2828
*/
2929
collapsed?: boolean | null;
30+
31+
/**
32+
* Whether to show the chevron, if the page has children
33+
*/
34+
showChevron?: boolean;
3035
}
3136

3237
export function SidebarLink({
@@ -36,6 +41,7 @@ export function SidebarLink({
3641
path,
3742
collapsed = null,
3843
className = '',
44+
showChevron = true,
3945
}: SidebarLinkProps) {
4046
const isActive = path?.indexOf(to) === 0;
4147
const enableSubtree = isActive || collapsed === false;
@@ -44,10 +50,16 @@ export function SidebarLink({
4450
const [showSubtree, setShowSubtree] = useState(enableSubtree);
4551

4652
return (
47-
<li className={`toc-item ${className}`} data-sidebar-branch data-path={path}>
53+
<li
54+
className={`toc-item ${className}`}
55+
data-sidebar-branch
56+
data-sidebar-branch-has-subtree={hasSubtree}
57+
data-path={path}
58+
>
4859
<SidebarNavItem
4960
to={to}
5061
data-sidebar-link
62+
data-sidebar-link-has-subtree={hasSubtree}
5163
isActive={to === getUnversionedPath(path)}
5264
onClick={() => {
5365
// Allow toggling the sidebar subtree only if the item is selected
@@ -57,9 +69,13 @@ export function SidebarLink({
5769
}}
5870
>
5971
{title || children}
60-
{hasSubtree && <Chevron direction={showSubtree ? 'down' : 'right'} />}
72+
{hasSubtree && showChevron && (
73+
<Chevron direction={showSubtree ? 'down' : 'right'} />
74+
)}
6175
</SidebarNavItem>
62-
{title && children && <ul data-sidebar-tree>{showSubtree && children}</ul>}
76+
{title && children && hasSubtree && (
77+
<ul data-sidebar-tree>{showSubtree && children}</ul>
78+
)}
6379
</li>
6480
);
6581
}

0 commit comments

Comments
 (0)