special-forms 1.0.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/.editorconfig +16 -0
- package/.storybook/db-theme.js +8 -0
- package/.storybook/main.js +15 -0
- package/.storybook/manager.js +7 -0
- package/.storybook/preview-head.html +16 -0
- package/.storybook/preview.js +20 -0
- package/.storybook/tsconfig.json +21 -0
- package/.storybook/typings.d.ts +4 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +20 -0
- package/.vscode/tasks.json +42 -0
- package/README.md +27 -0
- package/angular.json +38 -0
- package/documentation.json +10829 -0
- package/package.json +65 -0
- package/projects/special-forms/README.md +24 -0
- package/projects/special-forms/karma.conf.js +44 -0
- package/projects/special-forms/ng-package.json +7 -0
- package/projects/special-forms/package.json +11 -0
- package/projects/special-forms/src/lib/assets/styles.scss +213 -0
- package/projects/special-forms/src/lib/assets/themes/dark.scss +80 -0
- package/projects/special-forms/src/lib/assets/themes/light.scss +78 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-selector/form-control-selector.component.html +5 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-selector/form-control-selector.component.scss +6 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-selector/form-control-selector.component.spec.ts +21 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-selector/form-control-selector.component.ts +21 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-selector/form-control-selector.module.ts +36 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-viewer/form-control-viewer.component.html +5 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-viewer/form-control-viewer.component.scss +18 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-viewer/form-control-viewer.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-viewer/form-control-viewer.component.ts +66 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-control-viewer/form-control-viewer.module.ts +16 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/control-dialog.component.html +31 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/control-dialog.component.scss +0 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/control-dialog.component.spec.ts +22 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/control-dialog.component.ts +102 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/autocomplete.form.ts +87 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/checkbox.form.ts +51 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/common.form.interface.ts +24 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/common.form.ts +31 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/datepicker.form.ts +56 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/dropdown.form.ts +80 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/field.form.ts +189 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/input.form.ts +71 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/label.form.ts +33 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/text-area.form.ts +17 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/components/settings-strategy/upload.form.ts +35 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/form-group-viewer.component.html +37 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/form-group-viewer.component.scss +41 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/form-group-viewer.component.spec.ts +22 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/form-group-viewer.component.ts +95 -0
- package/projects/special-forms/src/lib/aux-storybook-components/form-group-viewer/form-group-viewer.module.ts +32 -0
- package/projects/special-forms/src/lib/components/index.ts +61 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.component.html +62 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.component.spec.ts +24 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.component.ts +58 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.interface.ts +20 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.module.ts +25 -0
- package/projects/special-forms/src/lib/components/special-autocomplete/special-autocomplete.stories.ts +81 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.component.html +17 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.component.ts +19 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.interface.ts +12 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.module.ts +25 -0
- package/projects/special-forms/src/lib/components/special-checkbox/special-checkbox.stories.ts +76 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.component.html +26 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.component.ts +21 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.interface.ts +13 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.module.ts +26 -0
- package/projects/special-forms/src/lib/components/special-datepicker/special-datepicker.stories.ts +69 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.component.html +41 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.component.scss +15 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.component.spec.ts +24 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.component.ts +34 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.interface.ts +18 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.module.ts +22 -0
- package/projects/special-forms/src/lib/components/special-dropdown/special-dropdown.stories.ts +83 -0
- package/projects/special-forms/src/lib/components/special-form/special-form-array.component.html +208 -0
- package/projects/special-forms/src/lib/components/special-form/special-form-array.component.scss +70 -0
- package/projects/special-forms/src/lib/components/special-form/special-form-array.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-form/special-form-array.module.ts +18 -0
- package/projects/special-forms/src/lib/components/special-form/special-form.component.html +20 -0
- package/projects/special-forms/src/lib/components/special-form/special-form.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-form/special-form.component.spec.ts +22 -0
- package/projects/special-forms/src/lib/components/special-form/special-form.component.ts +85 -0
- package/projects/special-forms/src/lib/components/special-form/special-form.module.ts +40 -0
- package/projects/special-forms/src/lib/components/special-form/special-form.stories.ts +45 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.component.html +37 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.component.ts +39 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.interface.ts +17 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.module.ts +24 -0
- package/projects/special-forms/src/lib/components/special-input/special-input.stories.ts +91 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.component.html +6 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.component.ts +27 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.interface.ts +14 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.module.ts +25 -0
- package/projects/special-forms/src/lib/components/special-label/special-label.stories.ts +99 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.component.html +82 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.component.ts +86 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.interface.ts +20 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.module.ts +28 -0
- package/projects/special-forms/src/lib/components/special-multiple-autocomplete/special-multiple-autocomplete.stories.ts +81 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.component.html +29 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.component.scss +3 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.component.ts +20 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.interface.ts +9 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.module.ts +24 -0
- package/projects/special-forms/src/lib/components/special-text-area/special-text-area.stories.ts +69 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.component.html +50 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.component.scss +29 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.component.spec.ts +23 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.component.ts +79 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.interface.ts +12 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.module.ts +23 -0
- package/projects/special-forms/src/lib/components/special-upload/special-upload.stories.ts +81 -0
- package/projects/special-forms/src/lib/core/aux-data/all-icons.ts +99 -0
- package/projects/special-forms/src/lib/core/aux-data/control-types.enum.ts +16 -0
- package/projects/special-forms/src/lib/core/aux-data/countries.ts +247 -0
- package/projects/special-forms/src/lib/core/aux-data/field-basic-data.ts +14 -0
- package/projects/special-forms/src/lib/core/aux-data/input-types.ts +23 -0
- package/projects/special-forms/src/lib/core/controls/icons.control.ts +8 -0
- package/projects/special-forms/src/lib/core/controls/index.ts +2 -0
- package/projects/special-forms/src/lib/core/controls/theme.control.ts +1 -0
- package/projects/special-forms/src/lib/core/controls/types.control.ts +9 -0
- package/projects/special-forms/src/lib/core/directives/control-render.directive.ts +19 -0
- package/projects/special-forms/src/lib/core/directives/control-render.module.ts +10 -0
- package/projects/special-forms/src/lib/core/forms/special-forms.ts +395 -0
- package/projects/special-forms/src/lib/core/interfaces/field-basics.interfaces.ts +22 -0
- package/projects/special-forms/src/lib/core/interfaces/form.interfaces.ts +83 -0
- package/projects/special-forms/src/lib/core/interfaces/special-control.interface.ts +9 -0
- package/projects/special-forms/src/lib/core/masks/currency.mask.ts +11 -0
- package/projects/special-forms/src/lib/core/masks/maks.enum.ts +12 -0
- package/projects/special-forms/src/lib/core/masks/number.mask.ts +4 -0
- package/projects/special-forms/src/lib/core/services/index.ts +3 -0
- package/projects/special-forms/src/lib/core/services/special-form-builder/special-form-builder.service.spec.ts +16 -0
- package/projects/special-forms/src/lib/core/services/special-form-builder/special-form-builder.service.ts +220 -0
- package/projects/special-forms/src/lib/core/utils/enum-to-array.util.ts +6 -0
- package/projects/special-forms/src/lib/pipes/controls-list-pipe/controls-list.pipe.module.ts +10 -0
- package/projects/special-forms/src/lib/pipes/controls-list-pipe/controls-list.pipe.ts +17 -0
- package/projects/special-forms/src/lib/pipes/error-message-pipe/error.pipe.module.ts +13 -0
- package/projects/special-forms/src/lib/pipes/error-message-pipe/error.pipe.ts +21 -0
- package/projects/special-forms/src/lib/pipes/index.ts +3 -0
- package/projects/special-forms/src/lib/pipes/text-by-function/text-by-function.pipe.module.ts +13 -0
- package/projects/special-forms/src/lib/pipes/text-by-function/text-by-function.pipe.ts +14 -0
- package/projects/special-forms/src/public-api.ts +8 -0
- package/projects/special-forms/src/test.ts +27 -0
- package/projects/special-forms/tsconfig.lib.json +15 -0
- package/projects/special-forms/tsconfig.lib.prod.json +10 -0
- package/projects/special-forms/tsconfig.spec.json +17 -0
- package/scss-bundle.config.json +6 -0
- package/stories/Button.stories.ts +42 -0
- package/stories/Header.stories.ts +35 -0
- package/stories/Introduction.stories.mdx +211 -0
- package/stories/Page.stories.ts +36 -0
- package/stories/User.ts +2 -0
- package/stories/assets/code-brackets.svg +1 -0
- package/stories/assets/colors.svg +1 -0
- package/stories/assets/comments.svg +1 -0
- package/stories/assets/direction.svg +1 -0
- package/stories/assets/flow.svg +1 -0
- package/stories/assets/plugin.svg +1 -0
- package/stories/assets/repo.svg +1 -0
- package/stories/assets/stackalt.svg +1 -0
- package/stories/button.component.ts +53 -0
- package/stories/button.css +30 -0
- package/stories/header.component.ts +75 -0
- package/stories/header.css +32 -0
- package/stories/page.component.ts +77 -0
- package/stories/page.css +69 -0
- package/tailwind.config.js +30 -0
- package/tsconfig.json +39 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { AbstractControl, ValidatorFn, Validators } from '@angular/forms';
|
|
3
|
+
import { IAutocompleteSettings } from '../../../components/special-autocomplete/special-autocomplete.interface';
|
|
4
|
+
import { EControlTypes } from '../../aux-data/control-types.enum';
|
|
5
|
+
import {
|
|
6
|
+
SpecialFormArray,
|
|
7
|
+
SpecialFormControl,
|
|
8
|
+
SpecialFormGroup,
|
|
9
|
+
} from '../../forms/special-forms';
|
|
10
|
+
import { IFieldData } from '../../interfaces/field-basics.interfaces';
|
|
11
|
+
import {
|
|
12
|
+
IFormStructure,
|
|
13
|
+
TRawFields,
|
|
14
|
+
TSpecialArray,
|
|
15
|
+
TSpecialFields,
|
|
16
|
+
TSpecialForm,
|
|
17
|
+
TSpecialInput,
|
|
18
|
+
} from '../../interfaces/form.interfaces';
|
|
19
|
+
|
|
20
|
+
interface IControlParams {
|
|
21
|
+
name: string;
|
|
22
|
+
control: SpecialFormArray | SpecialFormGroup | SpecialFormControl<any>;
|
|
23
|
+
}
|
|
24
|
+
@Injectable({
|
|
25
|
+
providedIn: 'root',
|
|
26
|
+
})
|
|
27
|
+
export class SpecialFormBuilderService {
|
|
28
|
+
private readonly defectField: IFieldData = {
|
|
29
|
+
asyncValidators: null,
|
|
30
|
+
validators: null,
|
|
31
|
+
defaultValue: null,
|
|
32
|
+
elementId: '',
|
|
33
|
+
hidden: false,
|
|
34
|
+
icon: '',
|
|
35
|
+
label: '',
|
|
36
|
+
disabled: false,
|
|
37
|
+
length: 0,
|
|
38
|
+
placeholder: '',
|
|
39
|
+
readOnly: false,
|
|
40
|
+
required: false,
|
|
41
|
+
styleClasses: '',
|
|
42
|
+
errorMessages: {},
|
|
43
|
+
tooltip: '',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
private readonly inputDefectField: TSpecialInput = {
|
|
47
|
+
...this.defectField,
|
|
48
|
+
settings: {},
|
|
49
|
+
type: EControlTypes.input,
|
|
50
|
+
name: '',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
private readonly formDefectField: TSpecialForm = {
|
|
54
|
+
...this.defectField,
|
|
55
|
+
settings: {
|
|
56
|
+
formFields: {},
|
|
57
|
+
},
|
|
58
|
+
type: EControlTypes.form,
|
|
59
|
+
name: '',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
private readonly arrayDefectField: TSpecialArray = {
|
|
63
|
+
...this.defectField,
|
|
64
|
+
settings: {
|
|
65
|
+
formFields: {},
|
|
66
|
+
},
|
|
67
|
+
type: EControlTypes.array,
|
|
68
|
+
name: '',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
constructor() {}
|
|
72
|
+
|
|
73
|
+
public control(field: Partial<TSpecialFields>): SpecialFormControl<any> {
|
|
74
|
+
const formField: TSpecialFields = {
|
|
75
|
+
...this.inputDefectField,
|
|
76
|
+
...field,
|
|
77
|
+
} as TSpecialFields;
|
|
78
|
+
const { control } = this.setFormControl(formField);
|
|
79
|
+
return control;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public group(
|
|
83
|
+
fields: IFormStructure,
|
|
84
|
+
parentField: Partial<TSpecialForm> = {}
|
|
85
|
+
) {
|
|
86
|
+
return this.formGenerator(this.fieldDataToArray(fields), parentField);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public array() {}
|
|
90
|
+
|
|
91
|
+
public fieldDataToArray(fields: IFormStructure): TSpecialFields[] {
|
|
92
|
+
return Object.entries(fields).map(([name, field]) =>
|
|
93
|
+
this.setDefectFieldOptions(name, field)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private setDefectFieldOptions(
|
|
98
|
+
name: string,
|
|
99
|
+
field: Partial<TRawFields>
|
|
100
|
+
): TSpecialFields {
|
|
101
|
+
return {
|
|
102
|
+
...this.inputDefectField,
|
|
103
|
+
...field,
|
|
104
|
+
name,
|
|
105
|
+
} as TSpecialFields;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private formGenerator(
|
|
109
|
+
fields: TSpecialFields[],
|
|
110
|
+
parentField: Partial<TSpecialForm> = {}
|
|
111
|
+
): SpecialFormGroup {
|
|
112
|
+
const formField: TSpecialForm = {
|
|
113
|
+
...this.formDefectField,
|
|
114
|
+
...parentField,
|
|
115
|
+
};
|
|
116
|
+
const structure = fields
|
|
117
|
+
.map((field) => this.getControlAndNameByType(field))
|
|
118
|
+
.reduce(
|
|
119
|
+
(prev, { name, control }: IControlParams) => ({
|
|
120
|
+
...prev,
|
|
121
|
+
[name]: control,
|
|
122
|
+
}),
|
|
123
|
+
{}
|
|
124
|
+
);
|
|
125
|
+
return new SpecialFormGroup(formField, structure);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private getControlAndNameByType(field: TSpecialFields) {
|
|
129
|
+
switch (field.type) {
|
|
130
|
+
case EControlTypes.array:
|
|
131
|
+
return this.setFormArray(field);
|
|
132
|
+
case EControlTypes.form:
|
|
133
|
+
return this.setFormGroup(field);
|
|
134
|
+
default:
|
|
135
|
+
return this.setFormControl(field);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private setFormGroup(field: TSpecialForm): {
|
|
140
|
+
name: string;
|
|
141
|
+
control: SpecialFormGroup;
|
|
142
|
+
} {
|
|
143
|
+
const control = this.formGenerator(
|
|
144
|
+
this.fieldDataToArray(field.settings.formFields),
|
|
145
|
+
field
|
|
146
|
+
);
|
|
147
|
+
return { control, name: field.name };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private setFormArray(field: TSpecialArray): {
|
|
151
|
+
name: string;
|
|
152
|
+
control: SpecialFormArray;
|
|
153
|
+
} {
|
|
154
|
+
const auxForm = (value = {}) => {
|
|
155
|
+
const auxForm = this.formGenerator(
|
|
156
|
+
this.fieldDataToArray(field.settings.formFields),
|
|
157
|
+
{}
|
|
158
|
+
);
|
|
159
|
+
auxForm.reset(value);
|
|
160
|
+
return auxForm;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
if (field.required) {
|
|
164
|
+
field.validators = this.setValidatorsArray(field.validators, [
|
|
165
|
+
this.arrayLengthRequired,
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
name: field.name,
|
|
171
|
+
control: new SpecialFormArray(field, auxForm, []),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private setFormControl(field: TSpecialFields): {
|
|
176
|
+
name: string;
|
|
177
|
+
control: SpecialFormControl<any>;
|
|
178
|
+
} {
|
|
179
|
+
const validators: ValidatorFn[] = [];
|
|
180
|
+
|
|
181
|
+
if (field.required) validators.push(this.setRequiredValidator(field));
|
|
182
|
+
if (field.length) validators.push(Validators.maxLength(field.length));
|
|
183
|
+
|
|
184
|
+
field.validators = this.setValidatorsArray(field.validators, validators);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
name: field.name,
|
|
188
|
+
control: new SpecialFormControl(field),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private setRequiredValidator(field: TSpecialFields): ValidatorFn {
|
|
193
|
+
if (field.type !== EControlTypes.autocomplete) {
|
|
194
|
+
return Validators.required;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return (control: SpecialFormControl<IAutocompleteSettings>) =>
|
|
198
|
+
!!control.value && control.value instanceof Object
|
|
199
|
+
? null
|
|
200
|
+
: { required: true };
|
|
201
|
+
}
|
|
202
|
+
private setValidatorsArray(
|
|
203
|
+
validators: ValidatorFn | ValidatorFn[] | null,
|
|
204
|
+
newValidators: ValidatorFn[]
|
|
205
|
+
): ValidatorFn[] {
|
|
206
|
+
if (!validators) {
|
|
207
|
+
return newValidators;
|
|
208
|
+
}
|
|
209
|
+
return validators instanceof Array
|
|
210
|
+
? [...validators, ...newValidators]
|
|
211
|
+
: [validators, ...newValidators];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private arrayLengthRequired(control: AbstractControl) {
|
|
215
|
+
if (control.value.length) {
|
|
216
|
+
return {};
|
|
217
|
+
}
|
|
218
|
+
return { noItems: 'NO_SELECTED_ITEM' };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import { NgModule } from '@angular/core';
|
|
3
|
+
import { FormControlsListPipe } from './controls-list.pipe';
|
|
4
|
+
|
|
5
|
+
@NgModule({
|
|
6
|
+
declarations: [FormControlsListPipe],
|
|
7
|
+
imports: [CommonModule],
|
|
8
|
+
exports: [FormControlsListPipe],
|
|
9
|
+
})
|
|
10
|
+
export class FormControlsListPipeModule {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
import { AbstractControl } from '@angular/forms';
|
|
3
|
+
import {
|
|
4
|
+
SpecialFormControl,
|
|
5
|
+
} from '../../core/forms/special-forms';
|
|
6
|
+
|
|
7
|
+
@Pipe({ name: 'controlsList' })
|
|
8
|
+
export class FormControlsListPipe implements PipeTransform {
|
|
9
|
+
transform(controls: {
|
|
10
|
+
[key: string]: AbstractControl;
|
|
11
|
+
}): SpecialFormControl<any>[] {
|
|
12
|
+
if (!controls) return [];
|
|
13
|
+
return Object.values(controls)
|
|
14
|
+
.filter((control: SpecialFormControl<any>) => !control.hidden)
|
|
15
|
+
.map((control) => control as SpecialFormControl<any>);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CommonModule } from "@angular/common";
|
|
2
|
+
import { NgModule } from "@angular/core";
|
|
3
|
+
import { ErrorMessagePipe } from "./error.pipe";
|
|
4
|
+
|
|
5
|
+
@NgModule({
|
|
6
|
+
declarations: [ErrorMessagePipe],
|
|
7
|
+
imports: [
|
|
8
|
+
CommonModule,
|
|
9
|
+
|
|
10
|
+
],
|
|
11
|
+
exports: [ErrorMessagePipe],
|
|
12
|
+
})
|
|
13
|
+
export class ErrorMessagePipeModule {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from "@angular/core";
|
|
2
|
+
import { FormControl } from "@angular/forms";
|
|
3
|
+
|
|
4
|
+
@Pipe({
|
|
5
|
+
name: "errorMessage",
|
|
6
|
+
})
|
|
7
|
+
export class ErrorMessagePipe implements PipeTransform {
|
|
8
|
+
transform(
|
|
9
|
+
errorsObj: { [key: string]: any },
|
|
10
|
+
errorMessages: { [key: string]: any },
|
|
11
|
+
control?: FormControl
|
|
12
|
+
): any {
|
|
13
|
+
const errors = errorsObj ? Object.keys(errorsObj) : [];
|
|
14
|
+
const error = errors[0];
|
|
15
|
+
const message = errorMessages[error] || error;
|
|
16
|
+
if (control) {
|
|
17
|
+
control.setErrors(errorsObj);
|
|
18
|
+
}
|
|
19
|
+
return message;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CommonModule } from "@angular/common";
|
|
2
|
+
import { NgModule } from "@angular/core";
|
|
3
|
+
import { TextByFunctionPipe } from "./text-by-function.pipe";
|
|
4
|
+
|
|
5
|
+
@NgModule({
|
|
6
|
+
declarations: [TextByFunctionPipe],
|
|
7
|
+
imports: [
|
|
8
|
+
CommonModule,
|
|
9
|
+
|
|
10
|
+
],
|
|
11
|
+
exports: [TextByFunctionPipe],
|
|
12
|
+
})
|
|
13
|
+
export class TextByFunctionPipeModule {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Pipe({ name: 'textByFunction' })
|
|
4
|
+
export class TextByFunctionPipe implements PipeTransform {
|
|
5
|
+
transform(value: any, field: string | ((value: any) => string)): any {
|
|
6
|
+
if (field instanceof Function) {
|
|
7
|
+
return field(value);
|
|
8
|
+
} else if (value instanceof Object) {
|
|
9
|
+
return value[field];
|
|
10
|
+
} else {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js';
|
|
4
|
+
import 'zone.js/testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
declare const require: {
|
|
12
|
+
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
+
<T>(id: string): T;
|
|
14
|
+
keys(): string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// First, initialize the Angular testing environment.
|
|
19
|
+
getTestBed().initTestEnvironment(
|
|
20
|
+
BrowserDynamicTestingModule,
|
|
21
|
+
platformBrowserDynamicTesting(),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Then we find all the tests.
|
|
25
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
26
|
+
// And load the modules.
|
|
27
|
+
context.keys().forEach(context);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/lib",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"inlineSources": true,
|
|
9
|
+
"types": []
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"src/test.ts",
|
|
13
|
+
"**/*.spec.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/spec",
|
|
6
|
+
"types": [
|
|
7
|
+
"jasmine"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/test.ts"
|
|
12
|
+
],
|
|
13
|
+
"include": [
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// also exported from '@storybook/angular' if you can deal with breaking changes in 6.1
|
|
2
|
+
import { Story, Meta } from '@storybook/angular/types-6-0';
|
|
3
|
+
import Button from './button.component';
|
|
4
|
+
|
|
5
|
+
// More on default export: https://storybook.js.org/docs/angular/writing-stories/introduction#default-export
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
component: Button,
|
|
9
|
+
// More on argTypes: https://storybook.js.org/docs/angular/api/argtypes
|
|
10
|
+
argTypes: {
|
|
11
|
+
backgroundColor: { control: 'color' },
|
|
12
|
+
},
|
|
13
|
+
} as Meta;
|
|
14
|
+
|
|
15
|
+
// More on component templates: https://storybook.js.org/docs/angular/writing-stories/introduction#using-args
|
|
16
|
+
const Template: Story<Button> = (args: Button) => ({
|
|
17
|
+
props: args,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const Primary = Template.bind({});
|
|
21
|
+
// More on args: https://storybook.js.org/docs/angular/writing-stories/args
|
|
22
|
+
Primary.args = {
|
|
23
|
+
primary: true,
|
|
24
|
+
label: 'Button',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Secondary = Template.bind({});
|
|
28
|
+
Secondary.args = {
|
|
29
|
+
label: 'Button',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Large = Template.bind({});
|
|
33
|
+
Large.args = {
|
|
34
|
+
size: 'large',
|
|
35
|
+
label: 'Button',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Small = Template.bind({});
|
|
39
|
+
Small.args = {
|
|
40
|
+
size: 'small',
|
|
41
|
+
label: 'Button',
|
|
42
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { moduleMetadata } from '@storybook/angular';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import type { Story, Meta } from '@storybook/angular';
|
|
4
|
+
|
|
5
|
+
import Button from './button.component';
|
|
6
|
+
import Header from './header.component';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: 'Example/Header',
|
|
10
|
+
component: Header,
|
|
11
|
+
decorators: [
|
|
12
|
+
moduleMetadata({
|
|
13
|
+
declarations: [Button],
|
|
14
|
+
imports: [CommonModule],
|
|
15
|
+
}),
|
|
16
|
+
],
|
|
17
|
+
parameters: {
|
|
18
|
+
// More on Story layout: https://storybook.js.org/docs/angular/configure/story-layout
|
|
19
|
+
layout: 'fullscreen',
|
|
20
|
+
},
|
|
21
|
+
} as Meta;
|
|
22
|
+
|
|
23
|
+
const Template: Story<Header> = (args: Header) => ({
|
|
24
|
+
props: args,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const LoggedIn = Template.bind({});
|
|
28
|
+
LoggedIn.args = {
|
|
29
|
+
user: {
|
|
30
|
+
name: 'Jane Doe',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const LoggedOut = Template.bind({});
|
|
35
|
+
LoggedOut.args = {};
|