|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -import {html, css} from 'lit'; |
8 | | -import {customElement} from 'lit/decorators.js'; |
| 7 | +import {html, css, TemplateResult} from 'lit'; |
| 8 | +import {customElement, property} from 'lit/decorators.js'; |
| 9 | +import {classMap} from 'lit/directives/class-map.js'; |
9 | 10 | import {WCOPage} from './wco-page.js'; |
10 | 11 | import './wco-top-bar.js'; |
11 | 12 |
|
| 13 | +export interface NavEntry { |
| 14 | + key: string; |
| 15 | + url: string; |
| 16 | + children?: NavEntry[]; |
| 17 | +} |
| 18 | + |
12 | 19 | /** |
13 | 20 | * A page with left and right side navigation areas. |
14 | 21 | */ |
@@ -36,16 +43,45 @@ export class WCONavPage extends WCOPage { |
36 | 43 | align-items: center; |
37 | 44 | border: solid 1px red; |
38 | 45 | } |
| 46 | +
|
| 47 | + nav li.active { |
| 48 | + font-weight: bold; |
| 49 | + } |
39 | 50 | `, |
40 | 51 | ]; |
41 | 52 |
|
| 53 | + @property({attribute: false}) |
| 54 | + navEntries?: NavEntry[]; |
| 55 | + |
42 | 56 | protected override renderMain() { |
43 | 57 | return html` |
44 | | - <nav id="main-outline"><slot name="outline"></slot></nav> |
| 58 | + <nav id="main-outline">${this._renderNav(this.navEntries)}</nav> |
45 | 59 | <article>${this.renderContent()}</article> |
46 | 60 | <nav id="right-nav">[Page ToC]</nav> |
47 | 61 | `; |
48 | 62 | } |
| 63 | + |
| 64 | + private _renderNav( |
| 65 | + entries: NavEntry[] | undefined |
| 66 | + ): TemplateResult | undefined { |
| 67 | + if (entries === undefined || entries.length === 0) { |
| 68 | + return; |
| 69 | + } |
| 70 | + return html`<ul> |
| 71 | + ${entries.map( |
| 72 | + (entry) => html`<li |
| 73 | + class="${classMap({ |
| 74 | + active: entry.url === globalThis.location.pathname, |
| 75 | + })}" |
| 76 | + > |
| 77 | + ${entry.url |
| 78 | + ? html`<a href="${entry.url}">${entry.key}</a>` |
| 79 | + : entry.key} |
| 80 | + ${this._renderNav(entry.children)} |
| 81 | + </li>` |
| 82 | + )} |
| 83 | + </ul>`; |
| 84 | + } |
49 | 85 | } |
50 | 86 |
|
51 | 87 | declare global { |
|
0 commit comments