1 | import { CommonModule } from '@angular/common';
|
2 | import { Component, ChangeDetectionStrategy, ViewEncapsulation, forwardRef, Renderer2, ViewChildren, ElementRef, Input, ChangeDetectorRef, ViewChild, HostBinding, EventEmitter, Output, Directive, ContentChildren, NgModule } from '@angular/core';
|
3 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
4 | import { trigger, state, style, transition, animate } from '@angular/animations';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | class BMDurationInputComponent {
|
11 | |
12 |
|
13 |
|
14 | constructor(renderer) {
|
15 | this.renderer = renderer;
|
16 |
|
17 | this.timeValues = new Array(3).fill(null);
|
18 |
|
19 |
|
20 | this.propagateChange = ( |
21 |
|
22 |
|
23 |
|
24 | (_) => { });
|
25 | }
|
26 | |
27 |
|
28 |
|
29 |
|
30 | set value(val) {
|
31 | this.writeValue(val);
|
32 | }
|
33 | |
34 |
|
35 |
|
36 | get value() {
|
37 | return this.computeTotalTime();
|
38 | }
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | format(index, $event) {
|
45 |
|
46 | const inputEle = ( ($event.target));
|
47 |
|
48 | let value = Number.parseInt(inputEle.value, 10);
|
49 | if (Number.isNaN(value)) {
|
50 | value = 0;
|
51 | }
|
52 | if (index && value >= 60) {
|
53 | value = (value % 100) % 60;
|
54 | }
|
55 | this.timeValues[index] = value;
|
56 | this.propagateChange(this.computeTotalTime());
|
57 |
|
58 | const formatedVal = this.timeValues[index] < 10
|
59 | ? '0' + this.timeValues[index]
|
60 | : this.timeValues[index];
|
61 | this.renderer.setProperty(inputEle, 'value', formatedVal);
|
62 | }
|
63 |
|
64 | |
65 |
|
66 |
|
67 |
|
68 | writeValue(value) {
|
69 | if (!value && value !== 0) {
|
70 |
|
71 | this.timeValues = new Array(3).fill(null);
|
72 | }
|
73 | else {
|
74 |
|
75 | let coerceInteger = Number.parseInt(value, 10);
|
76 | if (Number.isNaN(coerceInteger)) {
|
77 | coerceInteger = 0;
|
78 | }
|
79 | coerceInteger = Math.max(0, coerceInteger);
|
80 | [
|
81 | Math.floor(coerceInteger / 3600),
|
82 | Math.floor(coerceInteger / 60) % 60,
|
83 | coerceInteger % 60,
|
84 | ].forEach(( |
85 |
|
86 |
|
87 |
|
88 |
|
89 | (val, i) => {
|
90 | this.timeValues[i] = val;
|
91 | }));
|
92 | }
|
93 | this.updateInputValues();
|
94 | }
|
95 |
|
96 | |
97 |
|
98 |
|
99 |
|
100 | registerOnChange(fn) {
|
101 | this.propagateChange = fn;
|
102 | }
|
103 |
|
104 | |
105 |
|
106 |
|
107 | registerOnTouched() { }
|
108 | |
109 |
|
110 |
|
111 | ngAfterViewInit() {
|
112 | this.updateInputValues();
|
113 | }
|
114 | |
115 |
|
116 |
|
117 |
|
118 | computeTotalTime() {
|
119 | return this.timeValues.reduce(( |
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | (acum, curr, i) => {
|
126 | if (curr) {
|
127 | acum += (( (curr))) * Math.pow(60, (2 - i));
|
128 | }
|
129 | return acum;
|
130 | }), 0);
|
131 | }
|
132 | |
133 |
|
134 |
|
135 |
|
136 | updateInputValues() {
|
137 | if (this.viewTimeValues) {
|
138 | this.viewTimeValues.forEach(( |
139 |
|
140 |
|
141 |
|
142 |
|
143 | (element, index) => {
|
144 |
|
145 | const value = this.timeValues[index];
|
146 |
|
147 | const formatedValue = value < 10 ? '0' + value : value;
|
148 | this.renderer.setProperty(element.nativeElement, 'value', formatedValue);
|
149 | }));
|
150 | }
|
151 | }
|
152 | }
|
153 | BMDurationInputComponent.decorators = [
|
154 | { type: Component, args: [{
|
155 | selector: 'bm-input-duration',
|
156 | template: "<input #hours type=\"number\" min=\"0\" class=\"bm-input bm-duration-input__input\"\n (input)=\"format(0, $event)\" (keyup)=\"format(0, $event)\" placeholder=\"HH\" />\n<input #minutes type=\"number\" min=\"0\" max=\"59\" class=\"bm-input bm-duration-input__input\"\n (input)=\"format(1, $event)\" (keyup)=\"format(1, $event)\" placeholder=\"MM\"/>\n<input #seconds type=\"number\" min=\"0\" max=\"59\" class=\"bm-input bm-duration-input__input\"\n (input)=\"format(2, $event)\" (keyup)=\"format(2, $event)\" placeholder=\"SS\"/>",
|
157 | changeDetection: ChangeDetectionStrategy.OnPush,
|
158 | encapsulation: ViewEncapsulation.None,
|
159 | providers: [
|
160 | {
|
161 | provide: NG_VALUE_ACCESSOR,
|
162 |
|
163 | useExisting: forwardRef(( |
164 |
|
165 |
|
166 | () => BMDurationInputComponent)),
|
167 | multi: true,
|
168 | },
|
169 | ],
|
170 | styles: ["bm-input-duration{display:inline-flex;flex-wrap:nowrap}.bm-duration-input--inverse .bm-duration-input__input{background-color:#fff}.bm-duration-input__input{width:3em}"]
|
171 | }] }
|
172 | ];
|
173 |
|
174 | BMDurationInputComponent.ctorParameters = () => [
|
175 | { type: Renderer2 }
|
176 | ];
|
177 | BMDurationInputComponent.propDecorators = {
|
178 | viewTimeValues: [{ type: ViewChildren, args: ['hours, minutes, seconds', { read: ElementRef },] }],
|
179 | value: [{ type: Input }]
|
180 | };
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | class BMMultiselectComponent {
|
187 | |
188 |
|
189 |
|
190 | constructor(changeDetectorRef) {
|
191 | this.changeDetectorRef = changeDetectorRef;
|
192 | |
193 |
|
194 |
|
195 | this.name = '';
|
196 | this.tabIndex = 0;
|
197 | this.options = [];
|
198 | this.availableOptions = [];
|
199 | this.filteredOptions = [];
|
200 | this.selectedOptionsList = [];
|
201 | this.selectedOptions = new Set();
|
202 | this.showSuggestions = false;
|
203 |
|
204 | this.onTouched = ( |
205 |
|
206 |
|
207 | () => { });
|
208 |
|
209 |
|
210 | this.propagateChange = ( |
211 |
|
212 |
|
213 |
|
214 | (_) => { });
|
215 | }
|
216 | |
217 |
|
218 |
|
219 | get isFocused() {
|
220 | return this.focused;
|
221 | }
|
222 | |
223 |
|
224 |
|
225 |
|
226 | set value(v) {
|
227 | if (Array.isArray(v)) {
|
228 | this.selectedOptions = new Set(v);
|
229 | }
|
230 | this.updateListAndSuggestions();
|
231 | this.updateSelectedList();
|
232 | }
|
233 | |
234 |
|
235 |
|
236 | get value() {
|
237 | return Array.from(this.selectedOptions.values());
|
238 | }
|
239 | |
240 |
|
241 |
|
242 |
|
243 |
|
244 | selectOption(option, event) {
|
245 |
|
246 | const target = ( (event.target));
|
247 | if (target.nextElementSibling) {
|
248 | (( (target.nextElementSibling))).focus();
|
249 | }
|
250 | else if (target.previousElementSibling) {
|
251 | (( (target.previousElementSibling))).focus();
|
252 | }
|
253 | this.selectedOptions.add(option.key);
|
254 | this.valueChange();
|
255 | }
|
256 | |
257 |
|
258 |
|
259 |
|
260 | removeOption(option) {
|
261 | this.selectedOptions.delete(option.key);
|
262 | this.valueChange();
|
263 | }
|
264 | |
265 |
|
266 |
|
267 | removeAll() {
|
268 | this.selectedOptions.clear();
|
269 | this.valueChange();
|
270 | }
|
271 | |
272 |
|
273 |
|
274 | addAll() {
|
275 | this.selectedOptions = new Set(this.options.map(( |
276 |
|
277 |
|
278 |
|
279 | item => item.key)));
|
280 | this.valueChange();
|
281 | this.showSuggestions = false;
|
282 | }
|
283 | |
284 |
|
285 |
|
286 |
|
287 | inputKeyUp(event) {
|
288 | switch (event.keyCode) {
|
289 | case 40:
|
290 | this.showSuggestions = true;
|
291 | if (this.suggestionList.first &&
|
292 | this.suggestionList.first.nativeElement) {
|
293 | this.suggestionList.first.nativeElement.focus();
|
294 | }
|
295 | break;
|
296 | case 27:
|
297 | this.showSuggestions = false;
|
298 | break;
|
299 | default:
|
300 | this.updateSuggestionList();
|
301 | }
|
302 | }
|
303 | |
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 | suggestionKeyUp(event, index, value) {
|
310 |
|
311 | const suggestionLi = this.suggestionList.toArray();
|
312 |
|
313 | const keyDown = ( |
314 |
|
315 |
|
316 | () => {
|
317 | if (index === 0 &&
|
318 | this.suggestionList.last &&
|
319 | this.suggestionList.last.nativeElement) {
|
320 | this.suggestionList.last.nativeElement.focus();
|
321 | }
|
322 | else if (suggestionLi[index - 1] &&
|
323 | suggestionLi[index - 1].nativeElement) {
|
324 | suggestionLi[index - 1].nativeElement.focus();
|
325 | }
|
326 | });
|
327 | switch (event.keyCode) {
|
328 | case 40:
|
329 | if (index === this.filteredOptions.length - 1 &&
|
330 | this.suggestionList.first &&
|
331 | this.suggestionList.first.nativeElement) {
|
332 | this.suggestionList.first.nativeElement.focus();
|
333 | }
|
334 | else if (suggestionLi[index + 1] &&
|
335 | suggestionLi[index + 1].nativeElement) {
|
336 | suggestionLi[index + 1].nativeElement.focus();
|
337 | }
|
338 | event.preventDefault();
|
339 | break;
|
340 | case 38:
|
341 | keyDown();
|
342 | event.preventDefault();
|
343 | break;
|
344 | case 27:
|
345 | this.showSuggestions = false;
|
346 | break;
|
347 | case 13:
|
348 | this.selectOption(value, event);
|
349 | keyDown();
|
350 | break;
|
351 | default:
|
352 | return;
|
353 | }
|
354 | }
|
355 | |
356 |
|
357 |
|
358 |
|
359 |
|
360 | selectedItemKeyup(event, value) {
|
361 | if (event.keyCode === 46 || event.keyCode === 8) {
|
362 | event.preventDefault();
|
363 | this.removeOption(value);
|
364 | }
|
365 | }
|
366 | |
367 |
|
368 |
|
369 | afterOptionFocus() {
|
370 | this.showSuggestions = false;
|
371 | }
|
372 |
|
373 | |
374 |
|
375 |
|
376 | inputFocus() {
|
377 | this.focused = true;
|
378 | this.showSuggestions = true;
|
379 | }
|
380 | |
381 |
|
382 |
|
383 |
|
384 | inputFocusout(event) {
|
385 |
|
386 | const relatedTarget = ( (event.relatedTarget));
|
387 |
|
388 | const suggestions = this.suggestionList.map(( |
389 |
|
390 |
|
391 |
|
392 | item => item.nativeElement));
|
393 | if (suggestions.indexOf(relatedTarget) === -1) {
|
394 | this.showSuggestions = false;
|
395 | }
|
396 | this.focused = false;
|
397 | this.onTouched();
|
398 | }
|
399 | |
400 |
|
401 |
|
402 |
|
403 | suggestionFocusout(event) {
|
404 |
|
405 | const target = ( (event.target));
|
406 |
|
407 | const relatedTarget = ( (event.relatedTarget));
|
408 | if (!relatedTarget ||
|
409 | target.parentElement !== relatedTarget.parentElement) {
|
410 | this.showSuggestions = false;
|
411 | }
|
412 | }
|
413 | |
414 |
|
415 |
|
416 | ngAfterViewInit() {
|
417 | this.updateListAndSuggestions();
|
418 | }
|
419 |
|
420 | |
421 |
|
422 |
|
423 |
|
424 | writeValue(value) {
|
425 | this.value = value;
|
426 | this.changeDetectorRef.markForCheck();
|
427 | }
|
428 |
|
429 | |
430 |
|
431 |
|
432 |
|
433 | registerOnChange(fn) {
|
434 | this.propagateChange = fn;
|
435 | }
|
436 |
|
437 | |
438 |
|
439 |
|
440 |
|
441 | registerOnTouched(fn) {
|
442 | this.onTouched = fn;
|
443 | }
|
444 | |
445 |
|
446 |
|
447 | focus() {
|
448 | if (this.input && this.input.nativeElement) {
|
449 | this.input.nativeElement.focus();
|
450 | }
|
451 | }
|
452 | |
453 |
|
454 |
|
455 |
|
456 | updateSelectedList() {
|
457 | this.selectedOptionsList = this.options.filter(( |
458 |
|
459 |
|
460 |
|
461 | option => this.selectedOptions.has(option.key)));
|
462 | }
|
463 | |
464 |
|
465 |
|
466 |
|
467 | updateListAndSuggestions() {
|
468 | this.availableOptions = this.options.filter(( |
469 |
|
470 |
|
471 |
|
472 | option => !this.selectedOptions.has(option.key)));
|
473 | this.updateSuggestionList();
|
474 | }
|
475 | |
476 |
|
477 |
|
478 |
|
479 | updateSuggestionList() {
|
480 |
|
481 | const value = (( ((this.input.nativeElement)))).value.toLowerCase();
|
482 | this.filteredOptions = this.availableOptions.filter(( |
483 |
|
484 |
|
485 |
|
486 | item => item.displayValue.toLowerCase().search(value) !== -1));
|
487 | }
|
488 | |
489 |
|
490 |
|
491 |
|
492 | valueChange() {
|
493 | this.propagateChange(Array.from(this.selectedOptions.values()));
|
494 | this.updateListAndSuggestions();
|
495 | this.updateSelectedList();
|
496 | if (this.availableOptions.length === 0 &&
|
497 | this.input &&
|
498 | this.input.nativeElement) {
|
499 | this.input.nativeElement.focus();
|
500 | }
|
501 | }
|
502 | }
|
503 | BMMultiselectComponent.decorators = [
|
504 | { type: Component, args: [{
|
505 | selector: 'bm-multiselect',
|
506 | template: "<div class=\"bm-multiselect-input-container\">\n <input\n class=\"bm-multiselect-input bm-input\"\n #input\n autocomplete=\"off\"\n [required]=\"required\"\n [disabled]=\"disabled\"\n [name]=\"name\"\n [tabIndex]=\"tabIndex\"\n [readonly]=\"readonly\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n (keyup)=\"inputKeyUp($event)\"\n (focus)=\"inputFocus()\"\n (focusout)=\"inputFocusout($event)\"\n />\n <div\n *ngIf=\"showSuggestions\"\n tabindex=\"-1\"\n class=\"bm-multiselect-suggestions-container\"\n [@fadeInOut]=\"'in'\"\n >\n <ul>\n <li i18n tabindex=\"-1\" *ngIf=\"filteredOptions.length === 0\">\n No matches found\n </li>\n <li\n #sugg\n tabindex=\"0\"\n *ngFor=\"let option of filteredOptions; let i = index\"\n aria-selected=\"true\"\n (click)=\"selectOption(option, $event)\"\n (focusout)=\"suggestionFocusout($event)\"\n (keydown)=\"suggestionKeyUp($event, i, option)\"\n >\n {{ option.displayValue }}\n </li>\n </ul>\n </div>\n <button\n class=\"bm-multiselect-add-all\"\n i18n\n (click)=\"addAll()\"\n (focus)=\"afterOptionFocus()\"\n >\n Add all\n </button>\n</div>\n<div *ngIf=\"value.length\" class=\"bm-multiselect-selected-options\">\n <div class=\"bm-multiselect-button-container\">\n <button class=\"bm-multiselect-remove-all\" i18n (click)=\"removeAll()\">\n Remove all\n </button>\n </div>\n <ul>\n <li\n *ngFor=\"let option of selectedOptionsList\"\n tabindex=\"0\"\n aria-selected=\"false\"\n (keyup)=\"selectedItemKeyup($event, option)\"\n >\n <span>{{ option.displayValue }}</span>\n <button\n bmIconButton\n class=\"bm-multiselect-remove-item fas fa-trash\"\n arial-label=\"Remove this item\"\n (click)=\"removeOption(option)\"\n i18n-arial-label\n ></button>\n </li>\n </ul>\n</div>\n",
|
507 | changeDetection: ChangeDetectionStrategy.OnPush,
|
508 | encapsulation: ViewEncapsulation.None,
|
509 | providers: [
|
510 | {
|
511 | provide: NG_VALUE_ACCESSOR,
|
512 |
|
513 | useExisting: forwardRef(( |
514 |
|
515 |
|
516 | () => BMMultiselectComponent)),
|
517 | multi: true,
|
518 | },
|
519 | ],
|
520 | animations: [
|
521 | trigger('fadeInOut', [
|
522 | state('in', style({ opacity: 1 })),
|
523 | transition('void => *', [
|
524 | style({
|
525 | opacity: 0,
|
526 | }),
|
527 | animate('0.2s ease-in'),
|
528 | ]),
|
529 | transition('* => void', [
|
530 | animate('0.2s ease-out', style({
|
531 | opacity: 0,
|
532 | })),
|
533 | ]),
|
534 | ]),
|
535 | ],
|
536 | styles: ["bm-multiselect{display:inline-block}.bm-multiselect-input-container{display:block;position:relative}.bm-multiselect-input{width:100%;box-sizing:border-box}.bm-multiselect-add-all,.bm-multiselect-remove-all,.bm-multiselect-remove-item{background:0 0;color:#4399fd;border:none}.bm-multiselect-add-all{position:absolute;right:0;top:.5em}.bm-multiselect-suggestions-container{position:absolute;top:1.8em;width:100%;background:#fff;max-height:10em;box-shadow:0 0 4px 0 rgba(0,0,0,.09);overflow-x:auto;z-index:1000}.bm-multiselect-suggestions-container ul{list-style:none;padding:0;margin:0}.bm-multiselect-suggestions-container li{padding:.2em 1em;cursor:pointer}.bm-multiselect-suggestions-container li:nth-child(odd){background-color:#fff}.bm-multiselect-suggestions-container li:nth-child(even){background-color:var(--secondary-color,#bcbcbc)}.bm-multiselect-suggestions-container li:focus,.bm-multiselect-suggestions-container li:hover{background-color:var(--secondary-color-hover,#959494)}.bm-multiselect-selected-options{text-align:left}.bm-multiselect-selected-options .bm-multiselect-button-container{text-align:right;padding:1em 0}.bm-multiselect-selected-options .bm-multiselect-remove-item{display:none}.bm-multiselect-selected-options ul{margin:0;padding:0;max-height:15em;overflow-x:auto;list-style-type:none}.bm-multiselect-selected-options li{padding:.5em;display:flex}.bm-multiselect-selected-options li:nth-child(odd){background-color:#f5f7f8}.bm-multiselect-selected-options li:focus{background-color:var(--secondary-color-hover,#959494)}.bm-multiselect-selected-options li:hover .bm-multiselect-remove-item{display:block;margin-right:0;margin-left:auto}"]
|
537 | }] }
|
538 | ];
|
539 |
|
540 | BMMultiselectComponent.ctorParameters = () => [
|
541 | { type: ChangeDetectorRef }
|
542 | ];
|
543 | BMMultiselectComponent.propDecorators = {
|
544 | input: [{ type: ViewChild, args: ['input', { static: true },] }],
|
545 | suggestionList: [{ type: ViewChildren, args: ['sugg',] }],
|
546 | isFocused: [{ type: HostBinding, args: ['class.bm-multiselect-focused',] }],
|
547 | name: [{ type: Input }],
|
548 | tabIndex: [{ type: Input }],
|
549 | required: [{ type: Input }],
|
550 | disabled: [{ type: Input }],
|
551 | readonly: [{ type: Input }],
|
552 | ariaLabel: [{ type: Input, args: ['aria-label',] }],
|
553 | ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
|
554 | value: [{ type: Input }],
|
555 | options: [{ type: Input }]
|
556 | };
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 | class BMInputSearchComponent {
|
563 | |
564 |
|
565 |
|
566 | constructor(_renderer) {
|
567 | this._renderer = _renderer;
|
568 | |
569 |
|
570 |
|
571 | this.name = '';
|
572 | this.placeholder = '';
|
573 | this.tabIndex = 0;
|
574 |
|
575 | this.type = 'text';
|
576 | |
577 |
|
578 |
|
579 | this.showSuggestions = false;
|
580 | this.minSuggestionChars = 2;
|
581 | this.search = new EventEmitter();
|
582 |
|
583 | this.onTouched = ( |
584 |
|
585 |
|
586 | () => { });
|
587 |
|
588 |
|
589 | this.propagateChange = ( |
590 |
|
591 |
|
592 |
|
593 | (_) => { });
|
594 | }
|
595 | |
596 |
|
597 |
|
598 |
|
599 | set value(v) {
|
600 | if (v) {
|
601 | this._renderer.setProperty(this.input.nativeElement, 'value', v);
|
602 | }
|
603 | }
|
604 | |
605 |
|
606 |
|
607 | get value() {
|
608 | return this.input.nativeElement.value;
|
609 | }
|
610 | |
611 |
|
612 |
|
613 |
|
614 | inputKeyUp(event) {
|
615 | switch (event.keyCode) {
|
616 | case 40:
|
617 | if (this.suggestionList.first) {
|
618 | this.suggestionList.first.nativeElement.focus();
|
619 | }
|
620 | break;
|
621 | case 27:
|
622 | this.closeSuggestions();
|
623 | break;
|
624 | default:
|
625 |
|
626 | const value = (( (event.target))).value.toLowerCase();
|
627 | if (value.length >= this.minSuggestionChars &&
|
628 | Array.isArray(this.suggestions)) {
|
629 | this.showSuggestions = true;
|
630 | this.filteredSuggestions = this.suggestions
|
631 | .map(( |
632 |
|
633 |
|
634 |
|
635 | item => item.toString().toLowerCase()))
|
636 | .filter(( |
637 |
|
638 |
|
639 |
|
640 | item => item.search(value) !== -1));
|
641 | }
|
642 | else {
|
643 | this.showSuggestions = false;
|
644 | }
|
645 | return;
|
646 | }
|
647 | }
|
648 |
|
649 | |
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 | suggestionKeyUp(event, index, value) {
|
656 |
|
657 | const suggestionLi = this.suggestionList.toArray();
|
658 | switch (event.keyCode) {
|
659 | case 40:
|
660 | if (index === this.suggestions.length - 1) {
|
661 | this.suggestionList.first.nativeElement.focus();
|
662 | }
|
663 | else {
|
664 | suggestionLi[index + 1].nativeElement.focus();
|
665 | }
|
666 | event.preventDefault();
|
667 | break;
|
668 | case 38:
|
669 | if (index === 0) {
|
670 | this.suggestionList.last.nativeElement.focus();
|
671 | }
|
672 | else {
|
673 | suggestionLi[index - 1].nativeElement.focus();
|
674 | }
|
675 | event.preventDefault();
|
676 | break;
|
677 | case 27:
|
678 | this.closeSuggestions();
|
679 | break;
|
680 | case 13:
|
681 | this.setInput(value);
|
682 | break;
|
683 | default:
|
684 | return;
|
685 | }
|
686 | }
|
687 |
|
688 | |
689 |
|
690 |
|
691 |
|
692 | setInput(v) {
|
693 | this.value = v;
|
694 | this.propagateChange(this.value);
|
695 | this.closeSuggestions();
|
696 | }
|
697 | |
698 |
|
699 |
|
700 |
|
701 | inputBlur() {
|
702 | this.onTouched();
|
703 | }
|
704 |
|
705 | |
706 |
|
707 |
|
708 |
|
709 | writeValue(value) {
|
710 | this._renderer.setProperty(this.input.nativeElement, 'value', value);
|
711 | }
|
712 |
|
713 | |
714 |
|
715 |
|
716 |
|
717 | registerOnChange(fn) {
|
718 | this.propagateChange = fn;
|
719 | }
|
720 |
|
721 | |
722 |
|
723 |
|
724 |
|
725 | registerOnTouched(fn) {
|
726 | this.onTouched = fn;
|
727 | }
|
728 | |
729 |
|
730 |
|
731 |
|
732 | inputChange(event) {
|
733 | const { value } = ( (event.target));
|
734 | this.propagateChange(value);
|
735 | }
|
736 | |
737 |
|
738 |
|
739 | focus() {
|
740 | this.input.nativeElement.focus();
|
741 | }
|
742 | |
743 |
|
744 |
|
745 |
|
746 | closeSuggestions() {
|
747 | this.input.nativeElement.focus();
|
748 | this.showSuggestions = false;
|
749 | }
|
750 | }
|
751 | BMInputSearchComponent.decorators = [
|
752 | { type: Component, args: [{
|
753 | selector: 'bm-input-search',
|
754 | template: "<div class=\"bm-input bm-input-search__input-container\">\n <input\n #input\n class=\"bm-input bm-input-search__input\"\n autocomplete=\"off\"\n [type]=\"type\"\n [required]=\"required\"\n [disabled]=\"disabled\"\n [name]=\"name\"\n [tabIndex]=\"tabIndex\"\n [readonly]=\"readonly\"\n [placeholder]=\"placeholder\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n (keyup)=\"inputKeyUp($event)\"\n (change)=\"inputChange($event)\"\n (blur)=\"inputBlur()\"\n />\n <button\n class=\"bm-button bm-button--primary bm-input-search__search-button\"\n (click)=\"search.emit(input.value)\"\n >\n <i class=\"fas fa-search\" aria-hidden=\"true\"></i>\n </button>\n</div>\n\n<div class=\"bm-input-search__suggestions-container\" *ngIf=\"showSuggestions\">\n <ul class=\"bm-input-search__suggestions-list\">\n <li\n i18n\n tabindex=\"-1\"\n *ngIf=\"filteredSuggestions?.length === 0\"\n class=\"bm-input-search__suggestions-list-item\"\n >\n No matches found\n </li>\n <li\n #sugg\n tabindex=\"0\"\n *ngFor=\"let suggestion of filteredSuggestions; let i = index\"\n class=\"bm-input-search__suggestions-list-item\"\n (click)=\"setInput(suggestion)\"\n (keydown)=\"suggestionKeyUp($event, i, suggestion)\"\n >\n {{ suggestion }}\n </li>\n </ul>\n</div>\n",
|
755 | providers: [
|
756 | {
|
757 | provide: NG_VALUE_ACCESSOR,
|
758 |
|
759 | useExisting: forwardRef(( |
760 |
|
761 |
|
762 | () => BMInputSearchComponent)),
|
763 | multi: true,
|
764 | },
|
765 | ],
|
766 | changeDetection: ChangeDetectionStrategy.OnPush,
|
767 | encapsulation: ViewEncapsulation.None,
|
768 | styles: ["bm-input-search{display:inline-block;position:relative}.bm-input-search__input{padding:.3rem 3rem .3rem 1rem!important;width:100%;box-sizing:border-box}.bm-input-search__input-container{position:relative;width:100%;height:100%}.bm-input-search__search-button{display:block;position:absolute;right:0;top:1px;bottom:1px;border-top-left-radius:0;border-bottom-left-radius:0;padding:0 .75em;font-weight:400}.bm-input-search--inverse .bm-input-search__input{background-color:#fff}.bm-input-search__suggestions-container{position:absolute;top:2.4em;width:100%;max-height:10em;box-shadow:0 0 4px 0 rgba(0,0,0,.09);overflow-x:auto}.bm-input-search__suggestions-list{list-style:none;padding:0;margin:0}.bm-input-search__suggestions-list-item{padding:.2em 1em;cursor:pointer}.bm-input-search__suggestions-list-item:nth-child(odd){background-color:#fff}.bm-input-search__suggestions-list-item:nth-child(even){background-color:var(--secondary-color,#bcbcbc)}.bm-input-search__suggestions-list-item:focus,.bm-input-search__suggestions-list-item:hover{background-color:var(--secondary-color-hover,#959494)}"]
|
769 | }] }
|
770 | ];
|
771 |
|
772 | BMInputSearchComponent.ctorParameters = () => [
|
773 | { type: Renderer2 }
|
774 | ];
|
775 | BMInputSearchComponent.propDecorators = {
|
776 | input: [{ type: ViewChild, args: ['input', { static: true },] }],
|
777 | suggestionList: [{ type: ViewChildren, args: ['sugg',] }],
|
778 | name: [{ type: Input }],
|
779 | placeholder: [{ type: Input }],
|
780 | tabIndex: [{ type: Input }],
|
781 | required: [{ type: Input }],
|
782 | disabled: [{ type: Input }],
|
783 | readonly: [{ type: Input }],
|
784 | type: [{ type: Input }],
|
785 | ariaLabel: [{ type: Input, args: ['aria-label',] }],
|
786 | ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
|
787 | value: [{ type: Input }],
|
788 | minSuggestionChars: [{ type: Input }],
|
789 | suggestions: [{ type: Input }],
|
790 | search: [{ type: Output }]
|
791 | };
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 | class BMOptionDirective {
|
798 | }
|
799 | BMOptionDirective.decorators = [
|
800 | { type: Directive, args: [{
|
801 | selector: '[bmOption]',
|
802 | },] }
|
803 | ];
|
804 | class BMSelectComponent {
|
805 | |
806 |
|
807 |
|
808 | constructor(_renderer) {
|
809 | this._renderer = _renderer;
|
810 | |
811 |
|
812 |
|
813 | this.name = '';
|
814 | this.tabIndex = 0;
|
815 |
|
816 | this.type = 'text';
|
817 |
|
818 | this.onTouched = ( |
819 |
|
820 |
|
821 | () => { });
|
822 |
|
823 |
|
824 | this.propagateChange = ( |
825 |
|
826 |
|
827 |
|
828 | (_) => { });
|
829 | }
|
830 | |
831 |
|
832 |
|
833 |
|
834 | set value(v) {
|
835 | this._valueCopy = v;
|
836 | this.setCheckedOption();
|
837 | }
|
838 | |
839 |
|
840 |
|
841 | get value() {
|
842 | return this._valueCopy;
|
843 | }
|
844 | |
845 |
|
846 |
|
847 |
|
848 | inputBlur() {
|
849 | this.onTouched();
|
850 | }
|
851 |
|
852 | |
853 |
|
854 |
|
855 |
|
856 | writeValue(value) {
|
857 | this._valueCopy = value;
|
858 | this.setCheckedOption();
|
859 | }
|
860 |
|
861 | |
862 |
|
863 |
|
864 |
|
865 | registerOnChange(fn) {
|
866 | this.propagateChange = fn;
|
867 | }
|
868 |
|
869 | |
870 |
|
871 |
|
872 |
|
873 | registerOnTouched(fn) {
|
874 | this.onTouched = fn;
|
875 | }
|
876 | |
877 |
|
878 |
|
879 |
|
880 | inputChange(event) {
|
881 | const { value } = ( (event.target));
|
882 | this._valueCopy = value;
|
883 | this.propagateChange(value);
|
884 | }
|
885 | |
886 |
|
887 |
|
888 | focus() {
|
889 | (( (this.select.nativeElement))).focus();
|
890 | }
|
891 | |
892 |
|
893 |
|
894 | ngAfterContentInit() {
|
895 | this._optionsSubs = this.options.changes.subscribe(( |
896 |
|
897 |
|
898 | () => this.setCheckedOption()));
|
899 | this.setCheckedOption();
|
900 | }
|
901 | |
902 |
|
903 |
|
904 | ngOnDestroy() {
|
905 | if (this._optionsSubs) {
|
906 | this._optionsSubs.unsubscribe();
|
907 | }
|
908 | }
|
909 | |
910 |
|
911 |
|
912 |
|
913 | setCheckedOption() {
|
914 | if (this._valueCopy !== undefined) {
|
915 | this._renderer.setValue(this.select.nativeElement, this._valueCopy);
|
916 | }
|
917 | if (!this.options) {
|
918 | return;
|
919 | }
|
920 | this.options.forEach(( |
921 |
|
922 |
|
923 |
|
924 | elem => {
|
925 |
|
926 | const domEle = elem.nativeElement;
|
927 | if (domEle) {
|
928 | domEle.selected = domEle.value === this._valueCopy;
|
929 | }
|
930 | }));
|
931 | }
|
932 | }
|
933 | BMSelectComponent.decorators = [
|
934 | { type: Component, args: [{
|
935 | selector: 'bm-select',
|
936 | template: "<select #select\n class=\"bm-select__select\"\n [required]=\"required\"\n [disabled]=\"disabled\"\n [name]=\"name\"\n [tabIndex]=\"tabIndex\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n (change)=\"inputChange($event)\"\n (blur)=\"inputBlur()\">\n <ng-content></ng-content>\n</select>\n",
|
937 | providers: [
|
938 | {
|
939 | provide: NG_VALUE_ACCESSOR,
|
940 |
|
941 | useExisting: forwardRef(( |
942 |
|
943 |
|
944 | () => BMSelectComponent)),
|
945 | multi: true,
|
946 | },
|
947 | ],
|
948 | changeDetection: ChangeDetectionStrategy.OnPush,
|
949 | encapsulation: ViewEncapsulation.None,
|
950 | styles: [".bm-select__select{-moz-appearance:none;-ms-word-break:normal;-webkit-appearance:none;appearance:none;background:var(--header-color,#f8f8f8);border-radius:.333em;border:none;box-shadow:0 1px 1px 0 rgba(0,0,0,.2);font-family:proxima-regular;font-size:.815rem;font-weight:400;line-height:1.45rem;padding:.3em 2em .3em .6em;width:100%;word-break:normal}bm-select{min-width:200;display:inline-block;position:relative}bm-select--inverse .bm-select__select{background:#fff;box-shadow:inset 0 1px 1px 0 rgba(0,0,0,.2)}bm-select::after{content:'\\f0d7';font-weight:900;font-family:\"Font Awesome 5 Free\";pointer-events:none;position:absolute;right:8px;top:6px}"]
|
951 | }] }
|
952 | ];
|
953 |
|
954 | BMSelectComponent.ctorParameters = () => [
|
955 | { type: Renderer2 }
|
956 | ];
|
957 | BMSelectComponent.propDecorators = {
|
958 | select: [{ type: ViewChild, args: ['select', { static: true },] }],
|
959 | options: [{ type: ContentChildren, args: [BMOptionDirective, { read: ElementRef },] }],
|
960 | name: [{ type: Input }],
|
961 | tabIndex: [{ type: Input }],
|
962 | required: [{ type: Input }],
|
963 | disabled: [{ type: Input }],
|
964 | readonly: [{ type: Input }],
|
965 | type: [{ type: Input }],
|
966 | ariaLabel: [{ type: Input, args: ['aria-label',] }],
|
967 | ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
|
968 | value: [{ type: Input }]
|
969 | };
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 | class BMATFormsModule {
|
976 | }
|
977 | BMATFormsModule.decorators = [
|
978 | { type: NgModule, args: [{
|
979 | imports: [CommonModule],
|
980 | declarations: [
|
981 | BMDurationInputComponent,
|
982 | BMInputSearchComponent,
|
983 | BMMultiselectComponent,
|
984 | BMOptionDirective,
|
985 | BMSelectComponent,
|
986 | ],
|
987 | exports: [
|
988 | BMDurationInputComponent,
|
989 | BMInputSearchComponent,
|
990 | BMMultiselectComponent,
|
991 | BMOptionDirective,
|
992 | BMSelectComponent,
|
993 | ],
|
994 | providers: [],
|
995 | },] }
|
996 | ];
|
997 |
|
998 | export { BMATFormsModule, BMDurationInputComponent, BMInputSearchComponent, BMMultiselectComponent, BMOptionDirective, BMSelectComponent };
|
999 |
|