| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- "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(cd) {
- this.cd = cd;
- this.tabindex = 0;
- 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 ? objectutils_1.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, index) {
- if (this.disabled || option.disabled) {
- return;
- }
- 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 objectutils_1.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, { static: false }),
- __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\" #btn 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': 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\">\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 ",
- providers: [exports.SELECTBUTTON_VALUE_ACCESSOR]
- }),
- __metadata("design:paramtypes", [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
|