[DURACOM-195] New host-window service methods

This commit is contained in:
Davide Negretti
2023-11-23 00:34:05 +01:00
parent 2178e0e6a3
commit d95d5753b4
2 changed files with 51 additions and 10 deletions

View File

@@ -10,13 +10,15 @@ import { AppState } from '../app.reducer';
import { CSSVariableService } from './sass-helper/css-variable.service';
export enum WidthCategory {
XS,
SM,
MD,
LG,
XL
XS = 0,
SM = 1,
MD = 2,
LG = 3,
XL = 4,
}
export const maxMobileWidth = WidthCategory.SM;
const hostWindowStateSelector = (state: AppState) => state.hostWindow;
const widthSelector = createSelector(hostWindowStateSelector, (hostWindow: HostWindowState) => hostWindow.width);
@@ -99,6 +101,41 @@ export class HostWindowService {
);
}
is(exactWidthCat: WidthCategory): Observable<boolean> {
return this.widthCategory.pipe(
map((widthCat: WidthCategory) => widthCat === exactWidthCat),
distinctUntilChanged()
);
}
isIn(widthCatArray: [WidthCategory]): Observable<boolean> {
return this.widthCategory.pipe(
map((widthCat: WidthCategory) => widthCatArray.includes(widthCat)),
distinctUntilChanged()
);
}
isUpTo(maxWidthCat: WidthCategory): Observable<boolean> {
return this.widthCategory.pipe(
map((widthCat: WidthCategory) => widthCat <= maxWidthCat),
distinctUntilChanged()
);
}
isMobile(): Observable<boolean> {
return this.widthCategory.pipe(
map((widthCat: WidthCategory) => widthCat <= maxMobileWidth),
distinctUntilChanged()
);
}
isDesktop(): Observable<boolean> {
return this.widthCategory.pipe(
map((widthCat: WidthCategory) => widthCat > maxMobileWidth),
distinctUntilChanged()
);
}
isXsOrSm(): Observable<boolean> {
return observableCombineLatest(
this.isXs(),

View File

@@ -20,4 +20,8 @@ export class HostWindowServiceStub {
isXsOrSm(): Observable<boolean> {
return this.isXs();
}
isMobile(): Observable<boolean> {
return this.isXs();
}
}