@verisoft/ui-core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +48 -0
- package/README.md +7 -0
- package/jest.config.ts +21 -0
- package/ng-package.json +7 -0
- package/package.json +16 -0
- package/project.json +36 -0
- package/src/index.ts +4 -0
- package/src/lib/common/angular-helper.ts +44 -0
- package/src/lib/common/constants.ts +1 -0
- package/src/lib/common/control.models.ts +57 -0
- package/src/lib/common/datasource-component.model.spec.ts +42 -0
- package/src/lib/common/datasource-component.model.ts +41 -0
- package/src/lib/common/index.ts +4 -0
- package/src/lib/components/action-button-group/action-button-group.model.ts +16 -0
- package/src/lib/components/action-button-group/action-button.model.ts +16 -0
- package/src/lib/components/action-button-group/index.ts +2 -0
- package/src/lib/components/base-form/base-form-input.component.ts +115 -0
- package/src/lib/components/base-form/base-form.component.ts +209 -0
- package/src/lib/components/base-form/directives/detail-store.directive.ts +146 -0
- package/src/lib/components/base-form/index.ts +4 -0
- package/src/lib/components/base-form/models/base-form-input.models.ts +11 -0
- package/src/lib/components/base-form/models/base-form.models.ts +31 -0
- package/src/lib/components/base-form/models/index.ts +2 -0
- package/src/lib/components/breadcrumb/breadcrumb.model.ts +21 -0
- package/src/lib/components/breadcrumb/breadcrumb.service.ts +9 -0
- package/src/lib/components/breadcrumb/breadcrumbcore.component.ts +94 -0
- package/src/lib/components/breadcrumb/index.ts +3 -0
- package/src/lib/components/button/button.model.ts +22 -0
- package/src/lib/components/button/index.ts +1 -0
- package/src/lib/components/calendar/calendar.model.ts +16 -0
- package/src/lib/components/calendar/index.ts +1 -0
- package/src/lib/components/checkbox/checkbox.model.ts +9 -0
- package/src/lib/components/checkbox/index.ts +1 -0
- package/src/lib/components/confirm-dialog/confirm-dialog.model.ts +26 -0
- package/src/lib/components/confirm-dialog/index.ts +1 -0
- package/src/lib/components/dropdown/dropdown.model.ts +13 -0
- package/src/lib/components/dropdown/index.ts +1 -0
- package/src/lib/components/form-field/form-field.model.ts +15 -0
- package/src/lib/components/form-field/index.ts +1 -0
- package/src/lib/components/generic-field/generic-field.model.ts +10 -0
- package/src/lib/components/generic-field/index.ts +1 -0
- package/src/lib/components/header/header.model.ts +18 -0
- package/src/lib/components/header/index.ts +1 -0
- package/src/lib/components/index.ts +31 -0
- package/src/lib/components/input-group/index.ts +1 -0
- package/src/lib/components/input-group/input-group.model.ts +17 -0
- package/src/lib/components/loader/index.ts +1 -0
- package/src/lib/components/loader/loader.model.ts +8 -0
- package/src/lib/components/multiselect/index.ts +1 -0
- package/src/lib/components/multiselect/mutiselect.model.ts +13 -0
- package/src/lib/components/number-input/index.ts +1 -0
- package/src/lib/components/number-input/number-input.model.ts +14 -0
- package/src/lib/components/page-header/index.ts +1 -0
- package/src/lib/components/page-header/page-header.model.ts +17 -0
- package/src/lib/components/password/index.ts +1 -0
- package/src/lib/components/password/password.model.ts +11 -0
- package/src/lib/components/radiobutton/index.ts +1 -0
- package/src/lib/components/radiobutton/radiobutton.model.ts +16 -0
- package/src/lib/components/section/index.ts +1 -0
- package/src/lib/components/section/section.model.ts +11 -0
- package/src/lib/components/side-menu/index.ts +3 -0
- package/src/lib/components/side-menu/services/side-menu-provider.service.ts +13 -0
- package/src/lib/components/side-menu/services/side-menu.service.ts +58 -0
- package/src/lib/components/side-menu/side-menu.model.ts +64 -0
- package/src/lib/components/slider/index.ts +1 -0
- package/src/lib/components/slider/slider.model.ts +13 -0
- package/src/lib/components/snackbar/index.ts +1 -0
- package/src/lib/components/snackbar/snackbar.model.ts +8 -0
- package/src/lib/components/stepper/index.ts +1 -0
- package/src/lib/components/stepper/stepper.model.ts +14 -0
- package/src/lib/components/switch/index.ts +1 -0
- package/src/lib/components/switch/switch.model.ts +9 -0
- package/src/lib/components/tab-view/index.ts +1 -0
- package/src/lib/components/tab-view/tab-view.model.ts +19 -0
- package/src/lib/components/table/index.ts +2 -0
- package/src/lib/components/table/table.models.ts +189 -0
- package/src/lib/components/table/template-column.directive.ts +45 -0
- package/src/lib/components/table-filter/index.ts +1 -0
- package/src/lib/components/table-filter/table-filter.model.ts +22 -0
- package/src/lib/components/textarea/index.ts +1 -0
- package/src/lib/components/textarea/textarea.model.ts +13 -0
- package/src/lib/components/textfield/index.ts +1 -0
- package/src/lib/components/textfield/textfield.model.ts +13 -0
- package/src/lib/components/tristatecheckbox/index.ts +1 -0
- package/src/lib/components/tristatecheckbox/tristatecheckbox.model.ts +9 -0
- package/src/lib/components/unsubscribe.component.ts +12 -0
- package/src/lib/directives/datasource.directive.ts +275 -0
- package/src/lib/directives/index.ts +1 -0
- package/src/lib/pipes/error/error.codes.ts +6 -0
- package/src/lib/pipes/error/error.models.ts +27 -0
- package/src/lib/pipes/error/error.pipe.ts +27 -0
- package/src/lib/pipes/error/warning.codes.ts +5 -0
- package/src/lib/pipes/error/warning.pipe.ts +27 -0
- package/src/lib/pipes/gov/gov-color.pipe.ts +24 -0
- package/src/lib/pipes/gov/gov-size.pipe.ts +16 -0
- package/src/lib/pipes/index.ts +8 -0
- package/src/lib/pipes/keyOrFn/keyOrFn.pipe.ts +23 -0
- package/src/test-setup.ts +8 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +16 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../../../.eslintrc.base.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["*.ts"],
|
|
7
|
+
"extends": [
|
|
8
|
+
"plugin:@nx/angular",
|
|
9
|
+
"plugin:@angular-eslint/template/process-inline-templates"
|
|
10
|
+
],
|
|
11
|
+
"rules": {
|
|
12
|
+
"@angular-eslint/directive-selector": [
|
|
13
|
+
"error",
|
|
14
|
+
{
|
|
15
|
+
"type": "attribute",
|
|
16
|
+
"prefix": "v",
|
|
17
|
+
"style": "camelCase"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"@angular-eslint/component-selector": [
|
|
21
|
+
"error",
|
|
22
|
+
{
|
|
23
|
+
"type": "element",
|
|
24
|
+
"prefix": "v",
|
|
25
|
+
"style": "kebab-case"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"files": ["*.html"],
|
|
32
|
+
"extends": ["plugin:@nx/angular-template"],
|
|
33
|
+
"rules": {}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"files": ["*.json"],
|
|
37
|
+
"parser": "jsonc-eslint-parser",
|
|
38
|
+
"rules": {
|
|
39
|
+
"@nx/dependency-checks": [
|
|
40
|
+
"error",
|
|
41
|
+
{
|
|
42
|
+
"ignoredFiles": ["{projectRoot}/eslint.config.{js,cjs,mjs}"]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
package/README.md
ADDED
package/jest.config.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
displayName: 'ui-core',
|
|
3
|
+
preset: '../../../jest.preset.js',
|
|
4
|
+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
|
5
|
+
coverageDirectory: '../../../coverage/src/libs/ui-core',
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.(ts|mjs|js|html)$': [
|
|
8
|
+
'jest-preset-angular',
|
|
9
|
+
{
|
|
10
|
+
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
11
|
+
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
|
16
|
+
snapshotSerializers: [
|
|
17
|
+
'jest-preset-angular/build/serializers/no-ng-attributes',
|
|
18
|
+
'jest-preset-angular/build/serializers/ng-snapshot',
|
|
19
|
+
'jest-preset-angular/build/serializers/html-comment',
|
|
20
|
+
],
|
|
21
|
+
};
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@verisoft/ui-core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/core": "^18.2.8",
|
|
6
|
+
"@angular/router": "18.2.8",
|
|
7
|
+
"@verisoft/core": "18.0.0",
|
|
8
|
+
"@angular/forms": "18.2.8",
|
|
9
|
+
"primeng": "^17.18.11",
|
|
10
|
+
"rxjs": "~7.8.0",
|
|
11
|
+
"@angular/common": "^18.2.8",
|
|
12
|
+
"lodash-es": "^4.17.21",
|
|
13
|
+
"@verisoft/store": "18.0.0"
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false
|
|
16
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ui-core",
|
|
3
|
+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "src/libs/ui-core/src",
|
|
5
|
+
"prefix": "lib",
|
|
6
|
+
"projectType": "library",
|
|
7
|
+
"tags": [],
|
|
8
|
+
"targets": {
|
|
9
|
+
"build": {
|
|
10
|
+
"executor": "@nx/angular:package",
|
|
11
|
+
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
12
|
+
"options": {
|
|
13
|
+
"project": "src/libs/ui-core/ng-package.json"
|
|
14
|
+
},
|
|
15
|
+
"configurations": {
|
|
16
|
+
"production": {
|
|
17
|
+
"tsConfig": "src/libs/ui-core/tsconfig.lib.prod.json"
|
|
18
|
+
},
|
|
19
|
+
"development": {
|
|
20
|
+
"tsConfig": "src/libs/ui-core/tsconfig.lib.json"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"defaultConfiguration": "production"
|
|
24
|
+
},
|
|
25
|
+
"test": {
|
|
26
|
+
"executor": "@nx/jest:jest",
|
|
27
|
+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
28
|
+
"options": {
|
|
29
|
+
"jestConfig": "src/libs/ui-core/jest.config.ts"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"lint": {
|
|
33
|
+
"executor": "@nx/eslint:lint"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { OnChanges, SimpleChange, SimpleChanges } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
export function setComponentProperties<TComponent>(
|
|
4
|
+
component: TComponent,
|
|
5
|
+
value: Partial<TComponent>,
|
|
6
|
+
firstChange = false
|
|
7
|
+
) {
|
|
8
|
+
if (!value || !component) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const simpleChanges = Object.keys(value).reduce(
|
|
13
|
+
(changes: SimpleChanges, property: string) => {
|
|
14
|
+
const indexedComponent = component as unknown as {
|
|
15
|
+
[key: string]: TComponent[keyof TComponent];
|
|
16
|
+
};
|
|
17
|
+
const indexedValue = value as unknown as {
|
|
18
|
+
[key: string]: TComponent[keyof TComponent];
|
|
19
|
+
};
|
|
20
|
+
const previousValue = indexedComponent[property];
|
|
21
|
+
const currentValue = indexedValue[
|
|
22
|
+
property
|
|
23
|
+
] as TComponent[keyof TComponent];
|
|
24
|
+
if (currentValue !== previousValue) {
|
|
25
|
+
indexedComponent[property] = currentValue;
|
|
26
|
+
const change = new SimpleChange(
|
|
27
|
+
previousValue,
|
|
28
|
+
currentValue,
|
|
29
|
+
firstChange
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return { ...changes, [property]: change };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return changes;
|
|
36
|
+
},
|
|
37
|
+
{}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const changeableComponent = component as unknown as OnChanges;
|
|
41
|
+
if (changeableComponent['ngOnChanges']) {
|
|
42
|
+
changeableComponent.ngOnChanges(simpleChanges);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_DEBOUNCE_TIME = 300;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export enum ControlSeverity {
|
|
2
|
+
success = 'success',
|
|
3
|
+
info = 'info',
|
|
4
|
+
warning = 'warning',
|
|
5
|
+
danger = 'danger',
|
|
6
|
+
help = 'help',
|
|
7
|
+
primary = 'primary',
|
|
8
|
+
secondary = 'secondary',
|
|
9
|
+
contrast = 'contrast',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum GovControlSeverity {
|
|
13
|
+
primary = 'primary',
|
|
14
|
+
secondary = 'secondary',
|
|
15
|
+
neutral = 'neutral',
|
|
16
|
+
error = 'error',
|
|
17
|
+
success = 'success',
|
|
18
|
+
warning = 'warning',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum GovButtonType {
|
|
22
|
+
solid = 'solid',
|
|
23
|
+
outlined = "outlined",
|
|
24
|
+
base = "base",
|
|
25
|
+
link = "link"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export enum IconPosition {
|
|
29
|
+
left = 'left',
|
|
30
|
+
right = 'right',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export enum SlotPosition {
|
|
34
|
+
top = 'top',
|
|
35
|
+
bottom = 'bottom',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export enum FieldSize {
|
|
39
|
+
small = 'small',
|
|
40
|
+
medium = 'medium',
|
|
41
|
+
large = 'large',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export enum FieldType {
|
|
45
|
+
text = 'text',
|
|
46
|
+
number = 'number',
|
|
47
|
+
password = 'password',
|
|
48
|
+
search = 'search',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type ControlSeverityType = keyof typeof ControlSeverity;
|
|
52
|
+
export type GovControlSeverityType = keyof typeof GovControlSeverity;
|
|
53
|
+
export type GovButtonTypeType = keyof typeof GovButtonType;
|
|
54
|
+
export type IconPositionType = keyof typeof IconPosition;
|
|
55
|
+
export type SlotPositionType = keyof typeof SlotPosition;
|
|
56
|
+
export type FieldSizeType = keyof typeof FieldSize;
|
|
57
|
+
export type FieldTypeType = keyof typeof FieldType;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { setDataToArray } from './datasource-component.model';
|
|
2
|
+
|
|
3
|
+
describe('setDataToArray', () => {
|
|
4
|
+
test('Should return data when target array is null and data is passed.', () => {
|
|
5
|
+
const data = ['item 1', 'item 2'];
|
|
6
|
+
const targetData = undefined;
|
|
7
|
+
|
|
8
|
+
const actual = setDataToArray(targetData, data);
|
|
9
|
+
|
|
10
|
+
expect(actual).toEqual(data);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('Should return data when target array is null and data is passed.', () => {
|
|
14
|
+
const data = ['item 1', 'item 2'];
|
|
15
|
+
const targetData: string[] = [];
|
|
16
|
+
|
|
17
|
+
const actual = setDataToArray(targetData, data);
|
|
18
|
+
|
|
19
|
+
expect(actual).toEqual(data);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('Should return extended target array when target array is empty and data is passed and offset is specified.', () => {
|
|
23
|
+
const data = ['item 1', 'item 2'];
|
|
24
|
+
const targetData: string[] = [];
|
|
25
|
+
const offset = 1;
|
|
26
|
+
|
|
27
|
+
const actual = setDataToArray(targetData, data, offset);
|
|
28
|
+
|
|
29
|
+
expect(actual).toEqual([undefined, ...data]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('Should return target array extended to total items when data is passed and total is specified.', () => {
|
|
33
|
+
const data = ['item 1', 'item 2'];
|
|
34
|
+
const targetData: string[] = [];
|
|
35
|
+
const total = 5;
|
|
36
|
+
const offset = 0;
|
|
37
|
+
|
|
38
|
+
const actual = setDataToArray(targetData, data, offset, total);
|
|
39
|
+
|
|
40
|
+
expect(actual.length).toEqual(total);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { EventEmitter, SimpleChanges } from '@angular/core';
|
|
2
|
+
import { FilterEvent, LazyLoadEvent } from '@verisoft/core';
|
|
3
|
+
|
|
4
|
+
export interface DataSourceComponentModel<TEntity> {
|
|
5
|
+
ngOnChanges?: (changes: SimpleChanges) => void;
|
|
6
|
+
lazy: boolean;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
filter: boolean;
|
|
9
|
+
options?: TEntity[];
|
|
10
|
+
optionValue?: string;
|
|
11
|
+
optionLabel?: string;
|
|
12
|
+
showed: EventEmitter<any>;
|
|
13
|
+
cleared: EventEmitter<any>;
|
|
14
|
+
filtered: EventEmitter<FilterEvent>;
|
|
15
|
+
lazyLoad: EventEmitter<LazyLoadEvent>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function setDataToArray<T>(
|
|
19
|
+
targetArray: (T | undefined)[] | undefined,
|
|
20
|
+
data: T[],
|
|
21
|
+
offset = 0,
|
|
22
|
+
total: number | undefined = undefined,
|
|
23
|
+
defaultItem: T | undefined = undefined
|
|
24
|
+
): (T | undefined)[] {
|
|
25
|
+
const totalItems = total ?? data.length + offset;
|
|
26
|
+
if (!targetArray) {
|
|
27
|
+
targetArray = Array(totalItems).fill(defaultItem);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (targetArray.length < totalItems) {
|
|
31
|
+
targetArray = targetArray.concat(
|
|
32
|
+
new Array(totalItems - targetArray.length).fill(defaultItem)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < data.length; i++) {
|
|
37
|
+
targetArray[i + offset] = data[i] ?? defaultItem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return targetArray;
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { IconPositionType } from '../../common';
|
|
3
|
+
import { ActionButton } from './action-button.model';
|
|
4
|
+
|
|
5
|
+
export const ACTION_BUTTON_GROUP_COMPONENT_TOKEN = new InjectionToken<ActionButtonGroupCore>(
|
|
6
|
+
'ActionButtonGroupComponentToken'
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export interface ActionButtonGroupCore {
|
|
10
|
+
maxItems: number;
|
|
11
|
+
maxItemsMobile: number;
|
|
12
|
+
items: ActionButton[]
|
|
13
|
+
menuIconPos: IconPositionType;
|
|
14
|
+
menuIcon: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventEmitter } from "@angular/core";
|
|
2
|
+
import { ControlSeverityType, FieldSizeType } from "../../common";
|
|
3
|
+
|
|
4
|
+
export interface ActionButton {
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
toolTip?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
outlined: boolean;
|
|
10
|
+
raised: boolean;
|
|
11
|
+
text: boolean;
|
|
12
|
+
severity?: ControlSeverityType;
|
|
13
|
+
label?: string;
|
|
14
|
+
size?: FieldSizeType;
|
|
15
|
+
clickEvent: EventEmitter<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import { Component, Input, OnInit } from '@angular/core';
|
|
3
|
+
import {
|
|
4
|
+
AbstractControl,
|
|
5
|
+
ControlValueAccessor,
|
|
6
|
+
FormControl,
|
|
7
|
+
FormControlDirective,
|
|
8
|
+
FormControlName,
|
|
9
|
+
FormGroupDirective,
|
|
10
|
+
NgControl,
|
|
11
|
+
NgModel,
|
|
12
|
+
ReactiveFormsModule,
|
|
13
|
+
} from '@angular/forms';
|
|
14
|
+
import { BaseInputControls } from './models/base-form-input.models';
|
|
15
|
+
|
|
16
|
+
const noop = () => {
|
|
17
|
+
/* */
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
@Component({
|
|
21
|
+
template: '',
|
|
22
|
+
standalone: true,
|
|
23
|
+
imports: [CommonModule, ReactiveFormsModule],
|
|
24
|
+
})
|
|
25
|
+
export class BaseFormInputComponent
|
|
26
|
+
implements BaseInputControls<any>, ControlValueAccessor, OnInit
|
|
27
|
+
{
|
|
28
|
+
readonly ngControl?: NgControl;
|
|
29
|
+
|
|
30
|
+
formControl!: FormControl;
|
|
31
|
+
|
|
32
|
+
constructor(private readonly control: NgControl) {
|
|
33
|
+
this.ngControl = control;
|
|
34
|
+
if (this.control) {
|
|
35
|
+
this.ngControl.valueAccessor = this;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Input()
|
|
40
|
+
label?: string;
|
|
41
|
+
|
|
42
|
+
@Input()
|
|
43
|
+
required = false;
|
|
44
|
+
|
|
45
|
+
@Input()
|
|
46
|
+
readonly!: boolean;
|
|
47
|
+
|
|
48
|
+
@Input()
|
|
49
|
+
tooltip!: string;
|
|
50
|
+
|
|
51
|
+
@Input()
|
|
52
|
+
formDisplay: 'flex' | 'block' = 'flex';
|
|
53
|
+
|
|
54
|
+
@Input()
|
|
55
|
+
clearable = true;
|
|
56
|
+
|
|
57
|
+
@Input()
|
|
58
|
+
placeholder?: string = '';
|
|
59
|
+
|
|
60
|
+
@Input()
|
|
61
|
+
testId?: string;
|
|
62
|
+
|
|
63
|
+
inputId = Math.random().toString(36).substring(2);
|
|
64
|
+
|
|
65
|
+
selectionChanged: any = noop;
|
|
66
|
+
|
|
67
|
+
onTouch: any = noop;
|
|
68
|
+
|
|
69
|
+
registerOnChange(fn: any): void {
|
|
70
|
+
this.selectionChanged = fn;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
registerOnTouched(fn: any): void {
|
|
74
|
+
this.onTouch = fn;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
78
|
+
writeValue(value: any): void {}
|
|
79
|
+
|
|
80
|
+
ngOnInit(): void {
|
|
81
|
+
if (this.ngControl) {
|
|
82
|
+
if (this.ngControl instanceof FormControlName) {
|
|
83
|
+
this.formControl =
|
|
84
|
+
this.ngControl.control ||
|
|
85
|
+
((this.ngControl.formDirective as FormGroupDirective)?.form.controls[
|
|
86
|
+
this.ngControl.name as string
|
|
87
|
+
] as FormControl);
|
|
88
|
+
} else if (
|
|
89
|
+
this.ngControl instanceof FormControlDirective ||
|
|
90
|
+
this.ngControl instanceof NgModel
|
|
91
|
+
) {
|
|
92
|
+
this.formControl = this.ngControl.control;
|
|
93
|
+
if (this.ngControl instanceof NgModel) {
|
|
94
|
+
this.formControl.valueChanges.subscribe(() =>
|
|
95
|
+
this.ngControl?.viewToModelUpdate(this.control?.value)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
this.formControl = new FormControl();
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
this.formControl = new FormControl();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
isRequired() {
|
|
107
|
+
if (this.ngControl) {
|
|
108
|
+
const validator = this.ngControl?.control?.validator?.(
|
|
109
|
+
{} as AbstractControl
|
|
110
|
+
);
|
|
111
|
+
return this.required || (validator && validator['required']);
|
|
112
|
+
}
|
|
113
|
+
return this.required;
|
|
114
|
+
}
|
|
115
|
+
}
|