32 lines
804 B
TypeScript
32 lines
804 B
TypeScript
import { Component, OnInit, Input, ChangeDetectionStrategy } from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'kendo-rating',
|
|
template: `
|
|
@for (item of stars; track item) {
|
|
<span [ngClass]="ratingIcon(item)"></span>
|
|
}
|
|
`,
|
|
styles: [`
|
|
.yellow {
|
|
color: #ffa600;
|
|
}
|
|
`],
|
|
changeDetection: ChangeDetectionStrategy.Eager,
|
|
standalone: false,
|
|
})
|
|
export class RatingComponent implements OnInit {
|
|
@Input() public value: number;
|
|
@Input() public max: number;
|
|
|
|
public stars: number[];
|
|
|
|
public ngOnInit(): void {
|
|
this.stars = new Array(this.max).fill(1).map((item, index) => item + index);
|
|
}
|
|
|
|
public ratingIcon(item: number): string {
|
|
return (item <= this.value) ? 'k-icon k-i-star yellow' : 'k-icon k-i-star-outline';
|
|
}
|
|
}
|