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
394 lines (389 loc) • 20.1 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, 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 { style } from '@primeuix/styles/metergroup';
import { BaseStyle } from 'primeng/base';
const classes = {
root: ({ instance }) => [
'p-metergroup p-component',
{
'p-metergroup-horizontal': instance.orientation === 'horizontal',
'p-metergroup-vertical': instance.orientation === 'vertical'
}
],
meters: 'p-metergroup-meters',
meter: 'p-metergroup-meter',
labelList: ({ instance }) => [
'p-metergroup-label-list',
{
'p-metergroup-label-list-vertical': instance.labelOrientation === 'vertical',
'p-metergroup-label-list-horizontal': instance.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 = style;
classes = classes;
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: MeterGroupStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: MeterGroupStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", 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 extends BaseComponent {
value = null;
labelPosition = 'end';
labelOrientation = 'horizontal';
min;
max;
iconTemplate;
parentInstance = inject(forwardRef(() => MeterGroup));
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: MeterGroupLabel, deps: null, target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.3", type: MeterGroupLabel, isStandalone: true, selector: "p-meterGroupLabel, p-metergrouplabel", inputs: { value: "value", labelPosition: "labelPosition", labelOrientation: "labelOrientation", min: "min", max: "max", iconTemplate: "iconTemplate" }, usesInheritance: true, ngImport: i0, template: `
<ol [class]="cx('labelList')">
<li *ngFor="let labelItem of value; let index = index; trackBy: parentInstance.trackByFn" [class]="cx('label')">
<ng-container *ngIf="!iconTemplate">
<i *ngIf="labelItem.icon" [class]="labelItem.icon" [ngClass]="cx('labelIcon')" [ngStyle]="{ color: labelItem.color }"></i>
<span *ngIf="!labelItem.icon" [class]="cx('labelMarker')" [ngStyle]="{ backgroundColor: labelItem.color }"></span>
</ng-container>
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: labelItem, icon: labelItem.icon }"></ng-container>
<span [class]="cx('labelText')">{{ 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: "20.1.3", ngImport: i0, type: MeterGroupLabel, decorators: [{
type: Component,
args: [{
selector: 'p-meterGroupLabel, p-metergrouplabel',
standalone: true,
imports: [CommonModule, SharedModule],
template: `
<ol [class]="cx('labelList')">
<li *ngFor="let labelItem of value; let index = index; trackBy: parentInstance.trackByFn" [class]="cx('label')">
<ng-container *ngIf="!iconTemplate">
<i *ngIf="labelItem.icon" [class]="labelItem.icon" [ngClass]="cx('labelIcon')" [ngStyle]="{ color: labelItem.color }"></i>
<span *ngIf="!labelItem.icon" [class]="cx('labelMarker')" [ngStyle]="{ backgroundColor: labelItem.color }"></span>
</ng-container>
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: labelItem, icon: labelItem.icon }"></ng-container>
<span [class]="cx('labelText')">{{ 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';
/**
* Style class of the element.
* @deprecated since v20.0.0, use `class` instead.
* @group Props
*/
styleClass;
get vertical() {
return this.orientation === 'vertical';
}
labelTemplate;
meterTemplate;
endTemplate;
startTemplate;
iconTemplate;
templates;
_labelTemplate;
_meterTemplate;
_endTemplate;
_startTemplate;
_iconTemplate;
_componentStyle = inject(MeterGroupStyle);
constructor() {
super();
}
ngAfterViewInit() {
super.ngAfterViewInit();
const _container = this.el.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: "20.1.3", ngImport: i0, type: MeterGroup, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.3", 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", styleClass: "styleClass" }, host: { properties: { "attr.aria-valuemin": "min", "attr.role": "\"meter\"", "attr.aria-valuemax": "max", "attr.aria-valuenow": "totalPercent()", "class": "cn(cx('root'), 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 }], usesInheritance: true, ngImport: i0, template: `
@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]="cx('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: cx('meter'),
size: percentValue(meterItem.value),
totalPercent: totalPercent()
}
"
>
</ng-container>
<ng-container *ngIf="!meterTemplate && !_meterTemplate && meterItem.value > 0">
<span [class]="cx('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>
}
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { 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: "20.1.3", ngImport: i0, type: MeterGroup, decorators: [{
type: Component,
args: [{
selector: 'p-meterGroup, p-metergroup, p-meter-group',
standalone: true,
imports: [CommonModule, MeterGroupLabel, SharedModule],
template: `
@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]="cx('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: cx('meter'),
size: percentValue(meterItem.value),
totalPercent: totalPercent()
}
"
>
</ng-container>
<ng-container *ngIf="!meterTemplate && !_meterTemplate && meterItem.value > 0">
<span [class]="cx('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>
}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [MeterGroupStyle],
host: {
'[attr.aria-valuemin]': 'min',
'[attr.role]': '"meter"',
'[attr.aria-valuemax]': 'max',
'[attr.aria-valuenow]': 'totalPercent()',
'[class]': "cn(cx('root'), styleClass)"
}
}]
}], ctorParameters: () => [], propDecorators: { value: [{
type: Input
}], min: [{
type: Input
}], max: [{
type: Input
}], orientation: [{
type: Input
}], labelPosition: [{
type: Input
}], labelOrientation: [{
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]
}] } });
class MeterGroupModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: MeterGroupModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.3", ngImport: i0, type: MeterGroupModule, imports: [MeterGroup, SharedModule], exports: [MeterGroup, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: MeterGroupModule, imports: [MeterGroup, SharedModule, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", 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