ngwr 0.1.0 → 0.1.1

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.
package/fesm2020/ngwr.mjs CHANGED
@@ -3,11 +3,11 @@ import * as i0 from '@angular/core';
3
3
  import { Directive, Component, ViewEncapsulation, ChangeDetectionStrategy, HostBinding, Injectable, Optional, Inject, Input, NgModule, EventEmitter, forwardRef, ViewChild, Output } from '@angular/core';
4
4
  import { Subject, fromEvent } from 'rxjs';
5
5
  import { takeUntil } from 'rxjs/operators';
6
- import { coerceBooleanProperty } from '@angular/cdk/coercion';
6
+ import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
7
7
  import * as i1 from '@angular/common';
8
8
  import { DOCUMENT, CommonModule } from '@angular/common';
9
9
  import * as i2 from '@angular/forms';
10
- import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
10
+ import { NG_VALUE_ACCESSOR, FormsModule, NG_VALIDATORS } from '@angular/forms';
11
11
  import * as i1$1 from '@angular/cdk/a11y';
12
12
  import { A11yModule } from '@angular/cdk/a11y';
13
13
 
@@ -1016,20 +1016,85 @@ class WrInputComponent extends BaseComponent {
1016
1016
  this.elRef = elRef;
1017
1017
  this.focusMonitor = focusMonitor;
1018
1018
  this.ngZone = ngZone;
1019
- this.value = null;
1020
- this.type = 'text';
1021
- this.autocomplete = 'on';
1022
- this.inputmode = 'text';
1023
- this.disabled = false;
1024
- this.readonly = false;
1025
- this.autofocus = false;
1026
- this.passwordIcons = false;
1027
- this.placeholder = undefined;
1019
+ this.placeholder = '';
1028
1020
  this.prefix = null;
1029
1021
  this.suffix = null;
1022
+ this.passwordIcons = false;
1030
1023
  this.eyeOn = true;
1031
- this.onChange = () => { };
1032
- this.onTouch = () => { };
1024
+ this._value = '';
1025
+ this._disabled = false;
1026
+ this._readonly = false;
1027
+ this._required = false;
1028
+ this._autofocus = false;
1029
+ this._focused = false;
1030
+ this._autocomplete = 'off';
1031
+ this._type = 'text';
1032
+ this._mode = 'text';
1033
+ this.onChangeCallback = () => { };
1034
+ this.onTouchedCallback = () => { };
1035
+ }
1036
+ get type() {
1037
+ return this._type;
1038
+ }
1039
+ set type(type) {
1040
+ this._type = type;
1041
+ }
1042
+ get inputmode() {
1043
+ return this._mode;
1044
+ }
1045
+ set inputmode(mode) {
1046
+ this._mode = mode;
1047
+ }
1048
+ get disabled() {
1049
+ return this._disabled;
1050
+ }
1051
+ set disabled(disabled) {
1052
+ this._disabled = coerceBooleanProperty(disabled);
1053
+ }
1054
+ get readonly() {
1055
+ return this._readonly;
1056
+ }
1057
+ set readonly(readonly) {
1058
+ this._readonly = coerceBooleanProperty(readonly);
1059
+ }
1060
+ get required() {
1061
+ return this._required;
1062
+ }
1063
+ set required(required) {
1064
+ this._required = coerceBooleanProperty(required);
1065
+ }
1066
+ get autofocus() {
1067
+ return this._autofocus;
1068
+ }
1069
+ set autofocus(autofocus) {
1070
+ this._autofocus = coerceBooleanProperty(autofocus);
1071
+ }
1072
+ get autocomplete() {
1073
+ return this._autocomplete;
1074
+ }
1075
+ set autocomplete(autofocus) {
1076
+ this._autocomplete = autofocus;
1077
+ }
1078
+ get value() {
1079
+ return this.type === 'number' ? this.valueAsNumber : this._value;
1080
+ }
1081
+ set value(val) {
1082
+ if (val !== this._value) {
1083
+ this._value = val;
1084
+ this.onChangeCallback(this.value);
1085
+ }
1086
+ }
1087
+ get valueAsString() {
1088
+ if (this._value == null || typeof this._value === 'undefined')
1089
+ return '';
1090
+ return String(this._value);
1091
+ }
1092
+ get valueAsNumber() {
1093
+ return coerceNumberProperty(this._value);
1094
+ }
1095
+ get isBadInput() {
1096
+ const validity = this.inputElement?.nativeElement?.validity;
1097
+ return validity && validity.badInput;
1033
1098
  }
1034
1099
  get elClasses() {
1035
1100
  return {
@@ -1046,7 +1111,7 @@ class WrInputComponent extends BaseComponent {
1046
1111
  .pipe(takeUntil(this.ngUnsubscribe))
1047
1112
  .subscribe(event => {
1048
1113
  event.preventDefault();
1049
- this.focus();
1114
+ this.onFocus();
1050
1115
  if (this.disabled) {
1051
1116
  event.stopImmediatePropagation();
1052
1117
  return;
@@ -1059,62 +1124,68 @@ class WrInputComponent extends BaseComponent {
1059
1124
  }
1060
1125
  ngAfterViewInit() {
1061
1126
  if (this.autofocus) {
1062
- this.focus();
1127
+ this.onFocus();
1128
+ this.cdr.markForCheck();
1063
1129
  }
1064
1130
  }
1065
1131
  ngOnDestroy() {
1066
1132
  super.ngOnDestroy();
1067
1133
  this.focusMonitor.stopMonitoring(this.elRef);
1068
1134
  }
1069
- writeValue(value) {
1070
- this.value = value;
1071
- this.cdr.markForCheck();
1135
+ onFocus(event) {
1136
+ if (event) {
1137
+ event.stopPropagation();
1138
+ }
1139
+ this._focused = true;
1140
+ this.focusMonitor.focusVia(this.inputElement, 'keyboard');
1072
1141
  }
1073
- registerOnChange(fn) {
1074
- this.onChange = fn;
1142
+ onBlur(event) {
1143
+ if (event) {
1144
+ event.stopPropagation();
1145
+ }
1146
+ this._focused = false;
1147
+ // this.inputElement.nativeElement.blur();
1148
+ this.onTouchedCallback();
1075
1149
  }
1076
- registerOnTouched(fn) {
1077
- this.onTouch = fn;
1150
+ validate(control) {
1151
+ return {
1152
+ ...(this.isBadInput ? { badInput: true } : null)
1153
+ };
1078
1154
  }
1079
- setDisabledState(isDisabled) {
1080
- this.disabled = isDisabled;
1155
+ writeValue(value) {
1156
+ if (value !== this._value) {
1157
+ this._value = value;
1158
+ }
1081
1159
  this.cdr.markForCheck();
1082
1160
  }
1083
- focus() {
1084
- this.focusMonitor.focusVia(this.inputElement, 'keyboard');
1161
+ registerOnChange(fn) {
1162
+ this.onChangeCallback = fn;
1085
1163
  }
1086
- blur() {
1087
- this.inputElement.nativeElement.blur();
1164
+ registerOnTouched(fn) {
1165
+ this.onTouchedCallback = fn;
1088
1166
  }
1089
- onPasswordVisibilityChange(event) {
1090
- event.stopPropagation();
1167
+ onPasswordVisibilityChange() {
1091
1168
  this.type === 'password' ? (this.type = 'text') : (this.type = 'password');
1092
1169
  this.eyeOn = !this.eyeOn;
1170
+ this.onFocus();
1093
1171
  }
1094
- onModelChange(value) {
1095
- if (!this.disabled) {
1096
- this.value = value;
1097
- this.onChange(this.value);
1098
- }
1172
+ setDisabledState(isDisabled) {
1173
+ this.disabled = coerceBooleanProperty(isDisabled);
1099
1174
  }
1100
1175
  }
1101
1176
  WrInputComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: WrInputComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1$1.FocusMonitor }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
1102
- WrInputComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.8", type: WrInputComponent, selector: "wr-input", inputs: { value: "value", type: "type", autocomplete: "autocomplete", inputmode: "inputmode", disabled: "disabled", readonly: "readonly", autofocus: "autofocus", passwordIcons: "passwordIcons", placeholder: "placeholder", prefix: "prefix", suffix: "suffix" }, host: { properties: { "class": "this.elClasses" } }, providers: [
1177
+ WrInputComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.8", type: WrInputComponent, selector: "wr-input", inputs: { placeholder: "placeholder", prefix: "prefix", suffix: "suffix", passwordIcons: "passwordIcons", type: "type", inputmode: "inputmode", disabled: "disabled", readonly: "readonly", required: "required", autofocus: "autofocus", autocomplete: "autocomplete", value: "value" }, host: { properties: { "class": "this.elClasses" } }, providers: [
1103
1178
  {
1104
1179
  provide: NG_VALUE_ACCESSOR,
1105
1180
  useExisting: forwardRef(() => WrInputComponent),
1106
1181
  multi: true
1182
+ },
1183
+ {
1184
+ provide: NG_VALIDATORS,
1185
+ useExisting: forwardRef(() => WrInputComponent),
1186
+ multi: true
1107
1187
  }
1108
- ], viewQueries: [{ propertyName: "inputElement", first: true, predicate: ["inputElement"], descendants: true, static: true }], exportAs: ["wrInput"], usesInheritance: true, ngImport: i0, template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div\n *ngIf=\"passwordIcons\"\n class=\"wr-input-el-icon\"\n (click)=\"onPasswordVisibilityChange($event)\"\n >\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [type]=\"type\"\n [value]=\"value\"\n [placeholder]=\"placeholder ? placeholder : ''\"\n [attr.readonly]=\"readonly ? 'readonly' : null\"\n [attr.autofocus]=\"autofocus ? 'autofocus' : null\"\n [attr.disabled]=\"disabled ? 'disabled' : null\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange(value)\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: WrIconComponent, selector: "wr-icon[name]", inputs: ["name"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1109
- __decorate([
1110
- InputBoolean()
1111
- ], WrInputComponent.prototype, "disabled", void 0);
1112
- __decorate([
1113
- InputBoolean()
1114
- ], WrInputComponent.prototype, "readonly", void 0);
1115
- __decorate([
1116
- InputBoolean()
1117
- ], WrInputComponent.prototype, "autofocus", void 0);
1188
+ ], viewQueries: [{ propertyName: "inputElement", first: true, predicate: ["inputElement"], descendants: true, static: true }], exportAs: ["wrInput"], usesInheritance: true, ngImport: i0, template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div *ngIf=\"passwordIcons\" class=\"wr-input-el-icon\" (click)=\"onPasswordVisibilityChange()\">\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [ngModel]=\"valueAsString\"\n [placeholder]=\"placeholder\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly\"\n [type]=\"type\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n (focus)=\"onFocus($event)\"\n (blur)=\"onBlur($event)\"\n (ngModelChange)=\"value = $event\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: WrIconComponent, selector: "wr-icon[name]", inputs: ["name"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1118
1189
  __decorate([
1119
1190
  InputBoolean()
1120
1191
  ], WrInputComponent.prototype, "passwordIcons", void 0);
@@ -1125,13 +1196,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
1125
1196
  provide: NG_VALUE_ACCESSOR,
1126
1197
  useExisting: forwardRef(() => WrInputComponent),
1127
1198
  multi: true
1199
+ },
1200
+ {
1201
+ provide: NG_VALIDATORS,
1202
+ useExisting: forwardRef(() => WrInputComponent),
1203
+ multi: true
1128
1204
  }
1129
- ], template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div\n *ngIf=\"passwordIcons\"\n class=\"wr-input-el-icon\"\n (click)=\"onPasswordVisibilityChange($event)\"\n >\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [type]=\"type\"\n [value]=\"value\"\n [placeholder]=\"placeholder ? placeholder : ''\"\n [attr.readonly]=\"readonly ? 'readonly' : null\"\n [attr.autofocus]=\"autofocus ? 'autofocus' : null\"\n [attr.disabled]=\"disabled ? 'disabled' : null\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange(value)\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n" }]
1130
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1$1.FocusMonitor }, { type: i0.NgZone }]; }, propDecorators: { value: [{
1205
+ ], template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div *ngIf=\"passwordIcons\" class=\"wr-input-el-icon\" (click)=\"onPasswordVisibilityChange()\">\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [ngModel]=\"valueAsString\"\n [placeholder]=\"placeholder\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly\"\n [type]=\"type\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n (focus)=\"onFocus($event)\"\n (blur)=\"onBlur($event)\"\n (ngModelChange)=\"value = $event\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n" }]
1206
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1$1.FocusMonitor }, { type: i0.NgZone }]; }, propDecorators: { placeholder: [{
1131
1207
  type: Input
1132
- }], type: [{
1208
+ }], prefix: [{
1133
1209
  type: Input
1134
- }], autocomplete: [{
1210
+ }], suffix: [{
1211
+ type: Input
1212
+ }], passwordIcons: [{
1213
+ type: Input
1214
+ }], type: [{
1135
1215
  type: Input
1136
1216
  }], inputmode: [{
1137
1217
  type: Input
@@ -1139,15 +1219,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
1139
1219
  type: Input
1140
1220
  }], readonly: [{
1141
1221
  type: Input
1142
- }], autofocus: [{
1143
- type: Input
1144
- }], passwordIcons: [{
1222
+ }], required: [{
1145
1223
  type: Input
1146
- }], placeholder: [{
1224
+ }], autofocus: [{
1147
1225
  type: Input
1148
- }], prefix: [{
1226
+ }], autocomplete: [{
1149
1227
  type: Input
1150
- }], suffix: [{
1228
+ }], value: [{
1151
1229
  type: Input
1152
1230
  }], inputElement: [{
1153
1231
  type: ViewChild,