@twintag/twintag-form 1.4.0-beta.0 → 1.4.0-beta.2
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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +12 -0
- package/README.md +121 -62
- package/dev/main.tsx +453 -209
- package/dist/common/button.d.ts +3 -2
- package/dist/common/calendar.d.ts +4 -4
- package/dist/common/form.d.ts +11 -11
- package/dist/common/icon.d.ts +2 -1
- package/dist/common/input.d.ts +3 -2
- package/dist/common/label.d.ts +3 -2
- package/dist/common/slider.d.ts +4 -0
- package/dist/common/textarea.d.ts +3 -2
- package/dist/components/config.d.ts +4 -2
- package/dist/components/containers/accordion.d.ts +5 -6
- package/dist/components/containers/category.d.ts +3 -2
- package/dist/components/fields/checkbox.d.ts +5 -3
- package/dist/components/fields/date-picker.d.ts +4 -2
- package/dist/components/fields/file.d.ts +5 -3
- package/dist/components/fields/input.d.ts +5 -3
- package/dist/components/fields/radiogroup.d.ts +7 -3
- package/dist/components/fields/submit.d.ts +3 -2
- package/dist/components/fields/textarea.d.ts +5 -3
- package/dist/components/fields/toggle.d.ts +5 -3
- package/dist/components/fields/tri-toggle.d.ts +5 -0
- package/dist/components/form.d.ts +2 -2
- package/dist/components/provider.d.ts +21 -0
- package/dist/components/renderer.d.ts +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/twintag-form.react.js +12880 -12304
- package/dist/types/index.d.ts +43 -20
- package/dist/utils/data.d.ts +7 -2
- package/dist/utils/style.d.ts +2 -1
- package/index.html +6 -3
- package/lib/common/slider.tsx +38 -0
- package/lib/components/config.tsx +46 -17
- package/lib/components/containers/accordion.tsx +33 -18
- package/lib/components/containers/category.tsx +1 -1
- package/lib/components/fields/checkbox.tsx +5 -3
- package/lib/components/fields/date-picker.tsx +9 -2
- package/lib/components/fields/file.tsx +5 -4
- package/lib/components/fields/input.tsx +5 -3
- package/lib/components/fields/radiogroup.tsx +9 -3
- package/lib/components/fields/submit.tsx +1 -1
- package/lib/components/fields/textarea.tsx +5 -3
- package/lib/components/fields/toggle.tsx +5 -3
- package/lib/components/fields/tri-toggle.tsx +141 -0
- package/lib/components/form.tsx +5 -7
- package/lib/components/provider.tsx +163 -0
- package/lib/components/{Render/index.tsx → renderer.tsx} +19 -2
- package/lib/index.tsx +41 -41
- package/lib/types/index.ts +69 -29
- package/lib/utils/data.ts +5 -2
- package/package.json +6 -8
- package/dist/components/Render/index.d.ts +0 -7
- package/dist/components/Render/useJson.d.ts +0 -2
- package/dist/components/index.d.ts +0 -7
- package/dist/provider.d.ts +0 -8
- package/lib/components/Render/useJson.ts +0 -76
- package/lib/components/index.tsx +0 -24
- package/lib/provider.tsx +0 -39
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
> @twintag/twintag-form@1.4.0-beta.
|
|
2
|
+
> @twintag/twintag-form@1.4.0-beta.2 build C:\Users\daryl\Desktop\twintag-projects\twintag-admin\packages\twintag-form
|
|
3
3
|
> tsc && vite build
|
|
4
4
|
|
|
5
|
-
[36mvite
|
|
5
|
+
[36mvite v5.2.11 [32mbuilding for production...[36m[39m
|
|
6
6
|
transforming...
|
|
7
|
-
[32m✓[39m
|
|
7
|
+
[32m✓[39m 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
|
|
17
|
+
[vite:dts] Declaration files built in 5207ms.
|
|
18
18
|
|
|
19
19
|
[2mdist/[22m[36mtwintag-form.webcomponent.js [39m[1m[2m119.76 kB[22m[1m[22m[2m │ gzip: 33.52 kB[22m
|
|
20
|
-
[2mdist/[22m[36mtwintag-form.react.js [39m[1m[
|
|
21
|
-
[32m✓ built in
|
|
20
|
+
[2mdist/[22m[36mtwintag-form.react.js [39m[1m[33m706.32 kB[39m[22m[2m │ gzip: 144.27 kB[22m
|
|
21
|
+
[32m✓ built in 9.63s[39m
|
package/CHANGELOG.md
CHANGED
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
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
"props": {
|
|
53
|
+
"subtype": "simple",
|
|
54
|
+
"label": "Email",
|
|
55
|
+
"bind": "email"
|
|
56
|
+
}
|
|
55
57
|
},
|
|
56
58
|
{
|
|
57
59
|
"type": "input:textarea",
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
+
"props": {
|
|
61
|
+
"label": "Message",
|
|
62
|
+
"bind": "message"
|
|
63
|
+
}
|
|
60
64
|
},
|
|
61
65
|
{
|
|
62
66
|
"type": "input",
|
|
63
|
-
"
|
|
64
|
-
|
|
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
|
|
74
|
-
| --------------- |
|
|
75
|
-
| `variant` | `default/beta` | Variant of the form. |
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
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
|
-
#### **
|
|
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
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
"
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
"
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
"
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
"
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
"
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
"
|
|
170
|
-
|
|
171
|
-
|
|
201
|
+
"props": {
|
|
202
|
+
"subtype": "radiogroup",
|
|
203
|
+
"label": "Radio Group",
|
|
204
|
+
"bind": "radiogroup",
|
|
205
|
+
},
|
|
172
206
|
"children": [
|
|
173
207
|
{
|
|
174
208
|
"type": "item",
|
|
175
|
-
"
|
|
176
|
-
|
|
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
|
-
"
|
|
189
|
-
|
|
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
|
-
"
|
|
199
|
-
|
|
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
|
-
"
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
"
|
|
220
|
-
|
|
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
|
-
"
|
|
279
|
+
"props": {
|
|
280
|
+
"label": "Category"
|
|
281
|
+
},
|
|
236
282
|
"children": [
|
|
237
283
|
{
|
|
238
284
|
"type": "input",
|
|
239
|
-
"
|
|
240
|
-
|
|
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
|
|
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
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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 `
|
|
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 `
|
|
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. |
|