UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Join the chat at https://gitter.im/primefaces/primeng](https://badges.gitter.im/primefaces/primeng.svg)](https://gitter.im/primefaces/primeng?ut

174 lines 8.09 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var objectutils_1 = require("../utils/objectutils"); var forms_1 = require("@angular/forms"); exports.SELECTBUTTON_VALUE_ACCESSOR = { provide: forms_1.NG_VALUE_ACCESSOR, useExisting: core_1.forwardRef(function () { return SelectButton; }), multi: true }; var SelectButton = /** @class */ (function () { function SelectButton(objectUtils, cd) { this.objectUtils = objectUtils; this.cd = cd; this.onOptionClick = new core_1.EventEmitter(); this.onChange = new core_1.EventEmitter(); this.onModelChange = function () { }; this.onModelTouched = function () { }; } Object.defineProperty(SelectButton.prototype, "options", { get: function () { return this._options; }, set: function (val) { var opts = this.optionLabel || this.itemTemplate ? this.objectUtils.generateSelectItems(val, this.optionLabel) : val; this._options = opts; }, enumerable: true, configurable: true }); SelectButton.prototype.writeValue = function (value) { this.value = value; this.cd.markForCheck(); }; SelectButton.prototype.registerOnChange = function (fn) { this.onModelChange = fn; }; SelectButton.prototype.registerOnTouched = function (fn) { this.onModelTouched = fn; }; SelectButton.prototype.setDisabledState = function (val) { this.disabled = val; }; SelectButton.prototype.onItemClick = function (event, option, checkbox, index) { if (this.disabled || option.disabled) { return; } checkbox.focus(); if (this.multiple) { var itemIndex_1 = this.findItemIndex(option); if (itemIndex_1 != -1) this.value = this.value.filter(function (val, i) { return i != itemIndex_1; }); else this.value = (this.value || []).concat([option.value]); } else { this.value = option.value; } this.onOptionClick.emit({ originalEvent: event, option: option, index: index }); this.onModelChange(this.value); this.onChange.emit({ originalEvent: event, value: this.value }); }; SelectButton.prototype.onFocus = function (event) { this.focusedItem = event.target; }; SelectButton.prototype.onBlur = function (event) { this.focusedItem = null; this.onModelTouched(); }; SelectButton.prototype.isSelected = function (option) { if (this.multiple) return this.findItemIndex(option) != -1; else return this.objectUtils.equals(option.value, this.value, this.dataKey); }; SelectButton.prototype.findItemIndex = function (option) { var index = -1; if (this.value) { for (var i = 0; i < this.value.length; i++) { if (this.value[i] == option.value) { index = i; break; } } } return index; }; __decorate([ core_1.Input(), __metadata("design:type", Number) ], SelectButton.prototype, "tabindex", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], SelectButton.prototype, "multiple", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], SelectButton.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], SelectButton.prototype, "styleClass", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], SelectButton.prototype, "disabled", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], SelectButton.prototype, "dataKey", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], SelectButton.prototype, "optionLabel", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], SelectButton.prototype, "onOptionClick", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], SelectButton.prototype, "onChange", void 0); __decorate([ core_1.ContentChild(core_1.TemplateRef), __metadata("design:type", Object) ], SelectButton.prototype, "itemTemplate", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array), __metadata("design:paramtypes", [Array]) ], SelectButton.prototype, "options", null); SelectButton = __decorate([ core_1.Component({ selector: 'p-selectButton', template: "\n <div [ngClass]=\"'ui-selectbutton ui-buttonset ui-widget ui-corner-all ui-buttonset-' + (options ? options.length : 0)\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <div *ngFor=\"let option of options; let i = index\" class=\"ui-button ui-widget ui-state-default ui-button-text-only {{option.styleClass}}\"\n [ngClass]=\"{'ui-state-active':isSelected(option), 'ui-state-disabled': disabled || option.disabled, 'ui-state-focus': cbox == focusedItem, \n 'ui-button-text-icon-left': (option.icon != null), 'ui-button-icon-only': (option.icon && !option.label)}\" (click)=\"onItemClick($event,option,cbox,i)\" [attr.title]=\"option.title\">\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.value, index: i}\"></ng-container>\n </ng-template>\n <div class=\"ui-helper-hidden-accessible\">\n <input #cbox type=\"checkbox\" [checked]=\"isSelected(option)\" (focus)=\"onFocus($event)\" (blur)=\"onBlur($event)\" [attr.tabindex]=\"tabindex\" [attr.disabled]=\"disabled || option.disabled\">\n </div>\n </div>\n </div>\n ", providers: [objectutils_1.ObjectUtils, exports.SELECTBUTTON_VALUE_ACCESSOR] }), __metadata("design:paramtypes", [objectutils_1.ObjectUtils, core_1.ChangeDetectorRef]) ], SelectButton); return SelectButton; }()); exports.SelectButton = SelectButton; var SelectButtonModule = /** @class */ (function () { function SelectButtonModule() { } SelectButtonModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule], exports: [SelectButton], declarations: [SelectButton] }) ], SelectButtonModule); return SelectButtonModule; }()); exports.SelectButtonModule = SelectButtonModule; //# sourceMappingURL=selectbutton.js.map