forked from hazza/dspace-angular
[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';
|
import { CSSVariableService } from './sass-helper/css-variable.service';
|
||||||
|
|
||||||
export enum WidthCategory {
|
export enum WidthCategory {
|
||||||
XS,
|
XS = 0,
|
||||||
SM,
|
SM = 1,
|
||||||
MD,
|
MD = 2,
|
||||||
LG,
|
LG = 3,
|
||||||
XL
|
XL = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const maxMobileWidth = WidthCategory.SM;
|
||||||
|
|
||||||
const hostWindowStateSelector = (state: AppState) => state.hostWindow;
|
const hostWindowStateSelector = (state: AppState) => state.hostWindow;
|
||||||
const widthSelector = createSelector(hostWindowStateSelector, (hostWindow: HostWindowState) => hostWindow.width);
|
const widthSelector = createSelector(hostWindowStateSelector, (hostWindow: HostWindowState) => hostWindow.width);
|
||||||
|
|
||||||
@@ -31,11 +33,11 @@ export class HostWindowService {
|
|||||||
/* See _exposed_variables.scss */
|
/* See _exposed_variables.scss */
|
||||||
variableService.getAllVariables()
|
variableService.getAllVariables()
|
||||||
.subscribe((variables) => {
|
.subscribe((variables) => {
|
||||||
this.breakPoints.XL_MIN = parseInt(variables['--bs-xl-min'], 10);
|
this.breakPoints.XL_MIN = parseInt(variables['--bs-xl-min'], 10);
|
||||||
this.breakPoints.LG_MIN = parseInt(variables['--bs-lg-min'], 10);
|
this.breakPoints.LG_MIN = parseInt(variables['--bs-lg-min'], 10);
|
||||||
this.breakPoints.MD_MIN = parseInt(variables['--bs-md-min'], 10);
|
this.breakPoints.MD_MIN = parseInt(variables['--bs-md-min'], 10);
|
||||||
this.breakPoints.SM_MIN = parseInt(variables['--bs-sm-min'], 10);
|
this.breakPoints.SM_MIN = parseInt(variables['--bs-sm-min'], 10);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWidthObs(): Observable<number> {
|
private getWidthObs(): Observable<number> {
|
||||||
@@ -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> {
|
isXsOrSm(): Observable<boolean> {
|
||||||
return observableCombineLatest(
|
return observableCombineLatest(
|
||||||
this.isXs(),
|
this.isXs(),
|
||||||
|
@@ -20,4 +20,8 @@ export class HostWindowServiceStub {
|
|||||||
isXsOrSm(): Observable<boolean> {
|
isXsOrSm(): Observable<boolean> {
|
||||||
return this.isXs();
|
return this.isXs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMobile(): Observable<boolean> {
|
||||||
|
return this.isXs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user