{"version":3,"file":"primeng-togglebutton.js","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
\n \n {{checked ? hasOnLabel ? onLabel : '' : hasOffLabel ? offLabel : ''}}\n
\n `,\n providers: [TOGGLEBUTTON_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush,\n styleUrls: ['../button/button.css']\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 = 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;MAiBW,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,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;YAC7B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACf,aAAa,EAAE,KAAK;gBACpB,OAAO,EAAE,IAAI,CAAC,OAAO;aACxB,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC;SAC1B;KACJ;IAED,MAAM;QACF,IAAI,CAAC,cAAc,EAAE,CAAC;KACzB;IAED,UAAU,CAAC,KAAU;QACjB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,C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