{"version":3,"file":"primeng-selectbutton.js","sources":["../../src/app/components/selectbutton/selectbutton.ts","../../src/app/components/selectbutton/primeng-selectbutton.ts"],"sourcesContent":["import {NgModule,Component,Input,Output,EventEmitter,forwardRef,ChangeDetectorRef,ContentChild,TemplateRef,ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {ObjectUtils} from 'primeng/utils';\nimport {RippleModule} from 'primeng/ripple';\nimport {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';\n\nexport const SELECTBUTTON_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => SelectButton),\n multi: true\n};\n\n@Component({\n selector: 'p-selectButton',\n template: `\n
\n
\n \n \n {{getOptionLabel(option)}}\n \n \n \n \n
\n
\n `,\n providers: [SELECTBUTTON_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styleUrls: ['../button/button.css']\n})\nexport class SelectButton implements ControlValueAccessor {\n\n @Input() options: any[];\n\n @Input() optionLabel: string;\n\n @Input() optionValue: string;\n\n @Input() optionDisabled: string;\n\n @Input() tabindex: number = 0;\n\n @Input() multiple: boolean;\n \n @Input() style: any;\n \n @Input() styleClass: string;\n\n @Input() ariaLabelledBy: string;\n\n @Input() disabled: boolean;\n\n @Input() dataKey: string\n \n @Output() onOptionClick: EventEmitter = new EventEmitter();\n\n @Output() onChange: EventEmitter = new EventEmitter();\n\n @ContentChild(TemplateRef) itemTemplate;\n \n value: any;\n \n onModelChange: Function = () => {};\n \n onModelTouched: Function = () => {};\n \n constructor(public cd: ChangeDetectorRef) {}\n \n getOptionLabel(option: any) {\n return this.optionLabel ? ObjectUtils.resolveFieldData(option, this.optionLabel) : (option.label != undefined ? option.label : option);\n }\n\n getOptionValue(option: any) {\n return this.optionValue ? ObjectUtils.resolveFieldData(option, this.optionValue) : (this.optionLabel ? option : option.value);\n }\n\n isOptionDisabled(option: any) {\n return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : (option.disabled !== undefined ? option.disabled : false);\n }\n \n writeValue(value: any) : void {\n this.value = 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 onItemClick(event, option: any, index: number) {\n if (this.disabled || this.isOptionDisabled(option)) {\n return;\n }\n \n if (this.multiple) {\n if (this.isSelected(option))\n this.removeOption(option);\n else\n this.value = [...(this.value||[]), this.getOptionValue(option)];\n }\n else {\n this.value = this.getOptionValue(option);\n }\n \n this.onOptionClick.emit({\n originalEvent: event,\n option: option,\n index: index\n });\n \n this.onModelChange(this.value);\n \n this.onChange.emit({\n originalEvent: event,\n value: this.value\n });\n }\n \n onBlur() {\n this.onModelTouched();\n }\n\n removeOption(option: any): void {\n this.value = this.value.filter(val => !ObjectUtils.equals(val, this.getOptionValue(option), this.dataKey));\n }\n \n isSelected(option: any) {\n let selected = false;\n let optionValue = this.getOptionValue(option);\n\n if (this.multiple) {\n if (this.value) {\n for (let val of this.value) {\n if (ObjectUtils.equals(val, optionValue, this.dataKey)) {\n selected = true;\n break;\n }\n }\n }\n }\n else {\n selected = ObjectUtils.equals(this.getOptionValue(option), this.value, this.dataKey);\n }\n\n return selected;\n }\n}\n\n@NgModule({\n imports: [CommonModule,RippleModule],\n exports: [SelectButton],\n declarations: [SelectButton]\n})\nexport class SelectButtonModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;MAMa,2BAA2B,GAAQ;IAC9C,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,UAAU,CAAC,MAAM,YAAY,CAAC;IAC3C,KAAK,EAAE,IAAI;EACX;MA2BW,YAAY;IAoCrB,YAAmB,EAAqB;QAArB,OAAE,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