Skip to content

Commit 81f3388

Browse files
committed
refactor(Sidebar): inject SidebarService, subscribe and toggle action events
1 parent 0f65877 commit 81f3388

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

projects/coreui/angular/src/lib/sidebar/app-sidebar.component.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { DOCUMENT } from '@angular/common';
22
import { Component, EventEmitter, HostBinding, Inject, Input, OnDestroy, OnInit, Output, Renderer2 } from '@angular/core';
3+
import { Subscription } from 'rxjs';
4+
35
import { sidebarCssClasses } from '../shared';
6+
import { AppSidebarService } from './app-sidebar.service';
47

58
@Component({
69
selector: 'app-sidebar, cui-sidebar',
710
template: `<ng-content></ng-content>`
811
})
912
export class AppSidebarComponent implements OnInit, OnDestroy {
13+
14+
private subscriptionEvents: Subscription;
15+
private _minimized = false;
16+
1017
@Input() compact: boolean;
1118
@Input() display: any;
1219
@Input() fixed: boolean;
@@ -22,9 +29,9 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
2229
this._minimized = value;
2330
this._updateMinimized(value);
2431
this.minimizedChange.emit(value);
32+
this.sidebarService.toggle({ minimize: value } );
2533
}
2634
}
27-
private _minimized = false;
2835

2936
/**
3037
* Emits whenever the minimized state of the sidebar changes.
@@ -36,7 +43,8 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
3643

3744
constructor(
3845
@Inject(DOCUMENT) private document: any,
39-
private renderer: Renderer2
46+
private renderer: Renderer2,
47+
private sidebarService: AppSidebarService
4048
) {
4149
}
4250

@@ -45,9 +53,15 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
4553
this.isCompact(this.compact);
4654
this.isFixed(this.fixed);
4755
this.isOffCanvas(this.offCanvas);
56+
this.subscriptionEvents = this.sidebarService.events$.subscribe(action => {
57+
if (action.minimize === 'toggle') {
58+
this.toggleMinimized();
59+
}
60+
});
4861
}
4962

5063
ngOnDestroy(): void {
64+
this.subscriptionEvents.unsubscribe();
5165
this.minimizedChange.complete();
5266
this.renderer.removeClass(this.document.body, 'sidebar-fixed');
5367
}

0 commit comments

Comments
 (0)