primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 6.98 kB
JavaScript
import * as i0 from '@angular/core';
import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, NgModule } from '@angular/core';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
const RATING_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => Rating),
multi: true
};
class Rating {
constructor(cd) {
this.cd = cd;
this.stars = 5;
this.cancel = true;
this.iconOnClass = 'pi pi-star';
this.iconOffClass = 'pi pi-star-o';
this.iconCancelClass = 'pi pi-ban';
this.onRate = new EventEmitter();
this.onCancel = new EventEmitter();
this.onModelChange = () => { };
this.onModelTouched = () => { };
}
ngOnInit() {
this.starsArray = [];
for (let i = 0; i < this.stars; i++) {
this.starsArray[i] = i;
}
}
rate(event, i) {
if (!this.readonly && !this.disabled) {
this.value = (i + 1);
this.onModelChange(this.value);
this.onModelTouched();
this.onRate.emit({
originalEvent: event,
value: (i + 1)
});
}
event.preventDefault();
}
clear(event) {
if (!this.readonly && !this.disabled) {
this.value = null;
this.onModelChange(this.value);
this.onModelTouched();
this.onCancel.emit(event);
}
event.preventDefault();
}
writeValue(value) {
this.value = value;
this.cd.detectChanges();
}
registerOnChange(fn) {
this.onModelChange = fn;
}
registerOnTouched(fn) {
this.onModelTouched = fn;
}
setDisabledState(val) {
this.disabled = val;
this.cd.markForCheck();
}
}
Rating.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: Rating, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
Rating.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: Rating, selector: "p-rating", inputs: { disabled: "disabled", readonly: "readonly", stars: "stars", cancel: "cancel", iconOnClass: "iconOnClass", iconOnStyle: "iconOnStyle", iconOffClass: "iconOffClass", iconOffStyle: "iconOffStyle", iconCancelClass: "iconCancelClass", iconCancelStyle: "iconCancelStyle" }, outputs: { onRate: "onRate", onCancel: "onCancel" }, providers: [RATING_VALUE_ACCESSOR], ngImport: i0, template: `
<div class="p-rating" [ngClass]="{'p-readonly': readonly, 'p-disabled': disabled}">
<span [attr.tabindex]="(disabled || readonly) ? null : '0'" *ngIf="cancel" (click)="clear($event)" (keydown.enter)="clear($event)" class="p-rating-icon p-rating-cancel" [ngClass]="iconCancelClass" [ngStyle]="iconCancelStyle"></span>
<span *ngFor="let star of starsArray;let i=index" class="p-rating-icon" [attr.tabindex]="(disabled || readonly) ? null : '0'" (click)="rate($event,i)" (keydown.enter)="rate($event,i)"
[ngClass]="(!value || i >= value) ? iconOffClass : iconOnClass"
[ngStyle]="(!value || i >= value) ? iconOffStyle : iconOnStyle"></span>
</div>
`, isInline: true, styles: [".p-rating-icon{cursor:pointer}.p-rating.p-rating-readonly .p-rating-icon{cursor:default}"], directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: Rating, decorators: [{
type: Component,
args: [{
selector: 'p-rating',
template: `
<div class="p-rating" [ngClass]="{'p-readonly': readonly, 'p-disabled': disabled}">
<span [attr.tabindex]="(disabled || readonly) ? null : '0'" *ngIf="cancel" (click)="clear($event)" (keydown.enter)="clear($event)" class="p-rating-icon p-rating-cancel" [ngClass]="iconCancelClass" [ngStyle]="iconCancelStyle"></span>
<span *ngFor="let star of starsArray;let i=index" class="p-rating-icon" [attr.tabindex]="(disabled || readonly) ? null : '0'" (click)="rate($event,i)" (keydown.enter)="rate($event,i)"
[ngClass]="(!value || i >= value) ? iconOffClass : iconOnClass"
[ngStyle]="(!value || i >= value) ? iconOffStyle : iconOnStyle"></span>
</div>
`,
providers: [RATING_VALUE_ACCESSOR],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styleUrls: ['./rating.css']
}]
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { disabled: [{
type: Input
}], readonly: [{
type: Input
}], stars: [{
type: Input
}], cancel: [{
type: Input
}], iconOnClass: [{
type: Input
}], iconOnStyle: [{
type: Input
}], iconOffClass: [{
type: Input
}], iconOffStyle: [{
type: Input
}], iconCancelClass: [{
type: Input
}], iconCancelStyle: [{
type: Input
}], onRate: [{
type: Output
}], onCancel: [{
type: Output
}] } });
class RatingModule {
}
RatingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: RatingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
RatingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: RatingModule, declarations: [Rating], imports: [CommonModule], exports: [Rating] });
RatingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: RatingModule, imports: [[CommonModule]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: RatingModule, decorators: [{
type: NgModule,
args: [{
imports: [CommonModule],
exports: [Rating],
declarations: [Rating]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { RATING_VALUE_ACCESSOR, Rating, RatingModule };
//# sourceMappingURL=primeng-rating.js.map