Skip to content

Commit 9a75e0f

Browse files
committed
feat(config):Configurable toast messages position - toastPosition
Value based on config parameter or sidebarPoisiton if not defined
1 parent 0b809a0 commit 9a75e0f

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

projects/hslayers/common/toast/toast.component.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import {Component, Input, computed} from '@angular/core';
1+
import {Component, computed, input} from '@angular/core';
22
import {CommonModule} from '@angular/common';
33
import {toSignal} from '@angular/core/rxjs-interop';
44

55
import {HsToastService} from './toast.service';
66
import {HsToastItemComponent} from './toast-item.component';
7-
import {HsConfig} from 'hslayers-ng/config';
8-
9-
export type ToastPosition =
10-
| 'top-left'
11-
| 'top-right'
12-
| 'top-center'
13-
| 'bottom-left'
14-
| 'bottom-right'
15-
| 'bottom-center';
7+
import {HsConfig, ToastPosition} from 'hslayers-ng/config';
168

179
@Component({
1810
selector: 'hs-toast',
@@ -37,7 +29,7 @@ export type ToastPosition =
3729
},
3830
})
3931
export class HsToastComponent {
40-
@Input() position: ToastPosition = 'bottom-center';
32+
position = input<ToastPosition>('bottom-center');
4133

4234
constructor(
4335
public hsToastService: HsToastService,
@@ -58,10 +50,11 @@ export class HsToastComponent {
5850
*/
5951
positionClasses = computed(() => {
6052
this.configChanges();
53+
const containerPosition = this.position();
6154
const positionType =
6255
this.hsConfig.toastAnchor === 'screen'
6356
? 'position-fixed'
6457
: 'position-absolute';
65-
return `${this.position} ${positionType}`;
58+
return `${containerPosition} ${positionType}`;
6659
});
6760
}

projects/hslayers/config/config.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import {
1414
} from 'hslayers-ng/types';
1515
import {StyleLike} from 'ol/style/Style';
1616

17+
export type ToastPosition =
18+
| 'top-left'
19+
| 'top-right'
20+
| 'top-center'
21+
| 'bottom-left'
22+
| 'bottom-right'
23+
| 'bottom-center';
24+
1725
export type SymbolizerIcon = {
1826
name: string;
1927
url: string;
@@ -157,6 +165,11 @@ export class HsConfigObject {
157165
* 'map' - anchors toasts to the map container
158166
*/
159167
toastAnchor?: 'screen' | 'map' = 'map';
168+
/**
169+
* Controls the position of toast notifications
170+
* @default 'bottom-right'
171+
*/
172+
toastPosition?: ToastPosition;
160173
errorToastDuration?: number;
161174

162175
advancedForm?: boolean;

projects/hslayers/config/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export {
44
SymbolizerIcon,
55
MapSwipeOptions,
66
KeyNumberDict,
7+
ToastPosition,
78
} from './config.service';

projects/hslayers/core/hslayers.component.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ import {
1010
ViewChild,
1111
inject,
1212
} from '@angular/core';
13-
import {delay, filter, fromEvent, timer} from 'rxjs';
13+
import {
14+
combineLatestWith,
15+
delay,
16+
filter,
17+
fromEvent,
18+
map,
19+
startWith,
20+
timer,
21+
} from 'rxjs';
1422
import {takeUntilDestroyed, toSignal} from '@angular/core/rxjs-interop';
1523

16-
import {HsConfig, HsConfigObject} from 'hslayers-ng/config';
24+
import {HsConfig, HsConfigObject, ToastPosition} from 'hslayers-ng/config';
1725
import {HsEventBusService} from 'hslayers-ng/services/event-bus';
1826
import {HsExternalService} from 'hslayers-ng/services/external';
1927
import {HsLayoutService} from 'hslayers-ng/services/layout';
@@ -69,6 +77,7 @@ export class HslayersComponent implements AfterViewInit, OnInit {
6977
private panelSpace: HTMLElement;
7078
private mapSpace: HTMLElement;
7179

80+
toastPosition: Signal<ToastPosition>;
7281
constructor(
7382
public hsConfig: HsConfig,
7483
private elementRef: ElementRef,
@@ -83,6 +92,20 @@ export class HslayersComponent implements AfterViewInit, OnInit {
8392
) {
8493
this.sidebarPosition = toSignal(this.HsLayoutService.sidebarPosition);
8594
this.sidebarVisible = toSignal(this.HsLayoutService.sidebarVisible);
95+
96+
this.toastPosition = toSignal(
97+
this.HsLayoutService.sidebarPosition$.pipe(
98+
combineLatestWith(
99+
this.hsConfig.configChanges.pipe(startWith(this.hsConfig)),
100+
),
101+
map(([sidebarPosition, _]) => {
102+
return (
103+
this.hsConfig.toastPosition ??
104+
(sidebarPosition === 'left' ? 'bottom-right' : 'bottom-left')
105+
);
106+
}),
107+
),
108+
);
86109
}
87110

88111
async ngOnInit(): Promise<void> {

projects/hslayers/core/hslayers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</div>
3232
</div>
3333
</div>
34-
<hs-toast aria-live="polite" aria-atomic="true" [position]="sidebarPosition() === 'left' ? 'bottom-right' : 'bottom-left'"></hs-toast>
34+
<hs-toast aria-live="polite" aria-atomic="true" [position]="toastPosition()"></hs-toast>
3535
<div class="hs-dialog-area"></div>
3636
</div>
3737
<hs-dialog-container></hs-dialog-container>

projects/test-app/src/hslayers-app/hslayers-app.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ export class HslayersAppComponent {
425425
language: 'en',
426426
assetsPath: 'assets',
427427
saveMapStateOnReload: false,
428+
toastAnchor: 'screen',
428429
symbolizerIcons: [
429430
{name: 'bag', url: '/assets/icons/bag1.svg'},
430431
{name: 'banking', url: '/assets/icons/banking4.svg'},

0 commit comments

Comments
 (0)