diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html
new file mode 100644
index 000000000..b3e4b6b3e
--- /dev/null
+++ b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.scss b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts
index f1b12c95e..0ed02a91e 100644
--- a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts
+++ b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts
@@ -6,155 +6,120 @@ import {filter} from 'rxjs/operators';
import {MenuService} from './service/app.menu.service';
import {AsyncPipe, NgClass, NgForOf, NgIf} from '@angular/common';
import {Ripple} from 'primeng/ripple';
+import {Button} from 'primeng/button';
@Component({
- selector: '[app-menuitem]',
- template: `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- `,
- imports: [
- RouterLink,
- RouterLinkActive,
- NgClass,
- NgForOf,
- Ripple,
- NgIf,
- AsyncPipe
- ],
- animations: [
- trigger('children', [
- state('collapsed', style({
- height: '0'
- })),
- state('expanded', style({
- height: '*'
- })),
- transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
- ])
- ]
+ selector: '[app-menuitem]',
+ templateUrl: './app.menuitem.component.html',
+ styleUrl: './app.menuitem.component.scss',
+ imports: [
+ RouterLink,
+ RouterLinkActive,
+ NgClass,
+ NgForOf,
+ Ripple,
+ NgIf,
+ AsyncPipe,
+ Button
+ ],
+ animations: [
+ trigger('children', [
+ state('collapsed', style({
+ height: '0'
+ })),
+ state('expanded', style({
+ height: '*'
+ })),
+ transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
+ ])
+ ]
})
export class AppMenuitemComponent implements OnInit, OnDestroy {
- @Input() item: any;
- @Input() index!: number;
- @Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
- @Input() parentKey!: string;
+ @Input() item: any;
+ @Input() index!: number;
+ @Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
+ @Input() parentKey!: string;
- active = false;
- menuSourceSubscription: Subscription;
- menuResetSubscription: Subscription;
- key: string = "";
+ hovered = false;
- constructor(public router: Router, private menuService: MenuService) {
- this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
- Promise.resolve(null).then(() => {
- if (value.routeEvent) {
- this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
- } else {
- if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
+ active = false;
+ menuSourceSubscription: Subscription;
+ menuResetSubscription: Subscription;
+ key: string = "";
+
+ constructor(public router: Router, private menuService: MenuService) {
+ this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
+ Promise.resolve(null).then(() => {
+ if (value.routeEvent) {
+ this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
+ } else {
+ if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
+ this.active = false;
+ }
+ }
+ });
+ });
+
+ this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
this.active = false;
- }
- }
- });
- });
+ });
- this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
- this.active = false;
- });
+ this.router.events.pipe(filter(event => event instanceof NavigationEnd))
+ .subscribe(() => {
+ if (this.item.routerLink) {
+ this.updateActiveStateFromRoute();
+ }
+ });
+ }
- this.router.events.pipe(filter(event => event instanceof NavigationEnd))
- .subscribe(() => {
+ ngOnInit() {
+ this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
if (this.item.routerLink) {
- this.updateActiveStateFromRoute();
+ this.updateActiveStateFromRoute();
}
- });
- }
+ }
- ngOnInit() {
- this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
- if (this.item.routerLink) {
- this.updateActiveStateFromRoute();
+ updateActiveStateFromRoute() {
+ const activeRoute = this.router.isActive(this.item.routerLink[0], {
+ paths: 'exact',
+ queryParams: 'ignored',
+ matrixParams: 'ignored',
+ fragment: 'ignored'
+ });
+ if (activeRoute) {
+ this.menuService.onMenuStateChange({key: this.key, routeEvent: true});
+ }
}
- }
- updateActiveStateFromRoute() {
- const activeRoute = this.router.isActive(this.item.routerLink[0], {
- paths: 'exact',
- queryParams: 'ignored',
- matrixParams: 'ignored',
- fragment: 'ignored'
- });
- if (activeRoute) {
- this.menuService.onMenuStateChange({key: this.key, routeEvent: true});
+ itemClick(event: Event) {
+ if (this.item.disabled) {
+ event.preventDefault();
+ return;
+ }
+ if (this.item.command) {
+ this.item.command({originalEvent: event, item: this.item});
+ }
+ if (this.item.items) {
+ this.active = !this.active;
+ }
+ this.menuService.onMenuStateChange({key: this.key});
}
- }
- itemClick(event: Event) {
- if (this.item.disabled) {
- event.preventDefault();
- return;
+ get submenuAnimation() {
+ return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
}
- if (this.item.command) {
- this.item.command({originalEvent: event, item: this.item});
- }
- if (this.item.items) {
- this.active = !this.active;
- }
- this.menuService.onMenuStateChange({key: this.key});
- }
- get submenuAnimation() {
- return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
- }
-
- @HostBinding('class.active-menuitem')
- get activeClass() {
- return this.active && !this.root;
- }
-
- ngOnDestroy() {
- if (this.menuSourceSubscription) {
- this.menuSourceSubscription.unsubscribe();
+ @HostBinding('class.active-menuitem')
+ get activeClass() {
+ return this.active && !this.root;
}
- if (this.menuResetSubscription) {
- this.menuResetSubscription.unsubscribe();
+
+ ngOnDestroy() {
+ if (this.menuSourceSubscription) {
+ this.menuSourceSubscription.unsubscribe();
+ }
+ if (this.menuResetSubscription) {
+ this.menuResetSubscription.unsubscribe();
+ }
}
- }
}