@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
@@ -1,10 +1,10 @@
1
1
 
2
- > @twintag/twintag-form@1.3.0 build C:\Users\daryl\Desktop\twintag-projects\twintag-admin\packages\twintag-form
2
+ > @twintag/twintag-form@1.4.0-beta.1 build C:\Users\daryl\Desktop\twintag-projects\twintag-admin\packages\twintag-form
3
3
  > tsc && vite build
4
4
 
5
- vite v4.4.9 building for production...
5
+ vite v5.2.11 building for production...
6
6
  transforming...
7
- ✓ 2526 modules transformed.
7
+ ✓ 2514 modules transformed.
8
8
  rendering chunks...
9
9
 
10
10
  [vite:dts] Start generate declaration files...
@@ -14,8 +14,8 @@ computing gzip size...
14
14
  [vite:dts] Outside emitted: C:/Users/daryl/Desktop/twintag-projects/twintag-admin/packages/twintag-form/prettier.config.d.mts
15
15
  [vite:dts] Outside emitted: C:/Users/daryl/Desktop/twintag-projects/twintag-admin/packages/twintag-form/dev/main.d.ts
16
16
  [vite:dts] Outside emitted: C:/Users/daryl/Desktop/twintag-projects/twintag-admin/packages/twintag-form/vite.config.d.ts
17
- [vite:dts] Declaration files built in 4856ms.
17
+ [vite:dts] Declaration files built in 5217ms.
18
18
 
19
19
  dist/twintag-form.webcomponent.js 119.76 kB │ gzip: 33.52 kB
20
- dist/twintag-form.react.js 688.06 kB │ gzip: 139.99 kB
21
- ✓ built in 10.47s
20
+ dist/twintag-form.react.js 706.05 kB │ gzip: 144.21 kB
21
+ ✓ built in 10.31s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @twintag/twintag-form
2
2
 
3
+ ## 1.4.0-beta.1
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: tri-toggle field
8
+
9
+ ## 1.4.0-beta.0
10
+
11
+ ### Minor Changes
12
+
13
+ - fix: iOS zoom in issues
14
+
3
15
  ## 1.3.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  - [Config](#config)
9
9
  - [Options](#options)
10
10
  - [Inputs](#inputs)
11
- - [Options](#options)
11
+ - [Options](#input-options)
12
12
  - [Subtypes](#subtypes)
13
13
  - [Event Handling](#event-handling)
14
14
  - [CSS](#css)
@@ -49,19 +49,25 @@ The `config` object contains the form structure. It is organized by the index of
49
49
  [
50
50
  {
51
51
  "type": "input",
52
- "subtype": "simple",
53
- "label": "Email",
54
- "bind": "email"
52
+ "props": {
53
+ "subtype": "simple",
54
+ "label": "Email",
55
+ "bind": "email"
56
+ }
55
57
  },
56
58
  {
57
59
  "type": "input:textarea",
58
- "label": "Message",
59
- "bind": "message"
60
+ "props": {
61
+ "label": "Message",
62
+ "bind": "message"
63
+ }
60
64
  },
61
65
  {
62
66
  "type": "input",
63
- "subtype": "submit",
64
- "label": "Submit"
67
+ "props": {
68
+ "subtype": "submit",
69
+ "label": "Submit"
70
+ }
65
71
  }
66
72
  ]
67
73
  ```
@@ -70,15 +76,16 @@ The `config` object contains the form structure. It is organized by the index of
70
76
 
71
77
  Twintag Form provides some options to customize the form:
72
78
 
73
- | Option | Type | Description |
74
- | --------------- | -------------- | ------------------------------------------------------------------------- |
75
- | `variant` | `default/beta` | Variant of the form. |
76
- | `resetOnSubmit` | `boolean` | If `true`, the form will be reset after submitting. (`false` per default) |
77
- | `defaultValues` | `object` | The properties are the same as the bind values in your config. |
79
+ | Option | Type | Description |
80
+ | --------------- | ----------------- | ------------------------------------------------------------------------- |
81
+ | `variant` | `default / beta` | Variant of the form. |
82
+ | `size` | `base / sm` | Default: `base` (font-size set to 16px). |
83
+ | `resetOnSubmit` | `boolean` | If `true`, the form will be reset after submitting. (`false` per default) |
84
+ | `defaultValues` | `object` | The properties are the same as the bind values in your config. |
78
85
 
79
86
  ### **Inputs**
80
87
 
81
- #### **Options**
88
+ #### **Input options**
82
89
 
83
90
  Each input can be customized with the following optional options:
84
91
 
@@ -92,14 +99,16 @@ Each input can be customized with the following optional options:
92
99
  ```json
93
100
  {
94
101
  "type": "input",
95
- "subtype": "simple",
96
- "label": "Email",
97
- "bind": "email",
98
- "options": {
99
- "description": "Please enter you email",
100
- "error": "The field is empty."
101
- "placeholder": "Write here...",
102
- "optionalField": true
102
+ "props": {
103
+ "subtype": "simple",
104
+ "label": "Email",
105
+ "bind": "email",
106
+ "options": {
107
+ "description": "Please enter you email",
108
+ "error": "The field is empty."
109
+ "placeholder": "Write here...",
110
+ "optionalField": true
111
+ }
103
112
  }
104
113
  }
105
114
  ```
@@ -111,9 +120,11 @@ Each input can be customized with the following optional options:
111
120
  ```json
112
121
  {
113
122
  "type": "input",
114
- "subtype": "simple",
115
- "label": "Email",
116
- "bind": "email"
123
+ "props": {
124
+ "subtype": "simple",
125
+ "label": "Email",
126
+ "bind": "email"
127
+ }
117
128
  }
118
129
  ```
119
130
 
@@ -122,9 +133,11 @@ Each input can be customized with the following optional options:
122
133
  ```json
123
134
  {
124
135
  "type": "input",
125
- "subtype": "textarea",
126
- "label": "Message",
127
- "bind": "message"
136
+ "props": {
137
+ "subtype": "textarea",
138
+ "label": "Message",
139
+ "bind": "message"
140
+ }
128
141
  }
129
142
  ```
130
143
 
@@ -133,9 +146,11 @@ Each input can be customized with the following optional options:
133
146
  ```json
134
147
  {
135
148
  "type": "input",
136
- "subtype": "file",
137
- "label": "File",
138
- "bind": "file"
149
+ "props": {
150
+ "subtype": "file",
151
+ "label": "File",
152
+ "bind": "file"
153
+ }
139
154
  }
140
155
  ```
141
156
 
@@ -144,9 +159,11 @@ Each input can be customized with the following optional options:
144
159
  ```json
145
160
  {
146
161
  "type": "input",
147
- "subtype": "checkbox",
148
- "label": "Checkbox",
149
- "bind": "checkbox"
162
+ "props": {
163
+ "subtype": "checkbox",
164
+ "label": "Checkbox",
165
+ "bind": "checkbox"
166
+ }
150
167
  }
151
168
  ```
152
169
 
@@ -155,9 +172,24 @@ Each input can be customized with the following optional options:
155
172
  ```json
156
173
  {
157
174
  "type": "input",
158
- "subtype": "toggle",
159
- "label": "Toggle",
160
- "bind": "toggle"
175
+ "props": {
176
+ "subtype": "toggle",
177
+ "label": "Toggle",
178
+ "bind": "toggle"
179
+ }
180
+ }
181
+ ```
182
+
183
+ - Tri-Toggle
184
+
185
+ ```json
186
+ {
187
+ "type": "input",
188
+ "props": {
189
+ "subtype": "tri-toggle",
190
+ "label": "Toggle with 3 states",
191
+ "bind": "tri-states"
192
+ }
161
193
  }
162
194
  ```
163
195
 
@@ -166,14 +198,18 @@ Each input can be customized with the following optional options:
166
198
  ```json
167
199
  {
168
200
  "type": "input",
169
- "subtype": "radiogroup",
170
- "label": "Radio Group",
171
- "bind": "radiogroup",
201
+ "props": {
202
+ "subtype": "radiogroup",
203
+ "label": "Radio Group",
204
+ "bind": "radiogroup",
205
+ },
172
206
  "children": [
173
207
  {
174
208
  "type": "item",
175
- "label": "First item",
176
- "bind": "first-item"
209
+ "props": {
210
+ "label": "First item",
211
+ "bind": "first-item"
212
+ }
177
213
  },
178
214
  ...
179
215
  ]
@@ -185,8 +221,10 @@ Each input can be customized with the following optional options:
185
221
  ```json
186
222
  {
187
223
  "type": "input",
188
- "subtype": "submit",
189
- "label": "Submit"
224
+ "props": {
225
+ "subtype": "submit",
226
+ "label": "Submit"
227
+ }
190
228
  }
191
229
  ```
192
230
 
@@ -195,8 +233,10 @@ Each input can be customized with the following optional options:
195
233
  ```json
196
234
  {
197
235
  "type": "input",
198
- "subtype": "datepicker",
199
- "label": "Pick a date"
236
+ "props": {
237
+ "subtype": "datepicker",
238
+ "label": "Pick a date"
239
+ }
200
240
  }
201
241
  ```
202
242
 
@@ -210,14 +250,18 @@ Each input can be customized with the following optional options:
210
250
  "children": [
211
251
  {
212
252
  "type": "accordion",
213
- "subtype": "item",
214
- "label": "Your label",
215
- "icon": "archive-box-x-mark",
253
+ "props": {
254
+ "subtype": "item",
255
+ "label": "Your label"
256
+ "icon": "archive-box-x-mark",
257
+ },
216
258
  "children": [
217
259
  {
218
260
  "type": "input",
219
- "subtype": "simple",
220
- "bind": "first-item"
261
+ "props": {
262
+ "subtype": "simple",
263
+ "bind": "first-item"
264
+ }
221
265
  },
222
266
  ...
223
267
  ]
@@ -232,12 +276,16 @@ Each input can be customized with the following optional options:
232
276
  ```json
233
277
  {
234
278
  "type": "category",
235
- "label": "Category",
279
+ "props": {
280
+ "label": "Category"
281
+ },
236
282
  "children": [
237
283
  {
238
284
  "type": "input",
239
- "subtype": "simple",
240
- "label": "Your label"
285
+ "props": {
286
+ "subtype": "simple",
287
+ "label": "Your label"
288
+ }
241
289
  },
242
290
  ...
243
291
  ]
@@ -253,11 +301,19 @@ Each input can be customized with the following optional options:
253
301
  config='[{"type":"input:toggle","label":"Test","bind":"test","options":{"optionalField":true}},{"type":"input:submit","label":"Submit"}]'
254
302
  ></twintag-form>
255
303
 
256
- <button id="btn">Submit</button>
304
+ <button id="submit-btn">Submit</button>
305
+ <button id="get-values-btn">Submit</button>
257
306
 
258
307
  <script>
259
308
  const form = document.getElementById('yourform');
260
- const btn = document.getElementById('btn');
309
+ const submit = document.getElementById('submit-btn');
310
+ const getValues = document.getElementById('get-values-btn');
311
+
312
+ // You can validate the form outside the component:
313
+ submit.addEventListener('click', () => {
314
+ const submitEvent = new Event('twintag-form-validate');
315
+ form.shadowRoot.querySelector('form').dispatchEvent(submitEvent);
316
+ });
261
317
 
262
318
  // If there are no errors, the form will emit a custom event with the data on submit
263
319
  form.addEventListener('twintag-form-valid', (e) => {
@@ -269,10 +325,13 @@ Each input can be customized with the following optional options:
269
325
  console.log(e.detail); // { test: 'Test is required' }
270
326
  });
271
327
 
272
- // You can validate the form outside the component:
273
- btn.addEventListener('click', () => {
274
- const submitEvent = new Event('twintag-form-validate');
275
- form.shadowRoot.querySelector('form').dispatchEvent(submitEvent);
328
+ // You can get the values of the form outside the component:
329
+ form.addEventListener('twintag-form-values', (e) => {
330
+ console.log(e.detail);
331
+ });
332
+ getValues.addEventListener('click', () => {
333
+ const getValuesEvent = new Event('twintag-form-get_values');
334
+ form.shadowRoot.querySelector('form').dispatchEvent(getValuesEvent);
276
335
  });
277
336
  </script>
278
337
  ```
@@ -289,13 +348,13 @@ The form component exposes the following CSS variables:
289
348
  | --tf-background | Background color for the input fields. |
290
349
  | --tf-foreground | Text color for the input fields. |
291
350
  | | |
292
- | --tf-muted | Used for `switch` background when value is false. |
351
+ | --tf-muted | Used for `toggle` and `tri-toggle` background when value is false. |
293
352
  | --tf-muted-foreground | Color used for `placeholder` text (inputs) and description text. |
294
353
  | | |
295
354
  | --tf-primary | This color complements `primary-foreground`: `submit` button text |
296
355
  | --tf-primary-foreground | This color is used for, `submit` background, `label` text and input value. |
297
356
  | | |
298
- | --tf-accent | The accent color is used for `switch`, `checkbox` and `radiogroup` inputs. |
357
+ | --tf-accent | The accent color is used for `toggle`, `tri-toggle`, `checkbox` and `radiogroup` inputs. |
299
358
  | --tf-accent-foreground | This color complements `accent` to show contrast between elements: `checkbox` check icon. |
300
359
  | | |
301
360
  | --tf-destructive | This color is used for `error` messages and the asterisk to mark a required input. |