-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add menu items link active directive (#8)
- Loading branch information
Showing
10 changed files
with
89 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export const env = { | ||
production: true, | ||
api: { | ||
content: 'http://localhost:3000/content', | ||
account: 'http://localhost:3000/account', | ||
learning: 'http://localhost:3000/learning', | ||
book: 'http://localhost:3000/content/books', | ||
content: 'http://localhost:3000/api/content', | ||
account: 'http://localhost:3000/api/account', | ||
learning: 'http://localhost:3000/api/learning', | ||
book: 'http://localhost:3000/api/content/books', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './menu-items-link-active.directive' |
38 changes: 38 additions & 0 deletions
38
shared/ui-base/src/lib/directives/menu-items-link-active.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Input, Directive, DestroyRef, ElementRef} from '@angular/core' | ||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop' | ||
import {NavigationEnd, Router} from '@angular/router' | ||
import {filter} from 'rxjs' | ||
|
||
@Directive({ | ||
selector: '[devMenuLinkActive],[menuItemsLinkActive]', | ||
}) | ||
export class MenuItemsLinkActiveDirective { | ||
@Input({required: true}) | ||
menuItemsBaseLink = '' | ||
|
||
@Input({required: true}) | ||
menuItemsLinkActive = 'active' | ||
|
||
constructor( | ||
router: Router, | ||
destroyRef: DestroyRef, | ||
elementRef: ElementRef<HTMLButtonElement> | ||
) { | ||
router.events | ||
.pipe( | ||
filter((e) => e instanceof NavigationEnd), | ||
takeUntilDestroyed(destroyRef) | ||
) | ||
.subscribe(() => { | ||
if (router.url.startsWith(this.menuItemsBaseLink)) { | ||
elementRef.nativeElement.classList.add( | ||
this.menuItemsLinkActive ?? 'active' | ||
) | ||
} else { | ||
elementRef.nativeElement.classList.remove( | ||
this.menuItemsLinkActive ?? 'active' | ||
) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import {NgModule} from '@angular/core' | ||
import {CommonModule} from '@angular/common' | ||
import {RouterModule} from '@angular/router' | ||
import {MatButtonModule} from '@angular/material/button' | ||
import {MatMenuModule} from '@angular/material/menu' | ||
import {MatIconModule} from '@angular/material/icon' | ||
import {SelectionMenuComponent} from './components' | ||
import {MenuItemsLinkActiveDirective} from './directives' | ||
|
||
@NgModule({ | ||
imports: [CommonModule, MatButtonModule, MatIconModule, MatMenuModule], | ||
declarations: [SelectionMenuComponent], | ||
exports: [SelectionMenuComponent], | ||
imports: [ | ||
CommonModule, | ||
RouterModule, | ||
MatButtonModule, | ||
MatIconModule, | ||
MatMenuModule, | ||
], | ||
declarations: [SelectionMenuComponent, MenuItemsLinkActiveDirective], | ||
exports: [SelectionMenuComponent, MenuItemsLinkActiveDirective], | ||
}) | ||
export class UiBaseModule {} |
4 changes: 2 additions & 2 deletions
4
...src/generators/data-access/files/lib/infrastructure/__fileName__.service.mock.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...erators/entity/files/data-access/lib/infrastructure/__fileName__.service.mock.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters