fx-form-builder-wrapper 0.0.49 → 0.0.53

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 (59) hide show
  1. package/ng-package.json +9 -0
  2. package/package.json +16 -29
  3. package/src/lib/components/button/button.component.css +0 -0
  4. package/src/lib/components/button/button.component.html +1 -0
  5. package/src/lib/components/button/button.component.ts +24 -0
  6. package/src/lib/components/dynamic-table/dynamic-table.component.css +31 -0
  7. package/src/lib/components/dynamic-table/dynamic-table.component.html +69 -0
  8. package/src/lib/components/dynamic-table/dynamic-table.component.ts +258 -0
  9. package/src/lib/components/fx-form-component/fx-form-component.component.ts +86 -0
  10. package/src/lib/components/toggle/toggle.component.css +51 -0
  11. package/src/lib/components/toggle/toggle.component.html +12 -0
  12. package/src/lib/components/toggle/toggle.component.ts +33 -0
  13. package/src/lib/components/toggle-button/toggle-button.component.css +22 -0
  14. package/src/lib/components/toggle-button/toggle-button.component.html +10 -0
  15. package/src/lib/components/toggle-button/toggle-button.component.ts +40 -0
  16. package/src/lib/components/uploader/uploader.component.css +49 -0
  17. package/src/lib/components/uploader/uploader.component.html +23 -0
  18. package/src/lib/components/uploader/uploader.component.ts +59 -0
  19. package/src/lib/custom-controls/dispatch-to-clinic/dispatch-to-clinic.component.html +78 -0
  20. package/src/lib/custom-controls/dispatch-to-clinic/dispatch-to-clinic.component.ts +44 -0
  21. package/src/lib/form-builder.css +9 -0
  22. package/src/lib/fx-builder-wrapper.component.ts +68 -0
  23. package/src/lib/fx-builder-wrapper.service.ts +38 -0
  24. package/src/lib/panel/configuration-panel/configuration-panel.component.css +154 -0
  25. package/src/lib/panel/configuration-panel/configuration-panel.component.html +162 -0
  26. package/src/lib/panel/configuration-panel/configuration-panel.component.ts +120 -0
  27. package/src/lib/panel/settings-panel/settings-panel.component.css +30 -0
  28. package/src/lib/panel/settings-panel/settings-panel.component.html +28 -0
  29. package/src/lib/panel/settings-panel/settings-panel.component.ts +23 -0
  30. package/src/public-api.ts +8 -0
  31. package/tsconfig.lib.json +15 -0
  32. package/tsconfig.lib.prod.json +13 -0
  33. package/tsconfig.spec.json +15 -0
  34. package/esm2022/fx-form-builder-wrapper.mjs +0 -5
  35. package/esm2022/lib/components/dynamic-table/dynamic-table.component.mjs +0 -235
  36. package/esm2022/lib/components/fx-form-component/fx-form-component.component.mjs +0 -103
  37. package/esm2022/lib/components/toggle/toggle.component.mjs +0 -33
  38. package/esm2022/lib/components/toggle-button/toggle-button.component.mjs +0 -38
  39. package/esm2022/lib/components/uploader/uploader.component.mjs +0 -58
  40. package/esm2022/lib/custom-controls/dispatch-to-clinic/dispatch-to-clinic.component.mjs +0 -42
  41. package/esm2022/lib/fx-builder-wrapper.component.mjs +0 -79
  42. package/esm2022/lib/fx-builder-wrapper.service.mjs +0 -44
  43. package/esm2022/lib/panel/configuration-panel/configuration-panel.component.mjs +0 -117
  44. package/esm2022/lib/panel/settings-panel/settings-panel.component.mjs +0 -24
  45. package/esm2022/public-api.mjs +0 -7
  46. package/fesm2022/fx-form-builder-wrapper.mjs +0 -718
  47. package/fesm2022/fx-form-builder-wrapper.mjs.map +0 -1
  48. package/index.d.ts +0 -5
  49. package/lib/components/dynamic-table/dynamic-table.component.d.ts +0 -52
  50. package/lib/components/fx-form-component/fx-form-component.component.d.ts +0 -19
  51. package/lib/components/toggle/toggle.component.d.ts +0 -13
  52. package/lib/components/toggle-button/toggle-button.component.d.ts +0 -15
  53. package/lib/components/uploader/uploader.component.d.ts +0 -16
  54. package/lib/custom-controls/dispatch-to-clinic/dispatch-to-clinic.component.d.ts +0 -17
  55. package/lib/fx-builder-wrapper.component.d.ts +0 -19
  56. package/lib/fx-builder-wrapper.service.d.ts +0 -14
  57. package/lib/panel/configuration-panel/configuration-panel.component.d.ts +0 -27
  58. package/lib/panel/settings-panel/settings-panel.component.d.ts +0 -10
  59. package/public-api.d.ts +0 -3
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/fx-builder-wrapper",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts",
6
+ "styleIncludePaths": ["src/styles"]
7
+ },
8
+ "assets": ["src/styles"]
9
+ }
package/package.json CHANGED
@@ -1,29 +1,16 @@
1
- {
2
- "name": "fx-form-builder-wrapper",
3
- "version": "0.0.49",
4
- "peerDependencies": {
5
- "@angular/common": "^18.2.0",
6
- "@angular/core": "^18.2.0",
7
- "@instantsys-labs/fx": "2.0.2",
8
- "uuid": "^11.0.5",
9
- "primeng": "^17.18.10",
10
- "tailwindcss-primeui": "^0.4.0"
11
- },
12
- "dependencies": {
13
- "tslib": "^2.3.0"
14
- },
15
- "sideEffects": false,
16
- "module": "fesm2022/fx-form-builder-wrapper.mjs",
17
- "typings": "index.d.ts",
18
- "exports": {
19
- "./package.json": {
20
- "default": "./package.json"
21
- },
22
- ".": {
23
- "types": "./index.d.ts",
24
- "esm2022": "./esm2022/fx-form-builder-wrapper.mjs",
25
- "esm": "./esm2022/fx-form-builder-wrapper.mjs",
26
- "default": "./fesm2022/fx-form-builder-wrapper.mjs"
27
- }
28
- }
29
- }
1
+ {
2
+ "name": "fx-form-builder-wrapper",
3
+ "version": "0.0.53",
4
+ "peerDependencies": {
5
+ "@angular/common": "^18.2.0",
6
+ "@angular/core": "^18.2.0",
7
+ "@instantsys-labs/fx": "2.0.2",
8
+ "uuid": "^11.0.5",
9
+ "primeng": "^17.18.10",
10
+ "tailwindcss-primeui": "^0.4.0"
11
+ },
12
+ "dependencies": {
13
+ "tslib": "^2.3.0"
14
+ },
15
+ "sideEffects": false
16
+ }
File without changes
@@ -0,0 +1 @@
1
+ <p>button works!</p>
@@ -0,0 +1,24 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { ChangeDetectorRef, Component } from '@angular/core';
3
+ import { FxBaseComponent, FxSetting, FxStringSetting, FxValidation, FxValidatorService } from '@instantsys-labs/fx';
4
+
5
+ @Component({
6
+ selector: 'lib-button',
7
+ standalone: true,
8
+ imports: [CommonModule],
9
+ templateUrl: './button.component.html',
10
+ styleUrl: './button.component.css'
11
+ })
12
+ export class ButtonComponent extends FxBaseComponent {
13
+ constructor(private cdr: ChangeDetectorRef) {
14
+ super(cdr)
15
+ }
16
+
17
+ protected settings(): FxSetting[] {
18
+ return [new FxStringSetting({ key: 'heading-text', $title: 'Heading Text', value: 'My Default Value' })];
19
+ }
20
+
21
+ protected validations(): FxValidation[] {
22
+ return [FxValidatorService.required];
23
+ }
24
+ }
@@ -0,0 +1,31 @@
1
+ .formBuilder_dynamic_table{
2
+ border: 0.6px solid #ccc;
3
+ }
4
+ .formBuilder_dynamic_table>thead>tr {
5
+ background-color: #4682b4;
6
+ color: #fff;
7
+ }
8
+
9
+ .formBuilder_dynamic_table>thead>tr>th {
10
+ font-weight: 400 !important;
11
+ padding: .25rem .55rem;
12
+ font-size: .875rem;
13
+ }
14
+
15
+ .formBuilder_dynamic_table>tbody>tr:nth-child(odd) {
16
+ background-color: #fff;
17
+ }
18
+
19
+ .formBuilder_dynamic_table>tbody>tr:nth-child(even) {
20
+ background-color: #f6f6f6;
21
+ }
22
+
23
+ .formBuilder_dynamic_table>tbody>tr>td {
24
+ text-align: center;
25
+ padding: 0.25rem 0.55rem;
26
+ }
27
+
28
+
29
+ select:not([size]) {
30
+ width: 186px !important;
31
+ }
@@ -0,0 +1,69 @@
1
+ <fx-settings-panel [fxData]="fxData" (configuration)="onChangeConfiguration($event)">
2
+ <div *ngIf="fxData">
3
+ <table style="width: 100%;" class="formBuilder_dynamic_table">
4
+ <thead>
5
+ <tr>
6
+ <th *ngFor="let column of tableConfig.columns">{{ column.header }}</th>
7
+ </tr>
8
+ </thead>
9
+ <tbody>
10
+ <tr *ngFor="let row of tableConfig.rows; let rowIndex = index">
11
+ <td *ngFor="let column of tableConfig.columns">
12
+ <ng-container [ngSwitch]="column.cellType">
13
+ <span [class]="column?.className" *ngSwitchCase="'text'">{{row[column.header]}}</span>
14
+
15
+ <input [class]="column?.className" *ngSwitchCase="'input-text'" type="text"
16
+ [(ngModel)]="row[column.header]" />
17
+
18
+ <input [class]="column?.className" *ngSwitchCase="'input-number'" type="number"
19
+ [(ngModel)]="row[column.header]" />
20
+
21
+ <select [class]="column?.className" *ngSwitchCase="'dropdown'"
22
+ [(ngModel)]="row[column.header]">
23
+ <option *ngFor="let option of column?.options" [value]="option?.optionValue">
24
+ {{ option?.optionName }}
25
+ </option>
26
+ </select>
27
+
28
+ <select [class]="column?.className" style="width: 60%;" *ngSwitchCase="'smart-dropdown'"
29
+ [(ngModel)]="row[column.header]">
30
+ <option *ngFor="let option of smartDropdownOptions[column.header]" [value]="option?.value">
31
+ {{option?.name }}
32
+ </option>
33
+ </select>
34
+
35
+ <input [class]="column?.className" *ngSwitchCase="'checkbox'" type="checkbox"
36
+ [(ngModel)]="row[column.header]" />
37
+
38
+ <input name="radio-{{rowIndex}}" [class]="column?.className" *ngSwitchCase="'radio'" type="radio"
39
+ [(ngModel)]="row[column.header]" />
40
+
41
+ <div [class]="column?.className" style="display: flex; justify-content: center; gap: 10px;"
42
+ *ngSwitchCase="'radio-group'">
43
+ <label *ngFor="let option of column.options">
44
+ <input name="radio-group-{{rowIndex}}" type="radio" [value]="option?.optionName"
45
+ [(ngModel)]="row[column.header]" />
46
+ {{ option?.optionName }}
47
+ </label>
48
+ </div>
49
+
50
+ <ng-container *ngSwitchCase="'file-upload'">
51
+ <div style="display: flex; flex-direction: column; align-items: end;justify-content: end;">
52
+ <img width="100" *ngIf="uploadedImages?.[rowIndex]?.['result']" [src]="uploadedImages[rowIndex]?.['result']"
53
+ alt="Uploaded Image" (click)="deleteFile(uploadedImages[rowIndex], rowIndex)"/>
54
+ <input [class]="column?.className" type="file" name="file" #uploadFile hidden multiple
55
+ (change)="uploadImage($event, rowIndex)" />
56
+ <button (click)="uploadFile.click()">Upload</button>
57
+ </div>
58
+ </ng-container>
59
+
60
+ <ng-container *ngSwitchCase="'textarea'">
61
+ <textarea [class]="column?.className" name="" id="" cols="30" rows="2"></textarea>
62
+ </ng-container>
63
+ </ng-container>
64
+ </td>
65
+ </tr>
66
+ </tbody>
67
+ </table>
68
+ </div>
69
+ </fx-settings-panel>
@@ -0,0 +1,258 @@
1
+ import { AfterViewInit, ChangeDetectorRef, Component, inject, Input, NgZone, OnDestroy, OnInit } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
4
+ import { HttpClient } from '@angular/common/http';
5
+ import { FxBaseComponent, FxMode, FxSetting, FxStringSetting, FxValidation, FxValidatorService } from '@instantsys-labs/fx';
6
+ import { SettingsPanelComponent } from '../../panel/settings-panel/settings-panel.component';
7
+ import { FxBuilderWrapperService } from '../../fx-builder-wrapper.service';
8
+ import {Subject, takeUntil } from 'rxjs';
9
+
10
+ export interface TableColumnConfig {
11
+ header: string;
12
+ cellType: 'text' | 'input-text' | 'input-number' | 'dropdown' | 'smart-dropdown' | 'checkbox' | 'radio' | 'radio-group' | 'file-upload' | 'textarea';
13
+ placeholder?: string;
14
+ options?: string[];
15
+ apiUrl?: string;
16
+ valueKey?: string;
17
+ labelKey?: string;
18
+ className?: string;
19
+ }
20
+ export interface TableConfig {
21
+ columns: TableColumnConfig[];
22
+ rows: any[];
23
+ }
24
+ @Component({
25
+ selector: 'fx-dynamic-table',
26
+ standalone: true,
27
+ imports: [CommonModule, FormsModule, SettingsPanelComponent, ReactiveFormsModule],
28
+ templateUrl: './dynamic-table.component.html',
29
+ styleUrl: './dynamic-table.component.css',
30
+ })
31
+
32
+ export class DynamicTableComponent extends FxBaseComponent implements OnInit, AfterViewInit, OnDestroy {
33
+ @Input() tableRows: Array<any> = [];
34
+ @Input() previewType: FxMode = FxMode.VIEW;
35
+ @Input() tableConfig: any = {
36
+ columns: [
37
+ { header: 'Column 1', cellType: 'text' },
38
+ { header: 'Column 2', cellType: 'text' },
39
+ { header: 'Column 3', cellType: 'text' },
40
+ { header: 'Column 4', cellType: 'text' },
41
+ { header: 'Column 5', cellType: 'text' },
42
+ ],
43
+ };
44
+
45
+ private destroy$ = new Subject<Boolean>();
46
+ public uploadedImages: Array<Record<string, string | File | null> | null> = [];
47
+
48
+ public tableFormControl = new FormControl();
49
+ public smartDropdownOptions: { [key: string]: Array<{ name: string, value: string }> } = {};
50
+ private http = inject(HttpClient);
51
+ constructor(private cdr: ChangeDetectorRef, private fxBuilderWrapperService: FxBuilderWrapperService) {
52
+ super(cdr);
53
+ this.onInit.subscribe((fxData)=>{
54
+ this._register(this.tableFormControl);
55
+ })
56
+ }
57
+
58
+ public ngOnInit(): void {
59
+ this.fxBuilderWrapperService.variables$.pipe(
60
+ takeUntil(this.destroy$)).subscribe((variables: any) => {
61
+ if (variables) {
62
+ let dynamicTableValues: any;
63
+ for (const [key, value] of Object.entries(variables)) {
64
+ if (key.includes('dynamic-table')) {
65
+ dynamicTableValues = value;
66
+ }
67
+ }
68
+ if (Object.keys(dynamicTableValues).length) {
69
+ // const fileHeaderName = dynamicTableValues?.columns.find((f: any) => f.cellType === 'file-upload')?.header;
70
+ const fileHeaderName = dynamicTableValues?.columns.find((f: any) => f.cellType === 'file-upload')?.header;
71
+ dynamicTableValues?.rows?.forEach((item: any, index: number) => {
72
+ // // this.uploadedImages[index] = item[fileHeaderName] ? item[fileHeaderName]: null;
73
+ // const fileUrl = item[fileHeaderName]; // Get the file URL
74
+
75
+ // this.uploadedImages[index] = fileUrl
76
+ // ? { result: fileUrl, file: null } // Store the URL as 'result'
77
+ // : null;
78
+
79
+ if (item[fileHeaderName]) {
80
+ this.parseUrls(item[fileHeaderName], index);
81
+ }
82
+ })
83
+ console.log("uploadedImages", this.uploadedImages);
84
+ console.log("dynamictable", dynamicTableValues);
85
+ this.tableConfig = dynamicTableValues;
86
+ this.fxData.value = this.tableConfig;
87
+ // this.tableFormControl.reset();
88
+ // this.tableFormControl.setValue(this.tableConfig);
89
+ this.tableFormControl = new FormControl();
90
+ setTimeout(() => { // Delay to ensure proper patching
91
+ this.tableFormControl.patchValue(this.tableConfig, { emitEvent: true });
92
+ console.log("tableFormControl",this.tableFormControl);
93
+ this.cdr.detectChanges();
94
+ }, 50);
95
+ }
96
+ }
97
+ })
98
+ }
99
+
100
+ public ngAfterViewInit(): void {
101
+ setTimeout(() => {
102
+ if(this.fxData?.value && Object.keys(this.fxData?.value)?.length != 0) {
103
+ this.tableConfig = this.fxData.value;
104
+ this.fetchSmartDropdownData();
105
+ }
106
+ }, 100)
107
+ }
108
+
109
+ protected fetchSmartDropdownData(): void {
110
+ this.tableConfig.columns
111
+ .filter((column: TableColumnConfig) => column.cellType === 'smart-dropdown' && column?.apiUrl)
112
+ .forEach((column: TableColumnConfig) => {
113
+ this.http.get<any>(column.apiUrl!).subscribe((response: any) => {
114
+ this.smartDropdownOptions[column.header] = response.map((item: any) => ({
115
+ value: item[column.valueKey!],
116
+ name: item[column.labelKey!],
117
+ }));
118
+ });
119
+ });
120
+ }
121
+
122
+ public uploadImage(event: Event, rowIndex: number): void {
123
+ const file = (event.target as HTMLInputElement).files?.[0];
124
+ if (file) {
125
+ const reader = new FileReader();
126
+ reader.onload = () => {
127
+ this.uploadedImages[rowIndex] = {
128
+ result: reader.result as string,
129
+ file: file
130
+ }
131
+ this.tableConfig.rows[rowIndex][this.tableConfig.columns.find((f: any) => f.cellType === 'file-upload')?.header] = file;
132
+ console.log("tableConfig", this.tableConfig);
133
+ };
134
+ reader.readAsDataURL(file);
135
+ }
136
+ }
137
+
138
+ protected settings(): FxSetting[] {
139
+ return [
140
+ new FxStringSetting({ key: 'column-size', $title: 'No. of columns', value: 1 }),
141
+ new FxStringSetting({ key: 'table-config', $title: 'Table Configuration', value: {} }),
142
+ ];
143
+ }
144
+
145
+ protected validations(): FxValidation[] {
146
+ return [FxValidatorService.required];
147
+ }
148
+
149
+ public getArray(count: number): number[] {
150
+ return Array.from({ length: count });
151
+ }
152
+
153
+ public onChangeConfiguration(event: any): void {
154
+ const columns = event.columns.map((col: any) => {
155
+ return {
156
+ header: col?.header,
157
+ cellType: col?.cellType,
158
+ placeholder: col?.placeholder,
159
+ options: col?.options,
160
+ apiUrl: col?.apiUrl,
161
+ valueKey: col?.valueKey,
162
+ labelKey: col?.labelKey,
163
+ className: col?.className,
164
+ apiKey: col?.apiKey
165
+ }
166
+ });
167
+ if(!event?.enableAPI) {
168
+ this.tableConfig.columns = columns;
169
+ // this.tableConfig.rows = Array.from({ length: +event?.rows }, (e, index) => ({ name: `SKU-${index + 1}`, age: index % 2 !== 0, gender: 'male' }))
170
+ // this.tableConfig.rows = Array.from({ length: +event?.rows }, (e, index) => {
171
+ // const rows = columns.map((c: any) => {
172
+ // return {
173
+ // c?.header: null
174
+ // }
175
+ // })
176
+ // return rows
177
+ // })
178
+ this.tableConfig.rows = Array.from({ length: +event?.rows }, (_, index) => {
179
+ return columns.reduce((acc: any, c: any) => {
180
+ acc[c?.header] = ''; // Initialize each column key with null
181
+ return acc;
182
+ }, {});
183
+ });
184
+
185
+ this.fetchSmartDropdownData();
186
+ }
187
+ if(event?.enableAPI) {
188
+ this.drawTable(event, columns)
189
+ this.tableConfig = {
190
+ columns: columns,
191
+ rows: []
192
+ };
193
+ }
194
+
195
+ this.fxData.value = this.tableConfig;
196
+ this.tableFormControl.reset();
197
+ this.tableFormControl.setValue(this.tableConfig);
198
+ }
199
+
200
+ private updateSettings(): void{
201
+ if(this.fxData.settings){
202
+ for(let setting of this.fxData.settings){
203
+ if(setting.key === 'table-config'){
204
+ setting.value = this.tableConfig;
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ public drawTable(event: any, columns: any): void {
211
+ let rows;
212
+ this.http.get(event.api).subscribe((res: any) => {
213
+ if(res) {
214
+ rows = res.map((item: any) => {
215
+ const newObj: Record<string, any> = {};
216
+ columns.forEach((col: any) => {
217
+ newObj[col.header] = item[col.apiKey];
218
+ });
219
+ return newObj;
220
+ });
221
+ this.tableConfig = {
222
+ columns,
223
+ rows
224
+ }
225
+ this.fxData.value = this.tableConfig;
226
+ this.tableFormControl.reset();
227
+ this.tableFormControl.setValue(this.tableConfig);
228
+ }
229
+ })
230
+ }
231
+
232
+ public deleteFile(file: any, index: number): void {
233
+ this.uploadedImages.splice(index, 1, null);
234
+ this.tableConfig.rows[index][this.tableConfig.columns.find((f: any) => f.cellType === 'file-upload')?.header] = null;
235
+ console.log("tableConfig", this.tableConfig);
236
+ this.tableFormControl.setValue(this.tableConfig);
237
+ }
238
+
239
+ public parseUrls(url: string, index: number): void {
240
+ this.http.get(url, { responseType: 'blob' }).subscribe({
241
+ next: (imageBlob: Blob) => {
242
+ const imageURL = URL.createObjectURL(imageBlob);
243
+ this.uploadedImages[index] = {
244
+ result: imageURL,
245
+ file: null
246
+ };
247
+ },
248
+ error: (error) => {
249
+ console.error('Error fetching image:', error);
250
+ }
251
+ });
252
+ }
253
+
254
+ public ngOnDestroy(): void {
255
+ this.destroy$.next(true);
256
+ this.destroy$.complete();
257
+ }
258
+ }
@@ -0,0 +1,86 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
3
+ import { FxForm, FxFormComponent } from '@instantsys-labs/fx';
4
+ import { DispatchToClinicComponent } from '../../custom-controls/dispatch-to-clinic/dispatch-to-clinic.component';
5
+ import { FxBuilderWrapperService } from '../../fx-builder-wrapper.service';
6
+ import { DynamicTableComponent } from '../dynamic-table/dynamic-table.component';
7
+ import { ToggleButtonComponent } from '../toggle-button/toggle-button.component';
8
+ import { UploaderComponent } from '../uploader/uploader.component';
9
+ import { ToggleComponent } from '../toggle/toggle.component';
10
+
11
+ @Component({
12
+ selector: 'fx-form-component',
13
+ standalone: true,
14
+ imports: [CommonModule, FxFormComponent],
15
+ template: `
16
+ <fx-form
17
+ [fxForm]="fxForm"
18
+ [value]="variables"
19
+ (onSubmit)="onSubmit($event)"
20
+ #form
21
+ >
22
+ </fx-form>
23
+ `,
24
+ })
25
+ export class FxFormWrapperComponent implements OnChanges, OnInit {
26
+ @ViewChild('form') form!: FxFormComponent;
27
+ @Input() fxForm!: FxForm;
28
+ @Input() variables: any;
29
+ @Output() fxFormSubmit = new EventEmitter<any>();
30
+
31
+ constructor(private fxWrapperService: FxBuilderWrapperService) {
32
+ this.registerCustomComponents();
33
+ }
34
+
35
+ public ngOnChanges(changes: SimpleChanges): void {
36
+ // if('variables' in changes && !changes['fxForm']) {
37
+ // this.fxWrapperService.variables$.next(this.variables);
38
+ // }
39
+ if ('variables' in changes) {
40
+ this.fxWrapperService.variables$.next(this.variables);
41
+ }
42
+ }
43
+
44
+ public ngOnInit(): void {
45
+ // if (!Boolean(this.fxWrapperService.getComponent('dispatch-to-clinic'))) {
46
+ // this.fxWrapperService.registerCustomComponent('Dispatch To Clinic', 'dispatch-to-clinic', DispatchToClinicComponent);
47
+ // }
48
+ // if (!Boolean(this.fxWrapperService.getComponent('dynamic-table'))) {
49
+ // this.fxWrapperService.registerCustomComponent('Dynamic Table', 'dynamic-table', DynamicTableComponent);
50
+ // }
51
+ // if (!Boolean(this.fxWrapperService.getComponent('toggle-button'))) {
52
+ // this.fxWrapperService.registerCustomComponent('Toggle Button', 'toggle-button', ToggleButtonComponent);
53
+ // }
54
+ // if (!Boolean(this.fxWrapperService.getComponent('uploader'))) {
55
+ // this.fxWrapperService.registerCustomComponent('Uploader', 'uploader', UploaderComponent);
56
+ // }
57
+ // if (!Boolean(this.fxWrapperService.getComponent('toggle'))) {
58
+ // this.fxWrapperService.registerCustomComponent('Toggle', 'toggle', ToggleComponent);
59
+ // }
60
+ }
61
+
62
+
63
+ private registerCustomComponents(): void {
64
+ const components = [
65
+ { name: 'Dispatch To Clinic', key: 'dispatch-to-clinic', component: DispatchToClinicComponent },
66
+ { name: 'Dynamic Table', key: 'dynamic-table', component: DynamicTableComponent },
67
+ { name: 'Toggle Button', key: 'toggle-button', component: ToggleButtonComponent },
68
+ { name: 'Uploader', key: 'uploader', component: UploaderComponent },
69
+ { name: 'Toggle', key: 'toggle', component: ToggleComponent }
70
+ ];
71
+
72
+ components.forEach(({ name, key, component }) => {
73
+ if (!this.fxWrapperService.getComponent(key)) {
74
+ this.fxWrapperService.registerCustomComponent(name, key, component);
75
+ }
76
+ });
77
+ }
78
+
79
+ public onSubmit(event: any): void {
80
+ this.fxFormSubmit.emit(event);
81
+ }
82
+
83
+ public submit(): void {
84
+ this.form.submit();
85
+ }
86
+ }
@@ -0,0 +1,51 @@
1
+ label {
2
+ position: relative;
3
+ white-space: nowrap;
4
+ border-radius: 0;
5
+ border: 0 solid #999999;
6
+ margin: 0 14px 0 0;
7
+ width: 120px;
8
+ height: auto;
9
+ padding: 0;
10
+ text-align: center;
11
+ cursor: pointer;
12
+ }
13
+
14
+ .form-radio {
15
+ background-color: #DAE6F0;
16
+ color: white;
17
+ box-shadow: none;
18
+ transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
19
+ border: 1px solid #DEDEDE;
20
+ padding: 9px 10px;
21
+ margin: 0;
22
+ white-space: nowrap;
23
+ width: 100%;
24
+ height: 38px;
25
+ background-image: none;
26
+ border-radius: 4px;
27
+ }
28
+
29
+ .form-radio:checked {
30
+ background-color: #ADD8E6;
31
+ border-color: #9BBBD6;
32
+ }
33
+
34
+ .form-radio:focus {
35
+ box-shadow: 0 0 0 2px #fff, 0 0 0 4px #9dc1fb, 0 1px 2px 0 black;
36
+ background-color: #ADD8E6;
37
+ }
38
+
39
+ .form-radio:hover {
40
+ border-color: #4682B4;
41
+ }
42
+
43
+ span {
44
+ position: absolute;
45
+ left: 0;
46
+ right: 0;
47
+ top: 8px;
48
+ bottom: 0;
49
+ margin: 0;
50
+ padding: 0;
51
+ }
@@ -0,0 +1,12 @@
1
+ <fx-component [fxData]="fxData">
2
+ <div style="display: flex;">
3
+ <label>
4
+ <input [formControl]="toggleControl" type="radio" name="radio_grp" class="form-radio mr-3" value="true">
5
+ <span class="mt-1">{{setting('accept')}}</span>
6
+ </label>
7
+ <label>
8
+ <input [formControl]="toggleControl" type="radio" name="radio_grp" class="form-radio mr-3" value="false">
9
+ <span class="mt-1">{{setting('reject')}}</span>
10
+ </label>
11
+ </div>
12
+ </fx-component>
@@ -0,0 +1,33 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { ChangeDetectorRef, Component, inject } from '@angular/core';
3
+ import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
4
+ import { FxBaseComponent, FxComponent, FxSetting, FxStringSetting, FxValidation, FxValidatorService } from '@instantsys-labs/fx';
5
+
6
+ @Component({
7
+ selector: 'fx-toggle',
8
+ standalone: true,
9
+ imports: [CommonModule, FxComponent, FormsModule, ReactiveFormsModule],
10
+ templateUrl: './toggle.component.html',
11
+ styleUrl: './toggle.component.css'
12
+ })
13
+ export class ToggleComponent extends FxBaseComponent {
14
+ public toggleControl = new FormControl<boolean>(false)
15
+
16
+ constructor(private cdr: ChangeDetectorRef) {
17
+ super(cdr)
18
+ this.onInit.subscribe((fxData)=>{
19
+ this._register(this.toggleControl);
20
+ })
21
+ }
22
+
23
+ protected settings(): FxSetting[] {
24
+ return [
25
+ new FxStringSetting({ key: 'accept', $title: 'Accept Text', value: 'Yes' }),
26
+ new FxStringSetting({ key: 'reject', $title: 'Reject Text', value: 'No' })
27
+ ];
28
+ }
29
+
30
+ protected validations(): FxValidation[] {
31
+ return [FxValidatorService.required];
32
+ }
33
+ }
@@ -0,0 +1,22 @@
1
+ .custom-toggle-btn {
2
+ padding: 10px 20px;
3
+ font-size: 16px;
4
+ font-weight: bold;
5
+ color: white;
6
+ border: none;
7
+ border-radius: 5px;
8
+ cursor: pointer;
9
+ background-color: #ccc;
10
+ transition: background-color 0.3s;
11
+ }
12
+
13
+ .custom-toggle-btn.active {
14
+ background-color: #4caf50;
15
+ }
16
+
17
+ .custom-toggle-btn:hover {
18
+ opacity: 0.9;
19
+ }
20
+
21
+
22
+
@@ -0,0 +1,10 @@
1
+ <fx-component [fxData]="fxData">
2
+ <button
3
+ class="custom-toggle-btn"
4
+ [class]="setting('classes') ? setting('classes'): ''"
5
+ [class.active]="toggleBtnControl.value"
6
+ (click)="toggle()"
7
+ >
8
+ {{ toggleBtnControl.value ? setting('active-text') : setting('inactive-text') }}
9
+ </button>
10
+ </fx-component>