UNPKG

8.87 kBSource Map (JSON)View Raw
1{"version":3,"sources":["ng://primeng/selectbutton/selectbutton.ts"],"names":["SELECTBUTTON_VALUE_ACCESSOR","provide","NG_VALUE_ACCESSOR","useExisting","forwardRef","SelectButton","multi","cd","this","tabindex","onOptionClick","EventEmitter","onChange","onModelChange","onModelTouched","Object","defineProperty","prototype","_options","val","ngOnChanges","simpleChange","options","optionLabel","ObjectUtils","generateSelectItems","currentValue","writeValue","value","markForCheck","registerOnChange","fn","registerOnTouched","setDisabledState","disabled","onItemClick","event","option","index","multiple","itemIndex_1","findItemIndex","filter","i","__spread","emit","originalEvent","onFocus","focusedItem","target","onBlur","isSelected","equals","dataKey","length","ChangeDetectorRef","__decorate","Input","Output","ContentChild","TemplateRef","Component","selector","template","providers","changeDetection","ChangeDetectionStrategy","Default","SelectButtonModule","NgModule","imports","CommonModule","exports","declarations"],"mappings":"ouCAMaA,EAAmC,CAC9CC,QAASC,EAAAA,kBACTC,YAAaC,EAAAA,YAAW,WAAM,OAAAC,KAC9BC,OAAO,GAwBTD,EAAA,WAkCI,SAAAA,EAAoBE,GAAAC,KAAAD,GAAAA,EAhCXC,KAAAC,SAAmB,EAgBlBD,KAAAE,cAAmC,IAAIC,EAAAA,aAEvCH,KAAAI,SAA8B,IAAID,EAAAA,aAU5CH,KAAAK,cAA0B,aAE1BL,KAAAM,eAA2B,aA6F/B,OAzFaC,OAAAC,eAAIX,EAAAY,UAAA,UAAO,KAAX,WACL,OAAOT,KAAKU,cAGhB,SAAYC,qCAIZd,EAAAY,UAAAG,YAAA,SAAYC,GACJA,EAAaC,UACbd,KAAKU,SAAWV,KAAKe,YAAcC,EAAAA,YAAYC,oBAAoBJ,EAAaC,QAAQI,aAAclB,KAAKe,aAAeF,EAAaC,QAAQI,eAIvJrB,EAAAY,UAAAU,WAAA,SAAWC,GACPpB,KAAKoB,MAAQA,EACbpB,KAAKD,GAAGsB,gBAGZxB,EAAAY,UAAAa,iBAAA,SAAiBC,GACbvB,KAAK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wCAEQD,EAAA,CAARC,EAAAA,wCAEQD,EAAA,CAARC,EAAAA,qCAEQD,EAAA,CAARC,EAAAA,0CAEQD,EAAA,CAARC,EAAAA,8CAEQD,EAAA,CAARC,EAAAA,wCAEQD,EAAA,CAARC,EAAAA,uCAEQD,EAAA,CAARC,EAAAA,2CAESD,EAAA,CAATE,EAAAA,8CAESF,EAAA,CAATE,EAAAA,yCAE0BF,EAAA,CAA1BG,EAAAA,aAAaC,EAAAA,iDAcLJ,EAAA,CAARC,EAAAA,qCApCQpD,EAAYmD,EAAA,CArBxBK,EAAAA,UAAU,CACPC,SAAU,iBACVC,SAAU,ihDAgBVC,UAAW,CAAChE,GACZiE,gBAAiBC,EAAAA,wBAAwBC,WAEhC9D,GAAb,gBAoIA,SAAA+D,KAAkC,OAArBA,EAAkBZ,EAAA,CAL9Ba,EAAAA,SAAS,CACNC,QAAS,CAACC,EAAAA,cACVC,QAAS,CAACnE,GACVoE,aAAc,CAACpE,MAEN+D","sourcesContent":["import {NgModule,Component,Input,Output,EventEmitter,forwardRef,ChangeDetectorRef,ContentChild,TemplateRef,SimpleChanges,OnChanges,ChangeDetectionStrategy} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {SelectItem} from 'primeng/api';\nimport {ObjectUtils} from 'primeng/utils';\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 <div [ngClass]=\"'ui-selectbutton ui-buttonset ui-widget ui-corner-all ui-buttonset-' + (options ? options.length : 0)\" [ngStyle]=\"style\" [class]=\"styleClass\" role=\"group\">\n <div *ngFor=\"let option of options; let i = index\" #btn class=\"ui-button ui-widget ui-state-default ui-button-text-only {{option.styleClass}}\" role=\"button\" [attr.aria-pressed]=\"isSelected(option)\"\n [ngClass]=\"{'ui-state-active':isSelected(option), 'ui-state-disabled': disabled || option.disabled, 'ui-state-focus': btn == focusedItem, \n 'ui-button-text-icon-left': (option.icon != null), 'ui-button-icon-only': (option.icon && !option.label)}\" (click)=\"onItemClick($event,option,i)\" (keydown.enter)=\"onItemClick($event,option,i)\"\n [attr.title]=\"option.title\" [attr.aria-label]=\"option.label\" (focus)=\"onFocus($event)\" (blur)=\"onBlur($event)\" [attr.tabindex]=\"tabindex\" [attr.aria-labelledby]=\"ariaLabelledBy\">\n <ng-container *ngIf=\"!itemTemplate else customcontent\">\n <span [ngClass]=\"['ui-clickable', 'ui-button-icon-left']\" [class]=\"option.icon\" *ngIf=\"option.icon\"></span>\n <span class=\"ui-button-text ui-clickable\">{{option.label||'ui-btn'}}</span>\n </ng-container>\n <ng-template #customcontent>\n <ng-container *ngTemplateOutlet=\"itemTemplate; context: {$implicit: option, index: i}\"></ng-container>\n </ng-template>\n </div>\n </div>\n `,\n providers: [SELECTBUTTON_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.Default\n})\nexport class SelectButton implements ControlValueAccessor, OnChanges {\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 @Input() optionLabel: string;\n \n @Output() onOptionClick: EventEmitter<any> = new EventEmitter();\n\n @Output() onChange: EventEmitter<any> = new EventEmitter();\n\n @ContentChild(TemplateRef) itemTemplate;\n \n value: any;\n \n focusedItem: HTMLDivElement;\n \n _options: any[];\n \n onModelChange: Function = () => {};\n \n onModelTouched: Function = () => {};\n \n constructor(private cd: ChangeDetectorRef) {}\n \n @Input() get options(): any[] {\n return this._options;\n }\n\n set options(val: any[]) {\n //NoOp\n }\n\n ngOnChanges(simpleChange: SimpleChanges) {\n if (simpleChange.options) {\n this._options = this.optionLabel ? ObjectUtils.generateSelectItems(simpleChange.options.currentValue, this.optionLabel) : simpleChange.options.currentValue;\n }\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 }\n \n onItemClick(event, option: SelectItem, index: number) {\n if (this.disabled || option.disabled) {\n return;\n }\n \n if (this.multiple) {\n let itemIndex = this.findItemIndex(option);\n if (itemIndex != -1)\n this.value = this.value.filter((val,i) => i!=itemIndex);\n else\n this.value = [...this.value||[], option.value];\n }\n else {\n this.value = option.value;\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 onFocus(event: Event) {\n this.focusedItem = <HTMLDivElement> event.target;\n }\n \n onBlur(event) {\n this.focusedItem = null;\n this.onModelTouched();\n }\n \n isSelected(option: SelectItem) {\n if (this.multiple)\n return this.findItemIndex(option) != -1;\n else\n return ObjectUtils.equals(option.value, this.value, this.dataKey);\n }\n \n findItemIndex(option: SelectItem) {\n let index = -1;\n if (this.value) {\n for(let i = 0; i < this.value.length; i++) {\n if (this.value[i] == option.value) {\n index = i;\n break;\n }\n }\n }\n return index;\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [SelectButton],\n declarations: [SelectButton]\n})\nexport class SelectButtonModule { }\n"]}
\No newline at end of file