ionic3-star-rating-giabeni
Version:
A simple component for star rating
49 lines • 2.49 kB
JavaScript
import { Component, Input } from '@angular/core';
import { Events } from 'ionic-angular';
var HTML_TEMPLATE = "\n<div class=\"ionic3-star-rating\">\n <button *ngFor=\"let index of [0,1,2,3,4]\" id=\"{{index}}\" type=\"button\" ion-button icon-only (click)=\"changeRating($event)\">\n <ion-icon [ngStyle]=\"{'color':index < this.Math.round(this.parseFloat(rating)) ? activeColor : defaultColor }\" name=\"{{index < this.Math.round(this.parseFloat(rating)) ? activeIcon : defaultIcon}}\"></ion-icon>\n </button>\n</div>\n";
var CSS_STYLE = "\n .ionic3-star-rating .button {\n height: 28px;\n background: none;\n box-shadow: none;\n -webkit-box-shadow: none;\n width: 28px;\n }\n .ionic3-star-rating .button ion-icon {\n font-size: 32px;\n }\n";
var StarRating = (function () {
function StarRating(events) {
this.events = events;
this.rating = 3;
this.readonly = "false";
this.activeColor = '#488aff';
this.defaultColor = '#f4f4f4';
this.activeIcon = 'ios-star';
this.defaultIcon = 'ios-star-outline';
this.object = null;
this.Math = Math;
this.parseFloat = parseFloat;
}
StarRating.prototype.changeRating = function (event) {
if (this.readonly && this.readonly === "true")
return;
// event is different for firefox and chrome
this.rating = event.target.id ? parseInt(event.target.id) + 1 : parseInt(event.target.parentElement.id) + 1;
// subscribe this event to get the changed value in ypour parent compoanent
this.events.publish('star-rating:changed', {object: this.object, rating: this.rating});
};
StarRating.decorators = [
{ type: Component, args: [{
selector: 'ionic3-star-rating',
template: HTML_TEMPLATE,
styles: [CSS_STYLE]
},] },
];
/** @nocollapse */
StarRating.ctorParameters = function () { return [
{ type: Events, },
]; };
StarRating.propDecorators = {
"rating": [{ type: Input },],
"readonly": [{ type: Input },],
"activeColor": [{ type: Input },],
"defaultColor": [{ type: Input },],
"activeIcon": [{ type: Input },],
"defaultIcon": [{ type: Input },],
"object": [{ type: Input },],
};
return StarRating;
}());
export { StarRating };
//# sourceMappingURL=ionic3-star-rating-component.js.map