sagittarius-admin-template 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ng-package.json +11 -0
- package/package.json +3 -12
- package/src/lib/sagittarius-admin/drawer-component/drawer-component.html +1 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-component.scss +0 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-component.spec.ts +54 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-component.ts +123 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.html +23 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.scss +103 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.spec.ts +63 -0
- package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.ts +67 -0
- package/src/lib/sagittarius-admin/drawer-ref.ts +26 -0
- package/src/lib/sagittarius-admin/drawer-service.ts +58 -0
- package/src/lib/sagittarius-admin/sagittarius-admin.html +150 -0
- package/src/lib/sagittarius-admin/sagittarius-admin.labels.ts +63 -0
- package/src/lib/sagittarius-admin/sagittarius-admin.models.ts +60 -0
- package/src/lib/sagittarius-admin/sagittarius-admin.scss +592 -0
- package/src/lib/sagittarius-admin/sagittarius-admin.spec.ts +45 -0
- package/src/lib/sagittarius-admin/sagittarius-admin.ts +159 -0
- package/src/public-api.ts +9 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +14 -0
- package/fesm2022/sagittarius-admin-template.mjs +0 -399
- package/fesm2022/sagittarius-admin-template.mjs.map +0 -1
- package/index.d.ts +0 -203
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sagittarius-admin-template",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Angular admin layout: collapsible sidebar, header with user menu, stacked drawers, footer, design tokens (light/dark) and page CSS utilities. Built on Angular Material 3.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -42,18 +42,9 @@
|
|
|
42
42
|
"./styles/*": {
|
|
43
43
|
"sass": "./styles/*",
|
|
44
44
|
"default": "./styles/*"
|
|
45
|
-
},
|
|
46
|
-
"./package.json": {
|
|
47
|
-
"default": "./package.json"
|
|
48
|
-
},
|
|
49
|
-
".": {
|
|
50
|
-
"types": "./index.d.ts",
|
|
51
|
-
"default": "./fesm2022/sagittarius-admin-template.mjs"
|
|
52
45
|
}
|
|
53
46
|
},
|
|
54
47
|
"sideEffects": [
|
|
55
48
|
"*.scss"
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
"typings": "index.d.ts"
|
|
59
|
-
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<ng-template #vc></ng-template>
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Component } from '@angular/core';
|
|
2
|
+
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
|
3
|
+
import { provideRouter } from '@angular/router';
|
|
4
|
+
import { DrawerService } from '../drawer-service';
|
|
5
|
+
|
|
6
|
+
import { DrawerComponent } from './drawer-component';
|
|
7
|
+
|
|
8
|
+
describe('DrawerComponent', () => {
|
|
9
|
+
let component: DrawerComponent;
|
|
10
|
+
let fixture: ComponentFixture<DrawerComponent>;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
await TestBed.configureTestingModule({
|
|
14
|
+
imports: [DrawerComponent]
|
|
15
|
+
})
|
|
16
|
+
.compileComponents();
|
|
17
|
+
|
|
18
|
+
fixture = TestBed.createComponent(DrawerComponent);
|
|
19
|
+
component = fixture.componentInstance;
|
|
20
|
+
fixture.detectChanges();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should create', () => {
|
|
24
|
+
expect(component).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
@Component({ template: 'layer' })
|
|
29
|
+
class TestLayer {}
|
|
30
|
+
|
|
31
|
+
describe('DrawerComponent – zatváranie vrstvy', () => {
|
|
32
|
+
it('vrstvu zničí až po animácii odchodu a drawer zavrie po poslednej vrstve', fakeAsync(() => {
|
|
33
|
+
TestBed.configureTestingModule({ imports: [DrawerComponent], providers: [provideRouter([])] });
|
|
34
|
+
const fixture = TestBed.createComponent(DrawerComponent);
|
|
35
|
+
fixture.detectChanges();
|
|
36
|
+
const service = TestBed.inject(DrawerService);
|
|
37
|
+
const closeSpy = spyOn(service, 'close');
|
|
38
|
+
const host: HTMLElement = fixture.nativeElement.parentElement;
|
|
39
|
+
|
|
40
|
+
fixture.componentInstance.loadComponent(TestLayer);
|
|
41
|
+
fixture.componentInstance.close();
|
|
42
|
+
fixture.detectChanges();
|
|
43
|
+
|
|
44
|
+
// počas animácie je vrstva ešte v DOM s triedou .leaving a drawer je otvorený
|
|
45
|
+
tick(100);
|
|
46
|
+
expect(host.querySelector('.sg-admin-theme-drawer-wrapper.leaving')).not.toBeNull();
|
|
47
|
+
expect(closeSpy).not.toHaveBeenCalled();
|
|
48
|
+
|
|
49
|
+
tick(300);
|
|
50
|
+
fixture.detectChanges();
|
|
51
|
+
expect(host.querySelectorAll('.sg-admin-theme-drawer-wrapper').length).toBe(0);
|
|
52
|
+
expect(closeSpy).toHaveBeenCalledTimes(1);
|
|
53
|
+
}));
|
|
54
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Component, ComponentRef, DestroyRef, Injector, Type, ViewChild, ViewContainerRef, inject, reflectComponentType } from '@angular/core';
|
|
2
|
+
import { PlatformLocation } from '@angular/common';
|
|
3
|
+
import { NavigationStart, Router } from '@angular/router';
|
|
4
|
+
import { filter } from 'rxjs';
|
|
5
|
+
import { DrawerContent } from './drawer-content/drawer-content';
|
|
6
|
+
import { DrawerService } from '../drawer-service';
|
|
7
|
+
import { DrawerRef } from '../drawer-ref';
|
|
8
|
+
import { DrawerData, DrawerOptions } from '../sagittarius-admin.models';
|
|
9
|
+
|
|
10
|
+
interface DrawerLayer {
|
|
11
|
+
wrapper: ComponentRef<DrawerContent>;
|
|
12
|
+
component: ComponentRef<unknown>;
|
|
13
|
+
drawerRef: DrawerRef;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Component({
|
|
17
|
+
selector: 'lib-drawer-component',
|
|
18
|
+
imports: [],
|
|
19
|
+
templateUrl: './drawer-component.html',
|
|
20
|
+
styleUrl: './drawer-component.scss'
|
|
21
|
+
})
|
|
22
|
+
export class DrawerComponent {
|
|
23
|
+
@ViewChild('vc', { read: ViewContainerRef, static: true }) vc!: ViewContainerRef;
|
|
24
|
+
|
|
25
|
+
private readonly drawerService = inject(DrawerService);
|
|
26
|
+
private readonly injector = inject(Injector);
|
|
27
|
+
private readonly layers: DrawerLayer[] = [];
|
|
28
|
+
/** Vrstvy, ktoré práve dobiehajú animáciu odchodu. */
|
|
29
|
+
private readonly leaving = new Set<ComponentRef<DrawerContent>>();
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
const location = inject(PlatformLocation);
|
|
33
|
+
const destroyRef = inject(DestroyRef);
|
|
34
|
+
|
|
35
|
+
// Späť v prehliadači zatvorí vrchnú vrstvu
|
|
36
|
+
const unlisten = location.onPopState(() => this.close());
|
|
37
|
+
|
|
38
|
+
// Navigácia v aplikácii (napr. klik v menu) zatvorí všetky vrstvy
|
|
39
|
+
const sub = inject(Router, { optional: true })?.events
|
|
40
|
+
.pipe(filter((e): e is NavigationStart => e instanceof NavigationStart && e.navigationTrigger === 'imperative'))
|
|
41
|
+
.subscribe(() => this.closeAll());
|
|
42
|
+
|
|
43
|
+
destroyRef.onDestroy(() => {
|
|
44
|
+
unlisten();
|
|
45
|
+
sub?.unsubscribe();
|
|
46
|
+
this.layers.forEach(l => l.wrapper.destroy());
|
|
47
|
+
this.leaving.forEach(w => w.destroy());
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
close() {
|
|
52
|
+
const layer = this.layers.pop();
|
|
53
|
+
if (!layer) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const wrapper = layer.wrapper;
|
|
57
|
+
this.leaving.add(wrapper);
|
|
58
|
+
wrapper.instance.leave().then(() => {
|
|
59
|
+
if (!this.leaving.delete(wrapper)) {
|
|
60
|
+
return; // už zničená cez closeAll / destroy
|
|
61
|
+
}
|
|
62
|
+
wrapper.destroy();
|
|
63
|
+
// medzitým mohla byť otvorená nová vrstva – vtedy drawer nezatváraj
|
|
64
|
+
if (!this.layers.length) {
|
|
65
|
+
this.drawerService.close();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
closeAll() {
|
|
71
|
+
// navigácia na inú stránku – vrstvy zmiznú hneď, aj tie, čo práve odchádzajú
|
|
72
|
+
const hadLeaving = this.leaving.size > 0;
|
|
73
|
+
this.leaving.forEach(w => w.destroy());
|
|
74
|
+
this.leaving.clear();
|
|
75
|
+
if (!this.layers.length && !hadLeaving) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
while (this.layers.length) {
|
|
79
|
+
this.layers.pop()!.wrapper.destroy();
|
|
80
|
+
}
|
|
81
|
+
this.drawerService.close();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
loadComponent<T>(component: Type<T>, data?: DrawerData<T>, options?: DrawerOptions): { component: ComponentRef<T>, drawerRef: DrawerRef } {
|
|
85
|
+
const drawerRef = new DrawerRef(() => window.history.back());
|
|
86
|
+
drawerRef.setTitle(options?.title ?? '');
|
|
87
|
+
drawerRef.setFullPageUrl(options?.fullPageUrl ?? null);
|
|
88
|
+
|
|
89
|
+
const wrapper = this.vc.createComponent(DrawerContent);
|
|
90
|
+
wrapper.setInput('pos', this.layers.length);
|
|
91
|
+
wrapper.setInput('drawerRef', drawerRef);
|
|
92
|
+
if (options?.fullPageIcon) {
|
|
93
|
+
wrapper.setInput('fullPageIcon', options.fullPageIcon);
|
|
94
|
+
}
|
|
95
|
+
if (options?.fullPageLabel) {
|
|
96
|
+
wrapper.setInput('fullPageLabel', options.fullPageLabel);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const injector = Injector.create({
|
|
100
|
+
providers: [{ provide: DrawerRef, useValue: drawerRef }],
|
|
101
|
+
parent: this.injector,
|
|
102
|
+
});
|
|
103
|
+
const comp = wrapper.instance.loadComponent(component, injector);
|
|
104
|
+
|
|
105
|
+
if (data) {
|
|
106
|
+
const inputs = new Set(reflectComponentType(component)?.inputs.map(i => i.templateName) ?? []);
|
|
107
|
+
for (const [key, value] of Object.entries(data)) {
|
|
108
|
+
if (inputs.has(key)) {
|
|
109
|
+
comp.setInput(key, value);
|
|
110
|
+
} else {
|
|
111
|
+
(comp.instance as Record<string, unknown>)[key] = value;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Spätná kompatibilita: komponent bez vlastnej metódy close() dostane close z drawera
|
|
115
|
+
if (!('close' in (comp.instance as object))) {
|
|
116
|
+
(comp.instance as Record<string, unknown>)['close'] = () => drawerRef.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.layers.push({ wrapper, component: comp, drawerRef });
|
|
121
|
+
return { component: comp, drawerRef };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<div class="sg-admin-theme-drawer-wrapper" [class.animating]="animating()" [class.leaving]="leaving()" [attr.inert]="leaving() ? '' : null" (animationend)="onAnimationEnd($event)">
|
|
2
|
+
<div class="sg-admin-theme-drawer-header">
|
|
3
|
+
<div class="sg-admin-theme-drawer-close">
|
|
4
|
+
<button matIconButton (click)="close()" [attr.aria-label]="pos() ? labels.drawerBack : labels.drawerClose">
|
|
5
|
+
<mat-icon>{{ pos() ? 'arrow_back' : 'close' }}</mat-icon>
|
|
6
|
+
</button>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="sg-admin-theme-drawer-title">{{ drawerRef().title() }}</div>
|
|
9
|
+
<div class="sg-admin-theme-drawer-actions">
|
|
10
|
+
@if (drawerRef().fullPageUrl(); as url) {
|
|
11
|
+
<!-- routerLink = imperatívna navigácia -> DrawerComponent zavrie všetky vrstvy;
|
|
12
|
+
replaceUrl nahradí záznam histórie drawera, takže Späť vedie na pôvodnú stránku -->
|
|
13
|
+
<a matIconButton class="sg-admin-theme-drawer-full-page" [routerLink]="url" [replaceUrl]="true"
|
|
14
|
+
[matTooltip]="fullPageLabel()" [attr.aria-label]="fullPageLabel()">
|
|
15
|
+
<mat-icon>{{ fullPageIcon() }}</mat-icon>
|
|
16
|
+
</a>
|
|
17
|
+
}
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="sg-admin-theme-drawer-body">
|
|
21
|
+
<ng-template #vc></ng-template>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: contents;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
* {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sg-admin-theme-drawer-wrapper {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
position: absolute;
|
|
13
|
+
inset: 0;
|
|
14
|
+
z-index: 9;
|
|
15
|
+
background: var(--sg-bg);
|
|
16
|
+
animation: sg-drawer-in 220ms cubic-bezier(0.2, 0, 0, 1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.sg-admin-theme-drawer-header {
|
|
20
|
+
min-height: var(--sg-drawer-header-height);
|
|
21
|
+
max-height: var(--sg-drawer-header-height);
|
|
22
|
+
display: flex;
|
|
23
|
+
gap: 8px;
|
|
24
|
+
padding: 0 12px 0 6px;
|
|
25
|
+
align-items: center;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
background: var(--sg-surface);
|
|
28
|
+
border-bottom: 1px solid var(--sg-border);
|
|
29
|
+
position: relative;
|
|
30
|
+
z-index: 1;
|
|
31
|
+
|
|
32
|
+
.sg-admin-theme-drawer-close button,
|
|
33
|
+
.sg-admin-theme-drawer-full-page {
|
|
34
|
+
color: var(--sg-text-muted);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.sg-admin-theme-drawer-title {
|
|
38
|
+
flex-grow: 1;
|
|
39
|
+
font-size: 16px;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
color: var(--sg-text);
|
|
42
|
+
white-space: nowrap;
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.sg-admin-theme-drawer-actions {
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.sg-admin-theme-drawer-body {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
flex-grow: 1;
|
|
58
|
+
overflow: auto;
|
|
59
|
+
scrollbar-width: thin;
|
|
60
|
+
scrollbar-color: var(--sg-scrollbar) transparent;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@keyframes sg-drawer-in {
|
|
64
|
+
from {
|
|
65
|
+
transform: translateX(24px);
|
|
66
|
+
opacity: 0;
|
|
67
|
+
}
|
|
68
|
+
to {
|
|
69
|
+
transform: none;
|
|
70
|
+
opacity: 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@keyframes sg-drawer-out {
|
|
75
|
+
from {
|
|
76
|
+
transform: none;
|
|
77
|
+
opacity: 1;
|
|
78
|
+
}
|
|
79
|
+
to {
|
|
80
|
+
transform: translateX(24px);
|
|
81
|
+
opacity: 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.sg-admin-theme-drawer-wrapper.leaving {
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
animation: sg-drawer-out 180ms cubic-bezier(0.3, 0, 1, 1) forwards;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// počas animácie otvárania/zatvárania skry scrollbar tela (inak na chvíľu preblikne)
|
|
91
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
92
|
+
.sg-admin-theme-drawer-wrapper.animating .sg-admin-theme-drawer-body,
|
|
93
|
+
.sg-admin-theme-drawer-wrapper.leaving .sg-admin-theme-drawer-body {
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@media (prefers-reduced-motion: reduce) {
|
|
99
|
+
.sg-admin-theme-drawer-wrapper,
|
|
100
|
+
.sg-admin-theme-drawer-wrapper.leaving {
|
|
101
|
+
animation: none;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { provideRouter } from '@angular/router';
|
|
3
|
+
|
|
4
|
+
import { DrawerContent } from './drawer-content';
|
|
5
|
+
import { DrawerRef } from '../../drawer-ref';
|
|
6
|
+
import { SG_ADMIN_LABELS_SK, provideSgAdminLabels } from '../../sagittarius-admin.labels';
|
|
7
|
+
|
|
8
|
+
describe('DrawerContent', () => {
|
|
9
|
+
let component: DrawerContent;
|
|
10
|
+
let fixture: ComponentFixture<DrawerContent>;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
await TestBed.configureTestingModule({
|
|
14
|
+
imports: [DrawerContent],
|
|
15
|
+
providers: [provideRouter([])],
|
|
16
|
+
})
|
|
17
|
+
.compileComponents();
|
|
18
|
+
|
|
19
|
+
fixture = TestBed.createComponent(DrawerContent);
|
|
20
|
+
fixture.componentRef.setInput('drawerRef', new DrawerRef(() => {}));
|
|
21
|
+
component = fixture.componentInstance;
|
|
22
|
+
fixture.detectChanges();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should create', () => {
|
|
26
|
+
expect(component).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('bez fullPageUrl nezobrazí ikonu celej stránky', () => {
|
|
30
|
+
expect(fixture.nativeElement.querySelector('.sg-admin-theme-drawer-full-page')).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('s fullPageUrl zobrazí odkaz na celú stránku', () => {
|
|
34
|
+
component.drawerRef().setFullPageUrl(['/users', 42]);
|
|
35
|
+
fixture.detectChanges();
|
|
36
|
+
const link: HTMLAnchorElement = fixture.nativeElement.querySelector('.sg-admin-theme-drawer-full-page');
|
|
37
|
+
expect(link).not.toBeNull();
|
|
38
|
+
expect(link.getAttribute('href')).toBe('/users/42');
|
|
39
|
+
expect(link.getAttribute('aria-label')).toBe('Open as full page');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('fullPageLabel prebije predvolený text', () => {
|
|
43
|
+
fixture.componentRef.setInput('fullPageLabel', 'Detail');
|
|
44
|
+
component.drawerRef().setFullPageUrl('/users/42');
|
|
45
|
+
fixture.detectChanges();
|
|
46
|
+
const link: HTMLAnchorElement = fixture.nativeElement.querySelector('.sg-admin-theme-drawer-full-page');
|
|
47
|
+
expect(link.getAttribute('aria-label')).toBe('Detail');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('DrawerContent s provideSgAdminLabels', () => {
|
|
52
|
+
it('použije zadané texty', async () => {
|
|
53
|
+
await TestBed.configureTestingModule({
|
|
54
|
+
imports: [DrawerContent],
|
|
55
|
+
providers: [provideRouter([]), provideSgAdminLabels(SG_ADMIN_LABELS_SK)],
|
|
56
|
+
}).compileComponents();
|
|
57
|
+
const fixture = TestBed.createComponent(DrawerContent);
|
|
58
|
+
fixture.componentRef.setInput('drawerRef', new DrawerRef(() => {}));
|
|
59
|
+
fixture.detectChanges();
|
|
60
|
+
const button: HTMLButtonElement = fixture.nativeElement.querySelector('.sg-admin-theme-drawer-close button');
|
|
61
|
+
expect(button.getAttribute('aria-label')).toBe('Zavrieť');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Component, ComponentRef, Injector, Type, ViewChild, ViewContainerRef, computed, inject, input, signal } from '@angular/core';
|
|
2
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
3
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
4
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
5
|
+
import { RouterLink } from '@angular/router';
|
|
6
|
+
import { DrawerRef } from '../../drawer-ref';
|
|
7
|
+
import { SG_ADMIN_LABELS } from '../../sagittarius-admin.labels';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'lib-drawer-content',
|
|
11
|
+
imports: [
|
|
12
|
+
MatIconModule,
|
|
13
|
+
MatButtonModule,
|
|
14
|
+
MatTooltipModule,
|
|
15
|
+
RouterLink,
|
|
16
|
+
],
|
|
17
|
+
templateUrl: './drawer-content.html',
|
|
18
|
+
styleUrl: './drawer-content.scss'
|
|
19
|
+
})
|
|
20
|
+
export class DrawerContent {
|
|
21
|
+
@ViewChild('vc', { read: ViewContainerRef, static: true }) vc!: ViewContainerRef;
|
|
22
|
+
|
|
23
|
+
protected readonly labels = inject(SG_ADMIN_LABELS);
|
|
24
|
+
|
|
25
|
+
readonly pos = input(0);
|
|
26
|
+
readonly drawerRef = input.required<DrawerRef>();
|
|
27
|
+
readonly fullPageIcon = input('open_in_full');
|
|
28
|
+
/** Ak chýba, použije sa `SgAdminLabels.drawerFullPage`. */
|
|
29
|
+
readonly fullPageLabelInput = input<string | undefined>(undefined, { alias: 'fullPageLabel' });
|
|
30
|
+
readonly fullPageLabel = computed(() => this.fullPageLabelInput() ?? this.labels.drawerFullPage);
|
|
31
|
+
readonly animating = signal(true);
|
|
32
|
+
/** Vrstva práve odchádza (animácia zatvárania). */
|
|
33
|
+
readonly leaving = signal(false);
|
|
34
|
+
private leaveDone?: () => void;
|
|
35
|
+
|
|
36
|
+
loadComponent<T>(component: Type<T>, injector: Injector): ComponentRef<T> {
|
|
37
|
+
this.vc.clear();
|
|
38
|
+
return this.vc.createComponent(component, { injector });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onAnimationEnd(event: AnimationEvent) {
|
|
42
|
+
// animationend bubble-uje aj z obsahu – reaguj len na vlastnú animáciu
|
|
43
|
+
if (event.target === event.currentTarget) {
|
|
44
|
+
this.animating.set(false);
|
|
45
|
+
if (this.leaving()) {
|
|
46
|
+
this.leaveDone?.();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Spustí animáciu odchodu; promise sa splní po jej skončení (pri reduced motion hneď). */
|
|
52
|
+
leave(): Promise<void> {
|
|
53
|
+
if (typeof window === 'undefined' || window.matchMedia?.('(prefers-reduced-motion: reduce)').matches) {
|
|
54
|
+
return Promise.resolve();
|
|
55
|
+
}
|
|
56
|
+
this.leaving.set(true);
|
|
57
|
+
return new Promise(resolve => {
|
|
58
|
+
this.leaveDone = resolve;
|
|
59
|
+
// poistka, ak animationend nepríde (napr. skrytý tab)
|
|
60
|
+
setTimeout(resolve, 300);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
close() {
|
|
65
|
+
this.drawerRef().close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { signal } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Referencia na otvorený drawer. Komponent zobrazený v draweri ju získa cez `inject(DrawerRef)`.
|
|
5
|
+
*/
|
|
6
|
+
export class DrawerRef {
|
|
7
|
+
readonly title = signal('');
|
|
8
|
+
/** URL samostatnej stránky; ak je nastavená, hlavička drawera zobrazí ikonu na jej otvorenie. */
|
|
9
|
+
readonly fullPageUrl = signal<string | any[] | null>(null);
|
|
10
|
+
|
|
11
|
+
constructor(private readonly closeFn: () => void) {}
|
|
12
|
+
|
|
13
|
+
/** Zatvorí tento drawer (krok späť v histórii prehliadača). */
|
|
14
|
+
close(): void {
|
|
15
|
+
this.closeFn();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setTitle(title: string): void {
|
|
19
|
+
this.title.set(title);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Nastaví (alebo `null` = skryje) odkaz na samostatnú stránku v hlavičke drawera. */
|
|
23
|
+
setFullPageUrl(url: string | any[] | null): void {
|
|
24
|
+
this.fullPageUrl.set(url);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Injectable, Type } from '@angular/core';
|
|
2
|
+
import { Location } from '@angular/common';
|
|
3
|
+
import type { DrawerComponent } from './drawer-component/drawer-component';
|
|
4
|
+
import type { SagittariusAdmin } from './sagittarius-admin';
|
|
5
|
+
import { DrawerRef } from './drawer-ref';
|
|
6
|
+
import { DrawerData, DrawerOptions } from './sagittarius-admin.models';
|
|
7
|
+
|
|
8
|
+
@Injectable({
|
|
9
|
+
providedIn: 'root'
|
|
10
|
+
})
|
|
11
|
+
export class DrawerService {
|
|
12
|
+
private host?: DrawerComponent;
|
|
13
|
+
private app?: SagittariusAdmin;
|
|
14
|
+
|
|
15
|
+
constructor(private location: Location) { }
|
|
16
|
+
|
|
17
|
+
setHost(component: DrawerComponent, app: SagittariusAdmin) {
|
|
18
|
+
this.host = component;
|
|
19
|
+
this.app = app;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Otvorí komponent v draweri nad obsahom. Každé ďalšie volanie pridá novú vrstvu.
|
|
24
|
+
* Otvorenie pridá záznam do histórie, takže tlačidlo Späť v prehliadači zatvorí vrchnú vrstvu.
|
|
25
|
+
*
|
|
26
|
+
* @param data vstupy komponentu (signal `input()` aj bežné properties)
|
|
27
|
+
*/
|
|
28
|
+
open<T>(
|
|
29
|
+
component: Type<T>,
|
|
30
|
+
data?: DrawerData<T>,
|
|
31
|
+
options?: DrawerOptions
|
|
32
|
+
): { componentInstance: T, drawerRef: DrawerRef, close: () => void } {
|
|
33
|
+
if (!this.host || !this.app) {
|
|
34
|
+
throw new Error('Drawer host not initialized - <lib-sagittarius-admin> must be rendered');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { component: compRef, drawerRef } = this.host.loadComponent(component, data, options);
|
|
38
|
+
this.app.openDrawer();
|
|
39
|
+
this.location.go(this.location.path(true));
|
|
40
|
+
|
|
41
|
+
return { componentInstance: compRef.instance, drawerRef, close: () => drawerRef.close() };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Zatvorí vrchnú vrstvu drawera. */
|
|
45
|
+
closeTop() {
|
|
46
|
+
this.location.back();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Zatvorí všetky vrstvy (bez práce s históriou). */
|
|
50
|
+
closeAll() {
|
|
51
|
+
this.host?.closeAll();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @internal volá DrawerComponent, keď zanikne posledná vrstva */
|
|
55
|
+
close() {
|
|
56
|
+
this.app?.closeDrawer();
|
|
57
|
+
}
|
|
58
|
+
}
|