1 | {"version":3,"file":"primeng-togglebutton.mjs","sources":["../../src/app/components/togglebutton/togglebutton.ts","../../src/app/components/togglebutton/primeng-togglebutton.ts"],"sourcesContent":["import {NgModule,Component,Input,Output,EventEmitter,forwardRef,ChangeDetectionStrategy,ChangeDetectorRef} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {RippleModule} from 'primeng/ripple';\nimport {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';\n\nexport const TOGGLEBUTTON_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => ToggleButton),\n multi: true\n};\n\n@Component({\n selector: 'p-toggleButton',\n template: `\n <div [ngClass]=\"{'p-button p-togglebutton p-component': true, 'p-button-icon-only': (onIcon && offIcon && !hasOnLabel && !hasOffLabel),'p-highlight': checked,'p-disabled':disabled}\"\n [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"toggle($event)\" (keydown.enter)=\"toggle($event)\"\n [attr.tabindex]=\"disabled ? null : '0'\" role=\"checkbox\" [attr.aria-checked]=\"checked\" pRipple>\n <span *ngIf=\"onIcon||offIcon\" [class]=\"checked ? this.onIcon : this.offIcon\"\n [ngClass]=\"{'p-button-icon': true, 'p-button-icon-left': (iconPos === 'left'), 'p-button-icon-right': (iconPos === 'right')}\"></span>\n <span class=\"p-button-label\">{{checked ? hasOnLabel ? onLabel : '' : hasOffLabel ? offLabel : ''}}</span>\n </div>\n `,\n providers: [TOGGLEBUTTON_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush,\n styleUrls: ['../button/button.css'],\n host: {\n 'class': 'p-element'\n }\n})\nexport class ToggleButton implements ControlValueAccessor {\n\n @Input() onLabel: string;\n\n @Input() offLabel: string;\n\n @Input() onIcon: string;\n\n @Input() offIcon: string;\n\n @Input() ariaLabelledBy: string;\n\n @Input() disabled: boolean;\n\n @Input() style: any;\n\n @Input() styleClass: string;\n\n @Input() inputId: string;\n\n @Input() tabindex: number;\n\n @Input() iconPos: string = 'left';\n\n @Output() onChange: EventEmitter<any> = new EventEmitter();\n\n checked: boolean = false;\n\n onModelChange: Function = () => {};\n\n onModelTouched: Function = () => {};\n\n constructor(public cd: ChangeDetectorRef) { }\n\n toggle(event: Event) {\n if (!this.disabled) {\n this.checked = !this.checked;\n this.onModelChange(this.checked);\n this.onModelTouched();\n this.onChange.emit({\n originalEvent: event,\n checked: this.checked\n });\n\n this.cd.markForCheck();\n }\n }\n\n onBlur() {\n this.onModelTouched();\n }\n\n writeValue(value: any) : void {\n this.checked = value;\n this.cd.markForCheck();\n }\n\n registerOnChange(fn: Function): void {\n this.onModelChange = fn;\n }\n\n registerOnTouched(fn: Function): void {\n this.onModelTouched = fn;\n }\n\n setDisabledState(val: boolean): void {\n this.disabled = val;\n this.cd.markForCheck();\n }\n\n get hasOnLabel():boolean {\n return this.onLabel && this.onLabel.length > 0;\n }\n\n get hasOffLabel():boolean {\n return this.onLabel && this.onLabel.length > 0;\n }\n}\n\n@NgModule({\n imports: [CommonModule,RippleModule],\n exports: [ToggleButton],\n declarations: [ToggleButton]\n})\nexport class ToggleButtonModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;MAKa,2BAA2B,GAAQ;IAC9C,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,UAAU,CAAC,MAAM,YAAY,CAAC;IAC3C,KAAK,EAAE,IAAI;EACX;MAoBW,YAAY;IAgCrB,YAAmB,EAAqB;QAArB,OAAE,GAAF,EAAE,CAAmB;QAV/B,YAAO,GAAW,MAAM,CAAC;QAExB,aAAQ,GAAsB,IAAI,YAAY,EAAE,CAAC;QAE3D,YAAO,GAAY,KAAK,CAAC;QAEzB,kBAAa,GAAa,SAAQ,CAAC;QAEnC,mBAAc,GAAa,SAAQ,CAAC;KAES;IAE7C,MAAM,CAAC,KAAY;QACf,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChB,IAAI,CAAC,O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