mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[DURACOM-195] New host-window service methods
This commit is contained in:
@@ -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(),
|
||||
|
@@ -20,4 +20,8 @@ export class HostWindowServiceStub {
|
||||
isXsOrSm(): Observable<boolean> {
|
||||
return this.isXs();
|
||||
}
|
||||
|
||||
isMobile(): Observable<boolean> {
|
||||
return this.isXs();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user