Fix disabled color for labels
This commit is contained in:
parent
715069eabc
commit
aabd28d1f1
|
@ -23,15 +23,15 @@ import {properties} from "../../../../environments/environment";
|
||||||
import {ClickEvent} from "../../utils/click/click-outside-or-esc.directive";
|
import {ClickEvent} from "../../utils/click/click-outside-or-esc.directive";
|
||||||
|
|
||||||
export type InputType =
|
export type InputType =
|
||||||
'text'
|
'text'
|
||||||
| 'URL'
|
| 'URL'
|
||||||
| 'logoURL'
|
| 'logoURL'
|
||||||
| 'autocomplete'
|
| 'autocomplete'
|
||||||
| 'autocomplete_soft'
|
| 'autocomplete_soft'
|
||||||
| 'textarea'
|
| 'textarea'
|
||||||
| 'select'
|
| 'select'
|
||||||
| 'chips'
|
| 'chips'
|
||||||
| 'year-range';
|
| 'year-range';
|
||||||
|
|
||||||
export interface Option {
|
export interface Option {
|
||||||
icon?: string,
|
icon?: string,
|
||||||
|
@ -70,144 +70,144 @@ declare var UIkit;
|
||||||
@Component({
|
@Component({
|
||||||
selector: '[dashboard-input], [input]',
|
selector: '[dashboard-input], [input]',
|
||||||
template: `
|
template: `
|
||||||
<div *ngIf="formControl" [id]="id">
|
<div *ngIf="formControl" [id]="id">
|
||||||
<div class="input-wrapper" [class.disabled]="formControl.disabled" [class.opened]="opened"
|
<div class="input-wrapper" [class.disabled]="formControl.disabled" [class.opened]="opened"
|
||||||
[class.focused]="focused" [ngClass]="inputClass" [class.hint]="hint"
|
[class.focused]="focused" [ngClass]="inputClass" [class.hint]="hint"
|
||||||
[class.active]="!focused && (formAsControl?.value || selectable || formAsArray?.length > 0 || getLabel(formAsControl?.value) || yearRangeActive)"
|
[class.active]="!focused && (formAsControl?.value || selectable || formAsArray?.length > 0 || getLabel(formAsControl?.value) || yearRangeActive)"
|
||||||
[class.danger]="(formControl.invalid && (formControl.touched || !!searchControl?.touched)) || (!!searchControl?.invalid && !!searchControl?.touched)">
|
[class.danger]="(formControl.invalid && (formControl.touched || !!searchControl?.touched)) || (!!searchControl?.invalid && !!searchControl?.touched)">
|
||||||
<div #inputBox class="input-box" [class.select]="selectable" click-outside-or-esc
|
<div #inputBox class="input-box" [class.select]="selectable" click-outside-or-esc
|
||||||
[class.static]="placeholderInfo?.static" (clickOutside)="click($event)">
|
[class.static]="placeholderInfo?.static" (clickOutside)="click($event)">
|
||||||
<div *ngIf="!placeholderInfo?.static && placeholderInfo?.label" class="placeholder">
|
<div *ngIf="!placeholderInfo?.static && placeholderInfo?.label" class="placeholder">
|
||||||
<label>{{placeholderInfo.label}} <sup *ngIf="required">*</sup></label>
|
<label>{{placeholderInfo.label}} <sup *ngIf="required">*</sup></label>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-flex" [class.uk-flex-middle]="type !== 'textarea'"
|
<div class="uk-flex" [class.uk-flex-middle]="type !== 'textarea'"
|
||||||
[attr.uk-tooltip]="(tooltip && !focused && type !== 'chips' && type !== 'textarea' && (formControl.value || hint || placeholderInfo?.label))?('title: ' + (formControl.value ?getTooltip(formControl.value):(hint?hint:placeholderInfo?.label)) + '; delay: 500; pos: bottom-left'):null">
|
[attr.uk-tooltip]="(tooltip && !focused && type !== 'chips' && type !== 'textarea' && (formControl.value || hint || placeholderInfo?.label))?('title: ' + (formControl.value ?getTooltip(formControl.value):(hint?hint:placeholderInfo?.label)) + '; delay: 500; pos: bottom-left'):null">
|
||||||
<ng-template [ngIf]="type === 'text' || type === 'URL' || type === 'logoURL'">
|
<ng-template [ngIf]="type === 'text' || type === 'URL' || type === 'logoURL'">
|
||||||
<input #input class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
<input #input class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||||
[type]="password?'password':'text'" [formControl]="formAsControl"
|
[type]="password?'password':'text'" [formControl]="formAsControl"
|
||||||
[class.uk-text-truncate]="!focused">
|
[class.uk-text-truncate]="!focused">
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template [ngIf]="type === 'textarea'">
|
<ng-template [ngIf]="type === 'textarea'">
|
||||||
<textarea #textArea class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
<textarea #textArea class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||||
[rows]="rows" [formControl]="formAsControl"></textarea>
|
[rows]="rows" [formControl]="formAsControl"></textarea>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template [ngIf]="type === 'select'">
|
<ng-template [ngIf]="type === 'select'">
|
||||||
<ng-container *ngIf="placeholderInfo?.static">
|
<ng-container *ngIf="placeholderInfo?.static">
|
||||||
<div *ngIf="!getLabel(formControl.value)"
|
<div *ngIf="!getLabel(formControl.value)"
|
||||||
class="input placeholder uk-width-expand uk-text-truncate">{{placeholderInfo.label}}</div>
|
class="input placeholder uk-width-expand uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{placeholderInfo.label}}</div>
|
||||||
<div *ngIf="getLabel(formControl.value)"
|
<div *ngIf="getLabel(formControl.value)"
|
||||||
class="input uk-width-expand uk-text-truncate">{{getLabel(formControl.value)}}</div>
|
class="input uk-width-expand uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{getLabel(formControl.value)}}</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngIf="!placeholderInfo?.static">
|
<ng-container *ngIf="!placeholderInfo?.static">
|
||||||
<div *ngIf="!getLabel(formControl.value)"
|
<div *ngIf="!getLabel(formControl.value)"
|
||||||
class="input uk-width-expand uk-text-truncate">{{noValueSelected}}</div>
|
class="input uk-width-expand uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{noValueSelected}}</div>
|
||||||
<div *ngIf="getLabel(formControl.value)"
|
<div *ngIf="getLabel(formControl.value)"
|
||||||
class="input uk-width-expand uk-text-truncate">{{getLabel(formControl.value)}}</div>
|
class="input uk-width-expand uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{getLabel(formControl.value)}}</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template [ngIf]="type === 'autocomplete'">
|
<ng-template [ngIf]="type === 'autocomplete'">
|
||||||
<input *ngIf="focused" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
<input *ngIf="focused" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||||
#searchInput class="input" [formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
#searchInput class="input" [formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
||||||
<ng-container *ngIf="!focused && !selectable">
|
<ng-container *ngIf="!focused && !selectable">
|
||||||
<div *ngIf="!getLabel(formControl.value)"
|
<div *ngIf="!getLabel(formControl.value)"
|
||||||
class="input placeholder uk-text-truncate">{{placeholderInfo?.static ? placeholderInfo.label : getLabel(formAsControl.value)}}</div>
|
class="input placeholder uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{placeholderInfo?.static ? placeholderInfo.label : getLabel(formAsControl.value)}}</div>
|
||||||
<div *ngIf="getLabel(formControl.value)"
|
<div *ngIf="getLabel(formControl.value)"
|
||||||
class="input uk-text-truncate">{{getLabel(formAsControl.value)}}</div>
|
class="input uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{getLabel(formAsControl.value)}}</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngIf="!focused && selectable">
|
<ng-container *ngIf="!focused && selectable">
|
||||||
<div *ngIf="!getLabel(formControl.value)" class="input uk-text-truncate">{{noValueSelected}}</div>
|
<div *ngIf="!getLabel(formControl.value)" class="input uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{noValueSelected}}</div>
|
||||||
<div *ngIf="getLabel(formControl.value)"
|
<div *ngIf="getLabel(formControl.value)"
|
||||||
class="input uk-text-truncate">{{getLabel(formControl.value)}}</div>
|
class="input uk-text-truncate" [class.uk-disabled]="formControl.disabled">{{getLabel(formControl.value)}}</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template [ngIf]="type === 'autocomplete_soft'">
|
<ng-template [ngIf]="type === 'autocomplete_soft'">
|
||||||
<input #input class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
<input #input class="input" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||||
[formControl]="formAsControl" [class.uk-text-truncate]="!focused">
|
[formControl]="formAsControl" [class.uk-text-truncate]="!focused">
|
||||||
</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-overflow-auto uk-width-expand"
|
<div class="uk-grid uk-grid-small uk-grid-row-collapse uk-overflow-auto uk-width-expand"
|
||||||
[class.uk-flex-nowrap]="noWrap" [class.uk-overflow-auto]="noWrap" uk-grid>
|
[class.uk-flex-nowrap]="noWrap" [class.uk-overflow-auto]="noWrap" uk-grid>
|
||||||
<div *ngFor="let chip of formAsArray.controls; let i=index" #chip
|
<div *ngFor="let chip of formAsArray.controls; let i=index" #chip
|
||||||
[class.uk-hidden]="!focused && i > visibleChips - 1"
|
[class.uk-hidden]="!focused && i > visibleChips - 1"
|
||||||
class="chip">
|
class="chip">
|
||||||
<div class="uk-label uk-label-small uk-text-transform-none uk-flex uk-flex-middle"
|
<div class="uk-label uk-label-small uk-text-transform-none 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">
|
||||||
<span class="uk-text-truncate uk-width-expand">{{getLabel(chip.value)}}</span>
|
<span class="uk-text-truncate uk-width-expand">{{getLabel(chip.value)}}</span>
|
||||||
<icon *ngIf="focused" (click)="remove(i, $event)"
|
<icon *ngIf="focused" (click)="remove(i, $event)"
|
||||||
class="uk-link-text uk-margin-small-left clickable" [flex]="true"
|
class="uk-link-text uk-margin-small-left clickable" [flex]="true"
|
||||||
name="close" ratio="0.7"></icon>
|
name="close" ratio="0.7"></icon>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div *ngIf="searchControl && (focused || formAsArray.length === 0)" #chip
|
||||||
|
class="uk-width-expand search-input uk-flex uk-flex-column uk-flex-center">
|
||||||
|
<input #searchInput class="input" [class.search]="searchControl.value"
|
||||||
|
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||||
|
[formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
||||||
|
</div>
|
||||||
|
<div *ngIf="!focused && formAsArray.length > visibleChips"
|
||||||
|
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
||||||
|
+ {{(formAsArray.length - visibleChips)}} more
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template [ngIf]="type === 'year-range' && yearRange && formAsGroup">
|
||||||
|
<div class="uk-width-2-5">
|
||||||
|
<input #input class="input uk-text-center uk-text-truncate" [attr.placeholder]="yearRange.from.placeholder"
|
||||||
|
maxlength="4" (click)="activeIndex = 0;$event.preventDefault()" [formControl]="getFormByName(yearRange.from.control)">
|
||||||
|
</div>
|
||||||
|
<div class="uk-width-1-5 uk-text-center">-</div>
|
||||||
|
<div class="uk-width-2-5">
|
||||||
|
<input #input class="input uk-text-center uk-text-truncate" [attr.placeholder]="yearRange.to.placeholder"
|
||||||
|
maxlength="4" (click)="activeIndex = 1;$event.preventDefault()" [formControl]="getFormByName(yearRange.to.control)">
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
<div
|
||||||
|
*ngIf="(formControl.disabled && disabledIcon) || icon || (selectable && selectArrow) || type === 'autocomplete' || searchable"
|
||||||
|
class="uk-margin-small-left icon">
|
||||||
|
<icon *ngIf="formControl.disabled && disabledIcon" [name]="disabledIcon" [flex]="true"></icon>
|
||||||
|
<ng-template [ngIf]="formControl.enabled">
|
||||||
|
<icon *ngIf="!searchControl?.value && icon" [name]="icon" [flex]="true"></icon>
|
||||||
|
<icon *ngIf="!icon && selectable && selectArrow" [name]="selectArrow" [flex]="true"></icon>
|
||||||
|
<button *ngIf="focused && type === 'autocomplete'" class="uk-close uk-icon"
|
||||||
|
(click)="resetSearch($event)">
|
||||||
|
<icon [flex]="true" name="close"></icon>
|
||||||
|
</button>
|
||||||
|
<button *ngIf="(!focused && type === 'autocomplete') || (type !== 'autocomplete' && !searchControl?.value && !!formControl?.value && (searchable || !selectable))"
|
||||||
|
class="uk-close uk-icon" (click)="resetValue($event)">
|
||||||
|
<icon [flex]="true" name="close"></icon>
|
||||||
|
</button>
|
||||||
|
</ng-template>
|
||||||
|
</div>
|
||||||
|
<!-- use action-icon class in order to apply css in your icon button-->
|
||||||
|
<ng-content select="[action]"></ng-content>
|
||||||
|
</div>
|
||||||
|
<div class="tools">
|
||||||
|
<ng-content select="[tools]"></ng-content>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div *ngIf="searchControl && (focused || formAsArray.length === 0)" #chip
|
|
||||||
class="uk-width-expand search-input uk-flex uk-flex-column uk-flex-center">
|
|
||||||
<input #searchInput class="input" [class.search]="searchControl.value"
|
|
||||||
[attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
|
||||||
[formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
|
||||||
</div>
|
|
||||||
<div *ngIf="!focused && formAsArray.length > visibleChips"
|
|
||||||
class="uk-width-expand uk-flex uk-flex-column uk-flex-center more">
|
|
||||||
+ {{(formAsArray.length - visibleChips)}} more
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
|
||||||
<ng-template [ngIf]="type === 'year-range' && yearRange && formAsGroup">
|
|
||||||
<div class="uk-width-2-5">
|
|
||||||
<input #input class="input uk-text-center uk-text-truncate" [attr.placeholder]="yearRange.from.placeholder"
|
|
||||||
maxlength="4" (click)="activeIndex = 0;$event.preventDefault()" [formControl]="getFormByName(yearRange.from.control)">
|
|
||||||
</div>
|
|
||||||
<div class="uk-width-1-5 uk-text-center">-</div>
|
|
||||||
<div class="uk-width-2-5">
|
|
||||||
<input #input class="input uk-text-center uk-text-truncate" [attr.placeholder]="yearRange.to.placeholder"
|
|
||||||
maxlength="4" (click)="activeIndex = 1;$event.preventDefault()" [formControl]="getFormByName(yearRange.to.control)">
|
|
||||||
</div>
|
|
||||||
</ng-template>
|
|
||||||
<div
|
|
||||||
*ngIf="(formControl.disabled && disabledIcon) || icon || (selectable && selectArrow) || type === 'autocomplete' || searchable"
|
|
||||||
class="uk-margin-small-left icon">
|
|
||||||
<icon *ngIf="formControl.disabled && disabledIcon" [name]="disabledIcon" [flex]="true"></icon>
|
|
||||||
<ng-template [ngIf]="formControl.enabled">
|
|
||||||
<icon *ngIf="!searchControl?.value && icon" [name]="icon" [flex]="true"></icon>
|
|
||||||
<icon *ngIf="!icon && selectable && selectArrow" [name]="selectArrow" [flex]="true"></icon>
|
|
||||||
<button *ngIf="!!searchControl?.value && type === 'autocomplete'" class="uk-close uk-icon"
|
|
||||||
(click)="resetSearch($event)">
|
|
||||||
<icon [flex]="true" name="close"></icon>
|
|
||||||
</button>
|
|
||||||
<button *ngIf="!searchControl?.value && !!formControl?.value && (searchable || !selectable)"
|
|
||||||
class="uk-close uk-icon" (click)="resetValue($event)">
|
|
||||||
<icon [flex]="true" name="close"></icon>
|
|
||||||
</button>
|
|
||||||
</ng-template>
|
|
||||||
</div>
|
|
||||||
<!-- use action-icon class in order to apply css in your icon button-->
|
|
||||||
<ng-content select="[action]"></ng-content>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="tools">
|
<div class="options uk-dropdown" *ngIf="filteredOptions && filteredOptions.length > 0 && opened" #optionBox
|
||||||
<ng-content select="[tools]"></ng-content>
|
uk-dropdown="pos: bottom-justify; mode: none; offset: 15; boundary-align: true;" [attr.boundary]="'#' + id">
|
||||||
</div>
|
<ul class="uk-nav uk-dropdown-nav">
|
||||||
</div>
|
<li *ngFor="let option of filteredOptions; let i=index" [class.uk-hidden]="option.hidden"
|
||||||
</div>
|
[class.uk-active]="(formControl.value === option.value) || selectedIndex === i">
|
||||||
<div class="options uk-dropdown" *ngIf="filteredOptions && filteredOptions.length > 0 && opened" #optionBox
|
<a (click)="selectOption(option, $event)"
|
||||||
uk-dropdown="pos: bottom-justify; mode: none; offset: 15; boundary-align: true;" [attr.boundary]="'#' + id">
|
[class]="option.disabled ? 'uk-disabled uk-text-muted' : ''">
|
||||||
<ul class="uk-nav uk-dropdown-nav">
|
|
||||||
<li *ngFor="let option of filteredOptions; let i=index" [class.uk-hidden]="option.hidden"
|
|
||||||
[class.uk-active]="(formControl.value === option.value) || selectedIndex === i">
|
|
||||||
<a (click)="selectOption(option, $event)"
|
|
||||||
[class]="option.disabled ? 'uk-disabled uk-text-muted' : ''">
|
|
||||||
<span
|
<span
|
||||||
[attr.uk-tooltip]="(tooltip)?('title: ' + (option.tooltip ? option.tooltip : option.label) + '; delay: 500; pos:bottom-left'):null">{{option.label}}</span>
|
[attr.uk-tooltip]="(tooltip)?('title: ' + (option.tooltip ? option.tooltip : option.label) + '; delay: 500; pos:bottom-left'):null">{{option.label}}</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<span *ngIf="formControl?.invalid && formControl?.touched" class="uk-text-danger">
|
||||||
<span *ngIf="formControl?.invalid && formControl?.touched" class="uk-text-danger">
|
|
||||||
<span *ngIf="errors?.error">{{errors?.error}}</span>
|
<span *ngIf="errors?.error">{{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-small uk-text-danger">
|
<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-small uk-text-warning uk-margin-xsmall-top">
|
<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"
|
||||||
|
@ -215,9 +215,9 @@ 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>
|
||||||
<i class="uk-text-small uk-text-meta uk-margin-xsmall-top">
|
<i class="uk-text-small uk-text-meta uk-margin-xsmall-top">
|
||||||
<ng-content select="[note]"></ng-content>
|
<ng-content select="[note]"></ng-content>
|
||||||
</i>
|
</i>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
||||||
|
@ -261,7 +261,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
/** Year Range Configuration */
|
/** Year Range Configuration */
|
||||||
@Input() yearRange: YearRange;
|
@Input() yearRange: YearRange;
|
||||||
public activeIndex: 0 | 1 | null = null;
|
public activeIndex: 0 | 1 | null = null;
|
||||||
|
|
||||||
@Input() visibleRows: number = -1;
|
@Input() visibleRows: number = -1;
|
||||||
@Input() extendEnter: () => void = null;
|
@Input() extendEnter: () => void = null;
|
||||||
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
||||||
|
@ -282,7 +282,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
@ViewChild('optionBox') optionBox: ElementRef;
|
@ViewChild('optionBox') optionBox: ElementRef;
|
||||||
@ViewChild('searchInput') searchInput: ElementRef;
|
@ViewChild('searchInput') searchInput: ElementRef;
|
||||||
@ViewChildren('chip') chips: QueryList<ElementRef>;
|
@ViewChildren('chip') chips: QueryList<ElementRef>;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set placeholder(placeholder: string | Placeholder) {
|
set placeholder(placeholder: string | Placeholder) {
|
||||||
if(this.type === 'year-range') {
|
if(this.type === 'year-range') {
|
||||||
|
@ -297,7 +297,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.placeholderInfo = placeholder;
|
this.placeholderInfo = placeholder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set options(options: (Option | string | number) []) {
|
set options(options: (Option | string | number) []) {
|
||||||
this.optionsArray = options.map(option => {
|
this.optionsArray = options.map(option => {
|
||||||
|
@ -322,13 +322,13 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.selectable = true;
|
this.selectable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(private elementRef: ElementRef, private cdr: ChangeDetectorRef) {
|
constructor(private elementRef: ElementRef, private cdr: ChangeDetectorRef) {
|
||||||
if (elementRef.nativeElement.hasAttribute('dashboard-input') && this.properties.environment === "development") {
|
if (elementRef.nativeElement.hasAttribute('dashboard-input') && this.properties.environment === "development") {
|
||||||
console.warn("'dashboard-input' selector is deprecated; use 'input' instead.");
|
console.warn("'dashboard-input' selector is deprecated; use 'input' instead.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:keydown.arrowUp', ['$event'])
|
@HostListener('window:keydown.arrowUp', ['$event'])
|
||||||
arrowUp(event: KeyboardEvent) {
|
arrowUp(event: KeyboardEvent) {
|
||||||
if (this.opened) {
|
if (this.opened) {
|
||||||
|
@ -339,7 +339,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:keydown.arrowDown', ['$event'])
|
@HostListener('window:keydown.arrowDown', ['$event'])
|
||||||
arrowDown(event: KeyboardEvent) {
|
arrowDown(event: KeyboardEvent) {
|
||||||
if (this.opened) {
|
if (this.opened) {
|
||||||
|
@ -350,7 +350,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:keydown.arrowLeft', ['$event'])
|
@HostListener('window:keydown.arrowLeft', ['$event'])
|
||||||
arrowLeft(event: KeyboardEvent) {
|
arrowLeft(event: KeyboardEvent) {
|
||||||
if (this.type === 'chips' && this.focused) {
|
if (this.type === 'chips' && this.focused) {
|
||||||
|
@ -364,7 +364,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:keydown.arrowRight', ['$event'])
|
@HostListener('window:keydown.arrowRight', ['$event'])
|
||||||
arrowRight(event: KeyboardEvent) {
|
arrowRight(event: KeyboardEvent) {
|
||||||
if (this.type === 'chips' && this.focused) {
|
if (this.type === 'chips' && this.focused) {
|
||||||
|
@ -378,7 +378,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:keydown.enter', ['$event'])
|
@HostListener('window:keydown.enter', ['$event'])
|
||||||
enter(event: KeyboardEvent) {
|
enter(event: KeyboardEvent) {
|
||||||
if (this.opened && this.optionBox) {
|
if (this.opened && this.optionBox) {
|
||||||
|
@ -395,7 +395,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.extendEnter();
|
this.extendEnter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('keydown', ['$event'])
|
@HostListener('keydown', ['$event'])
|
||||||
onKeyDown(event: KeyboardEvent) {
|
onKeyDown(event: KeyboardEvent) {
|
||||||
if (this.separators.includes(event.key) || this.separators.includes(event.key.toLowerCase())) {
|
if (this.separators.includes(event.key) || this.separators.includes(event.key.toLowerCase())) {
|
||||||
|
@ -403,11 +403,11 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.add(event, true);
|
this.add(event, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
click(event: ClickEvent) {
|
click(event: ClickEvent) {
|
||||||
this.focus(!event.clicked);
|
this.focus(!event.clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
InputComponent.INPUT_COUNTER++;
|
InputComponent.INPUT_COUNTER++;
|
||||||
this.id = 'input-' + InputComponent.INPUT_COUNTER;
|
this.id = 'input-' + InputComponent.INPUT_COUNTER;
|
||||||
|
@ -430,11 +430,11 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
if (this.formControl) {
|
if (this.formControl) {
|
||||||
if (changes.value) {
|
if (changes.value) {
|
||||||
|
@ -455,11 +455,11 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormByName(name: string): UntypedFormControl {
|
getFormByName(name: string): UntypedFormControl {
|
||||||
if (this.formControl instanceof UntypedFormGroup) {
|
if (this.formControl instanceof UntypedFormGroup) {
|
||||||
return <UntypedFormControl>this.formControl.get(name);
|
return <UntypedFormControl>this.formControl.get(name);
|
||||||
|
@ -467,7 +467,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get formAsGroup(): UntypedFormGroup {
|
get formAsGroup(): UntypedFormGroup {
|
||||||
if (this.formControl instanceof UntypedFormGroup) {
|
if (this.formControl instanceof UntypedFormGroup) {
|
||||||
return this.formControl;
|
return this.formControl;
|
||||||
|
@ -475,7 +475,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get formAsControl(): UntypedFormControl {
|
get formAsControl(): UntypedFormControl {
|
||||||
if (this.formControl instanceof UntypedFormControl) {
|
if (this.formControl instanceof UntypedFormControl) {
|
||||||
return this.formControl;
|
return this.formControl;
|
||||||
|
@ -483,7 +483,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get formAsArray(): UntypedFormArray {
|
get formAsArray(): UntypedFormArray {
|
||||||
if (this.formControl instanceof UntypedFormArray) {
|
if (this.formControl instanceof UntypedFormArray) {
|
||||||
return this.formControl;
|
return this.formControl;
|
||||||
|
@ -491,26 +491,26 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get yearRangeActive(): boolean {
|
get yearRangeActive(): boolean {
|
||||||
if(this.yearRange) {
|
if(this.yearRange) {
|
||||||
return this.formAsGroup && (this.getFormByName(this.yearRange.from.control)?.value || this.getFormByName(this.yearRange.to.control)?.value);
|
return this.formAsGroup && (this.getFormByName(this.yearRange.from.control)?.value || this.getFormByName(this.yearRange.to.control)?.value);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get errors(): any {
|
get errors(): any {
|
||||||
if(this.formAsGroup) {
|
if(this.formAsGroup) {
|
||||||
return (this.formAsGroup.errors
|
return (this.formAsGroup.errors
|
||||||
?this.formAsGroup.errors:(this.getFormByName(this.yearRange.from.control).errors
|
?this.formAsGroup.errors:(this.getFormByName(this.yearRange.from.control).errors
|
||||||
?this.getFormByName(this.yearRange.from.control).errors:this.getFormByName(this.yearRange.to.control).errors));
|
?this.getFormByName(this.yearRange.from.control).errors:this.getFormByName(this.yearRange.to.control).errors));
|
||||||
} else if(this.formAsControl) {
|
} else if(this.formAsControl) {
|
||||||
return this.formAsControl.errors;
|
return this.formAsControl.errors;
|
||||||
} else {
|
} else {
|
||||||
return this.searchControl.errors;
|
return this.searchControl.errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.secure = true;
|
this.secure = true;
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
|
@ -601,7 +601,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsubscribe() {
|
unsubscribe() {
|
||||||
this.subscriptions.forEach(subscription => {
|
this.subscriptions.forEach(subscription => {
|
||||||
if (subscription instanceof Subscription) {
|
if (subscription instanceof Subscription) {
|
||||||
|
@ -609,7 +609,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateValidators() {
|
updateValidators() {
|
||||||
if (this.formAsArray) {
|
if (this.formAsArray) {
|
||||||
this.formAsArray.controls.forEach(control => {
|
this.formAsArray.controls.forEach(control => {
|
||||||
|
@ -621,7 +621,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.formControl.updateValueAndValidity();
|
this.formControl.updateValueAndValidity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(index: number, event) {
|
remove(index: number, event) {
|
||||||
if (this.focused) {
|
if (this.focused) {
|
||||||
this.formAsArray.removeAt(index);
|
this.formAsArray.removeAt(index);
|
||||||
|
@ -631,7 +631,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private filter(value: string): Option[] {
|
private filter(value: string): Option[] {
|
||||||
let options = this.optionsArray.filter(option => !option.hidden);
|
let options = this.optionsArray.filter(option => !option.hidden);
|
||||||
if (this.type === "chips") {
|
if (this.type === "chips") {
|
||||||
|
@ -649,7 +649,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
add(event, addChips = false) {
|
add(event, addChips = false) {
|
||||||
if (addChips && this.searchControl.value) {
|
if (addChips && this.searchControl.value) {
|
||||||
this.splitSearchControl();
|
this.splitSearchControl();
|
||||||
|
@ -657,7 +657,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.searchControl.setValue('');
|
this.searchControl.setValue('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
splitSearchControl() {
|
splitSearchControl() {
|
||||||
let values = [this.searchControl.value];
|
let values = [this.searchControl.value];
|
||||||
this.separators.forEach(separator => {
|
this.separators.forEach(separator => {
|
||||||
|
@ -681,17 +681,17 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
this.searchControl.setValue('');
|
this.searchControl.setValue('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLabel(value: any): string {
|
getLabel(value: any): string {
|
||||||
let option = this.optionsArray.find(option => HelperFunctions.equals(option.value, value));
|
let option = this.optionsArray.find(option => HelperFunctions.equals(option.value, value));
|
||||||
return (option) ? option.label : (value);
|
return (option) ? option.label : (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTooltip(value: any): string {
|
getTooltip(value: any): string {
|
||||||
let option = this.optionsArray.find(option => HelperFunctions.equals(option.value, value));
|
let option = this.optionsArray.find(option => HelperFunctions.equals(option.value, value));
|
||||||
return (option) ? (option.tooltip ? option.tooltip : option.label) : (value);
|
return (option) ? (option.tooltip ? option.tooltip : option.label) : (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
focus(value: boolean, event = null) {
|
focus(value: boolean, event = null) {
|
||||||
if(!this.activeIndex) {
|
if(!this.activeIndex) {
|
||||||
this.activeIndex = 0;
|
this.activeIndex = 0;
|
||||||
|
@ -699,41 +699,43 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
if (this.focused) {
|
if (this.focused) {
|
||||||
this.formControl.markAsTouched();
|
this.formControl.markAsTouched();
|
||||||
}
|
}
|
||||||
this.focused = value;
|
if(this.formControl.enabled) {
|
||||||
this.cdr.detectChanges();
|
this.focused = value;
|
||||||
if (this.focused) {
|
this.cdr.detectChanges();
|
||||||
if (this.input?.length > 0) {
|
if (this.focused) {
|
||||||
this.input.get(this.activeIndex).nativeElement.focus();
|
if (this.input?.length > 0) {
|
||||||
} else if (this.textArea) {
|
this.input.get(this.activeIndex).nativeElement.focus();
|
||||||
this.textArea.nativeElement.focus();
|
} else if (this.textArea) {
|
||||||
} else if (this.searchInput) {
|
this.textArea.nativeElement.focus();
|
||||||
this.searchInput.nativeElement.focus();
|
} else if (this.searchInput) {
|
||||||
this.activeElement.next(this.chips.last);
|
this.searchInput.nativeElement.focus();
|
||||||
}
|
this.activeElement.next(this.chips.last);
|
||||||
if (this.selectArrow) {
|
}
|
||||||
this.open(!this.opened);
|
if (this.selectArrow) {
|
||||||
} else if (this.type !== 'autocomplete' || this.showOptionsOnEmpty || !this.formControl.value) {
|
this.open(!this.opened);
|
||||||
this.open(true);
|
} else if (this.type !== 'autocomplete' || this.showOptionsOnEmpty || !this.formControl.value) {
|
||||||
}
|
this.open(true);
|
||||||
} else {
|
}
|
||||||
this.activeIndex = null;
|
} else {
|
||||||
this.open(false);
|
this.activeIndex = null;
|
||||||
if (this.input) {
|
this.open(false);
|
||||||
this.input.forEach(input => {
|
if (this.input) {
|
||||||
input.nativeElement.blur();
|
this.input.forEach(input => {
|
||||||
})
|
input.nativeElement.blur();
|
||||||
} else if (this.textArea) {
|
})
|
||||||
this.textArea.nativeElement.blur();
|
} else if (this.textArea) {
|
||||||
} else if (this.searchInput) {
|
this.textArea.nativeElement.blur();
|
||||||
this.searchInput.nativeElement.blur();
|
} else if (this.searchInput) {
|
||||||
}
|
this.searchInput.nativeElement.blur();
|
||||||
if (this.searchControl) {
|
}
|
||||||
this.add(event, this.addExtraChips);
|
if (this.searchControl) {
|
||||||
|
this.add(event, this.addExtraChips);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.focusEmitter.emit(this.focused);
|
||||||
}
|
}
|
||||||
this.focusEmitter.emit(this.focused);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open(value: boolean) {
|
open(value: boolean) {
|
||||||
this.opened = value && this.formControl.enabled;
|
this.opened = value && this.formControl.enabled;
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
|
@ -750,19 +752,19 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resetSearch(event: any) {
|
resetSearch(event: any) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
this.searchControl.setValue('');
|
this.searchControl.setValue('');
|
||||||
this.focus(true, event);
|
this.focus(true, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetValue(event: any) {
|
resetValue(event: any) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
this.formControl.setValue('');
|
this.formControl.setValue('');
|
||||||
this.focus(true, event);
|
this.focus(true, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectOption(option: Option, event) {
|
selectOption(option: Option, event) {
|
||||||
if (this.formControl.enabled) {
|
if (this.formControl.enabled) {
|
||||||
if (this.formAsControl) {
|
if (this.formAsControl) {
|
||||||
|
|
Loading…
Reference in New Issue