@nepwork/dashboards
Version:
Dashboards for emergencies and monitoring
103 lines • 3.01 kB
JavaScript
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { __decorate, __metadata, __param } from "tslib";
import { Inject, Injectable } from '@angular/core';
import { NB_MEDIA_BREAKPOINTS } from '../theme.options';
export var DEFAULT_MEDIA_BREAKPOINTS = [
{
name: 'xs',
width: 0,
},
{
name: 'is',
width: 400,
},
{
name: 'sm',
width: 576,
},
{
name: 'md',
width: 768,
},
{
name: 'lg',
width: 992,
},
{
name: 'xl',
width: 1200,
},
{
name: 'xxl',
width: 1400,
},
{
name: 'xxxl',
width: 1600,
},
];
/**
* Manages media breakpoints
*
* Provides access to available media breakpoints to convert window width to a configured breakpoint,
* e.g. 200px - *xs* breakpoint
*/
var NbMediaBreakpointsService = /** @class */ (function () {
function NbMediaBreakpointsService(breakpoints) {
this.breakpoints = breakpoints;
this.breakpointsMap = this.breakpoints.reduce(function (res, b) {
res[b.name] = b.width;
return res;
}, {});
}
/**
* Returns a configured breakpoint by width
* @param width number
* @returns {Z|{name: string, width: number}}
*/
NbMediaBreakpointsService.prototype.getByWidth = function (width) {
var unknown = { name: 'unknown', width: width };
var breakpoints = this.getBreakpoints();
return breakpoints
.find(function (point, index) {
var next = breakpoints[index + 1];
return width >= point.width && (!next || width < next.width);
}) || unknown;
};
/**
* Returns a configured breakpoint by name
* @param name string
* @returns NbMediaBreakpoint
*/
NbMediaBreakpointsService.prototype.getByName = function (name) {
var unknown = { name: 'unknown', width: NaN };
var breakpoints = this.getBreakpoints();
return breakpoints.find(function (point) { return name === point.name; }) || unknown;
};
/**
* Returns a list of configured breakpoints for the theme
* @returns NbMediaBreakpoint[]
*/
NbMediaBreakpointsService.prototype.getBreakpoints = function () {
return this.breakpoints;
};
/**
* Returns a map of configured breakpoints for the theme
* @returns {[p: string]: number}
*/
NbMediaBreakpointsService.prototype.getBreakpointsMap = function () {
return this.breakpointsMap;
};
NbMediaBreakpointsService = __decorate([
Injectable(),
__param(0, Inject(NB_MEDIA_BREAKPOINTS)),
__metadata("design:paramtypes", [Object])
], NbMediaBreakpointsService);
return NbMediaBreakpointsService;
}());
export { NbMediaBreakpointsService };
//# sourceMappingURL=breakpoints.service.js.map