1 | import * as i0 from '@angular/core';
|
---|
2 | import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, NgModule } from '@angular/core';
|
---|
3 | import * as i1 from '@angular/common';
|
---|
4 | import { CommonModule } from '@angular/common';
|
---|
5 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
---|
6 |
|
---|
7 | const RATING_VALUE_ACCESSOR = {
|
---|
8 | provide: NG_VALUE_ACCESSOR,
|
---|
9 | useExisting: forwardRef(() => Rating),
|
---|
10 | multi: true
|
---|
11 | };
|
---|
12 | class Rating {
|
---|
13 | constructor(cd) {
|
---|
14 | this.cd = cd;
|
---|
15 | this.stars = 5;
|
---|
16 | this.cancel = true;
|
---|
17 | this.iconOnClass = 'pi pi-star-fill';
|
---|
18 | this.iconOffClass = 'pi pi-star';
|
---|
19 | this.iconCancelClass = 'pi pi-ban';
|
---|
20 | this.onRate = new EventEmitter();
|
---|
21 | this.onCancel = new EventEmitter();
|
---|
22 | this.onModelChange = () => { };
|
---|
23 | this.onModelTouched = () => { };
|
---|
24 | }
|
---|
25 | ngOnInit() {
|
---|
26 | this.starsArray = [];
|
---|
27 | for (let i = 0; i < this.stars; i++) {
|
---|
28 | this.starsArray[i] = i;
|
---|
29 | }
|
---|
30 | }
|
---|
31 | rate(event, i) {
|
---|
32 | if (!this.readonly && !this.disabled) {
|
---|
33 | this.value = (i + 1);
|
---|
34 | this.onModelChange(this.value);
|
---|
35 | this.onModelTouched();
|
---|
36 | this.onRate.emit({
|
---|
37 | originalEvent: event,
|
---|
38 | value: (i + 1)
|
---|
39 | });
|
---|
40 | }
|
---|
41 | event.preventDefault();
|
---|
42 | }
|
---|
43 | clear(event) {
|
---|
44 | if (!this.readonly && !this.disabled) {
|
---|
45 | this.value = null;
|
---|
46 | this.onModelChange(this.value);
|
---|
47 | this.onModelTouched();
|
---|
48 | this.onCancel.emit(event);
|
---|
49 | }
|
---|
50 | event.preventDefault();
|
---|
51 | }
|
---|
52 | writeValue(value) {
|
---|
53 | this.value = value;
|
---|
54 | this.cd.detectChanges();
|
---|
55 | }
|
---|
56 | registerOnChange(fn) {
|
---|
57 | this.onModelChange = fn;
|
---|
58 | }
|
---|
59 | registerOnTouched(fn) {
|
---|
60 | this.onModelTouched = fn;
|
---|
61 | }
|
---|
62 | setDisabledState(val) {
|
---|
63 | this.disabled = val;
|
---|
64 | this.cd.markForCheck();
|
---|
65 | }
|
---|
66 | }
|
---|
67 | Rating.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Rating, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
---|
68 | Rating.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", 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" }, host: { classAttribute: "p-element" }, providers: [RATING_VALUE_ACCESSOR], ngImport: i0, template: `
|
---|
69 | <div class="p-rating" [ngClass]="{'p-readonly': readonly, 'p-disabled': disabled}">
|
---|
70 | <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>
|
---|
71 | <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)"
|
---|
72 | [ngClass]="(!value || i >= value) ? iconOffClass : iconOnClass"
|
---|
73 | [ngStyle]="(!value || i >= value) ? iconOffStyle : iconOnStyle"></span>
|
---|
74 | </div>
|
---|
75 | `, isInline: true, styles: [".p-rating-icon{cursor:pointer}.p-rating.p-rating-readonly .p-rating-icon{cursor:default}\n"], 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 });
|
---|
76 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Rating, decorators: [{
|
---|
77 | type: Component,
|
---|
78 | args: [{ selector: 'p-rating', template: `
|
---|
79 | <div class="p-rating" [ngClass]="{'p-readonly': readonly, 'p-disabled': disabled}">
|
---|
80 | <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>
|
---|
81 | <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)"
|
---|
82 | [ngClass]="(!value || i >= value) ? iconOffClass : iconOnClass"
|
---|
83 | [ngStyle]="(!value || i >= value) ? iconOffStyle : iconOnStyle"></span>
|
---|
84 | </div>
|
---|
85 | `, providers: [RATING_VALUE_ACCESSOR], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
---|
86 | 'class': 'p-element'
|
---|
87 | }, styles: [".p-rating-icon{cursor:pointer}.p-rating.p-rating-readonly .p-rating-icon{cursor:default}\n"] }]
|
---|
88 | }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { disabled: [{
|
---|
89 | type: Input
|
---|
90 | }], readonly: [{
|
---|
91 | type: Input
|
---|
92 | }], stars: [{
|
---|
93 | type: Input
|
---|
94 | }], cancel: [{
|
---|
95 | type: Input
|
---|
96 | }], iconOnClass: [{
|
---|
97 | type: Input
|
---|
98 | }], iconOnStyle: [{
|
---|
99 | type: Input
|
---|
100 | }], iconOffClass: [{
|
---|
101 | type: Input
|
---|
102 | }], iconOffStyle: [{
|
---|
103 | type: Input
|
---|
104 | }], iconCancelClass: [{
|
---|
105 | type: Input
|
---|
106 | }], iconCancelStyle: [{
|
---|
107 | type: Input
|
---|
108 | }], onRate: [{
|
---|
109 | type: Output
|
---|
110 | }], onCancel: [{
|
---|
111 | type: Output
|
---|
112 | }] } });
|
---|
113 | class RatingModule {
|
---|
114 | }
|
---|
115 | RatingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RatingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
116 | RatingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RatingModule, declarations: [Rating], imports: [CommonModule], exports: [Rating] });
|
---|
117 | RatingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RatingModule, imports: [[CommonModule]] });
|
---|
118 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RatingModule, decorators: [{
|
---|
119 | type: NgModule,
|
---|
120 | args: [{
|
---|
121 | imports: [CommonModule],
|
---|
122 | exports: [Rating],
|
---|
123 | declarations: [Rating]
|
---|
124 | }]
|
---|
125 | }] });
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Generated bundle index. Do not edit.
|
---|
129 | */
|
---|
130 |
|
---|
131 | export { RATING_VALUE_ACCESSOR, Rating, RatingModule };
|
---|