@firestitch/chip 13.0.1 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,291 +1,87 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, forwardRef, Component, ChangeDetectionStrategy, HostBinding, Input, EventEmitter, Optional, HostListener, Output, NgModule } from '@angular/core';
3
- import * as i3 from '@angular/common';
2
+ import { EventEmitter, Component, ChangeDetectionStrategy, HostBinding, Input, Output, HostListener, forwardRef, ContentChildren, NgModule } from '@angular/core';
3
+ import * as i2 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
- import * as i2 from '@angular/material/icon';
5
+ import * as i1 from '@angular/material/icon';
6
6
  import { MatIconModule } from '@angular/material/icon';
7
7
  import { FsLabelModule } from '@firestitch/label';
8
8
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
9
9
  import { Subject } from 'rxjs';
10
- import { takeUntil, debounceTime } from 'rxjs/operators';
11
- import { find } from 'lodash-es';
12
-
13
- class FsChipsService {
14
- constructor() {
15
- this.chips = [];
16
- this._chipItemsChanged$ = new Subject();
17
- this._selectionChanged$ = new Subject();
18
- this._destroy$ = new Subject();
19
- }
20
- get selectionChanged$() {
21
- return this._selectionChanged$.
22
- pipe(takeUntil(this._destroy$));
23
- }
24
- get chipItemsChanged$() {
25
- return this._chipItemsChanged$
26
- .pipe(takeUntil(this._destroy$), debounceTime(50));
27
- }
28
- ngOnDestroy() {
29
- this._destroy$.next();
30
- this._destroy$.complete();
31
- }
32
- selectionChanged(selected, value) {
33
- this._selectionChanged$.next({
34
- selected: selected,
35
- value: value,
36
- });
37
- }
38
- register(chip) {
39
- this.chips.push(chip);
40
- this._chipItemsChanged$.next();
41
- }
42
- destroy(chip) {
43
- const index = this.chips.indexOf(chip);
44
- if (index > -1) {
45
- this.chips.splice(index, 1);
46
- this._chipItemsChanged$.next();
47
- }
48
- }
49
- }
50
- FsChipsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
51
- FsChipsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsService });
52
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsService, decorators: [{
53
- type: Injectable
54
- }], ctorParameters: function () { return []; } });
55
-
56
- class FsChipsComponent {
57
- constructor(_cdRef, _chipsService) {
58
- this._cdRef = _cdRef;
59
- this._chipsService = _chipsService;
60
- this.classFsChips = true;
61
- this.classHasChips = false;
62
- this.multiple = true;
63
- this._value = [];
64
- this._destroy$ = new Subject();
65
- this._subscribeToItemsChange();
66
- this._subscribeToSelectionChange();
67
- }
68
- get chips() {
69
- return this._chipsService.chips;
70
- }
71
- set value(value) {
72
- if (this._value !== value) {
73
- this._value = value;
74
- this.onChange(this._value);
75
- this.onTouch(this._value);
76
- }
77
- }
78
- get value() {
79
- return this._value;
80
- }
81
- ngOnDestroy() {
82
- this._destroy$.next();
83
- this._destroy$.complete();
84
- }
85
- writeValue(value) {
86
- if (value !== this.value) {
87
- this._value = value;
88
- }
89
- this._updateChips();
90
- }
91
- registerOnChange(fn) {
92
- this.onChange = fn;
93
- }
94
- registerOnTouched(fn) {
95
- this.onTouch = fn;
96
- }
97
- /**
98
- * Update ngModel value when selection changed
99
- */
100
- _subscribeToSelectionChange() {
101
- this._chipsService.selectionChanged$
102
- .pipe(takeUntil(this._destroy$))
103
- .subscribe(({ selected, value }) => {
104
- if (!selected) {
105
- const valueIndex = this.value.findIndex((item) => {
106
- return this._compareFn(item, value);
107
- });
108
- if (valueIndex > -1) {
109
- this.value.splice(valueIndex, 1);
110
- this.onChange(this._value);
111
- this.onTouch(this._value);
112
- }
113
- }
114
- else {
115
- this.value.push(value);
116
- this.onChange(this._value);
117
- this.onTouch(this._value);
118
- }
119
- });
120
- }
121
- /**
122
- * Update selection if item was added or removed
123
- */
124
- _subscribeToItemsChange() {
125
- this._chipsService.chipItemsChanged$
126
- .pipe(takeUntil(this._destroy$))
127
- .subscribe(() => {
128
- this.classHasChips = !!this._chipsService.chips.length;
129
- this._updateChips();
130
- });
131
- }
132
- _compareFn(o1, o2) {
133
- if (this.compare) {
134
- return this.compare(o1, o2);
135
- }
136
- return o1 === o2;
137
- }
138
- _updateChips() {
139
- if (this.multiple && Array.isArray(this.value) && this.chips) {
140
- this.chips.forEach((chip) => {
141
- chip.selected = find(this.value, (o) => {
142
- return this._compareFn(o, chip.value);
143
- }) !== undefined;
144
- });
145
- }
146
- this._cdRef.markForCheck();
147
- }
148
- }
149
- FsChipsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: FsChipsService }], target: i0.ɵɵFactoryTarget.Component });
150
- FsChipsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: FsChipsComponent, selector: "fs-chips", inputs: { compare: "compare", multiple: "multiple" }, host: { properties: { "class.fs-chips": "this.classFsChips", "class.has-chips": "this.classHasChips" } }, providers: [
151
- {
152
- provide: NG_VALUE_ACCESSOR,
153
- useExisting: forwardRef(() => FsChipsComponent),
154
- multi: true,
155
- },
156
- FsChipsService,
157
- ], ngImport: i0, template: "<ng-content></ng-content>\n", styles: [":host{display:flex;flex-wrap:wrap}:host.has-chips{margin-top:-5px}:host ::ng-deep .fs-chip{margin-right:5px;margin-top:5px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
158
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsComponent, decorators: [{
159
- type: Component,
160
- args: [{ selector: 'fs-chips', providers: [
161
- {
162
- provide: NG_VALUE_ACCESSOR,
163
- useExisting: forwardRef(() => FsChipsComponent),
164
- multi: true,
165
- },
166
- FsChipsService,
167
- ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-content></ng-content>\n", styles: [":host{display:flex;flex-wrap:wrap}:host.has-chips{margin-top:-5px}:host ::ng-deep .fs-chip{margin-right:5px;margin-top:5px}\n"] }]
168
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: FsChipsService }]; }, propDecorators: { classFsChips: [{
169
- type: HostBinding,
170
- args: ['class.fs-chips']
171
- }], classHasChips: [{
172
- type: HostBinding,
173
- args: ['class.has-chips']
174
- }], compare: [{
175
- type: Input
176
- }], multiple: [{
177
- type: Input
178
- }] } });
10
+ import { takeUntil } from 'rxjs/operators';
179
11
 
180
12
  class FsChipComponent {
181
- constructor(_cdRef, _chips) {
13
+ constructor(_cdRef) {
182
14
  this._cdRef = _cdRef;
183
- this._chips = _chips;
184
15
  this.fsChip = true;
185
16
  this._outlined = false;
186
- this._selectable = false;
187
- this._image = false;
188
- this._selected = false;
189
- this._removable = false;
17
+ this.selectable = false;
18
+ this.removable = true;
190
19
  this.styleBackgroundColor = '';
191
20
  this.styleColor = '';
192
21
  this.styleBorderColor = '';
193
22
  this.classSmall = false;
194
23
  this.classTiny = false;
195
24
  this.classMicro = false;
25
+ this.selected = false;
196
26
  this.selectedToggled = new EventEmitter();
197
27
  this.removed = new EventEmitter();
198
- this.$destroy = new Subject();
28
+ this._destroy$ = new Subject();
199
29
  this._backgroundColor = '';
200
30
  this._color = '';
201
31
  }
202
32
  set setSize(value) {
203
- this._size = value;
204
33
  this.classSmall = value === 'small';
205
34
  this.classTiny = value === 'tiny';
206
35
  this.classMicro = value === 'micro';
207
36
  }
208
- ;
209
37
  click() {
210
38
  if (this.selectable) {
211
39
  this.selected = !this.selected;
212
40
  this.selectedToggled.emit({ value: this.value, selected: this.selected });
213
- if (this._chips) {
214
- this._chips.selectionChanged(this.selected, this.value);
215
- }
216
41
  }
217
42
  }
218
43
  set backgroundColor(value) {
219
44
  this._backgroundColor = value;
220
- this.updateStyles();
45
+ this._updateStyles();
221
46
  }
222
- ;
223
47
  set borderColor(value) {
224
48
  this.styleBorderColor = value;
225
- this.updateStyles();
49
+ this._updateStyles();
226
50
  }
227
51
  set color(value) {
228
52
  this._color = value;
229
- this.updateStyles();
53
+ this._updateStyles();
230
54
  }
231
- get color() {
232
- return this._color;
55
+ get destroy$() {
56
+ return this._destroy$.asObservable();
233
57
  }
234
58
  set outlined(value) {
235
59
  this._outlined = value;
236
- this.updateStyles();
237
- }
238
- ;
239
- get outlined() {
240
- return this._outlined;
241
- }
242
- set removable(value) {
243
- this._removable = value;
244
- this._cdRef.markForCheck();
60
+ this._updateStyles();
245
61
  }
246
- ;
247
- get removable() {
248
- return this._removable;
249
- }
250
- set selectable(value) {
251
- this._selectable = value;
252
- }
253
- ;
254
- get selectable() {
255
- return this._selectable;
256
- }
257
- set selected(value) {
258
- this._selected = value;
62
+ select() {
63
+ this.selected = true;
259
64
  this._cdRef.markForCheck();
260
65
  }
261
- ;
262
- get selected() {
263
- return this._selected;
264
- }
265
- set image(value) {
266
- this._image = value;
66
+ unselect() {
67
+ this.selected = false;
267
68
  this._cdRef.markForCheck();
268
69
  }
269
- ;
270
- get image() {
271
- return this._image;
272
- }
273
70
  ngOnInit() {
274
- if (this._chips) {
275
- this._chips.register(this);
71
+ if (this.removed.observers.length === 0) {
72
+ this.removable = false;
276
73
  }
277
74
  }
278
75
  ngOnDestroy() {
279
- if (this._chips) {
280
- this._chips.destroy(this);
281
- }
282
- this.$destroy.next();
283
- this.$destroy.complete();
76
+ this._destroy$.next();
77
+ this._destroy$.complete();
284
78
  }
285
79
  remove(event) {
80
+ event.stopImmediatePropagation();
81
+ event.stopPropagation();
286
82
  this.removed.next(event);
287
83
  }
288
- isContrastYIQBlack(hexcolor) {
84
+ _isContrastYIQBlack(hexcolor) {
289
85
  if (!hexcolor) {
290
86
  return true;
291
87
  }
@@ -296,13 +92,13 @@ class FsChipComponent {
296
92
  const yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
297
93
  return yiq >= 200;
298
94
  }
299
- updateStyles() {
95
+ _updateStyles() {
300
96
  this.styleBackgroundColor = this._backgroundColor;
301
97
  if (this._color) {
302
98
  this.styleColor = this._color;
303
99
  }
304
100
  else if (!this._outlined) {
305
- this.styleColor = this.isContrastYIQBlack(this.styleBackgroundColor) ? '#474747' : '#fff';
101
+ this.styleColor = this._isContrastYIQBlack(this.styleBackgroundColor) ? '#474747' : '#fff';
306
102
  }
307
103
  if (this._outlined) {
308
104
  this.styleBackgroundColor = '';
@@ -313,31 +109,25 @@ class FsChipComponent {
313
109
  this._cdRef.markForCheck();
314
110
  }
315
111
  }
316
- FsChipComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: FsChipsService, optional: true }], target: i0.ɵɵFactoryTarget.Component });
317
- FsChipComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: FsChipComponent, selector: "fs-chip", inputs: { setSize: ["size", "setSize"], value: "value", icon: "icon", backgroundColor: "backgroundColor", borderColor: "borderColor", color: "color", outlined: "outlined", removable: "removable", selectable: "selectable", selected: "selected", image: "image" }, outputs: { selectedToggled: "selectedToggled", removed: "removed" }, host: { listeners: { "click": "click()" }, properties: { "class.fs-chip": "this.fsChip", "class.outlined": "this._outlined", "class.selectable": "this._selectable", "class.imaged": "this._image", "class.selected": "this._selected", "class.removable": "this._removable", "style.backgroundColor": "this.styleBackgroundColor", "style.color": "this.styleColor", "style.borderColor": "this.styleBorderColor", "class.small": "this.classSmall", "class.tiny": "this.classTiny", "class.micro": "this.classMicro", "class.iconed": "this.icon" } }, ngImport: i0, template: "<img *ngIf=\"image\" [src]=\"image\" class=\"image\" alt=\"\">\n<ng-container *ngIf=\"icon\">\n <mat-icon class=\"icon\">{{icon}}</mat-icon>\n</ng-container>\n<div class=\"fs-chip-content\">\n <ng-content></ng-content>\n</div>\n<div class=\"selected-check\" *ngIf=\"selected\">\n <mat-icon [style.color]=\"styleColor\">check</mat-icon>\n</div>\n<a *ngIf=\"removable\" class=\"remove\" (click)=\"remove($event)\">\n <mat-icon [style.color]=\"styleColor\">cancel</mat-icon>\n</a>\n", styles: [":host{-webkit-user-select:none;user-select:none;transition:box-shadow .28s cubic-bezier(.4,0,.2,1);display:inline-flex;padding:0 12px;border-radius:16px;align-items:center;cursor:default;height:30px;background-color:#e0e0e0;overflow:hidden}:host.imaged{overflow:visible;padding-left:0}:host.imaged.outlined .image{margin-left:-2px}:host.iconed:not(.imaged){padding-left:5px}:host.removable,:host.selected{padding-right:3px}:host.selectable{cursor:pointer}:host.outlined{background-color:transparent;border:1px solid #e0e0e0;box-sizing:border-box}:host .icon{margin-right:5px}:host .image{height:30px;width:30px;border-radius:50%;object-fit:cover;margin-left:-1px;margin-right:8px}:host .fs-chip-content{max-width:250px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .selected-check{margin:0 5px;display:flex}:host .remove{display:flex;margin-left:5px;cursor:pointer}:host.micro{padding:0 5px;height:16px;line-height:normal}:host.micro .fs-chip-content{font-size:65%}:host.micro .image{height:100%;width:16px;margin-right:2px}:host.micro .remove{margin-left:1px}:host.micro .selected-check{margin:0 1px 0 0}:host.micro.imaged{padding-left:0}:host.micro.removable,:host.micro.selected{padding-right:0}:host.micro mat-icon{width:12px;height:12px;font-size:11px}:host.tiny{padding:0 6px;height:18px;line-height:normal}:host.tiny .fs-chip-content{font-size:75%}:host.tiny .image{height:18px;width:18px;margin-right:3px}:host.tiny.iconed:not(.imaged){padding-left:3px}:host.tiny .remove{margin-left:2px}:host.tiny .selected-check{margin:0 1px 0 0}:host.tiny.imaged{padding-left:0}:host.tiny.removable,:host.tiny.selected{padding-right:0}:host.tiny mat-icon{height:15px;width:15px;font-size:15px}:host.small{padding:0 8px;font-size:85%;height:25px;line-height:normal}:host.small .image{height:25px;width:25px;margin-right:5px}:host.small.iconed:not(.imaged){padding-left:4px}:host.small.imaged{padding-left:0}:host.small .remove{margin-left:3px}:host.small .selected-check{margin:0 2px 0 0}:host.small .selected-check mat-icon{transform:scale(.7)}:host.small.removable,:host.small.selected{padding-right:0}:host.small mat-icon{height:22px;width:22px;font-size:20px}\n"], components: [{ type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
112
+ FsChipComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
113
+ FsChipComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: FsChipComponent, selector: "fs-chip", inputs: { selectable: "selectable", removable: "removable", value: "value", icon: "icon", image: "image", selected: "selected", setSize: ["size", "setSize"], backgroundColor: "backgroundColor", borderColor: "borderColor", color: "color", outlined: "outlined" }, outputs: { selectedToggled: "selectedToggled", removed: "removed" }, host: { listeners: { "click": "click()" }, properties: { "class.fs-chip": "this.fsChip", "class.outlined": "this._outlined", "class.selectable": "this.selectable", "class.removable": "this.removable", "style.backgroundColor": "this.styleBackgroundColor", "style.color": "this.styleColor", "style.borderColor": "this.styleBorderColor", "class.small": "this.classSmall", "class.tiny": "this.classTiny", "class.micro": "this.classMicro", "class.iconed": "this.icon", "class.imaged": "this.image", "class.selected": "this.selected" } }, ngImport: i0, template: "<img *ngIf=\"image\" [src]=\"image\" class=\"image\" alt=\"\">\n<ng-container *ngIf=\"icon\">\n <mat-icon class=\"icon\">{{icon}}</mat-icon>\n</ng-container>\n<div class=\"fs-chip-content\">\n <ng-content></ng-content>\n</div>\n<ng-container *ngIf=\"selected\">\n <div class=\"selected-check\">\n <mat-icon [style.color]=\"styleColor\">check</mat-icon>\n </div>\n</ng-container>\n<div *ngIf=\"removed.observers.length && removable\" class=\"remove\" (click)=\"remove($event)\">\n <mat-icon [style.color]=\"styleColor\">cancel</mat-icon>\n</div>", styles: [":host{-webkit-user-select:none;user-select:none;transition:box-shadow .28s cubic-bezier(.4,0,.2,1);display:inline-flex;padding:0 12px;border-radius:16px;align-items:center;cursor:default;height:30px;background-color:#e0e0e0;overflow:hidden}:host.imaged{overflow:visible;padding-left:0;vertical-align:middle}:host.imaged.outlined .image{margin-left:-2px}:host.iconed:not(.imaged){padding-left:5px}:host.removable,:host.selected{padding-right:3px}:host.selectable{cursor:pointer}:host.outlined{background-color:transparent;border:1px solid #e0e0e0;box-sizing:border-box}:host .icon{margin-right:5px}:host mat-icon{font-size:25px}:host .image{height:30px;width:30px;border-radius:50%;object-fit:cover;margin-left:-1px;margin-right:8px}:host .fs-chip-content{max-width:250px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .selected-check{margin:0 5px;display:flex}:host .remove{display:flex;margin-left:5px;cursor:pointer}:host.micro{padding:0 5px;height:16px;line-height:normal}:host.micro .fs-chip-content{font-size:65%}:host.micro .image{height:100%;width:16px;margin-right:2px}:host.micro .remove{margin-left:1px}:host.micro .selected-check{margin:0 1px 0 0}:host.micro.imaged{padding-left:0}:host.micro.removable,:host.micro.selected{padding-right:0}:host.micro mat-icon{width:12px;height:12px;font-size:11px}:host.tiny{padding:0 6px;height:18px;line-height:normal}:host.tiny .fs-chip-content{font-size:75%}:host.tiny .image{height:18px;width:18px;margin-right:3px}:host.tiny.iconed:not(.imaged){padding-left:3px}:host.tiny .remove{margin-left:2px;margin-right:2px}:host.tiny .selected-check{margin:0 1px 0 0}:host.tiny.imaged{padding-left:0}:host.tiny.removable,:host.tiny.selected{padding-right:0}:host.tiny mat-icon{height:13px;width:13px;font-size:13px}:host.small{padding:0 8px;font-size:85%;height:25px;line-height:normal}:host.small .image{height:25px;width:25px;margin-right:5px}:host.small.iconed:not(.imaged){padding-left:4px}:host.small.imaged{padding-left:0}:host.small .remove{margin-right:2px}:host.small .selected-check{margin:0 2px 0 0}:host.small .selected-check mat-icon{transform:scale(.7)}:host.small.removable,:host.small.selected{padding-right:0}:host.small mat-icon{height:22px;width:22px;font-size:22px}\n"], components: [{ type: i1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
318
114
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipComponent, decorators: [{
319
115
  type: Component,
320
- args: [{ selector: 'fs-chip', changeDetection: ChangeDetectionStrategy.OnPush, template: "<img *ngIf=\"image\" [src]=\"image\" class=\"image\" alt=\"\">\n<ng-container *ngIf=\"icon\">\n <mat-icon class=\"icon\">{{icon}}</mat-icon>\n</ng-container>\n<div class=\"fs-chip-content\">\n <ng-content></ng-content>\n</div>\n<div class=\"selected-check\" *ngIf=\"selected\">\n <mat-icon [style.color]=\"styleColor\">check</mat-icon>\n</div>\n<a *ngIf=\"removable\" class=\"remove\" (click)=\"remove($event)\">\n <mat-icon [style.color]=\"styleColor\">cancel</mat-icon>\n</a>\n", styles: [":host{-webkit-user-select:none;user-select:none;transition:box-shadow .28s cubic-bezier(.4,0,.2,1);display:inline-flex;padding:0 12px;border-radius:16px;align-items:center;cursor:default;height:30px;background-color:#e0e0e0;overflow:hidden}:host.imaged{overflow:visible;padding-left:0}:host.imaged.outlined .image{margin-left:-2px}:host.iconed:not(.imaged){padding-left:5px}:host.removable,:host.selected{padding-right:3px}:host.selectable{cursor:pointer}:host.outlined{background-color:transparent;border:1px solid #e0e0e0;box-sizing:border-box}:host .icon{margin-right:5px}:host .image{height:30px;width:30px;border-radius:50%;object-fit:cover;margin-left:-1px;margin-right:8px}:host .fs-chip-content{max-width:250px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .selected-check{margin:0 5px;display:flex}:host .remove{display:flex;margin-left:5px;cursor:pointer}:host.micro{padding:0 5px;height:16px;line-height:normal}:host.micro .fs-chip-content{font-size:65%}:host.micro .image{height:100%;width:16px;margin-right:2px}:host.micro .remove{margin-left:1px}:host.micro .selected-check{margin:0 1px 0 0}:host.micro.imaged{padding-left:0}:host.micro.removable,:host.micro.selected{padding-right:0}:host.micro mat-icon{width:12px;height:12px;font-size:11px}:host.tiny{padding:0 6px;height:18px;line-height:normal}:host.tiny .fs-chip-content{font-size:75%}:host.tiny .image{height:18px;width:18px;margin-right:3px}:host.tiny.iconed:not(.imaged){padding-left:3px}:host.tiny .remove{margin-left:2px}:host.tiny .selected-check{margin:0 1px 0 0}:host.tiny.imaged{padding-left:0}:host.tiny.removable,:host.tiny.selected{padding-right:0}:host.tiny mat-icon{height:15px;width:15px;font-size:15px}:host.small{padding:0 8px;font-size:85%;height:25px;line-height:normal}:host.small .image{height:25px;width:25px;margin-right:5px}:host.small.iconed:not(.imaged){padding-left:4px}:host.small.imaged{padding-left:0}:host.small .remove{margin-left:3px}:host.small .selected-check{margin:0 2px 0 0}:host.small .selected-check mat-icon{transform:scale(.7)}:host.small.removable,:host.small.selected{padding-right:0}:host.small mat-icon{height:22px;width:22px;font-size:20px}\n"] }]
321
- }], ctorParameters: function () {
322
- return [{ type: i0.ChangeDetectorRef }, { type: FsChipsService, decorators: [{
323
- type: Optional
324
- }] }];
325
- }, propDecorators: { fsChip: [{
116
+ args: [{ selector: 'fs-chip', changeDetection: ChangeDetectionStrategy.OnPush, template: "<img *ngIf=\"image\" [src]=\"image\" class=\"image\" alt=\"\">\n<ng-container *ngIf=\"icon\">\n <mat-icon class=\"icon\">{{icon}}</mat-icon>\n</ng-container>\n<div class=\"fs-chip-content\">\n <ng-content></ng-content>\n</div>\n<ng-container *ngIf=\"selected\">\n <div class=\"selected-check\">\n <mat-icon [style.color]=\"styleColor\">check</mat-icon>\n </div>\n</ng-container>\n<div *ngIf=\"removed.observers.length && removable\" class=\"remove\" (click)=\"remove($event)\">\n <mat-icon [style.color]=\"styleColor\">cancel</mat-icon>\n</div>", styles: [":host{-webkit-user-select:none;user-select:none;transition:box-shadow .28s cubic-bezier(.4,0,.2,1);display:inline-flex;padding:0 12px;border-radius:16px;align-items:center;cursor:default;height:30px;background-color:#e0e0e0;overflow:hidden}:host.imaged{overflow:visible;padding-left:0;vertical-align:middle}:host.imaged.outlined .image{margin-left:-2px}:host.iconed:not(.imaged){padding-left:5px}:host.removable,:host.selected{padding-right:3px}:host.selectable{cursor:pointer}:host.outlined{background-color:transparent;border:1px solid #e0e0e0;box-sizing:border-box}:host .icon{margin-right:5px}:host mat-icon{font-size:25px}:host .image{height:30px;width:30px;border-radius:50%;object-fit:cover;margin-left:-1px;margin-right:8px}:host .fs-chip-content{max-width:250px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .selected-check{margin:0 5px;display:flex}:host .remove{display:flex;margin-left:5px;cursor:pointer}:host.micro{padding:0 5px;height:16px;line-height:normal}:host.micro .fs-chip-content{font-size:65%}:host.micro .image{height:100%;width:16px;margin-right:2px}:host.micro .remove{margin-left:1px}:host.micro .selected-check{margin:0 1px 0 0}:host.micro.imaged{padding-left:0}:host.micro.removable,:host.micro.selected{padding-right:0}:host.micro mat-icon{width:12px;height:12px;font-size:11px}:host.tiny{padding:0 6px;height:18px;line-height:normal}:host.tiny .fs-chip-content{font-size:75%}:host.tiny .image{height:18px;width:18px;margin-right:3px}:host.tiny.iconed:not(.imaged){padding-left:3px}:host.tiny .remove{margin-left:2px;margin-right:2px}:host.tiny .selected-check{margin:0 1px 0 0}:host.tiny.imaged{padding-left:0}:host.tiny.removable,:host.tiny.selected{padding-right:0}:host.tiny mat-icon{height:13px;width:13px;font-size:13px}:host.small{padding:0 8px;font-size:85%;height:25px;line-height:normal}:host.small .image{height:25px;width:25px;margin-right:5px}:host.small.iconed:not(.imaged){padding-left:4px}:host.small.imaged{padding-left:0}:host.small .remove{margin-right:2px}:host.small .selected-check{margin:0 2px 0 0}:host.small .selected-check mat-icon{transform:scale(.7)}:host.small.removable,:host.small.selected{padding-right:0}:host.small mat-icon{height:22px;width:22px;font-size:22px}\n"] }]
117
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { fsChip: [{
326
118
  type: HostBinding,
327
119
  args: ['class.fs-chip']
328
120
  }], _outlined: [{
329
121
  type: HostBinding,
330
122
  args: ['class.outlined']
331
- }], _selectable: [{
123
+ }], selectable: [{
124
+ type: Input
125
+ }, {
332
126
  type: HostBinding,
333
127
  args: ['class.selectable']
334
- }], _image: [{
335
- type: HostBinding,
336
- args: ['class.imaged']
337
- }], _selected: [{
338
- type: HostBinding,
339
- args: ['class.selected']
340
- }], _removable: [{
128
+ }], removable: [{
129
+ type: Input
130
+ }, {
341
131
  type: HostBinding,
342
132
  args: ['class.removable']
343
133
  }], styleBackgroundColor: [{
@@ -358,12 +148,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
358
148
  }], classMicro: [{
359
149
  type: HostBinding,
360
150
  args: ['class.micro']
361
- }], setSize: [{
362
- type: Input,
363
- args: ['size']
364
- }], click: [{
365
- type: HostListener,
366
- args: ['click']
367
151
  }], value: [{
368
152
  type: Input
369
153
  }], icon: [{
@@ -371,6 +155,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
371
155
  }, {
372
156
  type: HostBinding,
373
157
  args: ['class.iconed']
158
+ }], image: [{
159
+ type: Input
160
+ }, {
161
+ type: HostBinding,
162
+ args: ['class.imaged']
163
+ }], selected: [{
164
+ type: Input
165
+ }, {
166
+ type: HostBinding,
167
+ args: ['class.selected']
168
+ }], selectedToggled: [{
169
+ type: Output
170
+ }], removed: [{
171
+ type: Output
172
+ }], setSize: [{
173
+ type: Input,
174
+ args: ['size']
175
+ }], click: [{
176
+ type: HostListener,
177
+ args: ['click']
374
178
  }], backgroundColor: [{
375
179
  type: Input
376
180
  }], borderColor: [{
@@ -379,18 +183,143 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
379
183
  type: Input
380
184
  }], outlined: [{
381
185
  type: Input
382
- }], removable: [{
383
- type: Input
384
- }], selectable: [{
385
- type: Input
386
- }], selected: [{
186
+ }] } });
187
+
188
+ class FsChipsComponent {
189
+ constructor(_cdRef, _iterable) {
190
+ this._cdRef = _cdRef;
191
+ this._iterable = _iterable;
192
+ this.classFsChips = true;
193
+ this.classHasChips = false;
194
+ this.multiple = true;
195
+ this._value = [];
196
+ this._destroy$ = new Subject();
197
+ this._chipDiffer = this._iterable.find([]).create();
198
+ }
199
+ setDisabledState(isDisabled) {
200
+ //
201
+ }
202
+ ngAfterContentInit() {
203
+ this._subscribeToSelectionChange();
204
+ this._subscribeToItemsChange();
205
+ }
206
+ set value(value) {
207
+ if (this._value !== value) {
208
+ this._value = value;
209
+ this.onChange(this._value);
210
+ this.onTouch(this._value);
211
+ }
212
+ }
213
+ get value() {
214
+ return this._value;
215
+ }
216
+ ngOnDestroy() {
217
+ this._destroy$.next();
218
+ this._destroy$.complete();
219
+ }
220
+ writeValue(value) {
221
+ if (value !== this.value) {
222
+ this._value = value;
223
+ }
224
+ this._updateChips();
225
+ }
226
+ registerOnChange(fn) {
227
+ this.onChange = fn;
228
+ }
229
+ registerOnTouched(fn) {
230
+ this.onTouch = fn;
231
+ }
232
+ /**
233
+ * Update ngModel value when selection changed
234
+ */
235
+ _subscribeToSelectionChange() {
236
+ this._chipDiffer.diff(this.chips)
237
+ .forEachAddedItem((change) => {
238
+ change.item.selectedToggled
239
+ .pipe(takeUntil(change.item.destroy$), takeUntil(this._destroy$))
240
+ .subscribe(({ selected, value }) => {
241
+ if (!selected) {
242
+ const valueIndex = this.value.findIndex((item) => {
243
+ return this._compareFn(item, value);
244
+ });
245
+ if (valueIndex > -1) {
246
+ this.value.splice(valueIndex, 1);
247
+ this.onChange(this._value);
248
+ this.onTouch(this._value);
249
+ }
250
+ }
251
+ else {
252
+ this.value.push(value);
253
+ this.onChange(this._value);
254
+ this.onTouch(this._value);
255
+ }
256
+ });
257
+ });
258
+ }
259
+ /**
260
+ * Update selection if item was added or removed
261
+ */
262
+ _subscribeToItemsChange() {
263
+ this.chips.changes
264
+ .pipe(takeUntil(this._destroy$))
265
+ .subscribe(() => {
266
+ this.classHasChips = this.chips.length !== 0;
267
+ this._updateChips();
268
+ });
269
+ }
270
+ _compareFn(o1, o2) {
271
+ if (this.compare) {
272
+ return this.compare(o1, o2);
273
+ }
274
+ return o1 === o2;
275
+ }
276
+ _updateChips() {
277
+ if (this.multiple && Array.isArray(this.value) && this.chips) {
278
+ this.chips.forEach((chip) => {
279
+ const selected = this.value
280
+ .some((o) => {
281
+ return this._compareFn(o, chip.value);
282
+ });
283
+ if (selected) {
284
+ chip.select();
285
+ }
286
+ else {
287
+ chip.unselect();
288
+ }
289
+ });
290
+ }
291
+ }
292
+ }
293
+ FsChipsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.IterableDiffers }], target: i0.ɵɵFactoryTarget.Component });
294
+ FsChipsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: FsChipsComponent, selector: "fs-chips", inputs: { compare: "compare", multiple: "multiple" }, host: { properties: { "class.fs-chips": "this.classFsChips", "class.has-chips": "this.classHasChips" } }, providers: [
295
+ {
296
+ provide: NG_VALUE_ACCESSOR,
297
+ useExisting: forwardRef(() => FsChipsComponent),
298
+ multi: true,
299
+ },
300
+ ], queries: [{ propertyName: "chips", predicate: FsChipComponent }], ngImport: i0, template: "<ng-content></ng-content>\n", styles: [":host{display:flex;flex-wrap:wrap}:host.has-chips{margin-top:-5px}:host ::ng-deep .fs-chip{margin-right:5px;margin-top:5px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
301
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FsChipsComponent, decorators: [{
302
+ type: Component,
303
+ args: [{ selector: 'fs-chips', providers: [
304
+ {
305
+ provide: NG_VALUE_ACCESSOR,
306
+ useExisting: forwardRef(() => FsChipsComponent),
307
+ multi: true,
308
+ },
309
+ ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-content></ng-content>\n", styles: [":host{display:flex;flex-wrap:wrap}:host.has-chips{margin-top:-5px}:host ::ng-deep .fs-chip{margin-right:5px;margin-top:5px}\n"] }]
310
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.IterableDiffers }]; }, propDecorators: { classFsChips: [{
311
+ type: HostBinding,
312
+ args: ['class.fs-chips']
313
+ }], classHasChips: [{
314
+ type: HostBinding,
315
+ args: ['class.has-chips']
316
+ }], chips: [{
317
+ type: ContentChildren,
318
+ args: [FsChipComponent]
319
+ }], compare: [{
387
320
  type: Input
388
- }], image: [{
321
+ }], multiple: [{
389
322
  type: Input
390
- }], selectedToggled: [{
391
- type: Output
392
- }], removed: [{
393
- type: Output
394
323
  }] } });
395
324
 
396
325
  class FsChipModule {