@yaireo/tagify
Version:
lightweight, efficient Tags input component in Vanilla JS / React / Angular [super customizable, tiny size & top performance]
51 lines (44 loc) • 1.58 kB
text/typescript
import {AfterViewInit, Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
import {TagifyService} from './angular-tagify.service';
export interface SettingsModel {
delimiters?: string;
pattern?: string;
mode?: string;
duplicates?: boolean;
enforceWhitelist?: boolean;
autocomplete?: boolean;
whitelist?: string[];
blacklist?: string[];
addTagOnBlur?: boolean;
callbacks?: Object;
maxTags?: number;
transformTag?: Function;
tagTemplate?: Function;
'dropdown.enabled'?: number;
'dropdown.maxItems'?: string;
'dropdown.classname'?: string;
'dropdown.itemTemplate'?; Function;
}
({
selector: 'tagify',
template: `<input *ngIf="settings" #tagifyInputRef/>`
})
export class TagifyComponent implements AfterViewInit {
() add = new EventEmitter(); // returns the added tag + updated tags list
() remove = new EventEmitter(); // returns the updated tags list
() settings: SettingsModel; // get possible tagify settings
constructor(private tagifyService: TagifyService) { }
('tagifyInputRef') tagifyInputRef: any;
private tagify;
ngAfterViewInit() {
if (!this.settings) return;
this.settings.callbacks = {
add: () => this.add.emit({
tags: this.tagify.value,
added: this.tagify.value[this.tagify.value.length - 1]
}),
remove: () => this.remove.emit(this.tagify.value)
};
this.tagify = this.tagifyService.getTagifyRef(this.tagifyInputRef.nativeElement, this.settings);
}
}