Skip to content

Commit ac00120

Browse files
committed
DOC-13288 IA support for nested top-nav
1 parent c13fc05 commit ac00120

File tree

6 files changed

+87
-13
lines changed

6 files changed

+87
-13
lines changed

preview-src/ui-model.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@ site:
88
navGroups: |
99
[
1010
{ "title": "Server", "startPage": "home::server.adoc", "components": ["server", "*-connector"], "url": "/index.html" },
11-
{ "title": "Mobile", "startPage": "home::mobile.adoc", "components": ["couchbase-lite", "sync-gateway"], "url": "#" },
12-
{ "title": "Cloud", "startPage": "home::cloud.adoc", "components": ["operator"], "url": "#" }
11+
{ "title": "Develop",
12+
"subPages": [
13+
{
14+
"title": "Mobile",
15+
"startPage": "home::mobile.adoc",
16+
"components": ["couchbase-lite", "sync-gateway"],
17+
"url": "#"
18+
},
19+
{
20+
"title": "Cloud",
21+
"startPage": "home::cloud.adoc",
22+
"components": ["operator"],
23+
"url": "#"
24+
}
25+
]
26+
}
1327
]
1428
components:
1529
server:

src/css/header.css

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@
8989
padding: var(--base-extra-small-space) var(--base-space);
9090
}
9191

92+
.navbar-nav .nav-item .nav-submenu {
93+
display: none;
94+
padding-inline-start: 0;
95+
position: absolute;
96+
background-color: #333; /* var(--color-brand-black); */
97+
z-index: 1000;
98+
}
99+
100+
.navbar-nav .nav-item:hover .nav-submenu {
101+
display: block;
102+
}
103+
92104
.navbar-nav .nav-link {
93105
color: var(--color-brand-white);
94106
text-transform: uppercase;
@@ -217,11 +229,23 @@
217229
left: -0.75em;
218230
}
219231

220-
.nav-item-selected {
232+
.nav-item-selected,
233+
.nav-submenu-item-selected,
234+
.nav-item-selected:hover .nav-submenu-item:hover {
221235
background-color: var(--color-brand-red);
222236
}
223237

224-
.Columnar .nav-item-selected {
238+
.nav-item-selected:hover {
239+
background-color: inherit;
240+
}
241+
242+
.nav-item-selected:hover .nav-submenu-item-selected {
243+
background-color: #f99;
244+
}
245+
246+
.Columnar .nav-item-selected,
247+
.Columnar .nav-submenu-item-selected,
248+
.nav-item-selected:hover .Columnar .nav-submenu-item:hover {
225249
background-color: var(--color-brand-caution);
226250
}
227251

src/helpers/nav-group-for-page.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@ module.exports = (
99
}
1010
) => {
1111
const pageUrl = page.url
12-
const navGroupByUrl = navGroups.find(({ url }) => url === pageUrl)
13-
if (navGroupByUrl) return navGroupByUrl
12+
13+
const navGroupsAndSubgroups = [
14+
...navGroups,
15+
...navGroups.flatMap(({ subGroups }) => subGroups || [])]
16+
17+
const navGroupByUrl =
18+
navGroupsAndSubgroups.find(({ url }) => url === pageUrl)
19+
20+
if (navGroupByUrl) {
21+
return navGroupByUrl
22+
}
23+
1424
const pageComponentName = page.component.name
15-
if (pageComponentName === 'home' && page.module !== 'contribute') return
16-
return navGroups.find(({ components }) => ~components.indexOf(pageComponentName))
25+
if (pageComponentName === 'home' && page.module !== 'contribute') {
26+
return
27+
}
28+
29+
return navGroupsAndSubgroups.find(
30+
({ components }) => ~components.indexOf(pageComponentName))
1731
}

src/helpers/nav-group-selected.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ module.exports = module.exports = (navGroup, {
1919

2020
function selected (navGroup, page) {
2121
return (navGroup.url === page?.url) ||
22-
(navGroup.components?.includes(page.component?.name))
22+
(navGroup.components?.includes(page.component?.name)) ||
23+
(navGroup.subGroups?.some((it) => selected(it, page)))
2324
}

src/helpers/nav-groups.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,35 @@ module.exports = ({
99

1010
if (!navGroups) return []
1111
if (navGroups._compiled) return navGroups
12+
navGroups = JSON.parse(navGroups)
1213

1314
const components = site.components
1415
const componentNames = Object.keys(components)
15-
const claimed = []
16+
const claimed = [] // mutable array to track claimed components
1617

17-
navGroups = JSON.parse(navGroups).map((navGroup) => {
18+
function processNavGroup (navGroup) {
1819
const componentNamesInGroup =
1920
(navGroup.components || []).flatMap(
21+
// componentNamesInGroup can be a name like 'couchbase-lite'
22+
// or a glob pattern like '*-sdk'
2023
(componentName) => componentNames.filter(globbify(componentName)))
2124

2225
claimed.push(...componentNamesInGroup)
2326

27+
const navSubgroups = navGroup.subGroups?.map(processNavGroup)
28+
if (navSubgroups) {
29+
navGroup.subGroups = navSubgroups
30+
console.log(navSubgroups)
31+
}
32+
2433
return compileNavGroup(
2534
navGroup,
2635
componentNamesInGroup,
2736
contentCatalog,
2837
components)
29-
})
38+
}
3039

40+
navGroups = navGroups.map(processNavGroup)
3141
const orphaned = componentNames.filter((it) => !claimed.includes(it))
3242

3343
if (orphaned.length) {

src/partials/header-content.hbs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</a>
4343
</li>
4444
{{#each this}}
45-
{{#if ./url}}
45+
{{#if (or ./url ./subGroups)}}
4646
<li class="nav-item {{#if (nav-group-selected this)}}nav-item-selected{{/if}}">
4747
<a class="nav-link" href="{{relativize ./url}}">
4848
{{{./title}}}
@@ -53,6 +53,17 @@
5353
</span>
5454
{{/if}}
5555
</a>
56+
{{#with ./subGroups}}
57+
<ul class="nav-submenu">
58+
{{#each this}}
59+
<li class="nav-item nav-submenu-item {{#if (nav-group-selected this)}}nav-submenu-item-selected{{/if}}">
60+
<a class="nav-link nav-submenu-link" href="{{relativize ./url}}">
61+
{{{./title}}}
62+
</a>
63+
</li>
64+
{{/each}}
65+
</ul>
66+
{{/with}}
5667
</li>
5768
{{/if}}
5869
{{/each}}

0 commit comments

Comments
 (0)