@twintag/twintag-form 1.3.0 → 1.4.0-beta.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 (65) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +121 -62
  4. package/dev/main.tsx +233 -210
  5. package/dist/common/button.d.ts +17 -30
  6. package/dist/common/calendar.d.ts +212 -4
  7. package/dist/common/form.d.ts +151 -9
  8. package/dist/common/icon.d.ts +2 -1
  9. package/dist/common/input.d.ts +276 -2
  10. package/dist/common/label.d.ts +39 -1
  11. package/dist/common/slider.d.ts +4 -0
  12. package/dist/common/textarea.d.ts +139 -2
  13. package/dist/components/config.d.ts +4 -2
  14. package/dist/components/containers/accordion.d.ts +3 -2
  15. package/dist/components/containers/category.d.ts +3 -2
  16. package/dist/components/fields/checkbox.d.ts +4 -2
  17. package/dist/components/fields/date-picker.d.ts +3 -1
  18. package/dist/components/fields/file.d.ts +4 -2
  19. package/dist/components/fields/input.d.ts +4 -2
  20. package/dist/components/fields/radiogroup.d.ts +4 -2
  21. package/dist/components/fields/submit.d.ts +3 -2
  22. package/dist/components/fields/textarea.d.ts +4 -2
  23. package/dist/components/fields/toggle.d.ts +4 -2
  24. package/dist/components/fields/tri-toggle.d.ts +5 -0
  25. package/dist/components/form.d.ts +2 -2
  26. package/dist/components/provider.d.ts +21 -0
  27. package/dist/components/renderer.d.ts +1 -0
  28. package/dist/index.d.ts +5 -3
  29. package/dist/twintag-form.react.js +12868 -12156
  30. package/dist/types/index.d.ts +25 -16
  31. package/dist/utils/data.d.ts +2 -1
  32. package/dist/utils/style.d.ts +2 -1
  33. package/index.html +5 -3
  34. package/lib/common/button.tsx +4 -5
  35. package/lib/common/calendar.tsx +25 -5
  36. package/lib/common/form.tsx +40 -19
  37. package/lib/common/input.tsx +20 -10
  38. package/lib/common/label.tsx +16 -3
  39. package/lib/common/slider.tsx +38 -0
  40. package/lib/common/textarea.tsx +17 -9
  41. package/lib/components/config.tsx +46 -17
  42. package/lib/components/containers/accordion.tsx +24 -7
  43. package/lib/components/containers/category.tsx +16 -7
  44. package/lib/components/fields/checkbox.tsx +12 -6
  45. package/lib/components/fields/date-picker.tsx +54 -18
  46. package/lib/components/fields/file.tsx +83 -76
  47. package/lib/components/fields/input.tsx +15 -6
  48. package/lib/components/fields/radiogroup.tsx +13 -7
  49. package/lib/components/fields/submit.tsx +5 -2
  50. package/lib/components/fields/textarea.tsx +14 -6
  51. package/lib/components/fields/toggle.tsx +12 -6
  52. package/lib/components/fields/tri-toggle.tsx +141 -0
  53. package/lib/components/form.tsx +5 -7
  54. package/lib/components/provider.tsx +159 -0
  55. package/lib/components/{Render/index.tsx → renderer.tsx} +19 -2
  56. package/lib/index.tsx +41 -36
  57. package/lib/types/index.ts +49 -39
  58. package/package.json +5 -7
  59. package/dist/components/Render/index.d.ts +0 -7
  60. package/dist/components/Render/useJson.d.ts +0 -2
  61. package/dist/components/index.d.ts +0 -7
  62. package/dist/provider.d.ts +0 -8
  63. package/lib/components/Render/useJson.ts +0 -76
  64. package/lib/components/index.tsx +0 -24
  65. package/lib/provider.tsx +0 -36
package/dev/main.tsx CHANGED
@@ -1,210 +1,233 @@
1
- import type { ComponentProps } from 'react';
2
- import type { Form } from '../lib';
3
-
4
- import '../lib/webcomponent';
5
- import './index.css';
6
-
7
- const config = [
8
- {
9
- type: 'category',
10
- props: {
11
- label: 'Category 1st',
12
- },
13
- children: [
14
- {
15
- type: 'input',
16
- props: {
17
- subtype: 'datepicker',
18
- label: 'Date picker',
19
- bind: 'datepicker',
20
- options: {
21
- description: 'this field is required',
22
- },
23
- },
24
- },
25
- {
26
- type: 'accordion',
27
- children: [
28
- {
29
- type: 'accordion',
30
- props: {
31
- subtype: 'item',
32
- label: 'Required',
33
- icon: 'archive-box-x-mark',
34
- },
35
- children: [
36
- {
37
- type: 'input',
38
- props: {
39
- subtype: 'toggle',
40
- label: 'Required',
41
- bind: 'required',
42
- options: {
43
- description: 'this field is required',
44
- },
45
- },
46
- },
47
- ],
48
- },
49
- ],
50
- },
51
- ],
52
- },
53
- {
54
- type: 'category',
55
- props: {
56
- label: 'Category 2nd',
57
- },
58
- children: [
59
- {
60
- type: 'input',
61
- props: {
62
- subtype: 'simple',
63
- label: 'Email',
64
- bind: 'email',
65
- options: {
66
- error: 'This field is required',
67
- description: 'This field is required',
68
- },
69
- },
70
- },
71
- {
72
- type: 'input',
73
- props: {
74
- subtype: 'radiogroup',
75
- label: 'Radio Group',
76
- bind: 'radiogroup',
77
- options: {
78
- description: 'This field is required',
79
- error: 'This field is required',
80
- },
81
- },
82
- children: [
83
- {
84
- type: 'item',
85
- props: {
86
- label: 'Checkbox',
87
- bind: 'checkbox',
88
- options: {
89
- description: 'This field is required',
90
- error: 'This field is required',
91
- },
92
- },
93
- },
94
- {
95
- type: 'item',
96
- props: {
97
- label: 'Mote',
98
- bind: 'mote',
99
- options: {
100
- description: 'This field is required',
101
- error: 'This field is required',
102
- },
103
- },
104
- },
105
- ],
106
- },
107
- ],
108
- },
109
- {
110
- type: 'category',
111
- props: {
112
- label: 'Category 3rd',
113
- },
114
- children: [
115
- {
116
- type: 'input',
117
- props: {
118
- subtype: 'file',
119
- label: 'File',
120
- bind: 'file',
121
- options: {
122
- error: 'This field is required',
123
- description: 'This field is required',
124
- },
125
- },
126
- },
127
- ],
128
- },
129
- {
130
- type: 'category',
131
- props: {
132
- label: 'Category 4th',
133
- },
134
- children: [
135
- {
136
- type: 'input',
137
- props: {
138
- subtype: 'textarea',
139
- label: 'Textarea',
140
- bind: 'textarea',
141
- options: {
142
- description: 'This field is required',
143
- error: 'This field is required',
144
- },
145
- },
146
- },
147
- {
148
- type: 'input',
149
- props: {
150
- subtype: 'checkbox',
151
- label: 'Checkbox',
152
- bind: 'checkbox',
153
- options: {
154
- description: 'This field is required',
155
- error: 'This field is required',
156
- },
157
- },
158
- },
159
- ],
160
- },
161
- {
162
- type: 'input',
163
- props: {
164
- subtype: 'submit',
165
- label: 'Submit',
166
- },
167
- },
168
- ] satisfies React.ComponentProps<typeof Form>['config'];
169
-
170
- const options = {
171
- defaultValues: {
172
- required: 'true',
173
- email: 'This should work',
174
- radiogroup: 'mote',
175
- checkbox: true,
176
- textarea: 'This is a textarea',
177
- },
178
- resetOnSubmit: true,
179
- variant: 'beta',
180
- } as ComponentProps<typeof Form>['options'];
181
-
182
- // the key properties for the defaultValues object are the same as the bind properties
183
- const form = document.querySelector('twintag-form');
184
-
185
- form?.setAttribute('config', JSON.stringify(config));
186
- form?.setAttribute('options', JSON.stringify(options));
187
-
188
- form?.addEventListener('twintag-form-values', (event) => {
189
- console.log('form values', (event as CustomEvent).detail);
190
- });
191
- form?.addEventListener('twintag-form-valid', (e) => {
192
- console.log('form valid', (e as CustomEvent).detail);
193
- });
194
- form?.addEventListener('twintag-form-invalid', (e) => {
195
- console.log('form invalid', (e as CustomEvent).detail);
196
- });
197
-
198
- const getValues = document.getElementById('get-values');
199
- getValues?.addEventListener('click', () => {
200
- form?.shadowRoot
201
- ?.querySelector('form')
202
- ?.dispatchEvent(new CustomEvent('twintag-form-get_values'));
203
- });
204
-
205
- const submit = document.getElementById('submit');
206
- submit?.addEventListener('click', () => {
207
- form?.shadowRoot
208
- ?.querySelector('form')
209
- ?.dispatchEvent(new CustomEvent('twintag-form-validate'));
210
- });
1
+ import type { ComponentProps } from 'react';
2
+ import type { Form } from '../lib';
3
+
4
+ import '../lib/webcomponent';
5
+ import './index.css';
6
+
7
+ const config = [
8
+ {
9
+ type: 'category',
10
+ props: {
11
+ label: 'Category 1st',
12
+ },
13
+ children: [
14
+ {
15
+ type: 'input',
16
+ props: {
17
+ subtype: 'toggle',
18
+ label: 'Switch',
19
+ bind: 'switch',
20
+ options: {
21
+ description: 'this field is required',
22
+ },
23
+ },
24
+ },
25
+ {
26
+ type: 'input',
27
+ props: {
28
+ subtype: 'tri-toggle',
29
+ label: 'Tri-toggle',
30
+ bind: 'tri-toggle-bind',
31
+ options: {
32
+ description: 'this field is never required',
33
+ },
34
+ },
35
+ },
36
+ {
37
+ type: 'input',
38
+ props: {
39
+ subtype: 'datepicker',
40
+ label: 'Date picker',
41
+ bind: 'datepicker',
42
+ options: {
43
+ description: 'this field is required',
44
+ },
45
+ },
46
+ },
47
+ {
48
+ type: 'accordion',
49
+ children: [
50
+ {
51
+ type: 'accordion',
52
+ props: {
53
+ subtype: 'item',
54
+ label: 'Required',
55
+ icon: 'archive-box-x-mark',
56
+ },
57
+ children: [
58
+ {
59
+ type: 'input',
60
+ props: {
61
+ subtype: 'toggle',
62
+ label: 'Required',
63
+ bind: 'required',
64
+ options: {
65
+ description: 'this field is required',
66
+ },
67
+ },
68
+ },
69
+ ],
70
+ },
71
+ ],
72
+ },
73
+ ],
74
+ },
75
+ {
76
+ type: 'category',
77
+ props: {
78
+ label: 'Category 2nd',
79
+ },
80
+ children: [
81
+ {
82
+ type: 'input',
83
+ props: {
84
+ subtype: 'simple',
85
+ label: 'Email',
86
+ bind: 'email',
87
+ options: {
88
+ error: 'This field is required',
89
+ description: 'This field is required',
90
+ },
91
+ },
92
+ },
93
+ {
94
+ type: 'input',
95
+ props: {
96
+ subtype: 'radiogroup',
97
+ label: 'Radio Group',
98
+ bind: 'radiogroup',
99
+ options: {
100
+ description: 'This field is required',
101
+ error: 'This field is required',
102
+ },
103
+ },
104
+ children: [
105
+ {
106
+ type: 'item',
107
+ props: {
108
+ label: 'Checkbox',
109
+ bind: 'checkbox',
110
+ options: {
111
+ description: 'This field is required',
112
+ error: 'This field is required',
113
+ },
114
+ },
115
+ },
116
+ {
117
+ type: 'item',
118
+ props: {
119
+ label: 'Mote',
120
+ bind: 'mote',
121
+ options: {
122
+ description: 'This field is required',
123
+ error: 'This field is required',
124
+ },
125
+ },
126
+ },
127
+ ],
128
+ },
129
+ ],
130
+ },
131
+ {
132
+ type: 'category',
133
+ props: {
134
+ label: 'Category 3rd',
135
+ },
136
+ children: [
137
+ {
138
+ type: 'input',
139
+ props: {
140
+ subtype: 'file',
141
+ label: 'File',
142
+ bind: 'file',
143
+ options: {
144
+ error: 'This field is required',
145
+ description: 'This field is required',
146
+ },
147
+ },
148
+ },
149
+ ],
150
+ },
151
+ {
152
+ type: 'category',
153
+ props: {
154
+ label: 'Category 4th',
155
+ },
156
+ children: [
157
+ {
158
+ type: 'input',
159
+ props: {
160
+ subtype: 'textarea',
161
+ label: 'Textarea',
162
+ bind: 'textarea',
163
+ options: {
164
+ description: 'This field is required',
165
+ error: 'This field is required',
166
+ },
167
+ },
168
+ },
169
+ {
170
+ type: 'input',
171
+ props: {
172
+ subtype: 'checkbox',
173
+ label: 'Checkbox',
174
+ bind: 'checkbox',
175
+ options: {
176
+ description: 'This field is required',
177
+ error: 'This field is required',
178
+ },
179
+ },
180
+ },
181
+ ],
182
+ },
183
+ {
184
+ type: 'input',
185
+ props: {
186
+ subtype: 'submit',
187
+ label: 'Submit',
188
+ },
189
+ },
190
+ ] satisfies React.ComponentProps<typeof Form>['config'];
191
+
192
+ const options = {
193
+ defaultValues: {
194
+ 'tri-toggle-bind': null,
195
+ required: true,
196
+ email: 'This should work',
197
+ radiogroup: 'mote',
198
+ checkbox: true,
199
+ textarea: 'This is a textarea',
200
+ },
201
+ variant: 'beta',
202
+ resetOnSubmit: true,
203
+ } as ComponentProps<typeof Form>['options'];
204
+
205
+ // the key properties for the defaultValues object are the same as the bind properties
206
+ const form = document.querySelector('twintag-form');
207
+
208
+ form?.setAttribute('config', JSON.stringify(config));
209
+ form?.setAttribute('options', JSON.stringify(options));
210
+
211
+ form?.addEventListener('twintag-form-values', (event) => {
212
+ console.log('form values', (event as CustomEvent).detail);
213
+ });
214
+ form?.addEventListener('twintag-form-valid', (e) => {
215
+ console.log('form valid', (e as CustomEvent).detail);
216
+ });
217
+ form?.addEventListener('twintag-form-invalid', (e) => {
218
+ console.log('form invalid', (e as CustomEvent).detail);
219
+ });
220
+
221
+ const getValues = document.getElementById('get-values');
222
+ getValues?.addEventListener('click', () => {
223
+ form?.shadowRoot
224
+ ?.querySelector('form')
225
+ ?.dispatchEvent(new CustomEvent('twintag-form-get_values'));
226
+ });
227
+
228
+ const submit = document.getElementById('submit');
229
+ submit?.addEventListener('click', () => {
230
+ form?.shadowRoot
231
+ ?.querySelector('form')
232
+ ?.dispatchEvent(new CustomEvent('twintag-form-validate'));
233
+ });
@@ -1,5 +1,6 @@
1
+ import { VariantProps, TVReturnType } from 'tailwind-variants';
1
2
  import { TVConfig } from 'tailwind-variants/dist/config.js';
2
- import { TVReturnType, VariantProps } from 'tailwind-variants';
3
+
3
4
  import * as React from 'react';
4
5
  declare const buttonVariants: TVReturnType<{
5
6
  variant: {
@@ -8,9 +9,8 @@ declare const buttonVariants: TVReturnType<{
8
9
  ghost: string;
9
10
  };
10
11
  size: {
11
- default: string;
12
12
  sm: string;
13
- lg: string;
13
+ base: string;
14
14
  };
15
15
  }, undefined, string[], TVConfig<{
16
16
  variant: {
@@ -19,9 +19,8 @@ declare const buttonVariants: TVReturnType<{
19
19
  ghost: string;
20
20
  };
21
21
  size: {
22
- default: string;
23
22
  sm: string;
24
- lg: string;
23
+ base: string;
25
24
  };
26
25
  }, {
27
26
  variant: {
@@ -30,9 +29,8 @@ declare const buttonVariants: TVReturnType<{
30
29
  ghost: string;
31
30
  };
32
31
  size: {
33
- default: string;
34
32
  sm: string;
35
- lg: string;
33
+ base: string;
36
34
  };
37
35
  }>, {
38
36
  variant: {
@@ -41,9 +39,8 @@ declare const buttonVariants: TVReturnType<{
41
39
  ghost: string;
42
40
  };
43
41
  size: {
44
- default: string;
45
42
  sm: string;
46
- lg: string;
43
+ base: string;
47
44
  };
48
45
  }, undefined, TVReturnType<{
49
46
  variant: {
@@ -52,9 +49,8 @@ declare const buttonVariants: TVReturnType<{
52
49
  ghost: string;
53
50
  };
54
51
  size: {
55
- default: string;
56
52
  sm: string;
57
- lg: string;
53
+ base: string;
58
54
  };
59
55
  }, undefined, string[], TVConfig<{
60
56
  variant: {
@@ -63,9 +59,8 @@ declare const buttonVariants: TVReturnType<{
63
59
  ghost: string;
64
60
  };
65
61
  size: {
66
- default: string;
67
62
  sm: string;
68
- lg: string;
63
+ base: string;
69
64
  };
70
65
  }, {
71
66
  variant: {
@@ -74,24 +69,22 @@ declare const buttonVariants: TVReturnType<{
74
69
  ghost: string;
75
70
  };
76
71
  size: {
77
- default: string;
78
72
  sm: string;
79
- lg: string;
73
+ base: string;
80
74
  };
81
75
  }>, unknown, unknown, undefined>>;
82
76
  export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps<typeof buttonVariants> & {
83
77
  asChild?: boolean;
84
78
  };
85
- declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps<TVReturnType<{
79
+ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps< TVReturnType<{
86
80
  variant: {
87
81
  default: string;
88
82
  outline: string;
89
83
  ghost: string;
90
84
  };
91
85
  size: {
92
- default: string;
93
86
  sm: string;
94
- lg: string;
87
+ base: string;
95
88
  };
96
89
  }, undefined, string[], TVConfig<{
97
90
  variant: {
@@ -100,9 +93,8 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
100
93
  ghost: string;
101
94
  };
102
95
  size: {
103
- default: string;
104
96
  sm: string;
105
- lg: string;
97
+ base: string;
106
98
  };
107
99
  }, {
108
100
  variant: {
@@ -111,9 +103,8 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
111
103
  ghost: string;
112
104
  };
113
105
  size: {
114
- default: string;
115
106
  sm: string;
116
- lg: string;
107
+ base: string;
117
108
  };
118
109
  }>, {
119
110
  variant: {
@@ -122,9 +113,8 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
122
113
  ghost: string;
123
114
  };
124
115
  size: {
125
- default: string;
126
116
  sm: string;
127
- lg: string;
117
+ base: string;
128
118
  };
129
119
  }, undefined, TVReturnType<{
130
120
  variant: {
@@ -133,9 +123,8 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
133
123
  ghost: string;
134
124
  };
135
125
  size: {
136
- default: string;
137
126
  sm: string;
138
- lg: string;
127
+ base: string;
139
128
  };
140
129
  }, undefined, string[], TVConfig<{
141
130
  variant: {
@@ -144,9 +133,8 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
144
133
  ghost: string;
145
134
  };
146
135
  size: {
147
- default: string;
148
136
  sm: string;
149
- lg: string;
137
+ base: string;
150
138
  };
151
139
  }, {
152
140
  variant: {
@@ -155,9 +143,8 @@ declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes
155
143
  ghost: string;
156
144
  };
157
145
  size: {
158
- default: string;
159
146
  sm: string;
160
- lg: string;
147
+ base: string;
161
148
  };
162
149
  }>, unknown, unknown, undefined>>> & {
163
150
  asChild?: boolean | undefined;