Skip to content

DOC-13288 IA support for nested top-nav #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions preview-src/ui-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ site:
navGroups: |
[
{ "title": "Server", "startPage": "home::server.adoc", "components": ["server", "*-connector"], "url": "/index.html" },
{ "title": "Mobile", "startPage": "home::mobile.adoc", "components": ["couchbase-lite", "sync-gateway"], "url": "#" },
{ "title": "Cloud", "startPage": "home::cloud.adoc", "components": ["operator"], "url": "#" }
{ "title": "Develop",
"subPages": [
{
"title": "Mobile",
"startPage": "home::mobile.adoc",
"components": ["couchbase-lite", "sync-gateway"],
"url": "#"
},
{
"title": "Cloud",
"startPage": "home::cloud.adoc",
"components": ["operator"],
"url": "#"
}
]
}
]
components:
server:
Expand Down
28 changes: 26 additions & 2 deletions src/css/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@
padding: var(--base-extra-small-space) var(--base-space);
}

.navbar-nav .nav-item .nav-submenu {
display: none;
padding-inline-start: 0;
position: absolute;
background-color: #333; /* var(--color-brand-black); */
z-index: 1000;
}

.navbar-nav .nav-item:hover .nav-submenu {
display: block;
}

.navbar-nav .nav-link {
color: var(--color-brand-white);
text-transform: uppercase;
Expand Down Expand Up @@ -217,11 +229,23 @@
left: -0.75em;
}

.nav-item-selected {
.nav-item-selected,
.nav-submenu-item-selected,
.nav-item-selected:hover .nav-submenu-item:hover {
background-color: var(--color-brand-red);
}

.Columnar .nav-item-selected {
.nav-item-selected:hover {
background-color: inherit;
}

.nav-item-selected:hover .nav-submenu-item-selected {
background-color: #f99;
}

.Columnar .nav-item-selected,
.Columnar .nav-submenu-item-selected,
.nav-item-selected:hover .Columnar .nav-submenu-item:hover {
background-color: var(--color-brand-caution);
}

Expand Down
22 changes: 18 additions & 4 deletions src/helpers/nav-group-for-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ module.exports = (
}
) => {
const pageUrl = page.url
const navGroupByUrl = navGroups.find(({ url }) => url === pageUrl)
if (navGroupByUrl) return navGroupByUrl

const navGroupsAndSubgroups = [
...navGroups,
...navGroups.flatMap(({ subGroups }) => subGroups || [])]

const navGroupByUrl =
navGroupsAndSubgroups.find(({ url }) => url === pageUrl)

if (navGroupByUrl) {
return navGroupByUrl
}

const pageComponentName = page.component.name
if (pageComponentName === 'home' && page.module !== 'contribute') return
return navGroups.find(({ components }) => ~components.indexOf(pageComponentName))
if (pageComponentName === 'home' && page.module !== 'contribute') {
return
}

return navGroupsAndSubgroups.find(
({ components }) => ~components.indexOf(pageComponentName))
}
3 changes: 2 additions & 1 deletion src/helpers/nav-group-selected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = module.exports = (navGroup, {

function selected (navGroup, page) {
return (navGroup.url === page?.url) ||
(navGroup.components?.includes(page.component?.name))
(navGroup.components?.includes(page.component?.name)) ||
(navGroup.subGroups?.some((it) => selected(it, page)))
}
16 changes: 13 additions & 3 deletions src/helpers/nav-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,35 @@ module.exports = ({

if (!navGroups) return []
if (navGroups._compiled) return navGroups
navGroups = JSON.parse(navGroups)

const components = site.components
const componentNames = Object.keys(components)
const claimed = []
const claimed = [] // mutable array to track claimed components

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

claimed.push(...componentNamesInGroup)

const navSubgroups = navGroup.subGroups?.map(processNavGroup)
if (navSubgroups) {
navGroup.subGroups = navSubgroups
console.log(navSubgroups)
}

return compileNavGroup(
navGroup,
componentNamesInGroup,
contentCatalog,
components)
})
}

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

if (orphaned.length) {
Expand Down
13 changes: 12 additions & 1 deletion src/partials/header-content.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</a>
</li>
{{#each this}}
{{#if ./url}}
{{#if (or ./url ./subGroups)}}
<li class="nav-item {{#if (nav-group-selected this)}}nav-item-selected{{/if}}">
<a class="nav-link" href="{{relativize ./url}}">
{{{./title}}}
Expand All @@ -53,6 +53,17 @@
</span>
{{/if}}
</a>
{{#with ./subGroups}}
<ul class="nav-submenu">
{{#each this}}
<li class="nav-item nav-submenu-item {{#if (nav-group-selected this)}}nav-submenu-item-selected{{/if}}">
<a class="nav-link nav-submenu-link" href="{{relativize ./url}}">
{{{./title}}}
</a>
</li>
{{/each}}
</ul>
{{/with}}
</li>
{{/if}}
{{/each}}
Expand Down