Input component: Delete depracated inputs, add visibleChips limit, add separators for chips and style note with italic
This commit is contained in:
parent
799a62afc5
commit
4a03065dbd
|
@ -97,7 +97,7 @@ declare var UIkit;
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template [ngIf]="type === 'chips'">
|
<ng-template [ngIf]="type === 'chips'">
|
||||||
<div class="uk-grid uk-grid-small uk-grid-row-collapse uk-width-expand" uk-grid>
|
<div class="uk-grid uk-grid-small uk-grid-row-collapse uk-width-expand" uk-grid>
|
||||||
<div *ngFor="let chip of formAsArray.controls; let i=index" [class.uk-hidden]="!focused && i > 0"
|
<div *ngFor="let chip of formAsArray.controls; let i=index" [class.uk-hidden]="!focused && i > visibleChips - 1"
|
||||||
class="chip">
|
class="chip">
|
||||||
<div class="uk-label uk-label-small uk-flex uk-flex-middle"
|
<div class="uk-label uk-label-small uk-flex uk-flex-middle"
|
||||||
[attr.uk-tooltip]="(tooltip)?('title: ' + getLabel(chip.value) + '; delay: 500; pos: bottom-left'):null">
|
[attr.uk-tooltip]="(tooltip)?('title: ' + getLabel(chip.value) + '; delay: 500; pos: bottom-left'):null">
|
||||||
|
@ -112,9 +112,9 @@ declare var UIkit;
|
||||||
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||||
[formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
[formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="!focused && formAsArray.length > 1"
|
<div *ngIf="!focused && formAsArray.length > visibleChips"
|
||||||
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
||||||
+ {{(formAsArray.length - 1)}} more
|
+ {{(formAsArray.length - visibleChips)}} more
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@ -133,6 +133,7 @@ declare var UIkit;
|
||||||
</button>
|
</button>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
|
<ng-content select="[action]"></ng-content>
|
||||||
</div>
|
</div>
|
||||||
<div class="tools">
|
<div class="tools">
|
||||||
<ng-content select="[tools]"></ng-content>
|
<ng-content select="[tools]"></ng-content>
|
||||||
|
@ -155,10 +156,10 @@ declare var UIkit;
|
||||||
<span *ngIf="formControl.errors.error">{{formControl.errors.error}}</span>
|
<span *ngIf="formControl.errors.error">{{formControl.errors.error}}</span>
|
||||||
<span *ngIf="type === 'URL' || type === 'logoURL'">Please provide a valid URL (e.g. https://example.com)</span>
|
<span *ngIf="type === 'URL' || type === 'logoURL'">Please provide a valid URL (e.g. https://example.com)</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="uk-text-danger uk-text-small">
|
<span class="uk-text-small uk-text-danger">
|
||||||
<ng-content select="[error]"></ng-content>
|
<ng-content select="[error]"></ng-content>
|
||||||
</span>
|
</span>
|
||||||
<span *ngIf="formControl?.valid" class="uk-text-warning uk-text-small">
|
<span *ngIf="formControl?.valid" class="uk-text-small uk-text-warning uk-margin-xsmall-top">
|
||||||
<ng-content select="[warning]"></ng-content>
|
<ng-content select="[warning]"></ng-content>
|
||||||
<span *ngIf="!secure">
|
<span *ngIf="!secure">
|
||||||
<span class="uk-text-bold">Note:</span> Prefer urls like "<span class="uk-text-bold">https://</span>example.com/my-secure-image.png"
|
<span class="uk-text-bold">Note:</span> Prefer urls like "<span class="uk-text-bold">https://</span>example.com/my-secure-image.png"
|
||||||
|
@ -166,34 +167,13 @@ declare var UIkit;
|
||||||
<span class="uk-text-bold">Browsers may not load non secure content.</span>
|
<span class="uk-text-bold">Browsers may not load non secure content.</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="uk-text-small">
|
<i class="uk-text-small uk-text-meta uk-margin-xsmall-top">
|
||||||
<ng-content select="[note]"></ng-content>
|
<ng-content select="[note]"></ng-content>
|
||||||
</span>
|
</i>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
||||||
private static INPUT_COUNTER: number = 0;
|
private static INPUT_COUNTER: number = 0;
|
||||||
/** Deprecated options*/
|
|
||||||
/** @deprecated */
|
|
||||||
@Input('label') label: string;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() extraLeft: boolean = true;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() gridSmall: boolean = false;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() hideControl: boolean = false;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() flex: 'middle' | 'top' | 'bottom' = 'middle';
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() iconLeft: boolean = false;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() removable: boolean = true;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() smallChip: boolean = false;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() panelWidth: number = 300;
|
|
||||||
/** @deprecated */
|
|
||||||
@Input() panelClass: string = null;
|
|
||||||
/** Basic information */
|
/** Basic information */
|
||||||
@Input('formInput') formControl: AbstractControl;
|
@Input('formInput') formControl: AbstractControl;
|
||||||
@Input('type') type: InputType = 'text';
|
@Input('type') type: InputType = 'text';
|
||||||
|
@ -226,6 +206,8 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
/** Chip options */
|
/** Chip options */
|
||||||
@Input() addExtraChips: boolean = false;
|
@Input() addExtraChips: boolean = false;
|
||||||
@Input() showOptionsOnEmpty: boolean = true;
|
@Input() showOptionsOnEmpty: boolean = true;
|
||||||
|
@Input() visibleChips: number = 1;
|
||||||
|
@Input() separators: string[] = [];
|
||||||
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
||||||
/** LogoUrl information */
|
/** LogoUrl information */
|
||||||
public secure: boolean = true;
|
public secure: boolean = true;
|
||||||
|
@ -324,6 +306,14 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('keydown', ['$event'])
|
||||||
|
onKeyDown(event: KeyboardEvent) {
|
||||||
|
if (this.separators.includes(event.key)) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.add(event, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
click(event: ClickEvent) {
|
click(event: ClickEvent) {
|
||||||
this.focus(!event.clicked, event);
|
this.focus(!event.clicked, event);
|
||||||
}
|
}
|
||||||
|
@ -484,15 +474,17 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
add(event) {
|
add(event, addChips = false) {
|
||||||
if (this.addExtraChips && this.searchControl.value && this.searchControl.valid) {
|
if (addChips && this.searchControl.value && this.searchControl.valid) {
|
||||||
if (event && event.stopPropagation) {
|
if (event && event.stopPropagation) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
this.formAsArray.push(new UntypedFormControl(this.searchControl.value, this.validators));
|
this.formAsArray.push(new UntypedFormControl(this.searchControl.value, this.validators));
|
||||||
this.formAsArray.markAsDirty();
|
this.formAsArray.markAsDirty();
|
||||||
}
|
|
||||||
this.searchControl.setValue('');
|
this.searchControl.setValue('');
|
||||||
|
} else if(!this.focused) {
|
||||||
|
this.searchControl.setValue('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLabel(value: any): string {
|
getLabel(value: any): string {
|
||||||
|
@ -534,7 +526,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.searchInput.nativeElement.blur();
|
this.searchInput.nativeElement.blur();
|
||||||
}
|
}
|
||||||
if (this.searchControl) {
|
if (this.searchControl) {
|
||||||
this.add(event);
|
this.add(event, this.addExtraChips);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.focusEmitter.emit(this.focused);
|
this.focusEmitter.emit(this.focused);
|
||||||
|
|
|
@ -18,8 +18,9 @@ import {NotificationHandler} from "../../utils/notification-handler";
|
||||||
<div *ngIf="body" class="uk-grid uk-child-width-1-1" uk-grid [formGroup]="inviteForm">
|
<div *ngIf="body" class="uk-grid uk-child-width-1-1" uk-grid [formGroup]="inviteForm">
|
||||||
<div input [formInput]="inviteForm.get('name')" placeholder="From"></div>
|
<div input [formInput]="inviteForm.get('name')" placeholder="From"></div>
|
||||||
<div input [formInput]="inviteForm.get('recipients')" type="chips"
|
<div input [formInput]="inviteForm.get('recipients')" type="chips"
|
||||||
placeholder="Recipients" hint="Add a recipient"
|
placeholder="Recipients" hint="Add a recipient" [visibleChips]="3"
|
||||||
[addExtraChips]="true" [validators]="validators">
|
[addExtraChips]="true" [validators]="validators" [separators]="[',']">
|
||||||
|
<div note>Separate emails with commas</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="uk-text-meta">Message *</label>
|
<label class="uk-text-meta">Message *</label>
|
||||||
|
|
Loading…
Reference in New Issue