import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RippleModule } from 'primeng/ripple'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; const TOGGLEBUTTON_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ToggleButton), multi: true }; class ToggleButton { constructor(cd) { this.cd = cd; this.iconPos = 'left'; this.onChange = new EventEmitter(); this.checked = false; this.onModelChange = () => { }; this.onModelTouched = () => { }; } toggle(event) { if (!this.disabled) { this.checked = !this.checked; this.onModelChange(this.checked); this.onModelTouched(); this.onChange.emit({ originalEvent: event, checked: this.checked }); this.cd.markForCheck(); } } onBlur() { this.onModelTouched(); } writeValue(value) { this.checked = value; this.cd.markForCheck(); } registerOnChange(fn) { this.onModelChange = fn; } registerOnTouched(fn) { this.onModelTouched = fn; } setDisabledState(val) { this.disabled = val; this.cd.markForCheck(); } get hasOnLabel() { return this.onLabel && this.onLabel.length > 0; } get hasOffLabel() { return this.onLabel && this.onLabel.length > 0; } } ToggleButton.decorators = [ { type: Component, args: [{ selector: 'p-toggleButton', template: `
{{checked ? hasOnLabel ? onLabel : '' : hasOffLabel ? offLabel : ''}}
`, providers: [TOGGLEBUTTON_VALUE_ACCESSOR], changeDetection: ChangeDetectionStrategy.OnPush, styles: [".p-button{-moz-user-select:none;-ms-flex-align:center;-ms-user-select:none;-webkit-user-select:none;align-items:center;cursor:pointer;display:-ms-inline-flexbox;display:inline-flex;margin:0;overflow:hidden;position:relative;text-align:center;user-select:none;vertical-align:bottom}.p-button-label{-ms-flex:1 1 auto;flex:1 1 auto}.p-button-icon-right{-ms-flex-order:1;order:1}.p-button:disabled{cursor:default}.p-button-icon-only{-ms-flex-pack:center;justify-content:center}.p-button-icon-only .p-button-label{-ms-flex:0 0 auto;flex:0 0 auto;visibility:hidden;width:0}.p-button-vertical{-ms-flex-direction:column;flex-direction:column}.p-button-icon-bottom{-ms-flex-order:2;order:2}.p-buttonset .p-button{margin:0}.p-buttonset .p-button:not(:last-child){border-right:0}.p-buttonset .p-button:not(:first-of-type):not(:last-of-type){border-radius:0}.p-buttonset .p-button:first-of-type{border-bottom-right-radius:0;border-top-right-radius:0}.p-buttonset .p-button:last-of-type{border-bottom-left-radius:0;border-top-left-radius:0}.p-buttonset .p-button:focus{position:relative;z-index:1}"] },] } ]; ToggleButton.ctorParameters = () => [ { type: ChangeDetectorRef } ]; ToggleButton.propDecorators = { onLabel: [{ type: Input }], offLabel: [{ type: Input }], onIcon: [{ type: Input }], offIcon: [{ type: Input }], ariaLabelledBy: [{ type: Input }], disabled: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], inputId: [{ type: Input }], tabindex: [{ type: Input }], iconPos: [{ type: Input }], onChange: [{ type: Output }] }; class ToggleButtonModule { } ToggleButtonModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, RippleModule], exports: [ToggleButton], declarations: [ToggleButton] },] } ]; /** * Generated bundle index. Do not edit. */ export { TOGGLEBUTTON_VALUE_ACCESSOR, ToggleButton, ToggleButtonModule }; //# sourceMappingURL=primeng-togglebutton.js.map