primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 5.17 kB
JavaScript
import { forwardRef, EventEmitter, ChangeDetectorRef, Input, Output, Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var INPUTSWITCH_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return InputSwitch; }),
multi: true
};
var InputSwitch = /** @class */ (function () {
function InputSwitch(cd) {
this.cd = cd;
this.onChange = new EventEmitter();
this.checked = false;
this.focused = false;
this.onModelChange = function () { };
this.onModelTouched = function () { };
}
InputSwitch.prototype.onClick = function (event, cb) {
if (!this.disabled && !this.readonly) {
event.preventDefault();
this.toggle(event);
cb.focus();
}
};
InputSwitch.prototype.onInputChange = function (event) {
if (!this.readonly) {
var inputChecked = event.target.checked;
this.updateModel(event, inputChecked);
}
};
InputSwitch.prototype.toggle = function (event) {
this.updateModel(event, !this.checked);
};
InputSwitch.prototype.updateModel = function (event, value) {
this.checked = value;
this.onModelChange(this.checked);
this.onChange.emit({
originalEvent: event,
checked: this.checked
});
};
InputSwitch.prototype.onFocus = function (event) {
this.focused = true;
};
InputSwitch.prototype.onBlur = function (event) {
this.focused = false;
this.onModelTouched();
};
InputSwitch.prototype.writeValue = function (checked) {
this.checked = checked;
this.cd.markForCheck();
};
InputSwitch.prototype.registerOnChange = function (fn) {
this.onModelChange = fn;
};
InputSwitch.prototype.registerOnTouched = function (fn) {
this.onModelTouched = fn;
};
InputSwitch.prototype.setDisabledState = function (val) {
this.disabled = val;
};
InputSwitch.ctorParameters = function () { return [
{ type: ChangeDetectorRef }
]; };
__decorate([
Input()
], InputSwitch.prototype, "style", void 0);
__decorate([
Input()
], InputSwitch.prototype, "styleClass", void 0);
__decorate([
Input()
], InputSwitch.prototype, "tabindex", void 0);
__decorate([
Input()
], InputSwitch.prototype, "inputId", void 0);
__decorate([
Input()
], InputSwitch.prototype, "name", void 0);
__decorate([
Input()
], InputSwitch.prototype, "disabled", void 0);
__decorate([
Input()
], InputSwitch.prototype, "readonly", void 0);
__decorate([
Input()
], InputSwitch.prototype, "ariaLabelledBy", void 0);
__decorate([
Output()
], InputSwitch.prototype, "onChange", void 0);
InputSwitch = __decorate([
Component({
selector: 'p-inputSwitch',
template: "\n <div [ngClass]=\"{'ui-inputswitch ui-widget': true, 'ui-inputswitch-checked': checked, 'ui-state-disabled': disabled, 'ui-inputswitch-readonly': readonly, 'ui-inputswitch-focus': focused}\" \n [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"onClick($event, cb)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #cb type=\"checkbox\" [attr.id]=\"inputId\" [attr.name]=\"name\" [attr.tabindex]=\"tabindex\" [checked]=\"checked\" (change)=\"onInputChange($event)\"\n (focus)=\"onFocus($event)\" (blur)=\"onBlur($event)\" [disabled]=\"disabled\" role=\"switch\" [attr.aria-checked]=\"checked\" [attr.aria-labelledby]=\"ariaLabelledBy\"/>\n </div>\n <span class=\"ui-inputswitch-slider\"></span>\n </div>\n ",
providers: [INPUTSWITCH_VALUE_ACCESSOR],
changeDetection: ChangeDetectionStrategy.Default
})
], InputSwitch);
return InputSwitch;
}());
var InputSwitchModule = /** @class */ (function () {
function InputSwitchModule() {
}
InputSwitchModule = __decorate([
NgModule({
imports: [CommonModule],
exports: [InputSwitch],
declarations: [InputSwitch]
})
], InputSwitchModule);
return InputSwitchModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { INPUTSWITCH_VALUE_ACCESSOR, InputSwitch, InputSwitchModule };
//# sourceMappingURL=primeng-inputswitch.js.map