Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 9b81985

Browse files
committed
feat: add nav-list-item component
1 parent 3408d45 commit 9b81985

22 files changed

Lines changed: 340 additions & 4 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dev-demo",
33
"description": "DevIntent Application Development Tools",
4-
"version": "0.6.0",
4+
"version": "0.7.0",
55
"repository": "https://github.com/DevIntent/dev",
66
"homepage": "https://devintent-dev.web.app",
77
"bugs": "https://github.com/DevIntent/dev/issues",

projects/dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devintent/dev",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Application Development Library",
55
"keywords": [
66
"material", "design", "angular", "material design", "components"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface NavItem {
22
label: string;
3-
path: string;
3+
path?: string;
44
iconName: string;
55
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NavItem } from './nav-item';
2+
3+
export interface NestedNavItem extends NavItem {
4+
children: NestedNavItem[];
5+
}

projects/dev/src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Import library functions for theme creation.
22
@import '../../button-bar/button-bar-theme';
3+
@import '../../nav-list-item/nav-list-item-theme';
34

45
// Define a mixin that accepts a theme and outputs the theme-specific styles.
56
@mixin dev-theme($theme) {
@@ -12,6 +13,7 @@
1213
//$background: map-get($theme, background);
1314

1415
@include dev-button-bar-theme($theme);
16+
@include dev-nav-list-item-theme($theme);
1517
}
1618

1719
// TODO allow customizing some component typography
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@import '~@angular/material/theming';
2+
3+
@mixin dev-nav-list-item-theme($theme) {
4+
$primary: map-get($theme, primary);
5+
6+
dev-nav-list-item {
7+
.mat-list-item {
8+
&.active {
9+
background-color: mat-color($primary, 50);
10+
}
11+
}
12+
&:hover,
13+
&:focus {
14+
> .mat-list-item:not(.expanded) {
15+
background-color: mat-color($primary, 100);
16+
}
17+
}
18+
}
19+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Injectable } from '@angular/core';
2+
import { MatDrawer } from '@angular/material/sidenav';
3+
import { NavigationEnd, Router } from '@angular/router';
4+
import { BehaviorSubject, Observable } from 'rxjs';
5+
6+
@Injectable()
7+
export class DevNavService {
8+
private _appDrawer: MatDrawer | null = null;
9+
private _currentUrl = new BehaviorSubject<string>('');
10+
get currentUrl(): Observable<string> {
11+
return this._currentUrl.asObservable();
12+
}
13+
14+
constructor(private router: Router) {
15+
this.router.events.subscribe(event => {
16+
if (event instanceof NavigationEnd) {
17+
this._currentUrl.next(event.urlAfterRedirects);
18+
}
19+
});
20+
}
21+
22+
public closeNav(): Promise<'open' | 'close' | null> {
23+
if (this._appDrawer) {
24+
if (!this._appDrawer.disableClose) {
25+
return this._appDrawer.close();
26+
} else {
27+
return Promise.resolve<null>(null);
28+
}
29+
} else {
30+
return Promise.reject<null>('appDrawer has not been set.');
31+
}
32+
}
33+
34+
get appDrawer(): MatDrawer | null {
35+
return this._appDrawer;
36+
}
37+
38+
set appDrawer(value: MatDrawer | null) {
39+
this._appDrawer = value;
40+
}
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './public-api';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<a
2+
mat-list-item
3+
[ngStyle]="{ 'padding-left': depth * 12 + 'px' }"
4+
(click)="onItemSelected(item)"
5+
*ngIf="item"
6+
[ngClass]="{ active: item.path ? router.isActive(item.path, true) : false, expanded: expanded }"
7+
>
8+
<mat-icon class="dev-path-icon">{{ item.iconName }}</mat-icon>
9+
{{ item.label }}
10+
<span class="dev-caret-container" *ngIf="item.children && item.children.length">
11+
<mat-icon [@indicatorRotate]="expanded ? 'expanded' : 'collapsed'">
12+
expand_more
13+
</mat-icon>
14+
</span>
15+
</a>
16+
<div *ngIf="item && expanded">
17+
<dev-nav-list-item *ngFor="let child of item.children" [item]="child" [depth]="depth + 1"> </dev-nav-list-item>
18+
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@import '~@angular/material/theming';
2+
3+
dev-nav-list-item {
4+
display: flex;
5+
flex-direction: column;
6+
outline: none;
7+
width: 100%;
8+
9+
.mat-list-item {
10+
padding: 8px 0;
11+
display: flex;
12+
width: auto;
13+
14+
.dev-path-icon {
15+
margin-right: 40px;
16+
}
17+
.dev-caret-container {
18+
flex: auto;
19+
display: flex;
20+
justify-content: flex-end;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)