@corp-products/ui-components 3.5.9 → 3.6.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.
Files changed (146) hide show
  1. package/ng-package.json +7 -0
  2. package/package.json +22 -36
  3. package/src/enums/date-formatter.ts +22 -0
  4. package/src/helper/date-handler.ts +142 -0
  5. package/src/lib/alert-dialog/alert-dialog.component.html +22 -0
  6. package/src/lib/alert-dialog/alert-dialog.component.scss +0 -0
  7. package/src/lib/alert-dialog/alert-dialog.component.spec.ts +22 -0
  8. package/src/lib/alert-dialog/alert-dialog.component.ts +44 -0
  9. package/src/lib/alert-dialog/alert-dialog.interface.ts +6 -0
  10. package/src/lib/alert-dialog/alert-dialog.service.ts +33 -0
  11. package/src/lib/app-accordion/app-accordion.component.html +15 -0
  12. package/src/lib/app-accordion/app-accordion.component.scss +0 -0
  13. package/src/lib/app-accordion/app-accordion.component.spec.ts +21 -0
  14. package/src/lib/app-accordion/app-accordion.component.ts +21 -0
  15. package/src/lib/app-accordion/index.ts +2 -0
  16. package/src/lib/app-breadcrumb/app-breadcrumb.component.html +7 -0
  17. package/src/lib/app-breadcrumb/app-breadcrumb.component.scss +25 -0
  18. package/src/lib/app-breadcrumb/app-breadcrumb.component.ts +140 -0
  19. package/src/lib/app-breadcrumb/app-breadcrumb.interface.ts +15 -0
  20. package/src/lib/app-button/app-button.component.html +7 -0
  21. package/src/lib/app-button/app-button.component.scss +0 -0
  22. package/src/lib/app-button/app-button.component.ts +14 -0
  23. package/src/lib/app-button/app-button.ts +15 -0
  24. package/src/lib/app-button/index.ts +2 -0
  25. package/src/lib/app-dropdown-menu/app-dropdown-menu.component.html +22 -0
  26. package/src/lib/app-dropdown-menu/app-dropdown-menu.component.scss +39 -0
  27. package/src/lib/app-dropdown-menu/app-dropdown-menu.component.spec.ts +21 -0
  28. package/src/lib/app-dropdown-menu/app-dropdown-menu.component.ts +43 -0
  29. package/src/lib/app-dropdown-menu/app-dropdown-menu.ts +17 -0
  30. package/src/lib/app-dropdown-menu/index.ts +2 -0
  31. package/src/lib/app-dropdown-menu/menu-popup.pipe.ts +18 -0
  32. package/src/lib/app-header/app-header.component.html +26 -0
  33. package/src/lib/app-header/app-header.component.scss +0 -0
  34. package/src/lib/app-header/app-header.component.ts +43 -0
  35. package/src/lib/app-side-menu/app-side-menu.component.html +20 -0
  36. package/src/lib/app-side-menu/app-side-menu.component.ts +28 -0
  37. package/src/lib/app-side-menu/routes-names.ts +28 -0
  38. package/src/lib/app-side-menu/side-menu-items.ts +45 -0
  39. package/src/lib/app-side-menu/side-menu.ts +12 -0
  40. package/src/lib/app-tabs/app-tab.interface.ts +27 -0
  41. package/src/lib/app-tabs/app-tabs.component.html +37 -0
  42. package/src/lib/app-tabs/app-tabs.component.scss +103 -0
  43. package/src/lib/app-tabs/app-tabs.component.spec.ts +21 -0
  44. package/src/lib/app-tabs/app-tabs.component.ts +67 -0
  45. package/src/lib/app-tabs/index.ts +2 -0
  46. package/src/lib/bottom-sheet/bottom-sheet.component.html +18 -0
  47. package/src/lib/bottom-sheet/bottom-sheet.component.scss +31 -0
  48. package/src/lib/bottom-sheet/bottom-sheet.component.ts +26 -0
  49. package/src/lib/confirmation-dialog/confirmation-dialog.component.html +37 -0
  50. package/src/lib/confirmation-dialog/confirmation-dialog.component.scss +0 -0
  51. package/src/lib/confirmation-dialog/confirmation-dialog.component.spec.ts +22 -0
  52. package/src/lib/confirmation-dialog/confirmation-dialog.component.ts +64 -0
  53. package/src/lib/confirmation-dialog/confirmation-dialog.interface.ts +13 -0
  54. package/src/lib/confirmation-dialog/confirmation-dialog.service.ts +34 -0
  55. package/src/lib/dual-calender/date-picker-switcher/date-picker-switcher.component.html +27 -0
  56. package/src/lib/dual-calender/date-picker-switcher/date-picker-switcher.component.scss +22 -0
  57. package/src/lib/dual-calender/date-picker-switcher/date-picker-switcher.component.ts +64 -0
  58. package/src/lib/dual-calender/dual-calendar.component.html +32 -0
  59. package/src/lib/dual-calender/dual-calendar.component.scss +265 -0
  60. package/src/lib/dual-calender/dual-calendar.component.ts +158 -0
  61. package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.html +21 -0
  62. package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.scss +0 -0
  63. package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.spec.ts +21 -0
  64. package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.ts +65 -0
  65. package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.html +10 -0
  66. package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.scss +0 -0
  67. package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.spec.ts +21 -0
  68. package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.ts +66 -0
  69. package/src/lib/dual-calender/services/gregorian-i18n.service.ts +123 -0
  70. package/src/lib/dual-calender/services/islamic-i18n.service.ts +119 -0
  71. package/src/lib/dual-calender/utils/date-i18n.utils.ts +58 -0
  72. package/src/lib/dynamic-form/dynamic-form.component.html +84 -0
  73. package/src/lib/dynamic-form/dynamic-form.component.scss +0 -0
  74. package/src/lib/dynamic-form/dynamic-form.component.spec.ts +21 -0
  75. package/src/lib/dynamic-form/dynamic-form.component.ts +58 -0
  76. package/src/lib/dynamic-form/dynamic-form.interface.ts +96 -0
  77. package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.component.html +32 -0
  78. package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.component.scss +3 -0
  79. package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.component.ts +82 -0
  80. package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.config.ts +31 -0
  81. package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.service.ts +41 -0
  82. package/src/lib/form-components/@utils/form-utils.ts +12 -0
  83. package/src/lib/form-components/@utils/validations/error-keys.enum.ts +25 -0
  84. package/src/lib/form-components/@utils/validations/form-validation.service.ts +68 -0
  85. package/src/lib/form-components/@utils/validations/index.ts +4 -0
  86. package/src/lib/form-components/@utils/validations/numbers-only.validator.ts +10 -0
  87. package/src/lib/form-components/@utils/validations/validation-message.pipe.ts +24 -0
  88. package/src/lib/form-components/components/auto-complete/auto-complete.component.html +35 -0
  89. package/src/lib/form-components/components/auto-complete/auto-complete.component.scss +12 -0
  90. package/src/lib/form-components/components/auto-complete/auto-complete.component.spec.ts +21 -0
  91. package/src/lib/form-components/components/auto-complete/auto-complete.component.ts +82 -0
  92. package/src/lib/form-components/components/base-input.component.ts +35 -0
  93. package/src/lib/form-components/components/date-picker/date-picker.component.html +40 -0
  94. package/src/lib/form-components/components/date-picker/date-picker.component.scss +32 -0
  95. package/src/lib/form-components/components/date-picker/date-picker.component.spec.ts +21 -0
  96. package/src/lib/form-components/components/date-picker/date-picker.component.ts +81 -0
  97. package/src/lib/form-components/components/date-picker/date-picker.validator.ts +38 -0
  98. package/src/lib/form-components/components/input/input.component.html +80 -0
  99. package/src/lib/form-components/components/input/input.component.scss +46 -0
  100. package/src/lib/form-components/components/input/input.component.spec.ts +21 -0
  101. package/src/lib/form-components/components/input/input.component.ts +56 -0
  102. package/src/lib/form-components/components/select/select.component.html +123 -0
  103. package/src/lib/form-components/components/select/select.component.scss +53 -0
  104. package/src/lib/form-components/components/select/select.component.spec.ts +21 -0
  105. package/src/lib/form-components/components/select/select.component.ts +87 -0
  106. package/src/lib/form-components/components/select-button/select-button.component.html +21 -0
  107. package/src/lib/form-components/components/select-button/select-button.component.scss +0 -0
  108. package/src/lib/form-components/components/select-button/select-button.component.spec.ts +21 -0
  109. package/src/lib/form-components/components/select-button/select-button.component.ts +22 -0
  110. package/src/lib/form-components/components/switcher/switch.component.html +5 -0
  111. package/src/lib/form-components/components/switcher/switch.component.scss +0 -0
  112. package/src/lib/form-components/components/switcher/switch.component.spec.ts +21 -0
  113. package/src/lib/form-components/components/switcher/switch.component.ts +25 -0
  114. package/src/lib/form-components/index.ts +9 -0
  115. package/src/lib/form-components/interfaces/index.ts +1 -0
  116. package/src/lib/form-components/interfaces/label-value.ts +4 -0
  117. package/src/lib/ico-moon-icon/ico-moon-icon.component.ts +23 -0
  118. package/src/lib/read-more/read-more.component.html +17 -0
  119. package/src/lib/read-more/read-more.component.scss +0 -0
  120. package/src/lib/read-more/read-more.component.spec.ts +21 -0
  121. package/src/lib/read-more/read-more.component.ts +21 -0
  122. package/src/lib/side-bar/side-bar.component.html +24 -0
  123. package/src/lib/side-bar/side-bar.component.scss +22 -0
  124. package/src/lib/side-bar/side-bar.component.spec.ts +21 -0
  125. package/src/lib/side-bar/side-bar.component.ts +33 -0
  126. package/src/lib/side-bar-dynamic/data-injector.pipe.ts +15 -0
  127. package/src/lib/side-bar-dynamic/dynamic-sidebar.service.ts +116 -0
  128. package/src/lib/side-bar-dynamic/side-bar-dynamic.component.html +42 -0
  129. package/src/lib/side-bar-dynamic/side-bar-dynamic.component.scss +5 -0
  130. package/src/lib/side-bar-dynamic/side-bar-dynamic.component.spec.ts +21 -0
  131. package/src/lib/side-bar-dynamic/side-bar-dynamic.component.ts +37 -0
  132. package/src/lib/side-bar-dynamic/side-bar-utils.ts +30 -0
  133. package/src/lib/side-bar-dynamic/sidebar-config.ts +48 -0
  134. package/src/lib/user-autocomplete-card/user-autocomplete-card.component.html +20 -0
  135. package/src/lib/user-autocomplete-card/user-autocomplete-card.component.scss +0 -0
  136. package/src/lib/user-autocomplete-card/user-autocomplete-card.component.spec.ts +21 -0
  137. package/src/lib/user-autocomplete-card/user-autocomplete-card.component.ts +21 -0
  138. package/src/lib/user-info/user-info.component.html +10 -0
  139. package/src/lib/user-info/user-info.component.ts +11 -0
  140. package/src/public-api.ts +29 -0
  141. package/tsconfig.lib.json +18 -0
  142. package/tsconfig.lib.prod.json +11 -0
  143. package/tsconfig.spec.json +14 -0
  144. package/fesm2022/corp-products-ui-components.mjs +0 -2253
  145. package/fesm2022/corp-products-ui-components.mjs.map +0 -1
  146. package/index.d.ts +0 -721
@@ -0,0 +1,84 @@
1
+ <form [formGroup]="formGroup" class="dynamic-form">
2
+ <div class="grid grid-cols-12 gap-x-2">
3
+ @for (inputName of inputsNames; track $index) {
4
+ <div [ngClass]="inputsMap[inputName].rowSize">
5
+ @switch (inputsMap[inputName].fieldType) {
6
+ @case (fieldType.HIJRI_DATE_PICKER) {
7
+ <app-dual-calendar [control]="getFormControl(inputName, formGroup)" ></app-dual-calendar>
8
+ }
9
+
10
+ @case (fieldType.DATE_PICKER) {
11
+ <stc-date-picker [minDate]="inputsMap[inputName]?.dateRange?.min" [maxDate]="inputsMap[inputName]?.dateRange?.max"
12
+ [id]="inputsMap[inputName].inputId" [control]="getFormControl(inputName, formGroup)" [name]="inputName"
13
+ [label]="inputsMap[inputName].label" [placeholder]="inputsMap[inputName].placeholder || ''"
14
+ [hint]="inputsMap[inputName].hint"
15
+ [readonly]="inputsMap[inputName].readonly || dynamicFormData.isReadOnlyForm || false"
16
+ [disabled]="inputsMap[inputName].disabled || false" [variant]="inputsMap[inputName].variant || 'over'"
17
+ [showIcon]="inputsMap[inputName].showIcon !== false" [isTimeOnly]="inputsMap[inputName].isTimeOnly || false" />
18
+ }
19
+ @case (fieldType.SELECT_BUTTON) {
20
+ <stc-select-button [control]="getFormControl(inputName, formGroup)" [id]="inputsMap[inputName].inputId"
21
+ [name]="inputName" [label]="inputsMap[inputName].label"
22
+ [options]="inputsMap[inputName].selectButtonOptions || []"
23
+ (onChange)="selectButtonChange.emit({ name: inputName, value: $event })" />
24
+ }
25
+ @case (fieldType.INPUT) {
26
+ <stc-input [control]="getFormControl(inputName, formGroup)" [id]="inputsMap[inputName].inputId" [name]="inputName"
27
+ [label]="inputsMap[inputName].label" [placeholder]="inputsMap[inputName].placeholder || ''"
28
+ [hint]="inputsMap[inputName].hint"
29
+ [readonly]="inputsMap[inputName].readonly || dynamicFormData.isReadOnlyForm || false"
30
+ [disabled]="inputsMap[inputName].disabled || false" [type]="inputsMap[inputName].inputType || 'text'"
31
+ [contentType]="inputsMap[inputName].contentType || 'text'" [rows]="inputsMap[inputName].rows || 2"
32
+ [cols]="inputsMap[inputName].cols || 20" [autoResize]="inputsMap[inputName].autoResize ?? false"
33
+ [prefix]="inputsMap[inputName].prefix || ''" [size]="inputsMap[inputName].size || 'small'"
34
+ [variant]="inputsMap[inputName].variant || 'over'">
35
+ @if(inputsMap[inputName].maxLength){
36
+ <span class="text-xs text-gray-700">
37
+ {{ (getFormControl(inputName, formGroup).value?.length || 0) }}
38
+ <span> / {{ inputsMap[inputName].maxLength}}</span>
39
+ </span>
40
+ }
41
+ </stc-input>
42
+ }
43
+ @case (fieldType.SELECT) {
44
+ <stc-select [control]="getFormControl(inputName, formGroup)" [id]="inputsMap[inputName].inputId"
45
+ [name]="inputName" [label]="inputsMap[inputName].label" [placeholder]="inputsMap[inputName].placeholder || ''"
46
+ [hint]="inputsMap[inputName].hint"
47
+ [readonly]="inputsMap[inputName].readonly || dynamicFormData.isReadOnlyForm || false"
48
+ [disabled]="inputsMap[inputName].disabled || false" [options]="inputsMap[inputName].selectOptions || []"
49
+ [optionLabel]="inputsMap[inputName].optionLabel || 'label'" [filter]="inputsMap[inputName].filter || false"
50
+ [multiple]="inputsMap[inputName].multiple || false" [showClear]="inputsMap[inputName].showClear || false"
51
+ [checkmark]="inputsMap[inputName].checkmark ?? true" [filterBy]="inputsMap[inputName].filterBy || ''"
52
+ [selectedItemsLabel]="inputsMap[inputName].selectedItemsLabel || ''"
53
+ [size]="inputsMap[inputName].size || 'small'" [variant]="inputsMap[inputName].variant || 'over'"
54
+ (change)="selectChange.emit({ name: inputName, event: $event })"/>
55
+ }
56
+ @case (fieldType.SWITCH) {
57
+ <stc-switch [label]="inputsMap[inputName].label" [key]="inputName"
58
+ [checked]="getFormControl(inputName, formGroup).value"
59
+ (onChange)="getFormControl(inputName, formGroup).setValue(typeof $event === 'string' ? ($event === 'true') : $event); switchChange.emit({ name: inputName, value: (typeof $event === 'string' ? ($event === 'true') : $event) })" />
60
+ }
61
+ @case (fieldType.AUTO_COMPLETE) {
62
+ <stc-auto-complete [control]="getFormControl(inputName, formGroup)" [id]="inputsMap[inputName].inputId"
63
+ [name]="inputName" [label]="inputsMap[inputName].label" [placeholder]="inputsMap[inputName].placeholder || ''"
64
+ [hint]="inputsMap[inputName].hint"
65
+ [readonly]="inputsMap[inputName].readonly || dynamicFormData.isReadOnlyForm || false"
66
+ [disabled]="inputsMap[inputName].disabled || false" [items]="inputsMap[inputName].autoCompleteItems || []"
67
+ [minLengthToSearch]="inputsMap[inputName].minLengthToSearch || 2" [delay]="inputsMap[inputName].delay || 300"
68
+ (onSearch)="autoCompleteSearch.emit({ name: inputName, query: $event })"
69
+ (selectOption)="autoCompleteSelect.emit({ name: inputName, event: $event })"
70
+ [variant]="inputsMap[inputName].variant || 'over'" />
71
+ }
72
+ }
73
+ </div>
74
+ }
75
+ </div>
76
+ <div class="col-span-12">
77
+ <small class="p-error text-red-700">
78
+ @for (error of formGroup.errors | validationErrors: dynamicFormData.formValidationErrorsKeys;
79
+ track error) {
80
+ {{ error }}
81
+ }
82
+ </small>
83
+ </div>
84
+ </form>
@@ -0,0 +1,21 @@
1
+ import { ComponentFixture, TestBed } from "@angular/core/testing";
2
+ import { DynamicFormComponent } from "./dynamic-form.component";
3
+
4
+ describe("DynamicFormComponent", () => {
5
+ let component: DynamicFormComponent;
6
+ let fixture: ComponentFixture<DynamicFormComponent>;
7
+
8
+ beforeEach(async () => {
9
+ await TestBed.configureTestingModule({
10
+ imports: [DynamicFormComponent]
11
+ }).compileComponents();
12
+
13
+ fixture = TestBed.createComponent(DynamicFormComponent);
14
+ component = fixture.componentInstance;
15
+ fixture.detectChanges();
16
+ });
17
+
18
+ it("should create", () => {
19
+ expect(component).toBeTruthy();
20
+ });
21
+ });
@@ -0,0 +1,58 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
3
+ import { FormGroup, ReactiveFormsModule } from '@angular/forms';
4
+ import { TranslateModule } from '@ngx-translate/core';
5
+ import {
6
+ AutoCompleteComponent,
7
+ DatePickerComponent,
8
+ FormUtils,
9
+ InputComponent,
10
+ SelectButtonComponent,
11
+ SelectComponent,
12
+ SwitchComponent,
13
+ ValidationErrorsPipe,
14
+ } from '../form-components';
15
+ import { DynamicFormData, FormFieldTypeEnum, InputsMap } from './dynamic-form.interface';
16
+ import { DualCalendarComponent } from './../dual-calender/dual-calendar.component';
17
+
18
+ @Component({
19
+ selector: 'app-dynamic-form',
20
+ standalone: true,
21
+ imports: [
22
+ CommonModule,
23
+ ReactiveFormsModule,
24
+ DatePickerComponent,
25
+ ValidationErrorsPipe,
26
+ TranslateModule,
27
+ SelectButtonComponent,
28
+ DualCalendarComponent,
29
+ InputComponent,
30
+ SelectComponent,
31
+ AutoCompleteComponent,
32
+ SwitchComponent,
33
+ ],
34
+ templateUrl: './dynamic-form.component.html',
35
+ styleUrl: './dynamic-form.component.scss',
36
+ })
37
+ export class DynamicFormComponent implements OnInit {
38
+ @Input({ required: true }) dynamicFormData: DynamicFormData;
39
+ // Generic field change outputs (optional for consumers)
40
+ @Output() selectButtonChange = new EventEmitter<{ name: string; value: any }>();
41
+ @Output() selectChange = new EventEmitter<{ name: string; event: any }>();
42
+ @Output() switchChange = new EventEmitter<{ name: string; value: boolean }>();
43
+ @Output() autoCompleteSearch = new EventEmitter<{ name: string; query: string }>();
44
+ @Output() autoCompleteSelect = new EventEmitter<{ name: string; event: any }>();
45
+
46
+ inputsNames: string[] = [];
47
+ formGroup: FormGroup;
48
+ inputsMap: InputsMap;
49
+ readonly fieldType = FormFieldTypeEnum;
50
+ getFormControl = FormUtils.getFormControl;
51
+
52
+ ngOnInit(): void {
53
+ this.formGroup = this.dynamicFormData?.formGroup as FormGroup;
54
+ this.inputsMap = this.dynamicFormData?.inputsMap as InputsMap;
55
+ this.inputsNames = Object.keys(this.inputsMap || {});
56
+ }
57
+
58
+ }
@@ -0,0 +1,96 @@
1
+ import { FormGroup } from '@angular/forms';
2
+ import { LabelValue } from '../form-components';
3
+
4
+ export type InputType = 'text' | 'textarea';
5
+ export type InputContentType = 'text' | 'email' | 'number';
6
+
7
+ export interface Dropdown<T = unknown> {
8
+ id?: string;
9
+ keyValue: T;
10
+ label: string;
11
+ labelAr?: string;
12
+ labelEn?: string;
13
+ icon?: string;
14
+ hidden?: boolean;
15
+ disabled?: boolean;
16
+ }
17
+
18
+ export interface InputsMapData {
19
+ // General props
20
+ label: string;
21
+ rowSize?: string;
22
+ fieldType: FormFieldTypeEnum;
23
+ inputId?: string;
24
+ placeholder?: string;
25
+ hint?: string;
26
+ readonly?: boolean;
27
+ disabled?: boolean;
28
+ hidden?: boolean;
29
+ required?: boolean;
30
+ maxLength?: number;
31
+ minlength?: number;
32
+ // Date
33
+ dateRange?: DateRangeInterface;
34
+ isTimeOnly?: boolean;
35
+ showIcon?: boolean;
36
+
37
+ //select button
38
+ selectButtonOptions?: LabelValue<any>[];
39
+
40
+ // Input (text/textarea)
41
+ inputType?: InputType;
42
+ contentType?: InputContentType;
43
+ rows?: number;
44
+ cols?: number;
45
+ autoResize?: boolean;
46
+ prefix?: string;
47
+ size?: 'small' | 'large';
48
+ variant?: 'in' | 'over' | 'on';
49
+
50
+ // Select dropdown
51
+ selectOptions?: unknown[]; // Array of objects or primitives
52
+ optionLabel?: string; // property name to display when options are objects
53
+ filter?: boolean;
54
+ multiple?: boolean;
55
+ showClear?: boolean;
56
+ checkmark?: boolean;
57
+ filterBy?: string;
58
+ selectedItemsLabel?: string;
59
+
60
+ // Auto-complete
61
+ autoCompleteItems?: unknown[];
62
+ minLengthToSearch?: number;
63
+ delay?: number;
64
+ }
65
+
66
+ export interface InputsMap {
67
+ [key: string]: InputsMapData;
68
+ }
69
+
70
+ export interface DynamicFormData {
71
+ isActive?: boolean;
72
+ formGroup: FormGroup | null;
73
+ inputsMap: InputsMap | null;
74
+ title?: string;
75
+ isReadOnlyForm?: boolean;
76
+ formValidationErrorsKeys?: string[];
77
+ }
78
+
79
+ export interface DateRangeInterface {
80
+ min?: Date | null; // Static range, hard coded
81
+ max?: Date | null; // Static range, hard coded
82
+ notBeforeDateInput?: string; // For dynamic date range validation
83
+ notAfterDateInput?: string; // For dynamic date range validation
84
+ notBeforeOrSameDateInput?: string;
85
+ notAfterOrSameDateInput?: string;
86
+ }
87
+
88
+ export enum FormFieldTypeEnum {
89
+ DATE_PICKER = 'date-picker',
90
+ SELECT_BUTTON = 'select-button',
91
+ INPUT = 'input',
92
+ SELECT = 'select',
93
+ SWITCH = 'switch',
94
+ AUTO_COMPLETE = 'auto-complete',
95
+ HIJRI_DATE_PICKER = 'hijri-date'
96
+ }
@@ -0,0 +1,32 @@
1
+ <p-drawer
2
+ [(visible)]="show"
3
+ [position]="position"
4
+ appendTo="body"
5
+ [closable]="closable"
6
+ [closeOnEscape]="closeOnEscape"
7
+ [dismissible]="dismissible"
8
+ (onHide)="handleClose()"
9
+ [position]="'left'"
10
+ [styleClass]="'p-drawer-' + sidebarSize + ' custom-content bg-white ' + styleClass">
11
+ <ng-template pTemplate="header">
12
+ <p class="truncate" [pTooltip]="title">{{ title }}</p>
13
+ </ng-template>
14
+ <ng-template pTemplate="content">
15
+ <ng-template #contentContainer></ng-template>
16
+ </ng-template>
17
+ <ng-template pTemplate="footer">
18
+ <div class="flex gap-4 mt-4">
19
+ <div class="flex-auto">
20
+ <app-button (click)="handleSubmit()"
21
+ [icon]="actions?.save?.icon"
22
+ [iconPos]="actions?.save?.iconPos || 'right'"
23
+ [styleClass]="(actions?.save?.style || 'danger') + ' w-full'"
24
+ [label]="actions?.save?.title || ('actions.submit' | translate)"
25
+ [variant]="actions?.save?.variant"
26
+ />
27
+ </div>
28
+ <app-button (click)="handleClose()" severity="danger" variant="outlined"
29
+ [label]="actions?.cancel?.title || ('actions.cancel' | translate)" />
30
+ </div>
31
+ </ng-template>
32
+ </p-drawer>
@@ -0,0 +1,3 @@
1
+ .flex-auto {
2
+ flex: 1 1 auto;
3
+ }
@@ -0,0 +1,82 @@
1
+ import { AppButtonComponent } from './../app-button/app-button.component';
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import { CommonModule } from '@angular/common';
4
+ import {
5
+ AfterViewInit,
6
+ Component,
7
+ EventEmitter,
8
+ Input,
9
+ OnDestroy,
10
+ Output,
11
+ Type,
12
+ ViewChild,
13
+ ViewContainerRef
14
+ } from '@angular/core';
15
+ import { TranslatePipe } from '@ngx-translate/core';
16
+ import { DrawerModule } from 'primeng/drawer';
17
+ import { TooltipModule } from "primeng/tooltip";
18
+ import { SidebarV2Actions } from './dynamic-sidebar.config';
19
+
20
+ @Component({
21
+ selector: "app-dynamic-sidebar",
22
+ templateUrl: "./dynamic-sidebar.component.html",
23
+ styleUrls: ["./dynamic-sidebar.component.scss"],
24
+ standalone: true,
25
+ imports: [CommonModule, TranslatePipe, DrawerModule, TooltipModule, AppButtonComponent],
26
+ })
27
+ export class DynamicSidebarComponent implements AfterViewInit, OnDestroy {
28
+
29
+ @Input() component!: Type<any>;
30
+ @Input() data?: any;
31
+ @Input() title = '';
32
+ @Input() actions?: SidebarV2Actions;
33
+ @Input() sidebarSize: 'sm' | 'md' | 'lg' = 'md';
34
+ @Input() closable = true;
35
+ @Input() closeOnEscape = true;
36
+ @Input() dismissible = true;
37
+ @Input() position: 'left' | 'right' = 'left';
38
+ @Input() styleClass = '';
39
+ @Input() disabled = false;
40
+
41
+ @Output() closed = new EventEmitter();
42
+
43
+ @ViewChild('contentContainer', { read: ViewContainerRef })
44
+ private contentContainer!: ViewContainerRef;
45
+
46
+ private contentRef: any;
47
+
48
+ show = true;
49
+
50
+ ngAfterViewInit() {
51
+ this.renderContent();
52
+ }
53
+
54
+ private renderContent() {
55
+ if (!this.component) return;
56
+ this.contentContainer.clear();
57
+ this.contentRef = this.contentContainer.createComponent(this.component);
58
+ if (this.data) Object.assign(this.contentRef.instance, this.data);
59
+ }
60
+
61
+ handleClose() {
62
+ if(this.contentRef.instance.close) this.contentRef.instance.close();
63
+ this.closed.emit(null);
64
+ this.destroy();
65
+ }
66
+
67
+ handleSubmit() {
68
+ if(this.data.form) {
69
+ this.data.form.markAllAsTouched();
70
+ if(this.data.form.invalid) return;
71
+ }
72
+ if(this.contentRef.instance.submit) this.contentRef.instance.submit();
73
+ }
74
+
75
+ private destroy() {
76
+ this.contentRef?.destroy();
77
+ }
78
+
79
+ ngOnDestroy() {
80
+ this.destroy();
81
+ }
82
+ }
@@ -0,0 +1,31 @@
1
+ import { Type, ViewContainerRef } from "@angular/core";
2
+ import { AppButtonIconPos, AppButtonSeverity, AppButtonSize, AppButtonVariant } from "../app-button";
3
+
4
+ export interface DynamicSidebarV2Actions {
5
+ submit: () => void;
6
+ close: () => void;
7
+ }
8
+ export interface DynamicSidebarV2Config<T = any> {
9
+ title?: string;
10
+ component: Type<T>;
11
+ data?: Partial<T>;
12
+ size?: 'sm' | 'md' | 'lg';
13
+ position?: 'left' | 'right';
14
+ styleClass?: string;
15
+ viewContainerRef?: ViewContainerRef;
16
+ actions?: SidebarV2Actions
17
+ }
18
+
19
+ export interface SidebarActionV2Config {
20
+ title?: string;
21
+ icon?: string;
22
+ size?: AppButtonSize;
23
+ style?: AppButtonSeverity;
24
+ iconPos?: AppButtonIconPos;
25
+ variant?: AppButtonVariant;
26
+ }
27
+
28
+ export interface SidebarV2Actions {
29
+ cancel?: SidebarActionV2Config;
30
+ save?: SidebarActionV2Config;
31
+ }
@@ -0,0 +1,41 @@
1
+ import { ApplicationRef, ComponentRef, EnvironmentInjector, Injectable, Injector, createComponent, inject } from '@angular/core';
2
+ import { DynamicSidebarComponent } from './dynamic-sidebar.component';
3
+ import { DynamicSidebarV2Config } from './dynamic-sidebar.config';
4
+
5
+ @Injectable({ providedIn: 'root' })
6
+ export class DynamicSidebarV2Service {
7
+ private sidebarRef?: ComponentRef<DynamicSidebarComponent>;
8
+ private readonly appRef = inject(ApplicationRef);
9
+ private readonly injector = inject(Injector);
10
+ private readonly envInjector = inject(EnvironmentInjector);
11
+
12
+ open<T>(options: DynamicSidebarV2Config<T>) {
13
+ this.close();
14
+
15
+ this.sidebarRef = createComponent(DynamicSidebarComponent, {
16
+ environmentInjector: this.envInjector,
17
+ elementInjector: this.injector,
18
+ });
19
+
20
+ const instance = this.sidebarRef.instance;
21
+ instance.title = options.title ?? '';
22
+ instance.sidebarSize = options.size ?? 'md';
23
+ instance.position = options.position ?? 'left';
24
+ instance.styleClass = options.styleClass ?? '';
25
+ instance.component = options.component;
26
+ instance.data = options.data ?? {};
27
+ instance.actions = options.actions;
28
+ instance.closed.subscribe(() => this.close());
29
+
30
+ this.appRef.attachView(this.sidebarRef.hostView);
31
+ const domElem = (this.sidebarRef.hostView as any).rootNodes[0] as HTMLElement;
32
+ document.body.appendChild(domElem);
33
+ }
34
+
35
+ close() {
36
+ if (this.sidebarRef) {
37
+ this.sidebarRef.destroy();
38
+ this.sidebarRef = undefined;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,12 @@
1
+ import {FormControl, FormGroup} from "@angular/forms";
2
+
3
+ export class FormUtils {
4
+ static getFormControl(controlName: string, form: FormGroup): FormControl {
5
+ if (!form) throw new Error(`Form is not initialized.`);
6
+ const formControl = form.get(controlName) as FormControl;
7
+
8
+ if (!formControl) throw new Error(`There's no form control with given name. '${controlName}'`);
9
+
10
+ return formControl;
11
+ }
12
+ }
@@ -0,0 +1,25 @@
1
+ export enum BasicErrorKeysEnum {
2
+ required = 'REQUIRED',
3
+ email = 'EMAIL',
4
+ pattern = 'PATTERN',
5
+ invalidArFormat = 'INVALID_AR_FORMAT',
6
+ invalidLink = 'INVALID_LINK',
7
+ endDateBeforeStartDate = 'END_DATE_BEFORE_START_DATE',
8
+ startDateEqualsEndDate = 'START_DATE_EQUALS_END_DATE',
9
+ endTimeBeforeStartTime = 'END_TIME_BEFORE_START_TIME',
10
+ startTimeEqualsEndTime = 'START_TIME_EQUALS_END_TIME',
11
+ integer = 'INTEGER',
12
+ positiveNumber = 'POSITIVE_NUMBER',
13
+ fileSelected = 'FILE_SELECTED',
14
+ default = 'DEFAULT',
15
+ numbersOnly = 'NUMBERS_ONLY',
16
+ }
17
+ export enum ErrorsWithValuesKeysEnum {
18
+ minlength = 'MIN_LENGTH',
19
+ maxlength = 'MAX_LENGTH',
20
+ min = 'MIN',
21
+ max = 'MAX',
22
+ maxSize = 'MAX_SIZE',
23
+ maxFiles = 'MAX_FILES',
24
+ allowedTypes = 'ALLOWED_TYPES',
25
+ }
@@ -0,0 +1,68 @@
1
+ import { inject, Injectable } from '@angular/core';
2
+ import { TranslateService } from '@ngx-translate/core';
3
+ import { InterpolationParameters } from '@ngx-translate/core';
4
+ import { BasicErrorKeysEnum, ErrorsWithValuesKeysEnum } from './error-keys.enum';
5
+
6
+ @Injectable({
7
+ providedIn: 'root',
8
+ })
9
+ export class FormValidationService {
10
+ private translate = inject(TranslateService);
11
+
12
+ private getTranslation(key: string, interpolateParams?: InterpolationParameters): string {
13
+ return this.translate.instant(`VALIDATION.${key}`, interpolateParams);
14
+ }
15
+
16
+ getErrorMessage(errorKey: string, errorValue: any): string {
17
+ if (this.isBasicErrorKey(errorKey)) {
18
+ return this.getTranslation(BasicErrorKeysEnum[errorKey as keyof typeof BasicErrorKeysEnum]);
19
+ }
20
+
21
+ if (this.isErrorWithValueKey(errorKey)) {
22
+ return this.getErrorWithValueMessage(
23
+ errorKey as keyof typeof ErrorsWithValuesKeysEnum,
24
+ errorValue
25
+ );
26
+ }
27
+
28
+ return this.getTranslation(BasicErrorKeysEnum.default);
29
+ }
30
+
31
+ // Basic error keys are the keys that don't have any values to interpolate. like required, email, etc.
32
+ private isBasicErrorKey(key: string): key is keyof typeof BasicErrorKeysEnum {
33
+ return Object.keys(BasicErrorKeysEnum).includes(key as BasicErrorKeysEnum);
34
+ }
35
+
36
+ // Error keys with values are the keys that have values to interpolate. like minlength, maxlength, etc.
37
+ private isErrorWithValueKey(key: string): key is keyof typeof ErrorsWithValuesKeysEnum {
38
+ return Object.keys(ErrorsWithValuesKeysEnum).includes(key as ErrorsWithValuesKeysEnum);
39
+ }
40
+
41
+ private getErrorWithValueMessage(
42
+ errorKey: keyof typeof ErrorsWithValuesKeysEnum,
43
+ errorValue: any
44
+ ): string {
45
+ const messages: Record<keyof typeof ErrorsWithValuesKeysEnum, (value: any) => string> = {
46
+ minlength: (val) =>
47
+ this.getTranslation(ErrorsWithValuesKeysEnum.minlength, {
48
+ requiredLength: val?.requiredLength,
49
+ actualLength: val?.actualLength,
50
+ }),
51
+ maxlength: (val) =>
52
+ this.getTranslation(ErrorsWithValuesKeysEnum.maxlength, {
53
+ requiredLength: val?.requiredLength,
54
+ actualLength: val?.actualLength,
55
+ }),
56
+ min: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.min, { min: val?.min }),
57
+ max: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.max, { max: val?.max }),
58
+ maxSize: (val) =>
59
+ this.getTranslation(ErrorsWithValuesKeysEnum.maxSize, { size: val?.requiredLength }),
60
+ maxFiles: (val) =>
61
+ this.getTranslation(ErrorsWithValuesKeysEnum.maxFiles, { size: val?.requiredLength }),
62
+ allowedTypes: (val) =>
63
+ this.getTranslation(ErrorsWithValuesKeysEnum.allowedTypes, { types: val?.join(', ') }),
64
+ };
65
+
66
+ return messages[errorKey](errorValue);
67
+ }
68
+ }
@@ -0,0 +1,4 @@
1
+ export * from './error-keys.enum';
2
+ export * from './validation-message.pipe';
3
+ export * from './form-validation.service';
4
+ export * from './numbers-only.validator';
@@ -0,0 +1,10 @@
1
+ import { AbstractControl, ValidationErrors } from '@angular/forms';
2
+
3
+ export function numbersOnlyValidator(control: AbstractControl): ValidationErrors | null {
4
+ const value = control.value;
5
+ if (value === null || value === undefined || value === '') {
6
+ return null;
7
+ }
8
+ const isNumbersOnly = /^[0-9]+$/.test(value);
9
+ return isNumbersOnly ? null : { numbersOnly: true };
10
+ }
@@ -0,0 +1,24 @@
1
+ import { inject, Pipe, PipeTransform } from "@angular/core";
2
+ import { ValidationErrors } from "@angular/forms";
3
+ import { FormValidationService } from "./form-validation.service";
4
+
5
+ @Pipe({
6
+ name: "validationErrors",
7
+ standalone: true,
8
+ pure: true
9
+ })
10
+ export class ValidationErrorsPipe implements PipeTransform {
11
+ private formValidationService = inject(FormValidationService);
12
+
13
+ // allowed keys here to handle errors in case of cross-validators like startDate and endDate validators,
14
+ // we pass this custom key to handle the error messages only for the allowed keys
15
+ transform(errors: ValidationErrors | null, allowedKeys?: string[]): string[] {
16
+ if (!errors) return [];
17
+
18
+ return Object.keys(errors)
19
+ .filter((errorKey) => !allowedKeys || allowedKeys.includes(errorKey)) // Filter errors if allowedKeys are provided
20
+ .map((errorKey) => {
21
+ return this.formValidationService.getErrorMessage(errorKey, errors[errorKey]);
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,35 @@
1
+ <div class="field flex flex-col gap-2 my-3 relative">
2
+ @if (!required) {
3
+ <span class="absolute top-[6px] left-0 text-[10px] text-gray-400">{{'forms.config.optional' | translate}}</span>
4
+ }
5
+ <p-floatlabel [variant]="variant" class="autoComplete">
6
+ <p-auto-complete (keydown)="onKeyDown($event)" (onBlur)="onBlur($event)" (completeMethod)="search($event)" (onSelect)="onSelect($event)" [delay]="delay"
7
+ [disabled]="disabled" [formControl]="control" [id]="inputId" fluid [typeahead]="typeAhead"
8
+ [inputStyleClass]="'reset-default-styles w-full' + (basicInput ? ' basic-style': ' ')"
9
+ [minLength]="minLengthToSearch" [name]="name" [ngClass]="{ 'p-invalid ng-dirty ng-invalid': isInvalid}"
10
+ [placeholder]="placeholder" [styleClass]="'w-full'" multiple [suggestions]="items">
11
+ <ng-template let-item pTemplate="item">
12
+ @if (selectedItemTemplate) {
13
+ <ng-container [ngTemplateOutletContext]="{ $implicit: item }" [ngTemplateOutlet]="selectedItemTemplate" />
14
+ }
15
+ </ng-template>
16
+ </p-auto-complete>
17
+ <label [for]="inputId">
18
+ {{ label }}
19
+ @if (required) {
20
+ <span [class.text-required]="isInvalid">*</span>
21
+ }
22
+ </label>
23
+ </p-floatlabel>
24
+ @if (hint) {
25
+ <small class="p-mt-1">{{ hint }}</small>
26
+ }
27
+ @if (isInvalid && (control.dirty || control.touched)) {
28
+ <small class="p-error">
29
+ @for (error of control.errors | validationErrors; track error) {
30
+ {{ error }}<br>
31
+ }
32
+ </small>
33
+ }
34
+
35
+ </div>
@@ -0,0 +1,12 @@
1
+ .text-required {
2
+ color: red;
3
+ }
4
+
5
+ .p-error {
6
+ color: #dc2626;
7
+ }
8
+ .autoComplete{
9
+ .p-floatlabel-in {
10
+ height: auto !important;
11
+ }
12
+ }