tee3apps-cms-sdk-react 0.0.5 → 0.0.7

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 (31) hide show
  1. package/README.md +244 -2
  2. package/dist/index.d.ts +189 -1
  3. package/dist/index.js +3 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +3 -3
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +1 -1
  8. package/src/App.css +37 -0
  9. package/src/Page.tsx +5 -2
  10. package/src/PageComponents/Visual-Components/GroupProductComponent.tsx +182 -318
  11. package/src/PageComponents/Visual-Components/RichTextComponent.tsx +28 -0
  12. package/src/PageFormComponents/BooleanField.tsx +56 -0
  13. package/src/PageFormComponents/BoxRenderer.tsx +229 -0
  14. package/src/PageFormComponents/Button.tsx +127 -0
  15. package/src/PageFormComponents/DateField.tsx +46 -0
  16. package/src/PageFormComponents/ImageComponent.tsx +163 -0
  17. package/src/PageFormComponents/InputField.tsx +62 -0
  18. package/src/PageFormComponents/NumberField.tsx +56 -0
  19. package/src/PageFormComponents/PageForm.css +213 -0
  20. package/src/PageFormComponents/PageForm.tsx +267 -0
  21. package/src/PageFormComponents/RadioField.tsx +59 -0
  22. package/src/PageFormComponents/RowComponent.tsx +82 -0
  23. package/src/PageFormComponents/SelectField.tsx +183 -0
  24. package/src/PageFormComponents/Styles/BooleanField.css +56 -0
  25. package/src/PageFormComponents/Styles/DateField.css +44 -0
  26. package/src/PageFormComponents/Styles/InputField.css +50 -0
  27. package/src/PageFormComponents/Styles/NumberField.css +57 -0
  28. package/src/PageFormComponents/Styles/RadioField.css +66 -0
  29. package/src/PageFormComponents/Styles/SelectField.css +264 -0
  30. package/src/PageFormComponents/TextComponent.tsx +45 -0
  31. package/src/index.ts +2 -2
package/README.md CHANGED
@@ -5,7 +5,10 @@ A powerful and flexible React component library for dynamically rendering pages
5
5
  ## 🚀 Features
6
6
 
7
7
  - **Dynamic Page Rendering**: Convert JSON data into fully functional web pages
8
+ - **Dynamic Form Rendering**: Convert JSON data into interactive forms with validation
8
9
  - **Flexible Element Support**: Support for various page elements (text, images, buttons, forms, etc.)
10
+ - **Form Field Support**: Multiple form field types (text, number, date, select, radio, boolean)
11
+ - **Form Validation**: Built-in required field validation with custom toast notifications
9
12
  - **Easy Integration**: Simple drop-in component with minimal configuration
10
13
  - **TypeScript Support**: Full TypeScript support with comprehensive type definitions
11
14
  - **Customizable Styling**: Built-in themes with customization options
@@ -30,7 +33,7 @@ Here's a simple example of how to use the Dynamic Page Renderer:
30
33
 
31
34
  ```jsx
32
35
  import React, { useState, useEffect } from 'react';
33
- import { Page } from 'tee3apps-cms-sdk-react';
36
+ import { Page, PageForm } from 'tee3apps-cms-sdk-react';
34
37
 
35
38
  function App() {
36
39
  const [pageData, setPageData] = useState(null);
@@ -67,7 +70,60 @@ function App() {
67
70
  export default App;
68
71
  ```
69
72
 
70
- ## 📊 Data Structure
73
+ ## 📝 Using PageForm Component
74
+
75
+ The `PageForm` component allows you to render dynamic forms based on JSON data. It includes built-in validation, form state management, and toast notifications.
76
+
77
+ ### Basic PageForm Usage
78
+
79
+ ```jsx
80
+ import React, { useState, useEffect } from 'react';
81
+ import { PageForm } from 'tee3apps-cms-sdk-react';
82
+
83
+ function FormPage() {
84
+ const [formData, setFormData] = useState(null);
85
+ const [loading, setLoading] = useState(true);
86
+
87
+ useEffect(() => {
88
+ const fetchFormData = async () => {
89
+ try {
90
+ const response = await fetch('/api/form-data');
91
+ const data = await response.json();
92
+ const formElements = data?.data?.formElements;
93
+
94
+ setFormData(formElements);
95
+ } catch (error) {
96
+ console.error('Error fetching form data:', error);
97
+ } finally {
98
+ setLoading(false);
99
+ }
100
+ };
101
+
102
+ fetchFormData();
103
+ }, []);
104
+
105
+ const handleFormSubmit = (formValues) => {
106
+ console.log('Form submitted with values:', formValues);
107
+ // Handle form submission (e.g., send to API)
108
+ // Form values are automatically transformed to use field names instead of codes
109
+ };
110
+
111
+ if (loading) return <div>Loading...</div>;
112
+
113
+ return (
114
+ <div className="form-page">
115
+ <PageForm
116
+ jsonData={formData}
117
+ onSubmit={handleFormSubmit}
118
+ />
119
+ </div>
120
+ );
121
+ }
122
+
123
+ export default FormPage;
124
+ ```
125
+
126
+ ## 📊 Page Component Data Structure
71
127
 
72
128
  The package expects your `pageElements` data to follow this structure:
73
129
 
@@ -239,7 +295,193 @@ The package expects your `pageElements` data to follow this structure:
239
295
  ]
240
296
  ```
241
297
 
298
+ ## 📋 PageForm Component Data Structure
299
+
300
+ The `PageForm` component expects the same structure as `Page`, but with form-specific components. Here's an example with form fields:
301
+
302
+ ```json
303
+ [
304
+ {
305
+ "name": "Row",
306
+ "props": {
307
+ "minHeight": "auto",
308
+ "bgColor": "#ffffff",
309
+ "bgImage": "",
310
+ "align": "initial",
311
+ "justify": "flex-start",
312
+ "nowrap": false,
313
+ "bgsize": "cover",
314
+ "mode": {
315
+ "web": {
316
+ "isScroll": false,
317
+ "isVisible": true,
318
+ "top": "0px",
319
+ "bottom": "0px",
320
+ "flexView": true
321
+ },
322
+ "mobileweb": { ... },
323
+ "mobileapp": { ... },
324
+ "tablet": { ... }
325
+ }
326
+ },
327
+ "columns": [
328
+ {
329
+ "name": "Box",
330
+ "props": {
331
+ "bgColor": "#ffffff",
332
+ "align": "initial",
333
+ "justify": "flex-start",
334
+ "mode": {
335
+ "web": {
336
+ "colspan": 12,
337
+ "isVisible": true,
338
+ "height": "auto"
339
+ }
340
+ }
341
+ },
342
+ "components": [
343
+ {
344
+ "name": "InputField",
345
+ "props": {
346
+ "code": "email",
347
+ "name": {
348
+ "all": "Email Address"
349
+ },
350
+ "required": true,
351
+ "type": "email",
352
+ "placeholder": {
353
+ "all": "Enter your email"
354
+ }
355
+ },
356
+ "type": []
357
+ },
358
+ {
359
+ "name": "NumberField",
360
+ "props": {
361
+ "code": "age",
362
+ "name": {
363
+ "all": "Age"
364
+ },
365
+ "required": false,
366
+ "min": 18,
367
+ "max": 100
368
+ },
369
+ "type": []
370
+ },
371
+ {
372
+ "name": "SelectField",
373
+ "props": {
374
+ "code": "country",
375
+ "name": {
376
+ "all": "Country"
377
+ },
378
+ "required": true,
379
+ "multiSelect": false,
380
+ "lov": [
381
+ {
382
+ "id": "1",
383
+ "code": "us",
384
+ "name": "United States"
385
+ },
386
+ {
387
+ "id": "2",
388
+ "code": "uk",
389
+ "name": "United Kingdom"
390
+ }
391
+ ]
392
+ },
393
+ "type": []
394
+ },
395
+ {
396
+ "name": "DateField",
397
+ "props": {
398
+ "code": "birthdate",
399
+ "name": {
400
+ "all": "Date of Birth"
401
+ },
402
+ "required": true,
403
+ "format": "YYYY-MM-DD"
404
+ },
405
+ "type": []
406
+ },
407
+ {
408
+ "name": "RadioField",
409
+ "props": {
410
+ "code": "gender",
411
+ "name": {
412
+ "all": "Gender"
413
+ },
414
+ "required": true,
415
+ "lov": [
416
+ {
417
+ "id": "1",
418
+ "code": "male",
419
+ "name": "Male"
420
+ },
421
+ {
422
+ "id": "2",
423
+ "code": "female",
424
+ "name": "Female"
425
+ }
426
+ ]
427
+ },
428
+ "type": []
429
+ },
430
+ {
431
+ "name": "BooleanField",
432
+ "props": {
433
+ "code": "terms",
434
+ "name": {
435
+ "all": "I agree to the terms and conditions"
436
+ },
437
+ "required": true,
438
+ "onText": "Yes",
439
+ "offText": "No"
440
+ },
441
+ "type": []
442
+ }
443
+ ]
444
+ }
445
+ ]
446
+ }
447
+ ]
448
+ ```
449
+
450
+ ### Supported Form Field Types
242
451
 
452
+ - **InputField**: Text input fields (text, email, password, etc.)
453
+ - **NumberField**: Numeric input with min/max validation
454
+ - **DateField**: Date picker with format support
455
+ - **SelectField**: Dropdown select with single or multi-select
456
+ - **RadioField**: Radio button group
457
+ - **BooleanField**: Checkbox or toggle switch
458
+
459
+ ### Form Features
460
+
461
+ - **Automatic Validation**: Required fields are validated automatically
462
+ - **Toast Notifications**: Custom toast notifications for validation errors
463
+ - **Field Name Mapping**: Form values are automatically transformed from codes to field names
464
+ - **Responsive Design**: Forms adapt to different device modes (web, mobileweb, mobileapp, tablet)
465
+ - **Error Highlighting**: Invalid fields are visually highlighted
466
+
467
+ ### Form Submission
468
+
469
+ The `onSubmit` callback receives form data with field names as keys:
470
+
471
+ ```jsx
472
+ const handleFormSubmit = (formValues) => {
473
+ // formValues will have field names as keys
474
+ // Example: { "Email Address": "user@example.com", "Country": "us" }
475
+ console.log(formValues);
476
+
477
+ // Submit to your API
478
+ fetch('/api/submit-form', {
479
+ method: 'POST',
480
+ headers: { 'Content-Type': 'application/json' },
481
+ body: JSON.stringify(formValues)
482
+ });
483
+ };
484
+ ```
243
485
 
244
486
  ## 📄 License
245
487
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,193 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
2
3
 
3
4
  declare const Page: ({ data }: any) => react_jsx_runtime.JSX.Element;
4
5
 
5
- export { Page as default };
6
+ type LOVItem = {
7
+ id: string;
8
+ code: string;
9
+ name: string;
10
+ };
11
+ interface TextStyle {
12
+ headingTag: string;
13
+ fontSize: number;
14
+ fontStyle: {
15
+ isBold: boolean;
16
+ isItalic: boolean;
17
+ isUnderLine: boolean;
18
+ isStrikeThrough: boolean;
19
+ };
20
+ fontColor: string;
21
+ textAlign: string;
22
+ fontFamily: string;
23
+ }
24
+ interface ImageData {
25
+ isDynamic: boolean;
26
+ shape: string;
27
+ url: string;
28
+ alt: string;
29
+ }
30
+ interface ImageModeProps {
31
+ borderRadius: number;
32
+ width: string;
33
+ height: string;
34
+ bgColor?: string;
35
+ }
36
+ interface DeviceModes {
37
+ web: ImageModeProps | ButtonModeProps;
38
+ mobileweb: ImageModeProps | ButtonModeProps;
39
+ mobileapp: ImageModeProps | ButtonModeProps;
40
+ tablet: ImageModeProps | ButtonModeProps;
41
+ }
42
+ type ComponentProps = {
43
+ columnSize?: string;
44
+ name?: {
45
+ all?: string;
46
+ };
47
+ type?: string;
48
+ required?: boolean;
49
+ helperText?: string;
50
+ multiSelect?: boolean;
51
+ lov?: LOVItem[];
52
+ pattern?: string;
53
+ min?: number;
54
+ max?: number;
55
+ step?: number;
56
+ suffix?: string;
57
+ format?: string;
58
+ postaltype?: string;
59
+ textArea?: boolean;
60
+ minLength?: number;
61
+ maxLength?: number;
62
+ termsandcondition?: {
63
+ all?: string;
64
+ };
65
+ onText?: string;
66
+ offText?: string;
67
+ code?: string;
68
+ pd_id?: {
69
+ _id: string;
70
+ code: string;
71
+ name: object;
72
+ pd_type: string;
73
+ };
74
+ images?: {
75
+ all: ImageData;
76
+ };
77
+ linktype?: string;
78
+ link?: {
79
+ url: string;
80
+ target: string;
81
+ };
82
+ mode?: DeviceModes;
83
+ product?: {
84
+ _id: string;
85
+ code: string;
86
+ name: object;
87
+ pd_type: string;
88
+ pd_id?: any;
89
+ product_data?: any;
90
+ };
91
+ page?: {
92
+ _id: string;
93
+ code: string;
94
+ name: object;
95
+ pg_type: string;
96
+ facet_params: any[];
97
+ track_params: any[];
98
+ };
99
+ tag?: {
100
+ _id: string;
101
+ tag_id?: any;
102
+ code: string;
103
+ name: object;
104
+ tagtype: string;
105
+ };
106
+ text?: any;
107
+ style?: TextStyle;
108
+ height?: string;
109
+ disabled?: boolean;
110
+ bgColor?: string;
111
+ radius?: string;
112
+ };
113
+ type Component = {
114
+ name: string;
115
+ props: ComponentProps;
116
+ type: any[];
117
+ };
118
+ type Box = {
119
+ name: string;
120
+ props: {
121
+ bgColor: string;
122
+ bgImage: any;
123
+ align: string;
124
+ justify: string;
125
+ compOrder: string;
126
+ bgsize: string;
127
+ layout: string;
128
+ mode: {
129
+ web: {
130
+ colspan: number;
131
+ isVisible: boolean;
132
+ height: string;
133
+ top: string;
134
+ bottom: string;
135
+ left: string;
136
+ right: string;
137
+ radius: string;
138
+ };
139
+ mobileweb: any;
140
+ mobileapp: any;
141
+ tablet: any;
142
+ };
143
+ };
144
+ components: Component[];
145
+ };
146
+ interface ButtonModeProps {
147
+ radius?: string;
148
+ borderRadius?: number;
149
+ bgColor?: string;
150
+ textstyle?: {
151
+ fontSize: number;
152
+ fontColor: string;
153
+ fontStyle: {
154
+ isBold: boolean;
155
+ isItalic: boolean;
156
+ isUnderLine: boolean;
157
+ isStrikeThrough: boolean;
158
+ };
159
+ };
160
+ }
161
+ type Row = {
162
+ name: string;
163
+ props: {
164
+ minHeight: string;
165
+ bgColor: string;
166
+ bgImage: string;
167
+ align: string;
168
+ justify: string;
169
+ nowrap: boolean;
170
+ bgsize: string;
171
+ mode: {
172
+ web: {
173
+ isScroll: boolean;
174
+ isVisible: boolean;
175
+ top: string;
176
+ bottom: string;
177
+ flexView: boolean;
178
+ };
179
+ mobileweb: any;
180
+ mobileapp: any;
181
+ tablet: any;
182
+ };
183
+ };
184
+ columns: Box[];
185
+ };
186
+
187
+ interface PageFormProps {
188
+ jsonData: Row[];
189
+ onSubmit?: (data: Record<string, any>) => void;
190
+ }
191
+ declare const PageForm: React.FC<PageFormProps>;
192
+
193
+ export { Page, PageForm };