@nepwork/dashboards
Version:
Dashboards for emergencies and monitoring
237 lines • 7.28 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 } from "tslib";
import { Component, HostBinding, Input } from '@angular/core';
import { emptyStatusWarning } from '../helpers';
/**
* Badge is a simple labeling component.
* It can be used to add additional information to any content or highlight unread items.
*
* Element is absolute positioned, so parent should be
* [positioned element](https://developer.mozilla.org/en-US/docs/Web/CSS/position).
* It means parent `position` should be set to anything except `static`, e.g. `relative`,
* `absolute`, `fixed`, or `sticky`.
*
* ### Installation
*
* Import `NbBadgeModule` to your feature module.
* ```ts
* @NgModule({
* imports: [
* // ...
* NbBadgeModule,
* ],
* })
* export class PageModule { }
* ```
* ### Usage
*
* Badge with default position and status(color):
*
* ```html
* <nb-badge text="badgeText"></nb-badge>
* ```
*
* For example, badge can be placed into nb-card header:
* @stacked-example(Showcase, badge/badge-showcase.component)
*
* Badge located on the bottom right with warning status:
*
* ```html
* <nb-badge text="badgeText" status="warning" position="bottom right">
* </nb-badge>
* ```
*
* @styles
*
* badge-border-radius:
* badge-text-font-family:
* badge-text-font-size:
* badge-text-font-weight:
* badge-text-line-height:
* badge-padding:
* badge-basic-background-color:
* badge-basic-text-color:
* badge-primary-background-color:
* badge-primary-text-color:
* badge-success-background-color:
* badge-success-text-color:
* badge-info-background-color:
* badge-info-text-color:
* badge-warning-background-color:
* badge-warning-text-color:
* badge-danger-background-color:
* badge-danger-text-color:
* badge-control-background-color:
* badge-control-text-color:
*/
let NbBadgeComponent = class NbBadgeComponent {
constructor() {
/**
* Text to display
* @type string
*/
this.text = '';
this._defaultPosition = 'top right';
this._position = this._defaultPosition;
this._status = 'basic';
}
/**
* Badge position
*
* Can be set to any class or to one of predefined positions:
* 'top left', 'top right', 'bottom left', 'bottom right',
* 'top start', 'top end', 'bottom start', 'bottom end'
* @type string
*/
get position() {
return this._position;
}
set position(value) {
this._position = value || this._defaultPosition;
}
/**
* Badge status (adds specific styles):
* 'basic', 'primary', 'info', 'success', 'warning', 'danger', 'control'
*/
get status() {
return this._status;
}
set status(value) {
if (value === '') {
emptyStatusWarning('NbBadge');
value = 'basic';
}
this._status = value;
}
get primary() {
return this.status === 'primary';
}
get success() {
return this.status === 'success';
}
get info() {
return this.status === 'info';
}
get warning() {
return this.status === 'warning';
}
get danger() {
return this.status === 'danger';
}
get basic() {
return this.status === 'basic';
}
get control() {
return this.status === 'control';
}
get top() {
return this.position.includes('top');
}
get right() {
return this.position.includes('right');
}
get bottom() {
return this.position.includes('bottom');
}
get left() {
return this.position.includes('left');
}
get start() {
return this.position.includes('start');
}
get end() {
return this.position.includes('end');
}
};
__decorate([
Input(),
__metadata("design:type", String)
], NbBadgeComponent.prototype, "text", void 0);
__decorate([
Input(),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], NbBadgeComponent.prototype, "position", null);
__decorate([
Input(),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], NbBadgeComponent.prototype, "status", null);
__decorate([
HostBinding('class.status-primary'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "primary", null);
__decorate([
HostBinding('class.status-success'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "success", null);
__decorate([
HostBinding('class.status-info'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "info", null);
__decorate([
HostBinding('class.status-warning'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "warning", null);
__decorate([
HostBinding('class.status-danger'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "danger", null);
__decorate([
HostBinding('class.status-basic'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "basic", null);
__decorate([
HostBinding('class.status-control'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "control", null);
__decorate([
HostBinding('class.position-top'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "top", null);
__decorate([
HostBinding('class.position-right'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "right", null);
__decorate([
HostBinding('class.position-bottom'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "bottom", null);
__decorate([
HostBinding('class.position-left'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "left", null);
__decorate([
HostBinding('class.position-start'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "start", null);
__decorate([
HostBinding('class.position-end'),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [])
], NbBadgeComponent.prototype, "end", null);
NbBadgeComponent = __decorate([
Component({
selector: 'nb-badge',
template: `{{text}}`,
styles: [":host{position:absolute;text-align:center;white-space:nowrap;vertical-align:baseline}:host(.position-top){top:0}:host(.position-right){right:0}:host(.position-bottom){bottom:0}:host(.position-left){left:0}[dir=ltr] :host(.position-start){left:0}[dir=rtl] :host(.position-start){right:0}[dir=ltr] :host(.position-end){right:0}[dir=rtl] :host(.position-end){left:0}\n"]
})
], NbBadgeComponent);
export { NbBadgeComponent };
//# sourceMappingURL=badge.component.js.map