Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit d7fe664

Browse files
arutkowski00benjaminforras
authored andcommitted
feat(sidebar): add canCloseSidebar input
It allows to prevent closing sidebar when sidebar-sibling is clicked
1 parent c36ec42 commit d7fe664

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/modules/sidebar/components/sidebar-sibling.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,67 @@ import { Component, ElementRef, HostBinding, HostListener, Input, Renderer2 } fr
22
import { SidebarService, SidebarTransition } from "../services/sidebar.service";
33

44
@Component({
5-
selector: "sui-sidebar-sibling",
6-
template: `<ng-content></ng-content>`,
7-
styles: [`
8-
:host {
9-
display: block;
10-
}
11-
`]
12-
})
5+
selector: "sui-sidebar-sibling",
6+
template: `
7+
<ng-content></ng-content>`,
8+
styles: [`
9+
:host {
10+
display: block;
11+
}
12+
`]
13+
})
1314
export class SuiSidebarSibling {
1415
@Input()
15-
public isDimmedWhenVisible: boolean;
16+
public isDimmedWhenVisible:boolean;
1617
@HostBinding("class.pusher")
17-
public readonly hasClasses: boolean;
18+
public readonly hasClasses:boolean;
1819

19-
constructor(private _renderer: Renderer2, private _element: ElementRef) {
20+
constructor(private _renderer:Renderer2, private _element:ElementRef) {
2021
this.isDimmedWhenVisible = false;
2122

2223
this.hasClasses = true;
2324
}
2425

25-
private _service: SidebarService;
26+
private _service:SidebarService;
2627

27-
public get service(): SidebarService {
28+
public get service():SidebarService {
2829
return this._service;
2930
}
3031

31-
public set service(service: SidebarService) {
32+
public set service(service:SidebarService) {
3233
this._service = service;
3334

3435
setTimeout(() => this.updateTransform());
3536
this._service.isVisibleChange.subscribe(() => this.updateTransform());
3637
}
3738

39+
@Input()
40+
public canCloseSidebar:boolean = true;
41+
3842
@HostBinding("class.visible")
39-
public get isVisible(): boolean {
43+
public get isVisible():boolean {
4044
if (!this.service) {
4145
return false;
4246
}
4347
return this.service.isVisible;
4448
}
4549

4650
@HostBinding("class.dimmed")
47-
public get isDimmed(): boolean {
51+
public get isDimmed():boolean {
4852
if (!this.service) {
4953
return false;
5054
}
5155
return this.service.isVisible && this.isDimmedWhenVisible;
5256
}
5357

5458
@HostListener("click", ["$event"])
55-
public onClick(event: MouseEvent): void {
56-
if (this.service.isVisible && !this.service.wasJustOpened) {
59+
public onClick(event:MouseEvent):void {
60+
if (this.canCloseSidebar && this.service.isVisible && !this.service.wasJustOpened) {
5761
this.service.setVisibleState(false);
5862
}
5963
}
6064

61-
private updateTransform(): void {
65+
private updateTransform():void {
6266
this._renderer.removeStyle(this._element.nativeElement, "transform");
6367
this._renderer.removeStyle(this._element.nativeElement, "-webkit-transform");
6468

0 commit comments

Comments
 (0)