UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![Build Status](https://travis-ci.org/primefaces/primeng.

133 lines (129 loc) 4.43 kB
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; }; const INPUTSWITCH_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => InputSwitch), multi: true }; let InputSwitch = class InputSwitch { constructor(cd) { this.cd = cd; this.onChange = new EventEmitter(); this.checked = false; this.focused = false; this.onModelChange = () => { }; this.onModelTouched = () => { }; } onClick(event, cb) { if (!this.disabled && !this.readonly) { event.preventDefault(); this.toggle(event); cb.focus(); } } onInputChange(event) { if (!this.readonly) { const inputChecked = event.target.checked; this.updateModel(event, inputChecked); } } toggle(event) { this.updateModel(event, !this.checked); } updateModel(event, value) { this.checked = value; this.onModelChange(this.checked); this.onChange.emit({ originalEvent: event, checked: this.checked }); } onFocus(event) { this.focused = true; } onBlur(event) { this.focused = false; this.onModelTouched(); } writeValue(checked) { this.checked = checked; this.cd.markForCheck(); } registerOnChange(fn) { this.onModelChange = fn; } registerOnTouched(fn) { this.onModelTouched = fn; } setDisabledState(val) { this.disabled = val; } }; InputSwitch.ctorParameters = () => [ { 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: ` <div [ngClass]="{'ui-inputswitch ui-widget': true, 'ui-inputswitch-checked': checked, 'ui-state-disabled': disabled, 'ui-inputswitch-readonly': readonly, 'ui-inputswitch-focus': focused}" [ngStyle]="style" [class]="styleClass" (click)="onClick($event, cb)"> <div class="ui-helper-hidden-accessible"> <input #cb type="checkbox" [attr.id]="inputId" [attr.name]="name" [attr.tabindex]="tabindex" [checked]="checked" (change)="onInputChange($event)" (focus)="onFocus($event)" (blur)="onBlur($event)" [disabled]="disabled" role="switch" [attr.aria-checked]="checked" [attr.aria-labelledby]="ariaLabelledBy"/> </div> <span class="ui-inputswitch-slider"></span> </div> `, providers: [INPUTSWITCH_VALUE_ACCESSOR], changeDetection: ChangeDetectionStrategy.Default }) ], InputSwitch); let InputSwitchModule = class InputSwitchModule { }; InputSwitchModule = __decorate([ NgModule({ imports: [CommonModule], exports: [InputSwitch], declarations: [InputSwitch] }) ], InputSwitchModule); /** * Generated bundle index. Do not edit. */ export { INPUTSWITCH_VALUE_ACCESSOR, InputSwitch, InputSwitchModule }; //# sourceMappingURL=primeng-inputswitch.js.map