-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtab-bar.component.ts
More file actions
79 lines (71 loc) · 1.97 KB
/
tab-bar.component.ts
File metadata and controls
79 lines (71 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {
ChangeDetectionStrategy,
Component,
computed,
HostBinding,
inject,
Signal
} from '@angular/core';
import { ApplicationService } from 'services/application/application.service';
import { UiService } from 'services/ui/ui.service';
import { STRUCTURE_MAP } from 'styles/structure';
export interface TabBarItem {
label: string;
id: number;
route: string;
focused: boolean;
}
@Component({
selector: 'cs-tab-bar',
templateUrl: './tab-bar.component.html',
styleUrl: './tab-bar.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TabBarComponent {
@HostBinding('style.height')
get height(): string {
return this.isHidden() ? '0px' : STRUCTURE_MAP['tab-bar-h'];
}
/**
* Gives the tabs-bar the applications to display.
*/
private applicationService = inject(ApplicationService);
/**
* Gives the tab bar notice of when breakpoints are hit.
*/
private uiService = inject(UiService);
/**
* The tabs-bar that should be displayed.
*/
tabs: Signal<TabBarItem[]> = computed(() => {
const result: TabBarItem[] = [];
const focusedApp = this.applicationService.focusedApplication()?.id;
for (const app of this.applicationService.runningApplications().values()) {
result.push({
label: app.label,
id: app.id,
route: app.route,
focused: focusedApp === app.id
});
}
return result;
});
/**
* Hide the tabs bar if the screen size is small and there are no applications running.
*/
isHidden: Signal<boolean> = computed(
() =>
!this.uiService.isLargeViewport() && this.applicationService.runningApplications().size === 0
);
focusTab(tab: TabBarItem): void {
this.applicationService.router.navigateByUrl(tab.route);
}
/**
* Informs the application service to close a tabs.
*
* @param index - The index of the tabs to close.
*/
closeTab(index: number): void {
this.applicationService.closeApplication(index);
}
}