-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnav.gts
91 lines (75 loc) · 2.2 KB
/
nav.gts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { pascalCase } from 'change-case';
import type { TOC } from '@ember/component/template-only';
import type RouterService from '@ember/routing/router-service';
import type { Collection, DocsService, Page } from 'kolay';
export class Nav extends Component {
@service('kolay/docs') declare docs: DocsService;
<template>
<nav id="side-nav">
<Pages @item={{this.docs.tree}} />
</nav>
<style>
nav#side-nav { min-width: 150px; ul { padding-left: 0.5rem; list-style: none; line-height:
1.75rem; } }
</style>
</template>
}
function isCollection(x: Page | Collection): x is Collection {
return 'pages' in x;
}
function nameFor(x: Page) {
// We defined componentName via json file
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ('componentName' in x) {
return `${x.componentName}`;
}
if (x.path.includes('/components/')) {
return `<${pascalCase(x.name)} />`;
}
return x.name;
}
const Pages: TOC<{ Args: { item: Page | Collection } }> = <template>
<ul>
{{#if (isCollection @item)}}
{{#each @item.pages as |page|}}
<li>
{{#if (isCollection page)}}
{{page.name}}
{{/if}}
<Pages @item={{page}} />
</li>
{{/each}}
{{else}}
<a href={{@item.path}}>{{nameFor @item}}</a>
{{/if}}
</ul>
</template>;
export class TopNav extends Component {
@service('kolay/docs') declare docs: DocsService;
@service declare router: RouterService;
get groups() {
return this.docs.availableGroups.map((groupName) => {
if (groupName === 'root') return { text: 'Home', value: '/' };
return { text: groupName, value: `/${groupName}` };
});
}
isActive = (subPath: string) => {
if (subPath === '/') return false;
return this.router.currentURL?.startsWith(subPath);
};
<template>
<nav id="group-nav">
<ul>
{{#each this.groups as |group|}}
<li>
<a href={{group.value}} class={{if (this.isActive group.value) "active"}}>
{{group.text}}
</a>
</li>
{{/each}}
</ul>
</nav>
</template>
}