primeng
Version:
PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB
500 lines (480 loc) • 23.5 kB
JavaScript
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, inject, forwardRef, Input, Component, ElementRef, ViewChild, ContentChildren, ContentChild, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { getOuterHeight } from '@primeuix/utils';
import { SharedModule, PrimeTemplate } from 'primeng/api';
import { BaseComponent } from 'primeng/basecomponent';
import { BaseStyle } from 'primeng/base';
const theme = ({ dt }) => `
.p-metergroup {
display: flex;
gap: ${dt('metergroup.gap')};
}
.p-metergroup-meters {
display: flex;
background: ${dt('metergroup.meters.background')};
border-radius: ${dt('metergroup.border.radius')};
}
.p-metergroup-label-list {
display: flex;
flex-wrap: wrap;
margin: 0;
padding: 0;
list-style-type: none;
}
.p-metergroup-label {
display: inline-flex;
align-items: center;
gap: ${dt('metergroup.label.gap')};
}
.p-metergroup-label-marker {
display: inline-flex;
width: ${dt('metergroup.label.marker.size')};
height: ${dt('metergroup.label.marker.size')};
border-radius: 100%;
}
.p-metergroup-label-icon {
font-size: ${dt('metergroup.label.icon.size')};
width: ${dt('metergroup.label.icon.size')};
height: ${dt('metergroup.label.icon.size')};
}
.p-metergroup-horizontal {
flex-direction: column;
}
.p-metergroup-label-list-horizontal {
gap: ${dt('metergroup.label.list.horizontal.gap')};
}
.p-metergroup-horizontal .p-metergroup-meters {
height: ${dt('metergroup.meters.size')};
}
.p-metergroup-horizontal .p-metergroup-meter:first-of-type {
border-start-start-radius: ${dt('metergroup.border.radius')};
border-end-start-radius: ${dt('metergroup.border.radius')};
}
.p-metergroup-horizontal .p-metergroup-meter:last-of-type {
border-start-end-radius: ${dt('metergroup.border.radius')};
border-end-end-radius: ${dt('metergroup.border.radius')};
}
.p-metergroup-vertical {
flex-direction: row;
}
.p-metergroup-label-list-vertical {
flex-direction: column;
gap: ${dt('metergroup.label.list.vertical.gap')};
}
.p-metergroup-vertical .p-metergroup-meters {
flex-direction: column;
width: ${dt('metergroup.meters.size')};
height: 100%;
}
.p-metergroup-vertical .p-metergroup-label-list {
align-items: start;
}
.p-metergroup-vertical .p-metergroup-meter:first-of-type {
border-start-start-radius: ${dt('metergroup.border.radius')};
border-start-end-radius: ${dt('metergroup.border.radius')};
}
.p-metergroup-vertical .p-metergroup-meter:last-of-type {
border-end-start-radius: ${dt('metergroup.border.radius')};
border-end-end-radius: ${dt('metergroup.border.radius')};
}
`;
const classes = {
root: ({ props }) => [
'p-metergroup p-component',
{
'p-metergroup-horizontal': props.orientation === 'horizontal',
'p-metergroup-vertical': props.orientation === 'vertical'
}
],
meters: 'p-metergroup-meters',
meter: 'p-metergroup-meter',
labelList: ({ props }) => [
'p-metergroup-label-list',
{
'p-metergroup-label-list-vertical': props.labelOrientation === 'vertical',
'p-metergroup-label-list-horizontal': props.labelOrientation === 'horizontal'
}
],
label: 'p-metergroup-label',
labelIcon: 'p-metergroup-label-icon',
labelMarker: 'p-metergroup-label-marker',
labelText: 'p-metergroup-label-text'
};
class MeterGroupStyle extends BaseStyle {
name = 'metergroup';
theme = theme;
classes = classes;
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupStyle, decorators: [{
type: Injectable
}] });
/**
*
* MeterGroup is a group of process status indicators.
*
* [Live Demo](https://www.primeng.org/metergroup)
*
* @module metergroupstyle
*
*/
var MeterGroupClasses;
(function (MeterGroupClasses) {
/**
* Class name of the root element
*/
MeterGroupClasses["root"] = "p-metergroup";
/**
* Class name of the meters element
*/
MeterGroupClasses["meters"] = "p-metergroup-meters";
/**
* Class name of the meter element
*/
MeterGroupClasses["meter"] = "p-metergroup-meter";
/**
* Class name of the label list element
*/
MeterGroupClasses["labelList"] = "p-metergroup-label-list";
/**
* Class name of the label element
*/
MeterGroupClasses["label"] = "p-metergroup-label";
/**
* Class name of the label icon element
*/
MeterGroupClasses["labelIcon"] = "p-metergroup-label-icon";
/**
* Class name of the label marker element
*/
MeterGroupClasses["labelMarker"] = "p-metergroup-label-marker";
/**
* Class name of the label text element
*/
MeterGroupClasses["labelText"] = "p-metergroup-label-text";
})(MeterGroupClasses || (MeterGroupClasses = {}));
class MeterGroupLabel {
value = null;
labelPosition = 'end';
labelOrientation = 'horizontal';
min;
max;
iconTemplate;
get labelClass() {
return {
'p-metergroup-label-list p-component': true,
'p-metergroup-label-list-vertical': this.labelOrientation === 'vertical',
'p-metergroup-label-list-horizontal': this.labelOrientation === 'horizontal'
};
}
parentInstance = inject(forwardRef(() => MeterGroup));
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupLabel, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.2", type: MeterGroupLabel, isStandalone: true, selector: "p-meterGroupLabel, p-metergrouplabel", inputs: { value: "value", labelPosition: "labelPosition", labelOrientation: "labelOrientation", min: "min", max: "max", iconTemplate: "iconTemplate" }, ngImport: i0, template: `
<ol [ngClass]="labelClass">
<li *ngFor="let labelItem of value; let index = index; trackBy: parentInstance.trackByFn" class="p-metergroup-label">
<ng-container *ngIf="!iconTemplate">
<i *ngIf="labelItem.icon" [class]="labelItem.icon" [ngClass]="{ 'p-metergroup-label-icon': true }" [ngStyle]="{ color: labelItem.color }"></i>
<span *ngIf="!labelItem.icon" class="p-metergroup-label-marker" [ngStyle]="{ backgroundColor: labelItem.color }"></span>
</ng-container>
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: labelItem, icon: labelItem.icon }"></ng-container>
<span class="p-metergroup-label-text">{{ labelItem.label }} ({{ parentInstance.percentValue(labelItem.value) }})</span>
</li>
</ol>
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: SharedModule }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupLabel, decorators: [{
type: Component,
args: [{
selector: 'p-meterGroupLabel, p-metergrouplabel',
standalone: true,
imports: [CommonModule, SharedModule],
template: `
<ol [ngClass]="labelClass">
<li *ngFor="let labelItem of value; let index = index; trackBy: parentInstance.trackByFn" class="p-metergroup-label">
<ng-container *ngIf="!iconTemplate">
<i *ngIf="labelItem.icon" [class]="labelItem.icon" [ngClass]="{ 'p-metergroup-label-icon': true }" [ngStyle]="{ color: labelItem.color }"></i>
<span *ngIf="!labelItem.icon" class="p-metergroup-label-marker" [ngStyle]="{ backgroundColor: labelItem.color }"></span>
</ng-container>
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: labelItem, icon: labelItem.icon }"></ng-container>
<span class="p-metergroup-label-text">{{ labelItem.label }} ({{ parentInstance.percentValue(labelItem.value) }})</span>
</li>
</ol>
`
}]
}], propDecorators: { value: [{
type: Input
}], labelPosition: [{
type: Input
}], labelOrientation: [{
type: Input
}], min: [{
type: Input
}], max: [{
type: Input
}], iconTemplate: [{
type: Input
}] } });
/**
* MeterGroup displays scalar measurements within a known range.
* @group Components
*/
class MeterGroup extends BaseComponent {
/**
* Current value of the metergroup.
* @group Props
*/
value;
/**
* Mininum boundary value.
* @group Props
*/
min = 0;
/**
* Maximum boundary value.
* @group Props
*/
max = 100;
/**
* Specifies the layout of the component, valid values are 'horizontal' and 'vertical'.
* @group Props
*/
orientation = 'horizontal';
/**
* Specifies the label position of the component, valid values are 'start' and 'end'.
* @group Props
*/
labelPosition = 'end';
/**
* Specifies the label orientation of the component, valid values are 'horizontal' and 'vertical'.
* @group Props
*/
labelOrientation = 'horizontal';
/**
* Inline style of the element.
* @group Props
*/
style;
/**
* Style class of the element.
* @group Props
*/
styleClass;
get vertical() {
return this.orientation === 'vertical';
}
get containerClass() {
return {
'p-metergroup p-component': true,
'p-metergroup-horizontal': this.orientation === 'horizontal',
'p-metergroup-vertical': this.orientation === 'vertical'
};
}
labelTemplate;
meterTemplate;
endTemplate;
startTemplate;
iconTemplate;
templates;
_labelTemplate;
_meterTemplate;
_endTemplate;
_startTemplate;
_iconTemplate;
_componentStyle = inject(MeterGroupStyle);
container;
ngAfterViewInit() {
super.ngAfterViewInit();
const _container = this.container.nativeElement;
const height = getOuterHeight(_container);
this.vertical && (_container.style.height = height + 'px');
}
ngAfterContentInit() {
this.templates?.forEach((item) => {
switch (item.getType()) {
case 'label':
this._labelTemplate = item.template;
break;
case 'meter':
this._meterTemplate = item.template;
break;
case 'icon':
this._iconTemplate = item.template;
break;
case 'start':
this._startTemplate = item.template;
break;
case 'end':
this._endTemplate = item.template;
break;
}
});
}
percent(meter = 0) {
const percentOfItem = ((meter - this.min) / (this.max - this.min)) * 100;
return Math.round(Math.max(0, Math.min(100, percentOfItem)));
}
percentValue(meter) {
return this.percent(meter) + '%';
}
meterStyle(val) {
return {
backgroundColor: val.color,
width: this.orientation === 'horizontal' && this.percentValue(val.value),
height: this.orientation === 'vertical' && this.percentValue(val.value)
};
}
totalPercent() {
return this.percent(this.value.reduce((total, val) => total + val.value, 0));
}
percentages() {
let sum = 0;
const sumsArray = [];
this.value.forEach((item) => {
sum += item.value;
sumsArray.push(sum);
});
return sumsArray;
}
trackByFn(index) {
return index;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroup, deps: null, target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.2", type: MeterGroup, isStandalone: true, selector: "p-meterGroup, p-metergroup, p-meter-group", inputs: { value: "value", min: "min", max: "max", orientation: "orientation", labelPosition: "labelPosition", labelOrientation: "labelOrientation", style: "style", styleClass: "styleClass" }, providers: [MeterGroupStyle], queries: [{ propertyName: "labelTemplate", first: true, predicate: ["label"] }, { propertyName: "meterTemplate", first: true, predicate: ["meter"] }, { propertyName: "endTemplate", first: true, predicate: ["end"] }, { propertyName: "startTemplate", first: true, predicate: ["start"] }, { propertyName: "iconTemplate", first: true, predicate: ["icon"] }, { propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true, read: ElementRef }], usesInheritance: true, ngImport: i0, template: `
<div #container [ngClass]="containerClass" [attr.role]="'meter'" [attr.aria-valuemin]="min" [attr.aria-valuemax]="max" [attr.aria-valuenow]="totalPercent()" [ngStyle]="style" [class]="styleClass">
@if (labelPosition === 'start') {
<p-meterGroupLabel *ngIf="!labelTemplate && !_labelTemplate" [value]="value" [labelPosition]="labelPosition" [labelOrientation]="labelOrientation" [min]="min" [max]="max" [iconTemplate]="iconTemplate || _iconTemplate" />
<ng-container *ngTemplateOutlet="labelTemplate || labelTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
}
<ng-container *ngTemplateOutlet="startTemplate || _startTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
<div class="p-metergroup-meters">
<ng-container *ngFor="let meterItem of value; let index = index; trackBy: trackByFn">
<ng-container
*ngTemplateOutlet="
meterTemplate || _meterTemplate;
context: {
$implicit: meterItem,
index: index,
orientation: this.orientation,
class: 'p-metergroup-meter',
size: percentValue(meterItem.value),
totalPercent: totalPercent()
}
"
>
</ng-container>
<ng-container *ngIf="!meterTemplate && !_meterTemplate && meterItem.value > 0">
<span class="p-metergroup-meter" [ngStyle]="meterStyle(meterItem)"></span>
</ng-container>
</ng-container>
</div>
<ng-container *ngTemplateOutlet="endTemplate || _endTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
@if (labelPosition === 'end') {
<p-meterGroupLabel *ngIf="!labelTemplate && !_labelTemplate" [value]="value" [labelPosition]="labelPosition" [labelOrientation]="labelOrientation" [min]="min" [max]="max" [iconTemplate]="iconTemplate || _iconTemplate" />
<ng-container *ngTemplateOutlet="labelTemplate || _labelTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
}
</div>
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: MeterGroupLabel, selector: "p-meterGroupLabel, p-metergrouplabel", inputs: ["value", "labelPosition", "labelOrientation", "min", "max", "iconTemplate"] }, { kind: "ngmodule", type: SharedModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroup, decorators: [{
type: Component,
args: [{
selector: 'p-meterGroup, p-metergroup, p-meter-group',
standalone: true,
imports: [CommonModule, MeterGroupLabel, SharedModule],
template: `
<div #container [ngClass]="containerClass" [attr.role]="'meter'" [attr.aria-valuemin]="min" [attr.aria-valuemax]="max" [attr.aria-valuenow]="totalPercent()" [ngStyle]="style" [class]="styleClass">
@if (labelPosition === 'start') {
<p-meterGroupLabel *ngIf="!labelTemplate && !_labelTemplate" [value]="value" [labelPosition]="labelPosition" [labelOrientation]="labelOrientation" [min]="min" [max]="max" [iconTemplate]="iconTemplate || _iconTemplate" />
<ng-container *ngTemplateOutlet="labelTemplate || labelTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
}
<ng-container *ngTemplateOutlet="startTemplate || _startTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
<div class="p-metergroup-meters">
<ng-container *ngFor="let meterItem of value; let index = index; trackBy: trackByFn">
<ng-container
*ngTemplateOutlet="
meterTemplate || _meterTemplate;
context: {
$implicit: meterItem,
index: index,
orientation: this.orientation,
class: 'p-metergroup-meter',
size: percentValue(meterItem.value),
totalPercent: totalPercent()
}
"
>
</ng-container>
<ng-container *ngIf="!meterTemplate && !_meterTemplate && meterItem.value > 0">
<span class="p-metergroup-meter" [ngStyle]="meterStyle(meterItem)"></span>
</ng-container>
</ng-container>
</div>
<ng-container *ngTemplateOutlet="endTemplate || _endTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
@if (labelPosition === 'end') {
<p-meterGroupLabel *ngIf="!labelTemplate && !_labelTemplate" [value]="value" [labelPosition]="labelPosition" [labelOrientation]="labelOrientation" [min]="min" [max]="max" [iconTemplate]="iconTemplate || _iconTemplate" />
<ng-container *ngTemplateOutlet="labelTemplate || _labelTemplate; context: { $implicit: value, totalPercent: totalPercent(), percentages: percentages() }"></ng-container>
}
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [MeterGroupStyle]
}]
}], propDecorators: { value: [{
type: Input
}], min: [{
type: Input
}], max: [{
type: Input
}], orientation: [{
type: Input
}], labelPosition: [{
type: Input
}], labelOrientation: [{
type: Input
}], style: [{
type: Input
}], styleClass: [{
type: Input
}], labelTemplate: [{
type: ContentChild,
args: ['label', { descendants: false }]
}], meterTemplate: [{
type: ContentChild,
args: ['meter', { descendants: false }]
}], endTemplate: [{
type: ContentChild,
args: ['end', { descendants: false }]
}], startTemplate: [{
type: ContentChild,
args: ['start', { descendants: false }]
}], iconTemplate: [{
type: ContentChild,
args: ['icon', { descendants: false }]
}], templates: [{
type: ContentChildren,
args: [PrimeTemplate]
}], container: [{
type: ViewChild,
args: ['container', { read: ElementRef }]
}] } });
class MeterGroupModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupModule, imports: [MeterGroup, SharedModule], exports: [MeterGroup, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupModule, imports: [MeterGroup, SharedModule, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MeterGroupModule, decorators: [{
type: NgModule,
args: [{
imports: [MeterGroup, SharedModule],
exports: [MeterGroup, SharedModule]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { MeterGroup, MeterGroupClasses, MeterGroupLabel, MeterGroupModule, MeterGroupStyle };
//# sourceMappingURL=primeng-metergroup.mjs.map