@piserve-tech/drop-down 1.2.110 → 1.2.112

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,226 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- ChangeDetectorRef,
4
- Component,
5
- ElementRef,
6
- EventEmitter,
7
- HostListener,
8
- Input,
9
- OnInit,
10
- Output,
11
- SimpleChanges,
12
- ViewChild,
13
- ViewEncapsulation,
14
- } from "@angular/core";
15
- import { DropdownItem } from "./dropdown.model";
16
- import { v4 as uuidv4 } from 'uuid';
17
-
18
- @Component({
19
- selector: "lib-dropdown",
20
- templateUrl: "./dropdown.component.html",
21
- styleUrls: ["./dropdown.component.scss"],
22
- encapsulation: ViewEncapsulation.None,
23
- changeDetection: ChangeDetectionStrategy.OnPush,
24
- })
25
- export class DropdownComponent implements OnInit {
26
- @Input() multiple!: boolean;
27
- @Input() selectedItems: any[] = [];
28
- @Input() placeholder: String = "";
29
- @Input() showCreateNew!: boolean;
30
- @Input() selectedValues: string = "";
31
- @Input() customButtons: {
32
- label: string;
33
- icon: string;
34
- color: string;
35
- action: () => void;
36
- }[] = [];
37
- @Input() showBorder: boolean = true;
38
- @Input() disable: boolean = false;
39
- @Output() buttonClick: EventEmitter<Event> = new EventEmitter<Event>();
40
- @Output() selectedItemsChange: EventEmitter<any[]> = new EventEmitter<
41
- any[]
42
- >();
43
- @Output() onDropdownScroll: EventEmitter<Event> = new EventEmitter<Event>();
44
- @Output() onCreateNew: EventEmitter<Event> = new EventEmitter<Event>();
45
- @Output() onSearch: EventEmitter<string> = new EventEmitter<string>();
46
- //subLabel
47
- @Input() showSubLabel: boolean = false;
48
- dropdownId = uuidv4();
49
- dropdownOpened: boolean = false;
50
- selectedItem: any;
51
- selectedItemName: string = "";
52
- selectedItemImage: string = "";
53
- originalItems: DropdownItem[] = [];
54
- searchTerm: string = "";
55
- initialized: boolean = false;
56
- searchText: string = "";
57
- _filteredItems: DropdownItem[] = [];
58
-
59
- private _items: DropdownItem[] = [];
60
-
61
- @Input()
62
- set items(value: DropdownItem[]) {
63
- this._items = value || [];
64
- this.originalItems = this._items.slice();
65
- this._filteredItems = this._items.slice(); // use a separate variable for rendering
66
- this.cdr.markForCheck();
67
- }
68
- get items(): DropdownItem[] {
69
- return this._items;
70
- }
71
-
72
- constructor(private cdr: ChangeDetectorRef) {}
73
-
74
- ngOnInit(): void {}
75
-
76
-
77
-
78
- ngOnChanges(changes: SimpleChanges) {
79
- if (changes["selectedItems"]) {
80
- const item = changes["selectedItems"]["currentValue"];
81
- this.selectedItems = item;
82
- this.selectedItemName = this.selectedItems[0]?.label;
83
- this.selectedItemImage = this.selectedItems[0]?.image;
84
- }
85
- if (changes["items"]) {
86
- this.initialize();
87
- this.originalItems = this.items.slice();
88
- this.cdr.markForCheck();
89
- }
90
- if (changes["selectedValues"]) {
91
- this.selectedItemName = this.selectedValues;
92
- }
93
- }
94
-
95
- initialize() {
96
- setTimeout(() => {
97
- if (this.selectedItems && this.selectedItems.length > 0) {
98
- if (!this.multiple) {
99
- this.searchText = "";
100
- this.selectedItemName = this.selectedItems[0]?.label;
101
- this.selectedItemImage = this.selectedItems[0]?.image;
102
- }
103
- }
104
- }, 1000);
105
- const uniqueItems = this.items.filter(
106
- (selected, index, self) =>
107
- index === self.findIndex((t) => t.value === selected.value)
108
- );
109
-
110
- this.items = uniqueItems;
111
- }
112
-
113
- openDropdown() {
114
- this.dropdownOpened = !this.dropdownOpened;
115
- const inputId = `searchInput-${this.dropdownId}`;
116
- const inputEl = document.getElementById(inputId);
117
- setTimeout(() => {
118
- inputEl?.focus();
119
- }, 0);
120
-
121
- }
122
-
123
- @ViewChild("dropdownItems") dropdownitems!: ElementRef<any>;
124
- dropdownScroll(event: any): void {
125
- if (this.onDropdownScroll.observed) {
126
- this.onDropdownScroll.emit(event);
127
- this.cdr.markForCheck();
128
- }
129
- }
130
-
131
- selectItem(item: any) {
132
- if (this.multiple) {
133
- if (!this.selectedItems.includes(item)) {
134
- this.selectedItems.push(item);
135
- this.selectedItemsChange.emit(this.selectedItems);
136
- } else {
137
- this.selectedItems = this.selectedItems.filter(
138
- (selected: any) => selected !== item
139
- );
140
- this.selectedItemsChange.emit(this.selectedItems);
141
- }
142
- } else {
143
- this.searchText = "";
144
- this.selectedItems[0] = item;
145
- this.selectedItemName = this.selectedItems[0]?.label;
146
- this.selectedItemImage = this.selectedItems[0]?.image;
147
- this.dropdownOpened = false;
148
- this.selectedItemsChange.emit(this.selectedItems);
149
- }
150
- }
151
-
152
- unselectItem(item: any): void {
153
- this.selectedItems = this.selectedItems.filter(
154
- (selected: any) => selected !== item
155
- );
156
- this.selectedItemsChange.emit(this.selectedItems);
157
- }
158
-
159
- unselectAll() {
160
- this.selectedItems = [];
161
- this.selectedItemName = "";
162
- this.selectedItemImage = "";
163
- this.selectedItemsChange.emit(this.selectedItems);
164
- this.cdr.markForCheck();
165
- }
166
-
167
- @ViewChild("dropdown") dropdown!: ElementRef;
168
- @HostListener("document:click", ["$event"])
169
- onDocumentClick(event: Event): void {
170
- const isClickInsideDropdown = this.dropdown.nativeElement.contains(
171
- event.target
172
- );
173
-
174
- if (!isClickInsideDropdown) {
175
- this.dropdownOpened = false;
176
- }
177
- }
178
-
179
- createNew() {
180
- this.onCreateNew.emit();
181
- this.dropdownOpened = false;
182
- }
183
-
184
- search(event: any): void {
185
- const keyCode = event.keyCode;
186
- this.dropdownOpened = true;
187
- this.searchTerm = event.target.value.toLowerCase();
188
- if (!this.onSearch.observed) {
189
- if (this.searchTerm.trim() === "") {
190
- if (!this.multiple) {
191
- this.unselectAll();
192
- }
193
- this._filteredItems = this.originalItems.slice();
194
- } else {
195
- const lowerCaseSearchTerm = this.searchTerm.toLowerCase();
196
- this._filteredItems = this.originalItems.filter(
197
- (item) =>
198
- item.label.toLowerCase().includes(lowerCaseSearchTerm) ||
199
- (item.value &&
200
- item.value.toLowerCase().includes(lowerCaseSearchTerm))
201
- );
202
- }
203
- } else {
204
- this.onSearch.emit(this.searchTerm);
205
- }
206
- }
207
-
208
- handleButtonClick(action: () => void): void {
209
- action();
210
- this.buttonClick.emit();
211
- }
212
-
213
- highlightMatch(text: string): string {
214
- const search = this.searchText?.trim() || this.searchTerm?.trim();
215
- if (!search || !text) return text;
216
-
217
- const index = text.toLowerCase().indexOf(search.toLowerCase());
218
- if (index === -1) return text;
219
-
220
- const before = text.substring(0, index);
221
- const match = text.substring(index, index + search.length);
222
- const after = text.substring(index + search.length);
223
-
224
- return `${before}<span class="highlight-text">${match}</span>${after}`;
225
- }
226
- }
@@ -1,20 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { DropdownComponent } from './dropdown.component';
3
- import { FormsModule } from '@angular/forms';
4
- import { CommonModule } from '@angular/common';
5
-
6
-
7
-
8
- @NgModule({
9
- declarations: [
10
- DropdownComponent
11
- ],
12
- imports: [
13
- FormsModule,
14
- CommonModule,
15
- ],
16
- exports: [
17
- DropdownComponent
18
- ]
19
- })
20
- export class DropdownModule { }
@@ -1,16 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
-
3
- import { DropdownService } from './dropdown.service';
4
-
5
- describe('DropdownService', () => {
6
- let service: DropdownService;
7
-
8
- beforeEach(() => {
9
- TestBed.configureTestingModule({});
10
- service = TestBed.inject(DropdownService);
11
- });
12
-
13
- it('should be created', () => {
14
- expect(service).toBeTruthy();
15
- });
16
- });
@@ -1,9 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
-
3
- @Injectable({
4
- providedIn: 'root'
5
- })
6
- export class DropdownService {
7
-
8
- constructor() { }
9
- }
package/tsconfig.lib.json DELETED
@@ -1,14 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/lib",
6
- "declaration": true,
7
- "declarationMap": true,
8
- "inlineSources": true,
9
- "types": []
10
- },
11
- "exclude": [
12
- "**/*.spec.ts"
13
- ]
14
- }
@@ -1,10 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "./tsconfig.lib.json",
4
- "compilerOptions": {
5
- "declarationMap": false
6
- },
7
- "angularCompilerOptions": {
8
- "compilationMode": "partial"
9
- }
10
- }
@@ -1,14 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/spec",
6
- "types": [
7
- "jasmine"
8
- ]
9
- },
10
- "include": [
11
- "**/*.spec.ts",
12
- "**/*.d.ts"
13
- ]
14
- }