sagittarius-admin-template 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +174 -2
- package/ng-package.json +11 -0
- package/package.json +48 -4
- 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/styles/sagittarius-admin.scss +496 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Marian Spisiak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sagittarius-admin-template
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Admin application layout for **Angular 20 + Angular Material 3**: collapsible sidebar (hover overlay on desktop, full-screen overlay on mobile), header with user menu, content area with **stacked drawers**, footer. Ships with design tokens (light/dark theme) and CSS utility classes for building pages.
|
|
4
|
+
|
|
5
|
+
- **Live demo:** https://majo32.github.io/sagittarius-admin-template/
|
|
6
|
+
- **Source & demo app:** https://github.com/majo32/sagittarius-admin-template
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i sagittarius-admin-template
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Peer dependencies: `@angular/core`, `@angular/common`, `@angular/router`, `@angular/material`, `@angular/cdk` (20.x).
|
|
15
|
+
|
|
16
|
+
`angular.json` → `styles` (template stylesheet before your own styles):
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
"styles": [
|
|
20
|
+
"node_modules/sagittarius-admin-template/styles/sagittarius-admin.scss",
|
|
21
|
+
"src/styles.scss"
|
|
22
|
+
]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`index.html` – fonts and icons:
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
29
|
+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`styles.scss` – Material theme (the primary color is picked up by the template as well):
|
|
33
|
+
|
|
34
|
+
```scss
|
|
35
|
+
@use '@angular/material' as mat;
|
|
36
|
+
|
|
37
|
+
html {
|
|
38
|
+
color-scheme: light;
|
|
39
|
+
@include mat.theme((color: (primary: mat.$azure-palette), typography: Roboto, density: 0));
|
|
40
|
+
|
|
41
|
+
&.dark-theme { color-scheme: dark; }
|
|
42
|
+
}
|
|
43
|
+
body { margin: 0; }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { SagittariusAdmin, SgMenuItem, SgUser, SgUserMenuItem } from 'sagittarius-admin-template';
|
|
50
|
+
|
|
51
|
+
@Component({
|
|
52
|
+
selector: 'app-root',
|
|
53
|
+
imports: [RouterOutlet, SagittariusAdmin],
|
|
54
|
+
template: `
|
|
55
|
+
<lib-sagittarius-admin appTitle="My application" [menuItems]="menu" [user]="user" [userMenuItems]="userMenu">
|
|
56
|
+
<div sg-admin-header-actions>…icon buttons…</div>
|
|
57
|
+
<router-outlet />
|
|
58
|
+
<span sg-admin-footer>© 2026 My Company</span>
|
|
59
|
+
</lib-sagittarius-admin>
|
|
60
|
+
`,
|
|
61
|
+
})
|
|
62
|
+
export class App {
|
|
63
|
+
menu: SgMenuItem[] = [
|
|
64
|
+
{ label: 'Dashboard', icon: 'space_dashboard', route: '/dashboard' },
|
|
65
|
+
{ label: 'Management', spacer: true },
|
|
66
|
+
{ label: 'Users', icon: 'group', route: '/users', badge: 3 },
|
|
67
|
+
];
|
|
68
|
+
user: SgUser = { name: 'Jane Doe', subtitle: 'Administrator' };
|
|
69
|
+
userMenu: SgUserMenuItem[] = [
|
|
70
|
+
{ label: 'Profile', icon: 'person', route: '/profile' },
|
|
71
|
+
{ divider: true },
|
|
72
|
+
{ label: 'Sign out', icon: 'logout', action: () => this.logout() },
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Inputs:** `appTitle`, `appShortTitle`, `logoUrl`, `homeRoute`, `menuItems`, `user`, `userMenuItems`, `persistSidebarState` (stores the collapsed state in `localStorage`).
|
|
78
|
+
**Outputs:** `userMenuItemClick`.
|
|
79
|
+
|
|
80
|
+
**Content slots** (attribute on the projected element):
|
|
81
|
+
|
|
82
|
+
| Slot | Position |
|
|
83
|
+
|---|---|
|
|
84
|
+
| *(none)* | main content – typically `<router-outlet />` |
|
|
85
|
+
| `sg-admin-header-left` | left part of the header (breadcrumbs, title) |
|
|
86
|
+
| `sg-admin-header-middle` | middle of the header |
|
|
87
|
+
| `sg-admin-header-actions` | right side of the header, before the avatar |
|
|
88
|
+
| `sg-admin-sidebar-bottom` | bottom of the sidebar below the menu |
|
|
89
|
+
| `sg-admin-footer` | footer (defaults to `appTitle`) |
|
|
90
|
+
|
|
91
|
+
## Drawer
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
private drawer = inject(DrawerService);
|
|
95
|
+
|
|
96
|
+
openDetail(user: User) {
|
|
97
|
+
this.drawer.open(UserDetail, { userId: user.id }, { title: user.name });
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
@Component({ /* … */ })
|
|
103
|
+
export class UserDetail {
|
|
104
|
+
readonly userId = input.required<number>();
|
|
105
|
+
private drawerRef = inject(DrawerRef);
|
|
106
|
+
|
|
107
|
+
save() { /* … */ this.drawerRef.close(); }
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- `data` (2nd argument) are the component inputs – signal `input()`s are set via `setInput`, other keys are assigned to the instance.
|
|
112
|
+
- Layers can be nested (detail → edit); a nested layer shows a back arrow, the first one a close button.
|
|
113
|
+
- The browser / mobile **Back button closes the top layer**; router navigation (e.g. a menu click) closes all layers.
|
|
114
|
+
- `DrawerRef` offers `close()`, `setTitle()`, `title`, `setFullPageUrl()`, `fullPageUrl`.
|
|
115
|
+
|
|
116
|
+
### Options (`DrawerOptions`)
|
|
117
|
+
|
|
118
|
+
| Option | Type | Default | Description |
|
|
119
|
+
|---|---|---|---|
|
|
120
|
+
| `title` | `string` | `''` | Title in the drawer header (runtime: `DrawerRef.setTitle()`). |
|
|
121
|
+
| `fullPageUrl` | `string \| any[]` | – | URL of a standalone page with the same content. When set, an icon link in the header closes all layers and navigates there (replacing the drawer history entry). |
|
|
122
|
+
| `fullPageIcon` | `string` | `open_in_full` | Material icon of that link. |
|
|
123
|
+
| `fullPageLabel` | `string` | `Open as full page` | Tooltip and `aria-label` (default from `SgAdminLabels.drawerFullPage`). |
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
this.drawer.open(UserDetail, { userId: user.id }, {
|
|
127
|
+
title: user.name,
|
|
128
|
+
fullPageUrl: ['/users', user.id],
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A component that is used both inside and outside a drawer should inject the ref optionally: `inject(DrawerRef, { optional: true })`.
|
|
133
|
+
|
|
134
|
+
## Built-in texts (i18n)
|
|
135
|
+
|
|
136
|
+
Aria labels and tooltips rendered by the layout (open/close menu, drawer close/back, full-page link…) are English by default. Provide your own via `provideSgAdminLabels()` – missing keys fall back to English. A Slovak set is included:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { SG_ADMIN_LABELS_SK, provideSgAdminLabels } from 'sagittarius-admin-template';
|
|
140
|
+
|
|
141
|
+
bootstrapApplication(App, {
|
|
142
|
+
providers: [
|
|
143
|
+
provideSgAdminLabels(SG_ADMIN_LABELS_SK),
|
|
144
|
+
// or only some keys: provideSgAdminLabels({ drawerClose: 'Schließen', drawerBack: 'Zurück' })
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Keys (`SgAdminLabels`): `openMenu`, `closeMenu`, `expandMenu`, `collapseMenu`, `userMenu`, `drawerClose`, `drawerBack`, `drawerFullPage`.
|
|
150
|
+
|
|
151
|
+
## Theming
|
|
152
|
+
|
|
153
|
+
All colors and sizes are CSS custom properties `--sg-*`. Override them in `:root`:
|
|
154
|
+
|
|
155
|
+
```css
|
|
156
|
+
:root {
|
|
157
|
+
--sg-sidebar-bg: #1a1033;
|
|
158
|
+
--sg-sidebar-accent: #b18cff;
|
|
159
|
+
--sg-sidebar-width: 280px;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Dark theme: set `color-scheme: dark` on `<html>` (e.g. with a class, as above).
|
|
164
|
+
|
|
165
|
+
## Page utility classes
|
|
166
|
+
|
|
167
|
+
`sg-page`, `sg-page-header`, `sg-breadcrumbs`, `sg-card`, `sg-grid`, `sg-stat`, `sg-badge`, `sg-avatar`, `sg-toolbar`, `sg-table-clickable`, `sg-form-grid`, `sg-kv`, `sg-empty-state`, `sg-drawer-page`, `sg-muted`… See the demo app for examples of each.
|
|
168
|
+
|
|
169
|
+
## Notes
|
|
170
|
+
|
|
171
|
+
- The sidebar menu supports one level plus section headers.
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sagittarius-admin-template",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"angular-material",
|
|
8
|
+
"admin",
|
|
9
|
+
"admin-template",
|
|
10
|
+
"dashboard",
|
|
11
|
+
"layout",
|
|
12
|
+
"sidebar",
|
|
13
|
+
"drawer",
|
|
14
|
+
"material3",
|
|
15
|
+
"dark-mode"
|
|
16
|
+
],
|
|
17
|
+
"author": "Marian Spisiak",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"homepage": "https://majo32.github.io/sagittarius-admin-template/",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/majo32/sagittarius-admin-template.git",
|
|
23
|
+
"directory": "projects/sagittarius-admin-template"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/majo32/sagittarius-admin-template/issues"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@angular/cdk": "^20.2.0",
|
|
33
|
+
"@angular/common": "^20.2.0",
|
|
34
|
+
"@angular/core": "^20.2.0",
|
|
35
|
+
"@angular/material": "^20.2.0",
|
|
36
|
+
"@angular/router": "^20.2.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"tslib": "^2.3.0"
|
|
40
|
+
},
|
|
41
|
+
"exports": {
|
|
42
|
+
"./styles/*": {
|
|
43
|
+
"sass": "./styles/*",
|
|
44
|
+
"default": "./styles/*"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"sideEffects": [
|
|
48
|
+
"*.scss"
|
|
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
|
+
});
|