@klippa/ngx-enhancy-forms 1.0.0 → 2.1.0
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/README.md +179 -23
- package/bundles/klippa-ngx-enhancy-forms.umd.js +1206 -0
- package/bundles/klippa-ngx-enhancy-forms.umd.js.map +1 -0
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js +17 -0
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js.map +1 -0
- package/esm2015/klippa-ngx-enhancy-forms.js +6 -0
- package/esm2015/lib/elements/button/button.component.js +38 -0
- package/esm2015/lib/elements/checkbox/checkbox.component.js +18 -0
- package/esm2015/lib/elements/datepicker/datepicker.component.js +111 -0
- package/esm2015/lib/elements/email/email-input.component.js +21 -0
- package/esm2015/lib/elements/loading-indicator/loading-indicator.component.js +19 -0
- package/esm2015/lib/elements/number-input/number-input.component.js +17 -0
- package/esm2015/lib/elements/password-field/password-field.component.js +21 -0
- package/esm2015/lib/elements/select/select.component.js +35 -0
- package/esm2015/lib/elements/sortable-items/sortable-items.component.js +25 -0
- package/esm2015/lib/elements/text-input/text-input.component.js +22 -0
- package/esm2015/lib/elements/toggle/toggle.component.js +14 -0
- package/esm2015/lib/elements/value-accessor-base/value-accessor-base.component.js +88 -0
- package/esm2015/lib/form/form-caption/form-caption.component.js +35 -0
- package/esm2015/lib/form/form-element/form-element.component.js +100 -0
- package/esm2015/lib/form/form-error/form-error.component.js +37 -0
- package/esm2015/lib/form/form-submit-button/form-submit-button.component.js +53 -0
- package/esm2015/lib/form/form.component.js +72 -0
- package/esm2015/lib/material.module.js +17 -0
- package/esm2015/lib/ngx-enhancy-forms.module.js +75 -0
- package/esm2015/lib/types.js +2 -0
- package/esm2015/lib/util/values.js +38 -0
- package/esm2015/lib/validators/dateValidator.js +6 -0
- package/esm2015/public-api.js +24 -0
- package/fesm2015/klippa-ngx-enhancy-forms.js +804 -0
- package/fesm2015/klippa-ngx-enhancy-forms.js.map +1 -0
- package/klippa-ngx-enhancy-forms.d.ts +5 -0
- package/klippa-ngx-enhancy-forms.metadata.json +1 -0
- package/lib/elements/button/button.component.d.ts +11 -0
- package/lib/elements/checkbox/checkbox.component.d.ts +5 -0
- package/lib/elements/datepicker/datepicker.component.d.ts +26 -0
- package/lib/elements/email/email-input.component.d.ts +4 -0
- package/lib/elements/loading-indicator/loading-indicator.component.d.ts +4 -0
- package/lib/elements/number-input/number-input.component.d.ts +4 -0
- package/lib/elements/password-field/password-field.component.d.ts +4 -0
- package/lib/elements/select/select.component.d.ts +24 -0
- package/lib/elements/sortable-items/sortable-items.component.d.ts +6 -0
- package/lib/elements/text-input/text-input.component.d.ts +5 -0
- package/lib/elements/toggle/toggle.component.d.ts +3 -0
- package/lib/elements/value-accessor-base/value-accessor-base.component.d.ts +32 -0
- package/lib/form/form-caption/form-caption.component.d.ts +8 -0
- package/lib/form/form-element/form-element.component.d.ts +38 -0
- package/lib/form/form-error/form-error.component.d.ts +11 -0
- package/lib/form/form-submit-button/form-submit-button.component.d.ts +11 -0
- package/lib/form/form.component.d.ts +13 -0
- package/lib/material.module.d.ts +2 -0
- package/lib/ngx-enhancy-forms.module.d.ts +2 -0
- package/lib/types.d.ts +15 -0
- package/lib/util/values.d.ts +9 -0
- package/lib/validators/dateValidator.d.ts +3 -0
- package/package.json +16 -41
- package/public-api.d.ts +20 -0
- package/.editorconfig +0 -17
- package/.github/workflows/ci.yml +0 -18
- package/.github/workflows/release.yml +0 -22
- package/angular.json +0 -28
- package/ng-package.json +0 -7
- package/src/lib/elements/button/button.component.html +0 -18
- package/src/lib/elements/button/button.component.scss +0 -203
- package/src/lib/elements/button/button.component.ts +0 -34
- package/src/lib/elements/checkbox/checkbox.component.html +0 -15
- package/src/lib/elements/checkbox/checkbox.component.scss +0 -55
- package/src/lib/elements/checkbox/checkbox.component.ts +0 -14
- package/src/lib/elements/datepicker/datepicker.component.html +0 -20
- package/src/lib/elements/datepicker/datepicker.component.scss +0 -47
- package/src/lib/elements/datepicker/datepicker.component.ts +0 -142
- package/src/lib/elements/email/email-input.component.html +0 -8
- package/src/lib/elements/email/email-input.component.scss +0 -15
- package/src/lib/elements/email/email-input.component.ts +0 -13
- package/src/lib/elements/loading-indicator/loading-indicator.component.html +0 -40
- package/src/lib/elements/loading-indicator/loading-indicator.component.scss +0 -179
- package/src/lib/elements/loading-indicator/loading-indicator.component.ts +0 -11
- package/src/lib/elements/number-input/number-input.component.html +0 -7
- package/src/lib/elements/number-input/number-input.component.scss +0 -15
- package/src/lib/elements/number-input/number-input.component.ts +0 -13
- package/src/lib/elements/password-field/password-field.component.html +0 -10
- package/src/lib/elements/password-field/password-field.component.scss +0 -15
- package/src/lib/elements/password-field/password-field.component.ts +0 -11
- package/src/lib/elements/select/select.component.html +0 -22
- package/src/lib/elements/select/select.component.scss +0 -289
- package/src/lib/elements/select/select.component.ts +0 -44
- package/src/lib/elements/sortable-items/sortable-items.component.html +0 -23
- package/src/lib/elements/sortable-items/sortable-items.component.scss +0 -34
- package/src/lib/elements/sortable-items/sortable-items.component.ts +0 -18
- package/src/lib/elements/text-input/text-input.component.html +0 -10
- package/src/lib/elements/text-input/text-input.component.scss +0 -15
- package/src/lib/elements/text-input/text-input.component.ts +0 -14
- package/src/lib/elements/toggle/toggle.component.html +0 -9
- package/src/lib/elements/toggle/toggle.component.scss +0 -78
- package/src/lib/elements/toggle/toggle.component.ts +0 -11
- package/src/lib/elements/value-accessor-base/value-accessor-base.component.ts +0 -89
- package/src/lib/form/form-caption/form-caption.component.html +0 -3
- package/src/lib/form/form-caption/form-caption.component.scss +0 -3
- package/src/lib/form/form-caption/form-caption.component.ts +0 -28
- package/src/lib/form/form-element/form-element.component.html +0 -25
- package/src/lib/form/form-element/form-element.component.scss +0 -44
- package/src/lib/form/form-element/form-element.component.ts +0 -76
- package/src/lib/form/form-error/form-error.component.html +0 -3
- package/src/lib/form/form-error/form-error.component.scss +0 -4
- package/src/lib/form/form-error/form-error.component.ts +0 -29
- package/src/lib/form/form-submit-button/form-submit-button.component.html +0 -11
- package/src/lib/form/form-submit-button/form-submit-button.component.scss +0 -10
- package/src/lib/form/form-submit-button/form-submit-button.component.ts +0 -32
- package/src/lib/form/form.component.html +0 -5
- package/src/lib/form/form.component.scss +0 -6
- package/src/lib/form/form.component.ts +0 -67
- package/src/lib/ngx-enhancy-forms.module.ts +0 -68
- package/src/lib/util/values.ts +0 -46
- package/src/lib/validators/dateValidator.ts +0 -8
- package/src/public-api.ts +0 -5
- package/src/style/_form.scss +0 -502
- package/src/style/_klippa.scss +0 -1006
- package/src/style/_mixins.scss +0 -66
- package/src/style/_widgets.scss +0 -251
- package/src/style/app.scss +0 -1
- package/src/style/themes/default/_variables.scss +0 -156
- package/tsconfig.json +0 -37
- package/tsconfig.lib.json +0 -26
- package/tsconfig.lib.prod.json +0 -10
- package/tslint.json +0 -140
|
@@ -0,0 +1,804 @@
|
|
|
1
|
+
import { Component, Input, InjectionToken, Host, Optional, Inject, ViewChild, HostBinding, ContentChild, TemplateRef, NgModule } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { FormGroup, FormArray, FormControl, ControlContainer, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
|
|
4
|
+
import { isString } from 'lodash';
|
|
5
|
+
import { SortablejsModule } from 'ngx-sortablejs';
|
|
6
|
+
import { NgSelectModule } from '@ng-select/ng-select';
|
|
7
|
+
import { MAT_NATIVE_DATE_FORMATS, MAT_DATE_FORMATS, MatNativeDateModule } from '@angular/material/core';
|
|
8
|
+
import { MatDatepickerModule } from '@angular/material/datepicker';
|
|
9
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
10
|
+
import { MatInputModule } from '@angular/material/input';
|
|
11
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
12
|
+
|
|
13
|
+
const invalidFieldsSymbol = Symbol('Not all fields are valid');
|
|
14
|
+
class FormComponent {
|
|
15
|
+
constructor() {
|
|
16
|
+
// we keep track of what form controls are actually rendered. Only those count when looking at form validation
|
|
17
|
+
this.activeControls = [];
|
|
18
|
+
}
|
|
19
|
+
registerControl(formControl, formElement) {
|
|
20
|
+
this.activeControls.push({ formControl, formElement });
|
|
21
|
+
}
|
|
22
|
+
unregisterControl(formControl) {
|
|
23
|
+
this.activeControls = this.activeControls.filter((e) => e.formControl !== formControl);
|
|
24
|
+
}
|
|
25
|
+
disableInactiveFormGroupControls(formGroup) {
|
|
26
|
+
Object.values(formGroup.controls).forEach((value) => {
|
|
27
|
+
if (value instanceof FormGroup) {
|
|
28
|
+
this.disableInactiveFormGroupControls(value);
|
|
29
|
+
}
|
|
30
|
+
else if (value instanceof FormArray) {
|
|
31
|
+
this.disableInactiveFormArrayControls(value);
|
|
32
|
+
}
|
|
33
|
+
else if (value instanceof FormControl) {
|
|
34
|
+
this.disableInactiveFormControl(value);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
disableInactiveFormArrayControls(formArray) {
|
|
39
|
+
formArray.controls.forEach((value) => {
|
|
40
|
+
if (value instanceof FormGroup) {
|
|
41
|
+
this.disableInactiveFormGroupControls(value);
|
|
42
|
+
}
|
|
43
|
+
else if (value instanceof FormArray) {
|
|
44
|
+
this.disableInactiveFormArrayControls(value);
|
|
45
|
+
}
|
|
46
|
+
else if (value instanceof FormControl) {
|
|
47
|
+
this.disableInactiveFormControl(value);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
disableInactiveFormControl(control) {
|
|
52
|
+
if (this.activeControls.some((e) => e.formControl === control)) {
|
|
53
|
+
control.enable();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
control.disable();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
trySubmit() {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
this.formGroup.markAllAsTouched();
|
|
62
|
+
this.disableInactiveFormGroupControls(this.formGroup);
|
|
63
|
+
if (this.formGroup.valid) {
|
|
64
|
+
return Promise.resolve(this.formGroup.value);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(_b = (_a = this.activeControls.find((e) => !e.formControl.valid)) === null || _a === void 0 ? void 0 : _a.formElement) === null || _b === void 0 ? void 0 : _b.scrollTo();
|
|
68
|
+
return Promise.reject(invalidFieldsSymbol);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
FormComponent.decorators = [
|
|
73
|
+
{ type: Component, args: [{
|
|
74
|
+
selector: 'klp-form',
|
|
75
|
+
template: "<form>\n\t<ng-content></ng-content>\n</form>\n\n\n",
|
|
76
|
+
styles: [":host{display:block}:host.row{display:flex}"]
|
|
77
|
+
},] }
|
|
78
|
+
];
|
|
79
|
+
FormComponent.propDecorators = {
|
|
80
|
+
formGroup: [{ type: Input }]
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const FORM_ERROR_MESSAGES = new InjectionToken('form.error.messages');
|
|
84
|
+
const DEFAULT_ERROR_MESSAGES = {
|
|
85
|
+
min: "Use a number larger than %min%",
|
|
86
|
+
max: "Use a number smaller than %max%",
|
|
87
|
+
required: "This field is required",
|
|
88
|
+
email: "Use a valid email address",
|
|
89
|
+
minLength: "Has to be longer than %minLength% character(s)",
|
|
90
|
+
maxLength: "Has to be shorter than %maxLength% character(s)",
|
|
91
|
+
pattern: "This input is not valid",
|
|
92
|
+
matchPassword: "Passwords must match",
|
|
93
|
+
date: "Enter a valid date",
|
|
94
|
+
};
|
|
95
|
+
class FormElementComponent {
|
|
96
|
+
constructor(parent, customMessages) {
|
|
97
|
+
this.parent = parent;
|
|
98
|
+
this.customMessages = customMessages;
|
|
99
|
+
this.direction = 'horizontal';
|
|
100
|
+
this.captionSpacing = 'percentages';
|
|
101
|
+
this.swapInputAndCaption = false;
|
|
102
|
+
this.errorMessages = DEFAULT_ERROR_MESSAGES;
|
|
103
|
+
this.customErrorHandlers = [];
|
|
104
|
+
}
|
|
105
|
+
substituteParameters(message, parameters) {
|
|
106
|
+
return Object.keys(parameters).reduce((msg, key) => {
|
|
107
|
+
return msg.replace(`%${key}%`, parameters[key]);
|
|
108
|
+
}, message);
|
|
109
|
+
}
|
|
110
|
+
registerControl(formControl) {
|
|
111
|
+
this.attachedControl = formControl;
|
|
112
|
+
this.parent.registerControl(formControl, this);
|
|
113
|
+
}
|
|
114
|
+
unregisterControl(formControl) {
|
|
115
|
+
this.attachedControl = null;
|
|
116
|
+
this.parent.unregisterControl(formControl);
|
|
117
|
+
}
|
|
118
|
+
getAttachedControl() {
|
|
119
|
+
return this.attachedControl;
|
|
120
|
+
}
|
|
121
|
+
registerErrorHandler(error, templateRef) {
|
|
122
|
+
this.customErrorHandlers.push({ error, templateRef });
|
|
123
|
+
}
|
|
124
|
+
registerCaption(templateRef) {
|
|
125
|
+
this.captionRef = templateRef;
|
|
126
|
+
}
|
|
127
|
+
getErrorToShow() {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
if (((_a = this.attachedControl) === null || _a === void 0 ? void 0 : _a.touched) === true && ((_b = this.attachedControl) === null || _b === void 0 ? void 0 : _b.errors)) {
|
|
130
|
+
return Object.keys((_c = this.attachedControl) === null || _c === void 0 ? void 0 : _c.errors)[0];
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
getCustomErrorHandler(error) {
|
|
135
|
+
return this.customErrorHandlers.find((e) => e.error === error);
|
|
136
|
+
}
|
|
137
|
+
showDefaultError(error) {
|
|
138
|
+
return this.getErrorToShow() === error && !this.customErrorHandlers.some((e) => e.error === error);
|
|
139
|
+
}
|
|
140
|
+
getScrollableParent(node) {
|
|
141
|
+
if (node == null) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (node.scrollHeight > node.clientHeight) {
|
|
145
|
+
return node;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return this.getScrollableParent(node.parentNode);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
scrollTo() {
|
|
152
|
+
var _a;
|
|
153
|
+
this.internalComponentRef.nativeElement.scrollIntoView(true);
|
|
154
|
+
// to give some breathing room, we scroll 100px more to the top
|
|
155
|
+
(_a = this.getScrollableParent(this.internalComponentRef.nativeElement)) === null || _a === void 0 ? void 0 : _a.scrollBy(0, -100);
|
|
156
|
+
}
|
|
157
|
+
getErrorMessages(key) {
|
|
158
|
+
var _a, _b, _c;
|
|
159
|
+
return (_c = (_b = (_a = this.customMessages) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : this.errorMessages[key];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
FormElementComponent.decorators = [
|
|
163
|
+
{ type: Component, args: [{
|
|
164
|
+
selector: 'klp-form-element',
|
|
165
|
+
template: "<ng-template #errorRef>\n\t<div *ngIf=\"getErrorToShow()\" class=\"errorContainer\">\n\t\t<div *ngIf=\"showDefaultError('min')\">{{substituteParameters(getErrorMessages(\"min\"), {min: attachedControl.errors.min.min})}}</div>\n\t\t<div *ngIf=\"showDefaultError('max')\">{{substituteParameters(getErrorMessages(\"max\"), {max: attachedControl.errors.max.max})}}</div>\n\t\t<div *ngIf=\"showDefaultError('required')\">{{getErrorMessages(\"required\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('email')\">{{getErrorMessages(\"email\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('minlength')\">{{substituteParameters(getErrorMessages(\"minLength\"), {minLength: attachedControl.errors.minlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('maxlength')\">{{substituteParameters(getErrorMessages(\"maxLength\"), {maxLength: attachedControl.errors.maxlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('pattern')\">{{getErrorMessages(\"pattern\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('MatchPassword')\">{{getErrorMessages(\"matchPassword\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('date')\">{{getErrorMessages(\"date\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('message')\">{{attachedControl.errors.message.value}}</div>\n\t\t<div [ngTemplateOutlet]=\"getCustomErrorHandler(getErrorToShow())?.templateRef\"></div>\n\t</div>\n</ng-template>\n<ng-container *ngIf=\"direction === 'horizontal'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n<div *ngIf=\"attachedControl\" class=\"componentContainer\" [ngClass]=\"{vertical: direction === 'vertical', reverseOrder: swapInputAndCaption}\" #internalComponentRef>\n\t<div class=\"caption\" [ngClass]=\"{ hasErrors: getErrorToShow() && attachedControl.touched, percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<div *ngIf=\"captionRef\" [ngTemplateOutlet]=\"captionRef\"></div>\n\t\t<div *ngIf=\"!captionRef\">{{caption}}</div>\n\t</div>\n\t<ng-container *ngIf=\"direction === 'vertical'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n\t<div class=\"inputContainer\" [ngClass]=\"{ percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<ng-content></ng-content>\n\t</div>\n</div>\n",
|
|
166
|
+
styles: [":host{display:block;margin-top:1.25rem}.componentContainer{align-items:center;display:flex}.componentContainer.reverseOrder{flex-direction:row-reverse;justify-content:flex-end}.componentContainer.vertical{display:block;margin-bottom:1rem}.componentContainer.vertical .inputContainer{margin-top:.3125rem}.componentContainer.vertical .errorContainer{margin-left:0}.caption{color:#515365;flex:0 0 auto;font-weight:700}.caption.percentageSpacing{flex:0 0 40%}.caption.hasErrors{color:#ff8000}.inputContainer{flex:0 0 auto}.inputContainer.percentageSpacing{flex:0 0 60%}.errorContainer{color:#ff8000;margin-left:40%}"]
|
|
167
|
+
},] }
|
|
168
|
+
];
|
|
169
|
+
FormElementComponent.ctorParameters = () => [
|
|
170
|
+
{ type: FormComponent, decorators: [{ type: Host }, { type: Optional }] },
|
|
171
|
+
{ type: undefined, decorators: [{ type: Inject, args: [FORM_ERROR_MESSAGES,] }, { type: Optional }] }
|
|
172
|
+
];
|
|
173
|
+
FormElementComponent.propDecorators = {
|
|
174
|
+
caption: [{ type: Input }],
|
|
175
|
+
direction: [{ type: Input }],
|
|
176
|
+
captionSpacing: [{ type: Input }],
|
|
177
|
+
swapInputAndCaption: [{ type: Input }],
|
|
178
|
+
internalComponentRef: [{ type: ViewChild, args: ['internalComponentRef',] }]
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
function stringIsSetAndNotEmpty(s) {
|
|
182
|
+
return isString(s) && s.length > 0;
|
|
183
|
+
}
|
|
184
|
+
function isNullOrUndefined(value) {
|
|
185
|
+
return value === null || value === undefined;
|
|
186
|
+
}
|
|
187
|
+
function numberIsSet(value) {
|
|
188
|
+
return isValueSet(value) && typeof value === 'number';
|
|
189
|
+
}
|
|
190
|
+
function isValueSet(value) {
|
|
191
|
+
return value !== null && value !== undefined;
|
|
192
|
+
}
|
|
193
|
+
function stringOrArrayIsSetAndEmpty(value) {
|
|
194
|
+
return value !== null && value !== undefined && value.length === 0;
|
|
195
|
+
}
|
|
196
|
+
function useIfStringIsSet(s) {
|
|
197
|
+
if (stringIsSetAndNotEmpty(s)) {
|
|
198
|
+
return s;
|
|
199
|
+
}
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
function useIfArrayIsSetWithOneItem(a) {
|
|
203
|
+
if (!isNullOrUndefined(a) && a.length === 1) {
|
|
204
|
+
return a[0];
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
function convertParentToChild(originalClass, newClass) {
|
|
209
|
+
return Object.assign(newClass, originalClass);
|
|
210
|
+
}
|
|
211
|
+
function truncateString(s, length) {
|
|
212
|
+
if (s.length < length) {
|
|
213
|
+
return s;
|
|
214
|
+
}
|
|
215
|
+
return s.substring(0, length) + '...';
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* This component is a base in order to create a component that supports ngModel.
|
|
220
|
+
* Some important things to know about it:
|
|
221
|
+
*
|
|
222
|
+
* innerValue = your own inner state, which you should use to store the current state of what ngModel should be.
|
|
223
|
+
* writeValue() = called by angular, when ngModel is changed from OUTSIDE of the component. Feel free to patch this method if you need inner logic to happen when ngModel is altered from the outside. Always remember to also call the super.writeValue if you do!
|
|
224
|
+
* setInnerValueAndNotify() = call this when you want your ngModel to be updated from INSIDE of your component, and provide it to the OUTSIDE.
|
|
225
|
+
* ngOnInit() = Used to support the angular reactive forms framework. If you use ngOnInit in your own component (which happens fairly often) you must not forget to call the super.ngOnInit() method.
|
|
226
|
+
*/
|
|
227
|
+
class ValueAccessorBase {
|
|
228
|
+
constructor(parent, controlContainer) {
|
|
229
|
+
this.parent = parent;
|
|
230
|
+
this.controlContainer = controlContainer;
|
|
231
|
+
this.changed = new Array();
|
|
232
|
+
this.touched = new Array();
|
|
233
|
+
this.disabled = false;
|
|
234
|
+
// we support both providing just the formControlName and the full formControl
|
|
235
|
+
this.formControlName = null;
|
|
236
|
+
this.formControl = null;
|
|
237
|
+
}
|
|
238
|
+
ngOnInit() {
|
|
239
|
+
var _a, _b, _c;
|
|
240
|
+
if (this.formControl) {
|
|
241
|
+
this.attachedFormControl = this.formControl;
|
|
242
|
+
}
|
|
243
|
+
else if (stringIsSetAndNotEmpty(this.formControlName)) {
|
|
244
|
+
this.attachedFormControl = (_a = this.controlContainer) === null || _a === void 0 ? void 0 : _a.control.get(this.formControlName);
|
|
245
|
+
if (isNullOrUndefined(this.attachedFormControl)) {
|
|
246
|
+
throw new Error(`Form element '${this.formControlName}' with caption '${(_b = this.parent) === null || _b === void 0 ? void 0 : _b.caption}' is not declared in your FormGroup.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (this.attachedFormControl) {
|
|
250
|
+
this.disabled = this.attachedFormControl.disabled;
|
|
251
|
+
this.attachedFormControl.statusChanges.subscribe(() => {
|
|
252
|
+
this.disabled = this.attachedFormControl.disabled;
|
|
253
|
+
});
|
|
254
|
+
(_c = this.parent) === null || _c === void 0 ? void 0 : _c.registerControl(this.attachedFormControl);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
isInErrorState() {
|
|
258
|
+
return this.attachedFormControl && this.attachedFormControl.status === 'INVALID' && this.attachedFormControl.touched;
|
|
259
|
+
}
|
|
260
|
+
ngOnDestroy() {
|
|
261
|
+
var _a;
|
|
262
|
+
if (this.attachedFormControl) {
|
|
263
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.unregisterControl(this.attachedFormControl);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
touch() {
|
|
267
|
+
this.touched.forEach((f) => f());
|
|
268
|
+
}
|
|
269
|
+
writeValue(value) {
|
|
270
|
+
this.innerValue = value;
|
|
271
|
+
}
|
|
272
|
+
registerOnChange(fn) {
|
|
273
|
+
this.changed.push(fn);
|
|
274
|
+
}
|
|
275
|
+
registerOnTouched(fn) {
|
|
276
|
+
this.touched.push(fn);
|
|
277
|
+
}
|
|
278
|
+
setInnerValueAndNotify(value) {
|
|
279
|
+
this.innerValue = value;
|
|
280
|
+
this.changed.forEach((fn) => fn(value));
|
|
281
|
+
}
|
|
282
|
+
resetToNull() {
|
|
283
|
+
this.setInnerValueAndNotify(null);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
ValueAccessorBase.decorators = [
|
|
287
|
+
{ type: Component, args: [{
|
|
288
|
+
selector: '',
|
|
289
|
+
template: ''
|
|
290
|
+
},] }
|
|
291
|
+
];
|
|
292
|
+
ValueAccessorBase.ctorParameters = () => [
|
|
293
|
+
{ type: FormElementComponent, decorators: [{ type: Host }, { type: Optional }] },
|
|
294
|
+
{ type: ControlContainer, decorators: [{ type: Host }, { type: Optional }] }
|
|
295
|
+
];
|
|
296
|
+
ValueAccessorBase.propDecorators = {
|
|
297
|
+
disabled: [{ type: Input }],
|
|
298
|
+
formControlName: [{ type: Input }],
|
|
299
|
+
formControl: [{ type: Input }]
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
class ButtonComponent {
|
|
303
|
+
constructor() {
|
|
304
|
+
this.variant = 'white';
|
|
305
|
+
this.size = 'medium';
|
|
306
|
+
this.fullWidth = false;
|
|
307
|
+
this.hasBorder = true;
|
|
308
|
+
this.disabled = false;
|
|
309
|
+
this.isLoading = false;
|
|
310
|
+
this.type = 'button';
|
|
311
|
+
}
|
|
312
|
+
get _() {
|
|
313
|
+
return this.fullWidth;
|
|
314
|
+
}
|
|
315
|
+
onClick(event) {
|
|
316
|
+
if (this.disabled) {
|
|
317
|
+
event.stopPropagation();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
ButtonComponent.decorators = [
|
|
322
|
+
{ type: Component, args: [{
|
|
323
|
+
selector: 'klp-form-button',
|
|
324
|
+
template: "<button class=\"buttonFundamentals\"\n\t[ngClass]=\"[\n\t\tvariant,\n\t\tsize,\n\t\tfullWidth ? 'fullWidth' : '',\n\t\thasBorder ? '' : 'no-border',\n\t\tdisabled ? 'disabled' : ''\n\t]\"\n\t[type]=\"type\"\n\t(click)=\"onClick($event)\"\n>\n\t<div class=\"caption\" [ngClass]=\"{invisible: isLoading}\">\n\t\t<ng-content></ng-content>\n\t</div>\n\t<div class=\"loadingSpinnerContainer\" *ngIf=\"isLoading\">\n\t\t<klp-form-loading-indicator variant=\"spinner\" size=\"small\"></klp-form-loading-indicator>\n\t</div>\n</button>\n",
|
|
325
|
+
styles: [":host{display:inline-block}:host._fullWidth{display:block}.buttonFundamentals{border:1px solid #e6ecf5;border-radius:5px;color:#888da8;cursor:pointer;font-size:13px;font-weight:700;letter-spacing:1px;padding:10px 20px}.fullWidth{width:100%}.no-border{border:none}.caption.invisible{visibility:hidden}button{position:relative}.loadingSpinnerContainer{align-items:center;bottom:0;display:flex;justify-content:center;left:0;position:absolute;right:0;top:0}.small{padding-bottom:.375rem;padding-top:.375rem}.large{line-height:2}.white{background-color:#fff;border-color:#d4deee;color:#515365;font-weight:500}.white:active,.white:hover{background-color:#edf2f8;border-color:#edf2f8;color:#515365}.white:focus{text-decoration:underline}.greenFilled{background-color:#27bb5f;border-color:#27bb5f;color:#fff}.greenFilled:hover{background-color:#2bd06a;border-color:#2bd06a;color:#fff}.greenFilled:focus{text-decoration:underline}.greenFilled:active{background-color:#23a654;border-color:#23a654}.greenOutlined{background-color:#fff;border-color:#27bb5f;color:#27bb5f}.greenOutlined:hover{background-color:#2bd06a;border-color:#2bd06a;color:#fff}.greenOutlined:focus{text-decoration:underline}.greenOutlined:active{background-color:#23a654;border-color:#23a654}.greenLink{background:none;border:none;color:#27bb5f;padding:0}.greenLink:focus,.greenLink:hover{text-decoration:underline}.contextMenuItem{background-color:#fff;border-color:#fff;color:#888da8}.contextMenuItem:hover{background-color:#f6f7fb;border-color:#f6f7fb}.contextMenuItem:active,.contextMenuItem:focus{text-decoration:underline}.redFilled{background-color:#ff3c7e;border-color:#ff3c7e;color:#fff}.redFilled:hover{background-color:#ff568f;border-color:#ff568f;color:#fff}.redFilled:focus{text-decoration:underline}.redFilled:active{background-color:#ff236d;border-color:#ff236d}.redOutlined{background-color:#fff;border-color:#ff3c7e;color:#ff3c7e}.redOutlined:hover{background-color:#ff568f;border-color:#ff568f;color:#fff}.redOutlined:focus{text-decoration:underline}.redOutlined:active{background-color:#ff236d;border-color:#ff236d}.orangeFilled{background-color:#ff8000;border-color:#ff8000;color:#fff}.orangeFilled:hover{background-color:#ff8d1a;border-color:#ff8d1a;color:#fff}.orangeFilled:focus{text-decoration:underline}.orangeFilled:active{background-color:#e67300;border-color:#e67300}"]
|
|
326
|
+
},] }
|
|
327
|
+
];
|
|
328
|
+
ButtonComponent.propDecorators = {
|
|
329
|
+
variant: [{ type: Input }],
|
|
330
|
+
size: [{ type: Input }],
|
|
331
|
+
fullWidth: [{ type: Input }],
|
|
332
|
+
hasBorder: [{ type: Input }],
|
|
333
|
+
disabled: [{ type: Input }],
|
|
334
|
+
isLoading: [{ type: Input }],
|
|
335
|
+
type: [{ type: Input }],
|
|
336
|
+
_: [{ type: HostBinding, args: ['class._fullWidth',] }]
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
class CheckboxComponent extends ValueAccessorBase {
|
|
340
|
+
}
|
|
341
|
+
CheckboxComponent.decorators = [
|
|
342
|
+
{ type: Component, args: [{
|
|
343
|
+
selector: 'klp-form-checkbox',
|
|
344
|
+
template: "<label class=\"componentContainer\">\n\t<div class=\"checkboxContainer\">\n\t\t<input type=\"checkbox\" class=\"checkboxNative\"\n\t\t\t[(ngModel)]=\"innerValue\"\n\t\t\t(change)=\"setInnerValueAndNotify(innerValue); touch()\"\n\t\t\t[disabled]=\"disabled\"\n\t\t/>\n <div class=\"checkboxVisual\">\n <svg *ngIf=\"innerValue\" version=\"1.1\" viewBox=\"0 0 4.2333 4.2333\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"m0.17014 2.7065 1.3073 1.1798 2.5656-3.7404\" stroke=\"currentColor\" fill=\"none\" stroke-width=\".4646px\" />\n </svg>\n </div>\n\t</div>\n\t<div *ngIf=\"caption\" class=\"caption\">{{ caption }}</div>\n</label>\n",
|
|
345
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: CheckboxComponent, multi: true }],
|
|
346
|
+
styles: [":host{display:block}.componentContainer{display:flex;margin-bottom:0}.checkboxContainer{position:relative}.caption{color:#888da8;cursor:pointer;font-weight:700}.checkboxNative{left:0;opacity:0;position:absolute;top:0}.checkboxNative,.checkboxVisual{cursor:pointer;height:22px;width:22px}.checkboxVisual{background-color:#fff;border:2px solid #e6ecf5;border-radius:3px;color:#27bb5f;display:inline-block;font-size:15px;font-weight:400;line-height:19px;margin-right:10px;padding:.125rem;pointer-events:none;text-align:center;vertical-align:bottom}.checkboxNative[disabled]{cursor:not-allowed}.checkboxNative[disabled]+.checkboxVisual:before{color:#666}"]
|
|
347
|
+
},] }
|
|
348
|
+
];
|
|
349
|
+
CheckboxComponent.propDecorators = {
|
|
350
|
+
caption: [{ type: Input }],
|
|
351
|
+
disabled: [{ type: Input }]
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
class EmailInputComponent extends ValueAccessorBase {
|
|
355
|
+
constructor() {
|
|
356
|
+
super(...arguments);
|
|
357
|
+
this.placeholder = '';
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
EmailInputComponent.decorators = [
|
|
361
|
+
{ type: Component, args: [{
|
|
362
|
+
selector: 'klp-form-email-input',
|
|
363
|
+
template: "<input\n\ttype=\"email\"\n\tclass=\"form-control\"\n\t[(ngModel)]=\"innerValue\"\n\t(input)=\"setInnerValueAndNotify($event.target.value)\"\n\t[placeholder]=\"placeholder\"\n\t(blur)=\"touch()\"\n/>\n",
|
|
364
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: EmailInputComponent, multi: true }],
|
|
365
|
+
styles: [":host,input{display:block}input{-moz-transition:all .2s ease-in;-ms-transition:all .2s ease-in;-o-transition:all .2s ease-in;-webkit-transition:all .2s ease-in;border:1px solid #e6ecf5;border-radius:2px;box-shadow:none;color:#888da8;font-size:14px;height:42px;outline:none;padding:.375rem .625rem;transition:all .2s ease-in;width:100%}input::-webkit-input-placeholder{color:#adadad}input:-moz-placeholder,input::-moz-placeholder{color:#adadad}input:-ms-input-placeholder{color:#adadad}input:focus{border-color:#3ed778;box-shadow:none;outline:0 none}input.input-sm{height:30px}input.input-lg{height:50px}input.error{background-color:#ffeff4;border-color:#ff3c7e}input.valid{background-color:#ebfaeb;border-color:#37c936;color:#278d26}.showErrors{border-color:#ff8000}"]
|
|
366
|
+
},] }
|
|
367
|
+
];
|
|
368
|
+
EmailInputComponent.propDecorators = {
|
|
369
|
+
placeholder: [{ type: Input }]
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
class LoadingIndicatorComponent {
|
|
373
|
+
constructor() {
|
|
374
|
+
this.variant = '3dots';
|
|
375
|
+
this.size = 'medium';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
LoadingIndicatorComponent.decorators = [
|
|
379
|
+
{ type: Component, args: [{
|
|
380
|
+
selector: 'klp-form-loading-indicator',
|
|
381
|
+
template: "<div class=\"threeDots\" [class]=\"size\" *ngIf=\"variant === '3dots'\">\n\t<div></div>\n\t<div></div>\n\t<div></div>\n\t<div></div>\n</div>\n\n<div class=\"spinner\" [class]=\"size\" *ngIf=\"variant === 'spinner'\">\n\t<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 0 48 48\">\n\t\t<circle cx=\"24\" cy=\"4\" r=\"4\" fill=\"currentColor\" />\n\t\t<circle cx=\"12.19\" cy=\"7.86\" r=\"3.7\" fill=\"currentColor\" />\n\t\t<circle cx=\"5.02\" cy=\"17.68\" r=\"3.4\" fill=\"currentColor\" />\n\t\t<circle cx=\"5.02\" cy=\"30.32\" r=\"3.1\" fill=\"currentColor\" />\n\t\t<circle cx=\"12.19\" cy=\"40.14\" r=\"2.8\" fill=\"currentColor\" />\n\t\t<circle cx=\"24\" cy=\"44\" r=\"2.5\" fill=\"currentColor\" />\n\t\t<circle cx=\"35.81\" cy=\"40.14\" r=\"2.2\" fill=\"currentColor\" />\n\t\t<circle cx=\"42.98\" cy=\"30.32\" r=\"1.9\" fill=\"currentColor\" />\n\t\t<circle cx=\"42.98\" cy=\"17.68\" r=\"1.6\" fill=\"currentColor\" />\n\t\t<circle cx=\"35.81\" cy=\"7.86\" r=\"1.3\" fill=\"currentColor\" />\n\t</svg>\n</div>\n\n<div class=\"textInput\" *ngIf=\"variant === 'textInput'\">\n\t<input\n\t\tdisabled\n\t\ttype=\"text\"\n\t\tclass=\"form-control\"\n\t\tplaceholder=\"Loading...\"\n\t>\n</div>\n\n<div class=\"picker\" *ngIf=\"variant === 'picker'\">\n\t<input\n\t\tdisabled\n\t\ttype=\"text\"\n\t\tclass=\"form-control\"\n\t\tplaceholder=\"Loading...\"\n\t>\n\t<div class=\"chevronDown\"></div>\n</div>\n",
|
|
382
|
+
styles: [".threeDots,:host{display:block}.threeDots{height:var(--base);position:relative;width:calc(var(--base)*4)}.threeDots.tiny{--base:4px}.threeDots.small{--base:8px}.threeDots.medium{--base:12px}.threeDots.large{--base:18px}.threeDots.huge{--base:26px}.threeDots div{-webkit-animation-timing-function:cubic-bezier(0,1,1,0);animation-timing-function:cubic-bezier(0,1,1,0);background:#27bb5f;border-radius:50%;height:var(--base);position:absolute;top:0;width:var(--base)}.threeDots div:first-child{-webkit-animation:lds-ellipsis1 .6s infinite;animation:lds-ellipsis1 .6s infinite}.threeDots div:nth-child(2),.threeDots div:nth-child(3){-webkit-animation:lds-ellipsis2 .6s infinite;animation:lds-ellipsis2 .6s infinite}.threeDots div:nth-child(3){left:calc(var(--base)*1.5)}.threeDots div:nth-child(4){-webkit-animation:lds-ellipsis3 .6s infinite;animation:lds-ellipsis3 .6s infinite;left:calc(var(--base)*3)}@-webkit-keyframes lds-ellipsis1{0%{transform:scale(0)}to{transform:scale(1)}}@keyframes lds-ellipsis1{0%{transform:scale(0)}to{transform:scale(1)}}@-webkit-keyframes lds-ellipsis3{0%{transform:scale(1)}to{transform:scale(0)}}@keyframes lds-ellipsis3{0%{transform:scale(1)}to{transform:scale(0)}}@-webkit-keyframes lds-ellipsis2{0%{transform:translate(0)}to{transform:translate(150%)}}@keyframes lds-ellipsis2{0%{transform:translate(0)}to{transform:translate(150%)}}.spinner.tiny svg{height:1rem;width:1rem}.spinner.small svg{height:1.6rem;width:1.6rem}.spinner.medium svg{height:2.5rem;width:2.5rem}.spinner.large svg{height:3rem;width:3rem}.spinner.huge svg{height:4rem;width:4rem}.spinner svg{-moz-animation-duration:1.2s;-moz-animation-iteration-count:infinite;-moz-animation-name:rotate;-moz-animation-timing-function:linear;-moz-transition-property:-moz-transform;-webkit-animation-duration:1.2s;-webkit-animation-iteration-count:infinite;-webkit-animation-name:rotate;-webkit-animation-timing-function:linear;-webkit-transition-duration:1.2s;-webkit-transition-property:-webkit-transform;animation-duration:1.2s;animation-iteration-count:infinite;animation-name:rotate;animation-timing-function:linear;transition-property:transform}@-webkit-keyframes rotate{0%{-webkit-transform:rotate(0deg)}to{-webkit-transform:rotate(1turn)}}@keyframes rotate{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.picker{position:relative}.picker .chevronDown{border-left:5px solid transparent;border-right:5px solid transparent;border-top:5px solid #888da8;height:0;position:absolute;right:23px;top:18px;width:0}"]
|
|
383
|
+
},] }
|
|
384
|
+
];
|
|
385
|
+
LoadingIndicatorComponent.propDecorators = {
|
|
386
|
+
variant: [{ type: Input }],
|
|
387
|
+
size: [{ type: Input }]
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
class NumberInputComponent extends ValueAccessorBase {
|
|
391
|
+
}
|
|
392
|
+
NumberInputComponent.decorators = [
|
|
393
|
+
{ type: Component, args: [{
|
|
394
|
+
selector: 'klp-form-number-input',
|
|
395
|
+
template: "<input\n\ttype=\"number\"\n\tclass=\"form-control\"\n\t[(ngModel)]=\"innerValue\"\n\t(input)=\"setInnerValueAndNotify($event.target.value)\"\n\t[placeholder]=\"placeholder ? placeholder : ''\"\n/>\n",
|
|
396
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: NumberInputComponent, multi: true }],
|
|
397
|
+
styles: [":host,input{display:block}input{-moz-transition:all .2s ease-in;-ms-transition:all .2s ease-in;-o-transition:all .2s ease-in;-webkit-transition:all .2s ease-in;border:1px solid #e6ecf5;border-radius:2px;box-shadow:none;color:#888da8;font-size:14px;height:42px;outline:none;padding:.375rem .625rem;transition:all .2s ease-in;width:100%}input::-webkit-input-placeholder{color:#adadad}input:-moz-placeholder,input::-moz-placeholder{color:#adadad}input:-ms-input-placeholder{color:#adadad}input:focus{border-color:#3ed778;box-shadow:none;outline:0 none}input.input-sm{height:30px}input.input-lg{height:50px}input.error{background-color:#ffeff4;border-color:#ff3c7e}input.valid{background-color:#ebfaeb;border-color:#37c936;color:#278d26}.showErrors{border-color:#ff8000}"]
|
|
398
|
+
},] }
|
|
399
|
+
];
|
|
400
|
+
NumberInputComponent.propDecorators = {
|
|
401
|
+
placeholder: [{ type: Input }]
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
class PasswordFieldComponent extends ValueAccessorBase {
|
|
405
|
+
constructor() {
|
|
406
|
+
super(...arguments);
|
|
407
|
+
this.placeholder = 'Password';
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
PasswordFieldComponent.decorators = [
|
|
411
|
+
{ type: Component, args: [{
|
|
412
|
+
selector: 'klp-form-password-field',
|
|
413
|
+
template: "<input\n\ttype=\"password\"\n\tclass=\"form-control\"\n [ngClass]=\"{showErrors: isInErrorState()}\"\n\t[(ngModel)]=\"innerValue\"\n\t(input)=\"setInnerValueAndNotify($event.target.value)\"\n\t[placeholder]=\"placeholder\"\n\t(blur)=\"touch()\"\n/>\n",
|
|
414
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: PasswordFieldComponent, multi: true }],
|
|
415
|
+
styles: [":host,input{display:block}input{-moz-transition:all .2s ease-in;-ms-transition:all .2s ease-in;-o-transition:all .2s ease-in;-webkit-transition:all .2s ease-in;border:1px solid #e6ecf5;border-radius:2px;box-shadow:none;color:#888da8;font-size:14px;height:42px;outline:none;padding:.375rem .625rem;transition:all .2s ease-in;width:100%}input::-webkit-input-placeholder{color:#adadad}input:-moz-placeholder,input::-moz-placeholder{color:#adadad}input:-ms-input-placeholder{color:#adadad}input:focus{border-color:#3ed778;box-shadow:none;outline:0 none}input.input-sm{height:30px}input.input-lg{height:50px}input.error{background-color:#ffeff4;border-color:#ff3c7e}input.valid{background-color:#ebfaeb;border-color:#37c936;color:#278d26}.showErrors{border-color:#ff8000}"]
|
|
416
|
+
},] }
|
|
417
|
+
];
|
|
418
|
+
PasswordFieldComponent.propDecorators = {
|
|
419
|
+
placeholder: [{ type: Input }]
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
class SelectComponent extends ValueAccessorBase {
|
|
423
|
+
constructor(parent, controlContainer) {
|
|
424
|
+
super(parent, controlContainer);
|
|
425
|
+
this.parent = parent;
|
|
426
|
+
this.controlContainer = controlContainer;
|
|
427
|
+
this.placeholder = 'Pick an option';
|
|
428
|
+
this.multiple = false;
|
|
429
|
+
this.clearable = true;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
SelectComponent.decorators = [
|
|
433
|
+
{ type: Component, args: [{
|
|
434
|
+
selector: 'klp-form-select',
|
|
435
|
+
template: "<ng-select\n\t[placeholder]=\"placeholder\"\n\tbindLabel=\"name\"\n\tbindValue=\"id\"\n\t[items]=\"options\"\n\t[clearable]=\"clearable\"\n\t[(ngModel)]=\"innerValue\"\n\t[ngClass]=\"{showErrors: isInErrorState()}\"\n\t(change)=\"setInnerValueAndNotify(innerValue)\"\n\t[multiple]=\"multiple\"\n\t[disabled]=\"disabled\"\n\t(blur)=\"touch()\"\n\t[dropdownPosition]=\"dropdownPosition\"\n\t[searchFn]=\"customSearchFn\"\n>\n\t<ng-template let-item=\"item\" ng-option-tmp>\n\t\t{{ item.name }}\n\t\t<div *ngIf=\"item.description\" class=\"dropdown-item-description\">\n\t\t\t{{ item.description }}\n\t\t</div>\n\t</ng-template>\n</ng-select>\n",
|
|
436
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: SelectComponent, multi: true }],
|
|
437
|
+
styles: [":host{display:block}.showErrors ::ng-deep .ng-select-container,:host.showErrors ::ng-deep .ng-select-container{border-color:#ff8000}:host ::ng-deep ng-select.ng-select .ng-select-container{color:#888da8}:host ::ng-deep .ng-select.ng-select-opened>.ng-select-container{background:#fff;border-color:#3ed778}:host ::ng-deep .ng-select.ng-select-opened>.ng-select-container:hover{box-shadow:none}:host ::ng-deep .ng-select.ng-select-opened>.ng-select-container .ng-arrow{border-color:transparent transparent #999;border-width:0 5px 5px;top:-2px}:host ::ng-deep .ng-select.ng-select-opened>.ng-select-container .ng-arrow:hover{border-color:transparent transparent #666}:host ::ng-deep .ng-select.ng-select-opened.ng-select-bottom>.ng-select-container{border-bottom-left-radius:0;border-bottom-right-radius:0}:host ::ng-deep .ng-select.ng-select-opened.ng-select-top>.ng-select-container{border-top-left-radius:0;border-top-right-radius:0}:host ::ng-deep .ng-select.ng-select-disabled>.ng-select-container{background-color:#f9f9f9}:host ::ng-deep .ng-select .ng-has-value .ng-placeholder{display:none}:host ::ng-deep .ng-select .ng-select-container{align-items:center;background-clip:padding-box;background-color:#fff;border:1px solid #e6ecf5;border-radius:4px;border-radius:2px;box-shadow:none;box-sizing:border-box;color:#888da8;display:flex;flex-direction:row;font-size:1rem;font-size:14px;line-height:1.5;margin:0;min-height:42px;outline:none;overflow:visible;padding:.375rem .75rem;transition-delay:0s;transition-duration:.2s;transition-property:all;transition-timing-function:ease-in;width:100%}:host ::ng-deep .ng-select .ng-select-container:hover{box-shadow:0 1px 0 rgba(0,0,0,.06)}:host ::ng-deep .ng-select .ng-select-container .ng-value-container{align-items:center;overflow:hidden;padding-left:10px}:host ::ng-deep .ng-select .ng-select-container .ng-value-container .ng-placeholder{color:#aaa}:host ::ng-deep .ng-select.ng-select-single .ng-select-container{height:42px}:host ::ng-deep .ng-select.ng-select-single .ng-select-container .ng-value-container .ng-input{left:0;padding-left:10px;padding-right:50px;top:5px}:host ::ng-deep .ng-select.ng-select-multiple.ng-select-disabled>.ng-select-container .ng-value-container .ng-value{background-color:#f9f9f9;border:1px solid #e3e3e3}:host ::ng-deep .ng-select.ng-select-multiple.ng-select-disabled>.ng-select-container .ng-value-container .ng-value .ng-value-label{padding:0 5px}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container{padding-left:7px;padding-right:10px;padding-top:2px}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value{background-color:#e7faee;border:1px solid #93e8b3;border-radius:2px;display:flex;font-size:.9em;margin-bottom:5px;margin-right:5px;overflow:hidden}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value.ng-value-disabled{background-color:#f9f9f9;border:1px solid #e3e3e3}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value.ng-value-disabled .ng-value-label{padding-left:5px}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-label{display:inline-block;overflow:hidden;padding:0 5px;text-overflow:ellipsis}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon{display:inline-block;padding:0 5px}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon:hover{background-color:#93e8b3}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon.left{border-right:1px solid #93e8b3}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon.right{border-left:1px solid #c2e0ff}:host ::ng-deep .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-input{padding-bottom:3px;padding-left:3px}:host ::ng-deep ng-select.ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-placeholder{padding-bottom:3px;padding-left:3px;position:static;top:5px}:host ::ng-deep .ng-select .ng-clear-wrapper{color:#999}:host ::ng-deep .ng-select .ng-clear-wrapper .ng-clear:hover{color:#ff3c7e}:host ::ng-deep .ng-select .ng-spinner-zone{padding-right:5px;padding-top:5px}:host ::ng-deep .ng-select .ng-arrow-wrapper{padding-right:5px;width:25px}:host ::ng-deep .ng-select .ng-arrow-wrapper:hover .ng-arrow{border-top-color:#666}:host ::ng-deep .ng-select .ng-arrow-wrapper .ng-arrow{border-color:#999 transparent transparent;border-style:solid;border-width:5px 5px 2.5px}:host ::ng-deep .ng-dropdown-panel{background-color:#fff;border:1px solid #3ed778;box-shadow:0 1px 0 rgba(0,0,0,.06)}:host ::ng-deep .ng-dropdown-panel.ng-select-bottom{border-bottom-left-radius:4px;border-bottom-right-radius:4px;border-top-color:#e6e6e6;margin-top:-1px;top:100%}:host ::ng-deep .ng-dropdown-panel.ng-select-bottom .ng-dropdown-panel-items .ng-option:last-child{border-bottom-left-radius:4px;border-bottom-right-radius:4px}:host ::ng-deep .ng-dropdown-panel.ng-select-top{border-bottom-color:#e6e6e6;border-top-left-radius:4px;border-top-right-radius:4px;bottom:100%;margin-bottom:-1px}:host ::ng-deep .ng-dropdown-panel.ng-select-top .ng-dropdown-panel-items .ng-option:first-child{border-top-left-radius:4px;border-top-right-radius:4px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-header{border-bottom:1px solid #ccc;padding:5px 7px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-footer{border-top:1px solid #ccc;padding:5px 7px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items{margin-bottom:1px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-optgroup{-moz-user-select:none;-ms-user-select:none;-webkit-user-select:none;color:rgba(0,0,0,.54);cursor:default;cursor:pointer;font-weight:500;padding:8px 10px;user-select:none}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-optgroup.ng-option-disabled{cursor:default}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-optgroup.ng-option-marked{background-color:#ebf5ff}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-optgroup.ng-option-selected{background-color:#f5faff;font-weight:600}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option{background-color:#fff;color:rgba(0,0,0,.87);padding:8px 10px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-selected{background-color:#e7faee;color:#333}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-selected .ng-option-label{font-weight:600}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-marked{background-color:#e7faee;color:#333}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-disabled{color:#ccc}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-child{padding-left:22px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option .ng-tag-label{font-size:80%;font-weight:400;padding-right:5px}:host ::ng-deep ng-select.ng-select .ng-select-container .ng-value-container{padding-left:0}:host ::ng-deep ng-select.ng-select.ng-select-single .ng-select-container .ng-value-container .ng-input{color:#888da8;top:9px}:host ::ng-deep .ng-dropdown-panel .ng-dropdown-panel-items .ng-option,:host ::ng-deep .ng-select .ng-select-container .ng-value-container .ng-input>input{color:#888da8}:host ::ng-deep .ng-select.ng-select-auto-grow{max-width:inherit}:host ::ng-deep .ng-select.ng-select-auto-grow .ng-dropdown-panel{width:auto}"]
|
|
438
|
+
},] }
|
|
439
|
+
];
|
|
440
|
+
SelectComponent.ctorParameters = () => [
|
|
441
|
+
{ type: FormElementComponent, decorators: [{ type: Optional }, { type: Host }] },
|
|
442
|
+
{ type: ControlContainer, decorators: [{ type: Optional }, { type: Host }] }
|
|
443
|
+
];
|
|
444
|
+
SelectComponent.propDecorators = {
|
|
445
|
+
placeholder: [{ type: Input }],
|
|
446
|
+
options: [{ type: Input }],
|
|
447
|
+
multiple: [{ type: Input }],
|
|
448
|
+
clearable: [{ type: Input }],
|
|
449
|
+
dropdownPosition: [{ type: Input }],
|
|
450
|
+
customSearchFn: [{ type: Input }]
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
class SortableItemsComponent extends ValueAccessorBase {
|
|
454
|
+
constructor() {
|
|
455
|
+
super(...arguments);
|
|
456
|
+
this.sortableItemSize = 'lg';
|
|
457
|
+
this.itemsOrderChanged = () => {
|
|
458
|
+
this.setInnerValueAndNotify(this.innerValue);
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
SortableItemsComponent.decorators = [
|
|
463
|
+
{ type: Component, args: [{
|
|
464
|
+
selector: 'klp-form-sortable-items',
|
|
465
|
+
template: "<ng-template #listItem>\n\t<li *ngFor=\"let item of innerValue; index as index\"\n\t class=\"sortableItem\"\n\t [ngClass]=\"{\n\t\t\tlargeSortableItem: sortableItemSize === 'lg',\n\t\t \tsmallSortableItem: sortableItemSize === 'sm'\n\t\t }\"\n\t>\n\t\t<ng-container [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item, index:index }\" ></ng-container>\n\t</li>\n</ng-template>\n\n<ol *ngIf='!disabled'\n [sortablejs]=\"innerValue\"\n [sortablejsOptions]=\"{ onUpdate: itemsOrderChanged }\"\n class=\"itemsContainer\"\n>\n\t<ng-container *ngTemplateOutlet=\"listItem\"></ng-container>\n</ol>\n\n<ol *ngIf='disabled' class=\"itemsContainer disabled-mouse-cursor\">\n\t<ng-container *ngTemplateOutlet=\"listItem\"></ng-container>\n</ol>\n",
|
|
466
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: SortableItemsComponent, multi: true }],
|
|
467
|
+
styles: [":host{display:block}.itemsContainer{border:1px solid #e6ecf5;border-radius:5px;margin-bottom:0;padding:0}.sortableItem{border-top:1px solid #e6ecf5;cursor:-webkit-grab;cursor:grab;list-style:none}.sortableItem:hover{background:#f8f9fa}.sortableItem:first-child{border-top:none}.largeSortableItem{padding:15px}.smallSortableItem{padding:0 10px}.disabled-mouse-cursor li{cursor:no-drop}"]
|
|
468
|
+
},] }
|
|
469
|
+
];
|
|
470
|
+
SortableItemsComponent.propDecorators = {
|
|
471
|
+
template: [{ type: ContentChild, args: [TemplateRef,] }],
|
|
472
|
+
sortableItemSize: [{ type: Input }]
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
class TextInputComponent extends ValueAccessorBase {
|
|
476
|
+
constructor() {
|
|
477
|
+
super(...arguments);
|
|
478
|
+
this.type = 'text';
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
TextInputComponent.decorators = [
|
|
482
|
+
{ type: Component, args: [{
|
|
483
|
+
selector: 'klp-form-text-input',
|
|
484
|
+
template: "<input\n\t[type]=\"type\"\n\tclass=\"form-control\"\n\t[ngClass]=\"{showErrors: isInErrorState()}\"\n\t[(ngModel)]=\"innerValue\"\n\t(input)=\"setInnerValueAndNotify($event.target.value)\"\n\t[placeholder]=\"placeholder ? placeholder : ''\"\n\t(blur)=\"touch()\"\n\t[disabled]='disabled'\n/>\n",
|
|
485
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: TextInputComponent, multi: true }],
|
|
486
|
+
styles: [":host,input{display:block}input{-moz-transition:all .2s ease-in;-ms-transition:all .2s ease-in;-o-transition:all .2s ease-in;-webkit-transition:all .2s ease-in;border:1px solid #e6ecf5;border-radius:2px;box-shadow:none;color:#888da8;font-size:14px;height:42px;outline:none;padding:.375rem .625rem;transition:all .2s ease-in;width:100%}input::-webkit-input-placeholder{color:#adadad}input:-moz-placeholder,input::-moz-placeholder{color:#adadad}input:-ms-input-placeholder{color:#adadad}input:focus{border-color:#3ed778;box-shadow:none;outline:0 none}input.input-sm{height:30px}input.input-lg{height:50px}input.error{background-color:#ffeff4;border-color:#ff3c7e}input.valid{background-color:#ebfaeb;border-color:#37c936;color:#278d26}.showErrors{border-color:#ff8000}"]
|
|
487
|
+
},] }
|
|
488
|
+
];
|
|
489
|
+
TextInputComponent.propDecorators = {
|
|
490
|
+
placeholder: [{ type: Input }],
|
|
491
|
+
type: [{ type: Input }]
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
class ToggleComponent extends ValueAccessorBase {
|
|
495
|
+
}
|
|
496
|
+
ToggleComponent.decorators = [
|
|
497
|
+
{ type: Component, args: [{
|
|
498
|
+
selector: 'klp-form-toggle',
|
|
499
|
+
template: "<div class=\"componentContainer\" [ngClass]=\"{disabled: disabled}\">\n\t<input type=\"checkbox\" class=\"nativeCheckbox\"\n\t\t[(ngModel)]=\"innerValue\"\n\t\t(input)=\"setInnerValueAndNotify($event.target.checked); touch()\"\n\t\t[disabled]=\"disabled\"\n\t\t[ngClass]=\"{showErrors: isInErrorState()}\"\n\t/>\n\t<div class=\"toggleVisual\"></div>\n</div>\n",
|
|
500
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: ToggleComponent, multi: true }],
|
|
501
|
+
styles: [":host{display:block}.componentContainer{position:relative}.nativeCheckbox{cursor:pointer;height:20px;left:0;opacity:0;position:absolute;top:0;width:35px}.toggleVisual{-moz-transition:.4s ease;-ms-transition:.4s ease;-o-transition:.4s ease;-webkit-transition:.4s ease;border:1px solid #e6ecf5;border-radius:35px;display:block;height:20px;pointer-events:none;position:relative;transition:.4s ease;width:35px}.toggleVisual:before{-moz-transition:.2s cubic-bezier(.24,0,.5,1);-ms-transition:.2s cubic-bezier(.24,0,.5,1);-o-transition:.2s cubic-bezier(.24,0,.5,1);-webkit-transition:.2s cubic-bezier(.24,0,.5,1);border-radius:30px;height:18px;left:-1px;margin:1px;transition:.2s cubic-bezier(.24,0,.5,1);width:33px}.toggleVisual:after,.toggleVisual:before{content:\"\";display:block;position:absolute;top:-1px}.toggleVisual:after{-moz-transition:.35s cubic-bezier(.54,1.6,.5,1);-ms-transition:.35s cubic-bezier(.54,1.6,.5,1);-o-transition:.35s cubic-bezier(.54,1.6,.5,1);-webkit-transition:.35s cubic-bezier(.54,1.6,.5,1);background:#f7f7f7;border-radius:60px;box-shadow:0 0 0 1px rgba(0,0,0,.1),0 4px 0 0 rgba(0,0,0,.04),0 4px 9px rgba(0,0,0,.13),0 3px 3px rgba(0,0,0,.05);height:20px;left:0;transition:.35s cubic-bezier(.54,1.6,.5,1);width:20px}.nativeCheckbox:checked+.toggleVisual:before{-moz-transition:width .2s cubic-bezier(0,0,0,.1);-ms-transition:width .2s cubic-bezier(0,0,0,.1);-o-transition:width .2s cubic-bezier(0,0,0,.1);-webkit-transition:width .2s cubic-bezier(0,0,0,.1);background:#37c936;transition:width .2s cubic-bezier(0,0,0,.1)}.nativeCheckbox:checked+.toggleVisual:after{left:18px}.disabled{opacity:.6}.showErrors+.toggleVisual:before{border:1px solid #ff8000}"]
|
|
502
|
+
},] }
|
|
503
|
+
];
|
|
504
|
+
|
|
505
|
+
class FormCaptionComponent {
|
|
506
|
+
constructor(parent) {
|
|
507
|
+
this.parent = parent;
|
|
508
|
+
}
|
|
509
|
+
ngOnInit() {
|
|
510
|
+
// this is being run next cycle, because we dont want to fail if the order of components is as follows:
|
|
511
|
+
// <app-form-error />
|
|
512
|
+
// <some-input />
|
|
513
|
+
// That would fail, because the logic of the form error is run first, and at that moment, the `some-input` isnt registered yet
|
|
514
|
+
setTimeout(() => {
|
|
515
|
+
const attachedControl = this.parent.getAttachedControl();
|
|
516
|
+
this.parent.registerCaption(this.contentRef);
|
|
517
|
+
if (isNullOrUndefined(attachedControl)) {
|
|
518
|
+
throw new Error('You added a Form Caption component without an attached Form Control');
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
FormCaptionComponent.decorators = [
|
|
524
|
+
{ type: Component, args: [{
|
|
525
|
+
selector: 'klp-form-caption',
|
|
526
|
+
template: "<ng-template #contentRef>\n\t<ng-content></ng-content>\n</ng-template>\n",
|
|
527
|
+
styles: [":host{display:block}"]
|
|
528
|
+
},] }
|
|
529
|
+
];
|
|
530
|
+
FormCaptionComponent.ctorParameters = () => [
|
|
531
|
+
{ type: FormElementComponent, decorators: [{ type: Host }, { type: Optional }] }
|
|
532
|
+
];
|
|
533
|
+
FormCaptionComponent.propDecorators = {
|
|
534
|
+
contentRef: [{ type: ViewChild, args: ['contentRef',] }]
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
class FormErrorComponent {
|
|
538
|
+
constructor(parent) {
|
|
539
|
+
this.parent = parent;
|
|
540
|
+
this.showError = false;
|
|
541
|
+
}
|
|
542
|
+
ngOnInit() {
|
|
543
|
+
// this is being run next cycle, because we dont want to fail if the order of components is as follows:
|
|
544
|
+
// <app-form-error />
|
|
545
|
+
// <some-input />
|
|
546
|
+
// That would fail, because the logic of the form error is run first, and at that moment, the `some-input` isnt registered yet
|
|
547
|
+
setTimeout(() => {
|
|
548
|
+
const attachedControl = this.parent.getAttachedControl();
|
|
549
|
+
this.parent.registerErrorHandler(this.error, this.contentRef);
|
|
550
|
+
if (isNullOrUndefined(attachedControl)) {
|
|
551
|
+
throw new Error('You added a Form Error component without an attached Form Control');
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
FormErrorComponent.decorators = [
|
|
557
|
+
{ type: Component, args: [{
|
|
558
|
+
selector: 'klp-form-error',
|
|
559
|
+
template: "<ng-template #contentRef>\n\t<ng-content></ng-content>\n</ng-template>\n",
|
|
560
|
+
styles: [":host{display:block}"]
|
|
561
|
+
},] }
|
|
562
|
+
];
|
|
563
|
+
FormErrorComponent.ctorParameters = () => [
|
|
564
|
+
{ type: FormElementComponent, decorators: [{ type: Host }, { type: Optional }] }
|
|
565
|
+
];
|
|
566
|
+
FormErrorComponent.propDecorators = {
|
|
567
|
+
error: [{ type: Input }],
|
|
568
|
+
contentRef: [{ type: ViewChild, args: ['contentRef',] }]
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
class FormSubmitButtonComponent {
|
|
572
|
+
constructor(parentForm) {
|
|
573
|
+
this.parentForm = parentForm;
|
|
574
|
+
this.isLoading = false;
|
|
575
|
+
this.fullWidth = false;
|
|
576
|
+
this.variant = 'greenFilled';
|
|
577
|
+
}
|
|
578
|
+
get _() {
|
|
579
|
+
return this.fullWidth;
|
|
580
|
+
}
|
|
581
|
+
submitForm() {
|
|
582
|
+
this.parentForm
|
|
583
|
+
.trySubmit()
|
|
584
|
+
.then((value) => {
|
|
585
|
+
this.isLoading = true;
|
|
586
|
+
const submitCallbackResult = this.submitCallback(value);
|
|
587
|
+
if (isNullOrUndefined(submitCallbackResult)) {
|
|
588
|
+
throw new Error('No promise is returned in your submit function.');
|
|
589
|
+
}
|
|
590
|
+
return submitCallbackResult.then(() => (this.isLoading = false)).catch((e) => {
|
|
591
|
+
this.isLoading = false;
|
|
592
|
+
throw e;
|
|
593
|
+
});
|
|
594
|
+
})
|
|
595
|
+
.catch((e) => {
|
|
596
|
+
if (e === invalidFieldsSymbol) {
|
|
597
|
+
return; // swallow the error, the framework will scroll to the field that needs attention
|
|
598
|
+
}
|
|
599
|
+
throw e;
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
FormSubmitButtonComponent.decorators = [
|
|
604
|
+
{ type: Component, args: [{
|
|
605
|
+
selector: 'klp-form-submit-button',
|
|
606
|
+
template: "<klp-form-button\n\t\t[variant]=\"variant\"\n\t\t(click)=\"submitForm()\"\n\t\t[disabled]=\"isLoading\"\n\t\t[isLoading]=\"isLoading\"\n\t\t[fullWidth]=\"fullWidth\"\n\t\ttype=\"submit\"\n\t\t[ngClass]=\"fullWidth ? 'fullWidth' : ''\"\n\t>\n\t<ng-content></ng-content>\n</klp-form-button>\n",
|
|
607
|
+
styles: [":host{display:inline-block}:host._fullWidth{display:block}.fullWidth{width:100%}"]
|
|
608
|
+
},] }
|
|
609
|
+
];
|
|
610
|
+
FormSubmitButtonComponent.ctorParameters = () => [
|
|
611
|
+
{ type: FormComponent, decorators: [{ type: Host }, { type: Optional }] }
|
|
612
|
+
];
|
|
613
|
+
FormSubmitButtonComponent.propDecorators = {
|
|
614
|
+
isLoading: [{ type: Input }],
|
|
615
|
+
fullWidth: [{ type: Input }],
|
|
616
|
+
variant: [{ type: Input }],
|
|
617
|
+
submitCallback: [{ type: Input }],
|
|
618
|
+
_: [{ type: HostBinding, args: ['class._fullWidth',] }]
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
const invalidDateKey = '--invalid_date--';
|
|
622
|
+
function dateValidator(control) {
|
|
623
|
+
const invalid = control.value === invalidDateKey;
|
|
624
|
+
return invalid ? { date: control.value } : null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const KLP_DATE_FORMATS = new InjectionToken('klp.form.date.formats');
|
|
628
|
+
function matDateFormatsFactory(component, dateFormats) {
|
|
629
|
+
var _a;
|
|
630
|
+
return (_a = dateFormats === null || dateFormats === void 0 ? void 0 : dateFormats(component.format)) !== null && _a !== void 0 ? _a : MAT_NATIVE_DATE_FORMATS;
|
|
631
|
+
}
|
|
632
|
+
class DatepickerComponent extends ValueAccessorBase {
|
|
633
|
+
constructor() {
|
|
634
|
+
super(...arguments);
|
|
635
|
+
this.minDate = undefined;
|
|
636
|
+
this.maxDate = undefined;
|
|
637
|
+
this.placeholder = 'Select date';
|
|
638
|
+
this.clearable = false;
|
|
639
|
+
this.minDateStartOfDay = undefined;
|
|
640
|
+
this.maxDateEndOfDay = undefined;
|
|
641
|
+
}
|
|
642
|
+
ngOnChanges(changes) {
|
|
643
|
+
if (changes.minDate) {
|
|
644
|
+
this.setMinDate(changes.minDate.currentValue);
|
|
645
|
+
}
|
|
646
|
+
if (changes.maxDate) {
|
|
647
|
+
this.setMaxDate(changes.maxDate.currentValue);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
setMinDate(minDate) {
|
|
651
|
+
if (minDate) {
|
|
652
|
+
this.minDateStartOfDay = new Date(minDate);
|
|
653
|
+
this.minDateStartOfDay.setHours(0, 0, 0, 0);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
this.minDateStartOfDay = undefined;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
setMaxDate(maxDate) {
|
|
660
|
+
if (maxDate) {
|
|
661
|
+
this.maxDateEndOfDay = new Date(maxDate);
|
|
662
|
+
this.maxDateEndOfDay.setHours(23, 59, 59, 999);
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
this.maxDateEndOfDay = undefined;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
// dateChanged is called when the output of the datepicker is changed and
|
|
669
|
+
// parsed correctly. If the date is invalid, it will be called the first time
|
|
670
|
+
// with null but never again until a valid input is provided.
|
|
671
|
+
dateChanged(event) {
|
|
672
|
+
const nativeInputValue = this.nativeInputRef.nativeElement.value;
|
|
673
|
+
const date = event.value;
|
|
674
|
+
if (isNullOrUndefined(date) && stringIsSetAndNotEmpty(nativeInputValue)) {
|
|
675
|
+
this.setInnerValueAndNotify(invalidDateKey);
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
this.setInnerValueAndNotify(date);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
writeValue(value) {
|
|
682
|
+
super.writeValue(value);
|
|
683
|
+
this.valueForMaterialDatePicker = value === invalidDateKey ? null : value;
|
|
684
|
+
}
|
|
685
|
+
// nativeValueChanged is called when the internal text value changes, but not
|
|
686
|
+
// when the date is changed via the date picker. We need this so that we can
|
|
687
|
+
// determine if the datepicker is empty or invalid.
|
|
688
|
+
nativeValueChanged(event) {
|
|
689
|
+
const nativeInputValue = event.target.value;
|
|
690
|
+
const date = this.valueForMaterialDatePicker;
|
|
691
|
+
if (this.datePickerRef.opened) {
|
|
692
|
+
// if the user is typing instead of using the picker, close it.
|
|
693
|
+
this.datePickerRef.close();
|
|
694
|
+
}
|
|
695
|
+
if (isNullOrUndefined(date) && stringIsSetAndNotEmpty(nativeInputValue)) {
|
|
696
|
+
this.setInnerValueAndNotify(invalidDateKey);
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
this.setInnerValueAndNotify(date);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
resetToNull() {
|
|
703
|
+
this.setInnerValueAndNotify(null);
|
|
704
|
+
this.valueForMaterialDatePicker = null;
|
|
705
|
+
this.nativeInputRef.nativeElement.value = null;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
DatepickerComponent.decorators = [
|
|
709
|
+
{ type: Component, args: [{
|
|
710
|
+
selector: 'klp-form-datepicker',
|
|
711
|
+
template: "<div class=\"componentContainer\" [ngClass]=\"{showErrors: isInErrorState()}\">\n\t<mat-form-field [floatLabel]=\"'never'\">\n\t\t<input\n\t\t\t#nativeInput\n\t\t\tmatInput\n\t\t\t[matDatepicker]=\"picker\"\n\t\t\t[(ngModel)]=\"valueForMaterialDatePicker\"\n\t\t\t(dateInput)=\"dateChanged($event)\"\n\t\t\t(input)=\"nativeValueChanged($event)\"\n\t\t\t[min]=\"minDateStartOfDay\"\n\t\t\t[max]=\"maxDateEndOfDay\"\n\t\t\t[placeholder]=\"placeholder\"\n\t\t\t(click)=\"picker.open()\"\n\t\t\t(blur)=\"touch()\"\n\t\t>\n\t\t<mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\n\t\t<mat-datepicker #picker\n\t\t></mat-datepicker>\n\t</mat-form-field>\n\t<button *ngIf=\"clearable\" class=\"clearButton\" (click)=\"resetToNull()\">\u00D7</button>\n</div>\n",
|
|
712
|
+
providers: [
|
|
713
|
+
{ provide: NG_VALUE_ACCESSOR, useExisting: DatepickerComponent, multi: true },
|
|
714
|
+
{ provide: MAT_DATE_FORMATS,
|
|
715
|
+
deps: [DatepickerComponent, [new Optional(), KLP_DATE_FORMATS]],
|
|
716
|
+
useFactory: matDateFormatsFactory,
|
|
717
|
+
}
|
|
718
|
+
],
|
|
719
|
+
styles: [":host{display:block}:host ::ng-deep mat-form-field{display:block;height:100%}:host ::ng-deep mat-form-field.mat-focused .mat-form-field-label,:host ::ng-deep mat-form-field .mat-form-field-label{color:#adadad}:host ::ng-deep .mat-datepicker-toggle-active{color:#666}:host ::ng-deep .mat-form-field-wrapper{padding-bottom:none}:host ::ng-deep .mat-form-field-flex{flex-direction:row-reverse}:host ::ng-deep .mat-form-field-infix{border-top:none}:host ::ng-deep .mat-form-field-suffix{margin-right:.625rem}:host ::ng-deep .mat-form-field-suffix:hover .mat-button-focus-overlay{opacity:.1}:host ::ng-deep .mat-form-field-underline{display:none}.componentContainer{-moz-transition:all .2s ease-in;-ms-transition:all .2s ease-in;-o-transition:all .2s ease-in;-webkit-transition:all .2s ease-in;border:1px solid #e6ecf5;border-radius:2px;box-shadow:none;color:#888da8;display:block;font-size:14px;height:42px;padding:.375rem .625rem;position:relative;transition:all .2s ease-in;width:100%}.componentContainer::-webkit-input-placeholder{color:#adadad}.componentContainer:-moz-placeholder,.componentContainer::-moz-placeholder{color:#adadad}.componentContainer:-ms-input-placeholder{color:#adadad}.componentContainer:focus{border-color:#3ed778;box-shadow:none;outline:0 none}.componentContainer.input-sm{height:30px}.componentContainer.input-lg{height:50px}.componentContainer.error{background-color:#ffeff4;border-color:#ff3c7e}.componentContainer.valid{background-color:#ebfaeb;border-color:#37c936;color:#278d26}.componentContainer.showErrors{border-color:#ff8000}.componentContainer .clearButton{align-items:center;background:none;border:none;bottom:0;color:#7b7b7b;display:flex;font-size:18px;position:absolute;right:1.25rem;top:0}"]
|
|
720
|
+
},] }
|
|
721
|
+
];
|
|
722
|
+
DatepickerComponent.propDecorators = {
|
|
723
|
+
minDate: [{ type: Input }],
|
|
724
|
+
maxDate: [{ type: Input }],
|
|
725
|
+
format: [{ type: Input }],
|
|
726
|
+
placeholder: [{ type: Input }],
|
|
727
|
+
clearable: [{ type: Input }],
|
|
728
|
+
nativeInputRef: [{ type: ViewChild, args: ['nativeInput',] }],
|
|
729
|
+
datePickerRef: [{ type: ViewChild, args: ['picker',] }]
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
// material.module.ts
|
|
733
|
+
class MaterialModule {
|
|
734
|
+
}
|
|
735
|
+
MaterialModule.decorators = [
|
|
736
|
+
{ type: NgModule, args: [{
|
|
737
|
+
imports: [MatDatepickerModule, MatFormFieldModule, MatNativeDateModule, MatInputModule, MatButtonModule],
|
|
738
|
+
exports: [MatDatepickerModule, MatFormFieldModule, MatNativeDateModule, MatInputModule, MatButtonModule],
|
|
739
|
+
providers: [MatDatepickerModule],
|
|
740
|
+
},] }
|
|
741
|
+
];
|
|
742
|
+
|
|
743
|
+
class NgxEnhancyFormsModule {
|
|
744
|
+
}
|
|
745
|
+
NgxEnhancyFormsModule.decorators = [
|
|
746
|
+
{ type: NgModule, args: [{
|
|
747
|
+
imports: [
|
|
748
|
+
CommonModule,
|
|
749
|
+
FormsModule,
|
|
750
|
+
NgSelectModule,
|
|
751
|
+
SortablejsModule,
|
|
752
|
+
MaterialModule,
|
|
753
|
+
],
|
|
754
|
+
declarations: [
|
|
755
|
+
ValueAccessorBase,
|
|
756
|
+
ButtonComponent,
|
|
757
|
+
CheckboxComponent,
|
|
758
|
+
DatepickerComponent,
|
|
759
|
+
EmailInputComponent,
|
|
760
|
+
LoadingIndicatorComponent,
|
|
761
|
+
NumberInputComponent,
|
|
762
|
+
PasswordFieldComponent,
|
|
763
|
+
SelectComponent,
|
|
764
|
+
SortableItemsComponent,
|
|
765
|
+
TextInputComponent,
|
|
766
|
+
ToggleComponent,
|
|
767
|
+
FormCaptionComponent,
|
|
768
|
+
FormElementComponent,
|
|
769
|
+
FormErrorComponent,
|
|
770
|
+
FormSubmitButtonComponent,
|
|
771
|
+
FormComponent,
|
|
772
|
+
],
|
|
773
|
+
exports: [
|
|
774
|
+
ValueAccessorBase,
|
|
775
|
+
ButtonComponent,
|
|
776
|
+
DatepickerComponent,
|
|
777
|
+
CheckboxComponent,
|
|
778
|
+
EmailInputComponent,
|
|
779
|
+
LoadingIndicatorComponent,
|
|
780
|
+
NumberInputComponent,
|
|
781
|
+
PasswordFieldComponent,
|
|
782
|
+
SelectComponent,
|
|
783
|
+
SortableItemsComponent,
|
|
784
|
+
TextInputComponent,
|
|
785
|
+
ToggleComponent,
|
|
786
|
+
FormCaptionComponent,
|
|
787
|
+
FormElementComponent,
|
|
788
|
+
FormErrorComponent,
|
|
789
|
+
FormSubmitButtonComponent,
|
|
790
|
+
FormComponent,
|
|
791
|
+
]
|
|
792
|
+
},] }
|
|
793
|
+
];
|
|
794
|
+
|
|
795
|
+
/*
|
|
796
|
+
* Public API Surface of ngx-enhancy-forms
|
|
797
|
+
*/
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Generated bundle index. Do not edit.
|
|
801
|
+
*/
|
|
802
|
+
|
|
803
|
+
export { ButtonComponent, CheckboxComponent, DEFAULT_ERROR_MESSAGES, DatepickerComponent, EmailInputComponent, FORM_ERROR_MESSAGES, FormCaptionComponent, FormComponent, FormElementComponent, FormErrorComponent, FormSubmitButtonComponent, KLP_DATE_FORMATS, LoadingIndicatorComponent, NgxEnhancyFormsModule, NumberInputComponent, PasswordFieldComponent, SelectComponent, SortableItemsComponent, TextInputComponent, ToggleComponent, ValueAccessorBase, dateValidator, invalidDateKey, invalidFieldsSymbol, matDateFormatsFactory, MaterialModule as ɵa };
|
|
804
|
+
//# sourceMappingURL=klippa-ngx-enhancy-forms.js.map
|