ngx-material-rating
Version:
A Material Design rating component
173 lines (165 loc) • 7.75 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/coercion'), require('@angular/core'), require('@angular/forms'), require('@angular/material/button'), require('@angular/material/icon'), require('ngx-range')) :
typeof define === 'function' && define.amd ? define('ngx-material-rating', ['exports', '@angular/cdk/coercion', '@angular/core', '@angular/forms', '@angular/material/button', '@angular/material/icon', 'ngx-range'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-material-rating'] = {}, global.ng.cdk.coercion, global.ng.core, global.ng.forms, global.ng.material.button, global.ng.material.icon, global['ngx-range']));
}(this, (function (exports, coercion, core, forms, button, icon, ngxRange) { 'use strict';
var NGX_MATERIAL_RATING_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: core.forwardRef(function () { return NgxMaterialRatingComponent; }),
multi: true,
};
var NgxMaterialRatingComponent = /** @class */ (function () {
function NgxMaterialRatingComponent(_changeDetectorRef) {
this._changeDetectorRef = _changeDetectorRef;
this.color = undefined;
this._max = 5;
this._value = null;
this._roundToDecimal = 1;
this._disabled = false;
this._dense = false;
this._readonly = false;
this.change = new core.EventEmitter();
this.valueChange = new core.EventEmitter();
this.onTouched = function () { };
this._cvaChangeFn = function () { };
}
Object.defineProperty(NgxMaterialRatingComponent.prototype, "max", {
get: function () {
return this._max;
},
set: function (v) {
this._max = coercion.coerceNumberProperty(v, this._max);
this._changeDetectorRef.markForCheck();
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgxMaterialRatingComponent.prototype, "value", {
get: function () {
if (this._value === null) {
this.value = 0;
}
return this._value;
},
set: function (v) {
if (v !== this._value) {
var value = coercion.coerceNumberProperty(v);
if (this._roundToDecimal && value !== 0 && value !== this.max) {
value = parseFloat(value.toFixed(this._roundToDecimal));
}
this._value = value;
this._changeDetectorRef.markForCheck();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgxMaterialRatingComponent.prototype, "disabled", {
get: function () {
return this._disabled;
},
set: function (value) {
this._disabled = coercion.coerceBooleanProperty(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgxMaterialRatingComponent.prototype, "dense", {
get: function () {
return this._dense;
},
set: function (value) {
this._dense = coercion.coerceBooleanProperty(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgxMaterialRatingComponent.prototype, "readonly", {
get: function () {
return this._readonly;
},
set: function (value) {
this._readonly = coercion.coerceBooleanProperty(value);
},
enumerable: false,
configurable: true
});
NgxMaterialRatingComponent.prototype.writeValue = function (value) {
this.value = value;
};
NgxMaterialRatingComponent.prototype.registerOnChange = function (fn) {
this._cvaChangeFn = fn;
};
NgxMaterialRatingComponent.prototype.registerOnTouched = function (fn) {
this.onTouched = fn;
};
NgxMaterialRatingComponent.prototype.setDisabledState = function (isDisabled) {
this.disabled = isDisabled;
};
NgxMaterialRatingComponent.prototype.onClick = function (index) {
if (this.disabled || this.readonly) {
return;
}
var newValue = index + 1;
this.value = this.value === newValue ? index : newValue;
this._emitChangeEvent();
};
NgxMaterialRatingComponent.prototype.getStar = function (index) {
var value = this.value || 0;
if (index < value) {
return 'star';
}
return 'star_border';
};
NgxMaterialRatingComponent.prototype._emitChangeEvent = function () {
this._cvaChangeFn(this.value);
this.valueChange.emit(this.value);
this.change.emit({ source: this, value: this.value });
};
return NgxMaterialRatingComponent;
}());
NgxMaterialRatingComponent.decorators = [
{ type: core.Component, args: [{
selector: 'ngx-material-rating',
exportAs: 'ngxMaterialRating',
providers: [NGX_MATERIAL_RATING_VALUE_ACCESSOR],
template: "<ng-container *ngxRange=\"let index from 0 to max\">\r\n <button mat-icon-button [class.dense]=\"dense\" [class.readonly]=\"readonly\" [color]=\" color\" [disabled]=\"disabled\"\r\n [disableRipple]=\"readonly\" (click)=\"onClick(index)\">\r\n <mat-icon>{{getStar(index)}}</mat-icon>\r\n </button>\r\n</ng-container>\r\n",
styles: [".dense.mat-icon-button{height:1.5rem;line-height:1.5rem;width:1.5rem}.readonly.mat-icon-button{cursor:default}"]
},] }
];
NgxMaterialRatingComponent.ctorParameters = function () { return [
{ type: core.ChangeDetectorRef }
]; };
NgxMaterialRatingComponent.propDecorators = {
color: [{ type: core.Input }],
max: [{ type: core.Input }],
value: [{ type: core.Input }],
disabled: [{ type: core.Input }],
dense: [{ type: core.Input }],
readonly: [{ type: core.Input }],
change: [{ type: core.Output }]
};
var NgxMaterialRatingModule = /** @class */ (function () {
function NgxMaterialRatingModule() {
}
return NgxMaterialRatingModule;
}());
NgxMaterialRatingModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgxMaterialRatingComponent],
imports: [button.MatButtonModule, icon.MatIconModule, ngxRange.NgxRangeModule],
exports: [NgxMaterialRatingComponent],
},] }
];
/*
* Public API Surface of ngx-material-rating
*/
/**
* Generated bundle index. Do not edit.
*/
exports.NGX_MATERIAL_RATING_VALUE_ACCESSOR = NGX_MATERIAL_RATING_VALUE_ACCESSOR;
exports.NgxMaterialRatingComponent = NgxMaterialRatingComponent;
exports.NgxMaterialRatingModule = NgxMaterialRatingModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-material-rating.umd.js.map