1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/utils'), require('@angular/forms')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/selectbutton', ['exports', '@angular/core', '@angular/common', 'primeng/utils', '@angular/forms'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.selectbutton = {}), global.ng.core, global.ng.common, global.primeng.utils, global.ng.forms));
|
5 | }(this, (function (exports, core, common, utils, forms) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | 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;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var __read = (this && this.__read) || function (o, n) {
|
14 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
15 | if (!m) return o;
|
16 | var i = m.call(o), r, ar = [], e;
|
17 | try {
|
18 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
19 | }
|
20 | catch (error) { e = { error: error }; }
|
21 | finally {
|
22 | try {
|
23 | if (r && !r.done && (m = i["return"])) m.call(i);
|
24 | }
|
25 | finally { if (e) throw e.error; }
|
26 | }
|
27 | return ar;
|
28 | };
|
29 | var __spread = (this && this.__spread) || function () {
|
30 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
31 | return ar;
|
32 | };
|
33 | var SELECTBUTTON_VALUE_ACCESSOR = {
|
34 | provide: forms.NG_VALUE_ACCESSOR,
|
35 | useExisting: core.forwardRef(function () { return SelectButton; }),
|
36 | multi: true
|
37 | };
|
38 | var SelectButton = (function () {
|
39 | function SelectButton(cd) {
|
40 | this.cd = cd;
|
41 | this.tabindex = 0;
|
42 | this.onOptionClick = new core.EventEmitter();
|
43 | this.onChange = new core.EventEmitter();
|
44 | this.onModelChange = function () { };
|
45 | this.onModelTouched = function () { };
|
46 | }
|
47 | Object.defineProperty(SelectButton.prototype, "options", {
|
48 | get: function () {
|
49 | return this._options;
|
50 | },
|
51 | set: function (val) {
|
52 |
|
53 | },
|
54 | enumerable: true,
|
55 | configurable: true
|
56 | });
|
57 | SelectButton.prototype.ngOnChanges = function (simpleChange) {
|
58 | if (simpleChange.options) {
|
59 | this._options = this.optionLabel ? utils.ObjectUtils.generateSelectItems(simpleChange.options.currentValue, this.optionLabel) : simpleChange.options.currentValue;
|
60 | }
|
61 | };
|
62 | SelectButton.prototype.writeValue = function (value) {
|
63 | this.value = value;
|
64 | this.cd.markForCheck();
|
65 | };
|
66 | SelectButton.prototype.registerOnChange = function (fn) {
|
67 | this.onModelChange = fn;
|
68 | };
|
69 | SelectButton.prototype.registerOnTouched = function (fn) {
|
70 | this.onModelTouched = fn;
|
71 | };
|
72 | SelectButton.prototype.setDisabledState = function (val) {
|
73 | this.disabled = val;
|
74 | };
|
75 | SelectButton.prototype.onItemClick = function (event, option, index) {
|
76 | if (this.disabled || option.disabled) {
|
77 | return;
|
78 | }
|
79 | if (this.multiple) {
|
80 | var itemIndex_1 = this.findItemIndex(option);
|
81 | if (itemIndex_1 != -1)
|
82 | this.value = this.value.filter(function (val, i) { return i != itemIndex_1; });
|
83 | else
|
84 | this.value = __spread(this.value || [], [option.value]);
|
85 | }
|
86 | else {
|
87 | this.value = option.value;
|
88 | }
|
89 | this.onOptionClick.emit({
|
90 | originalEvent: event,
|
91 | option: option,
|
92 | index: index
|
93 | });
|
94 | this.onModelChange(this.value);
|
95 | this.onChange.emit({
|
96 | originalEvent: event,
|
97 | value: this.value
|
98 | });
|
99 | };
|
100 | SelectButton.prototype.onFocus = function (event) {
|
101 | this.focusedItem = event.target;
|
102 | };
|
103 | SelectButton.prototype.onBlur = function (event) {
|
104 | this.focusedItem = null;
|
105 | this.onModelTouched();
|
106 | };
|
107 | SelectButton.prototype.isSelected = function (option) {
|
108 | if (this.multiple)
|
109 | return this.findItemIndex(option) != -1;
|
110 | else
|
111 | return utils.ObjectUtils.equals(option.value, this.value, this.dataKey);
|
112 | };
|
113 | SelectButton.prototype.findItemIndex = function (option) {
|
114 | var index = -1;
|
115 | if (this.value) {
|
116 | for (var i = 0; i < this.value.length; i++) {
|
117 | if (this.value[i] == option.value) {
|
118 | index = i;
|
119 | break;
|
120 | }
|
121 | }
|
122 | }
|
123 | return index;
|
124 | };
|
125 | SelectButton.ctorParameters = function () { return [
|
126 | { type: core.ChangeDetectorRef }
|
127 | ]; };
|
128 | __decorate([
|
129 | core.Input()
|
130 | ], SelectButton.prototype, "tabindex", void 0);
|
131 | __decorate([
|
132 | core.Input()
|
133 | ], SelectButton.prototype, "multiple", void 0);
|
134 | __decorate([
|
135 | core.Input()
|
136 | ], SelectButton.prototype, "style", void 0);
|
137 | __decorate([
|
138 | core.Input()
|
139 | ], SelectButton.prototype, "styleClass", void 0);
|
140 | __decorate([
|
141 | core.Input()
|
142 | ], SelectButton.prototype, "ariaLabelledBy", void 0);
|
143 | __decorate([
|
144 | core.Input()
|
145 | ], SelectButton.prototype, "disabled", void 0);
|
146 | __decorate([
|
147 | core.Input()
|
148 | ], SelectButton.prototype, "dataKey", void 0);
|
149 | __decorate([
|
150 | core.Input()
|
151 | ], SelectButton.prototype, "optionLabel", void 0);
|
152 | __decorate([
|
153 | core.Output()
|
154 | ], SelectButton.prototype, "onOptionClick", void 0);
|
155 | __decorate([
|
156 | core.Output()
|
157 | ], SelectButton.prototype, "onChange", void 0);
|
158 | __decorate([
|
159 | core.ContentChild(core.TemplateRef)
|
160 | ], SelectButton.prototype, "itemTemplate", void 0);
|
161 | __decorate([
|
162 | core.Input()
|
163 | ], SelectButton.prototype, "options", null);
|
164 | SelectButton = __decorate([
|
165 | core.Component({
|
166 | selector: 'p-selectButton',
|
167 | 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 ",
|
168 | providers: [SELECTBUTTON_VALUE_ACCESSOR],
|
169 | changeDetection: core.ChangeDetectionStrategy.Default
|
170 | })
|
171 | ], SelectButton);
|
172 | return SelectButton;
|
173 | }());
|
174 | var SelectButtonModule = (function () {
|
175 | function SelectButtonModule() {
|
176 | }
|
177 | SelectButtonModule = __decorate([
|
178 | core.NgModule({
|
179 | imports: [common.CommonModule],
|
180 | exports: [SelectButton],
|
181 | declarations: [SelectButton]
|
182 | })
|
183 | ], SelectButtonModule);
|
184 | return SelectButtonModule;
|
185 | }());
|
186 |
|
187 | exports.SELECTBUTTON_VALUE_ACCESSOR = SELECTBUTTON_VALUE_ACCESSOR;
|
188 | exports.SelectButton = SelectButton;
|
189 | exports.SelectButtonModule = SelectButtonModule;
|
190 |
|
191 | Object.defineProperty(exports, '__esModule', { value: true });
|
192 |
|
193 | })));
|
194 |
|