@twintag/twintag-form 0.1.0 → 0.2.0
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 +7 -7
- package/CHANGELOG.md +6 -0
- package/README.md +203 -0
- package/dist/index.es.js +3 -3
- package/dist/index.umd.js +15 -15
- package/dist/lib/components/Input/file.d.ts.map +1 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/webcomponent.es.js +1036 -1036
- package/dist/webcomponent.umd.js +1 -1
- package/lib/components/Input/file.tsx +3 -1
- package/lib/components/Input/simple.tsx +1 -1
- package/lib/components/Input/textarea.tsx +1 -1
- package/lib/types/index.ts +1 -0
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @twintag/twintag-form@0.
|
|
2
|
+
> @twintag/twintag-form@0.2.0 build /home/runner/work/twintag-templates/twintag-templates/packages/twintag-form
|
|
3
3
|
> tsc && node ./scripts/build.js
|
|
4
4
|
|
|
5
5
|
[36mvite v4.1.0 [32mbuilding for production...[36m[39m
|
|
@@ -23,14 +23,14 @@ computing gzip size...
|
|
|
23
23
|
[2mdist/[22m[32mlib/components/Input/textarea.d.ts [39m[1m[2m 0.39 kB[22m[1m[22m
|
|
24
24
|
[2mdist/[22m[32mlib/components/Input/checkbox.d.ts [39m[1m[2m 0.39 kB[22m[1m[22m
|
|
25
25
|
[2mdist/[22m[32mlib/components/Form/register.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
26
|
-
[2mdist/[22m[32mlib/types/index.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
27
26
|
[2mdist/[22m[32mlib/index.d.ts [39m[1m[2m 0.44 kB[22m[1m[22m
|
|
27
|
+
[2mdist/[22m[32mlib/types/index.d.ts [39m[1m[2m 0.45 kB[22m[1m[22m
|
|
28
28
|
[2mdist/[22m[32mlib/styles.d.ts [39m[1m[2m 2.87 kB[22m[1m[22m
|
|
29
|
-
[2mdist/[22m[36mwebcomponent.es.js [39m[1m[33m1,009.
|
|
29
|
+
[2mdist/[22m[36mwebcomponent.es.js [39m[1m[33m1,009.24 kB[39m[22m[2m │ gzip: 240.07 kB[22m
|
|
30
30
|
[1m[33m[plugin:typescript][39m[22m [33m@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.[39m
|
|
31
31
|
rendering chunks...
|
|
32
32
|
computing gzip size...
|
|
33
|
-
[2mdist/[22m[36mindex.es.js [39m[1m[33m892.
|
|
33
|
+
[2mdist/[22m[36mindex.es.js [39m[1m[33m892.99 kB[39m[22m[2m │ gzip: 208.25 kB[22m
|
|
34
34
|
[1m[33m[plugin:typescript][39m[22m [33m@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.[39m
|
|
35
35
|
[2mdist/[22m[32mlib/webcomponent.d.ts [39m[1m[2m 0.05 kB[22m[1m[22m
|
|
36
36
|
[2mdist/[22m[32mlib/components/Input/index.d.ts [39m[1m[2m 0.24 kB[22m[1m[22m
|
|
@@ -43,8 +43,8 @@ computing gzip size...
|
|
|
43
43
|
[2mdist/[22m[32mlib/components/Input/textarea.d.ts [39m[1m[2m 0.39 kB[22m[1m[22m
|
|
44
44
|
[2mdist/[22m[32mlib/components/Input/checkbox.d.ts [39m[1m[2m 0.39 kB[22m[1m[22m
|
|
45
45
|
[2mdist/[22m[32mlib/components/Form/register.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
46
|
-
[2mdist/[22m[32mlib/types/index.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
47
46
|
[2mdist/[22m[32mlib/index.d.ts [39m[1m[2m 0.44 kB[22m[1m[22m
|
|
47
|
+
[2mdist/[22m[32mlib/types/index.d.ts [39m[1m[2m 0.45 kB[22m[1m[22m
|
|
48
48
|
[2mdist/[22m[32mlib/styles.d.ts [39m[1m[2m 2.87 kB[22m[1m[22m
|
|
49
|
-
[2mdist/[22m[36mwebcomponent.umd.js [39m[1m[
|
|
50
|
-
[2mdist/[22m[36mindex.umd.js [39m[1m[33m556.
|
|
49
|
+
[2mdist/[22m[36mwebcomponent.umd.js [39m[1m[33m622.14 kB[39m[22m[2m │ gzip: 194.59 kB[22m
|
|
50
|
+
[2mdist/[22m[36mindex.umd.js [39m[1m[33m556.21 kB[39m[22m[2m │ gzip: 172.27 kB[22m
|
package/CHANGELOG.md
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# **Twintag Form**
|
|
2
|
+
|
|
3
|
+
## **Content**
|
|
4
|
+
|
|
5
|
+
- [Introduction](#introduction)
|
|
6
|
+
- [Framework Agnostic](#framework-agnostic)
|
|
7
|
+
- [Parameters](#parameters)
|
|
8
|
+
- [Config](#config)
|
|
9
|
+
- [Options](#options)
|
|
10
|
+
- [Inputs](#inputs)
|
|
11
|
+
- [Input Options](#input-options)
|
|
12
|
+
- [Simple](#simple)
|
|
13
|
+
- [Textarea](#textarea)
|
|
14
|
+
- [File](#file)
|
|
15
|
+
- [Checkbox](#checkbox)
|
|
16
|
+
- [Toggle](#toggle)
|
|
17
|
+
- [Submit](#submit)
|
|
18
|
+
- [Event Handling](#event-handling)
|
|
19
|
+
|
|
20
|
+
## **Introduction**
|
|
21
|
+
|
|
22
|
+
Twintag Form provides a web component that allows you to create a form based on a JSON object, leaving the actions to the developer.
|
|
23
|
+
|
|
24
|
+
## **Framework Agnostic**
|
|
25
|
+
|
|
26
|
+
Twintag Form exposes a web component that can be used in any framework or vanilla JS.
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<twintag-form options='...' config='[...]'></twintag-form>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## **Parameters**
|
|
33
|
+
|
|
34
|
+
The form component receives the following parameters:
|
|
35
|
+
|
|
36
|
+
| Parameter | Type | Description |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `config` | `array` | Array that contains the form structure. |
|
|
39
|
+
| `options` | `object` | Options to customize the form |
|
|
40
|
+
|
|
41
|
+
### **Config**
|
|
42
|
+
|
|
43
|
+
The `config` object contains the form structure. It is organized by the index of the items, where each item is an `Input` field represented by an object with the following properties:
|
|
44
|
+
|
|
45
|
+
| Property | Type | Description |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `input:<subtype>` | `string` | Type of the input. |
|
|
48
|
+
| `label` | `string` | Name of the form. |
|
|
49
|
+
| `bind` | `string` | Unique identifier for the form. (Optional for `Submit` inputs) |
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
[
|
|
53
|
+
{
|
|
54
|
+
"type": "input:simple",
|
|
55
|
+
"label": "Email",
|
|
56
|
+
"bind": "email"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"type": "input:textarea",
|
|
60
|
+
"label": "Message",
|
|
61
|
+
"bind": "message"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "input:submit",
|
|
65
|
+
"label": "Submit"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### **Options**
|
|
71
|
+
|
|
72
|
+
Twintag Form provides some options to customize the form:
|
|
73
|
+
|
|
74
|
+
| Option | Type | Description |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `variant` | `alpha | beta` | Variant of the form. |
|
|
77
|
+
| `resetOnSubmit` | `boolean` | If `true`, the form will be reset after submitting. (`false` per default) |
|
|
78
|
+
|
|
79
|
+
### **Inputs**
|
|
80
|
+
|
|
81
|
+
#### **Input Options**
|
|
82
|
+
|
|
83
|
+
Each input can be customized with the following options:
|
|
84
|
+
|
|
85
|
+
| Option | Type | Description |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| `variant` | `alpha | beta` | Variant of the input. |
|
|
88
|
+
| `placeholder` | `string` | Placeholder of the input. |
|
|
89
|
+
| `optionalField` | `boolean` | If `true`, the field will be optional. (`false` per default) |
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"type": "input:simple",
|
|
94
|
+
"label": "Email",
|
|
95
|
+
"bind": "email",
|
|
96
|
+
"options": {
|
|
97
|
+
"variant": "alpha",
|
|
98
|
+
"placeholder": "Enter your email",
|
|
99
|
+
"optionalField": true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### **Simple**
|
|
105
|
+
|
|
106
|
+
The `simple` input is a simple text input.
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"type": "input:simple",
|
|
111
|
+
"label": "Email",
|
|
112
|
+
"bind": "email"
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### **Textarea**
|
|
117
|
+
|
|
118
|
+
The `textarea` input is a textarea input.
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"type": "input:textarea",
|
|
123
|
+
"label": "Message",
|
|
124
|
+
"bind": "message"
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### **File**
|
|
129
|
+
|
|
130
|
+
The `file` input is a file input.
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"type": "input:file",
|
|
135
|
+
"label": "File",
|
|
136
|
+
"bind": "file"
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### **Checkbox**
|
|
141
|
+
|
|
142
|
+
The `checkbox` input is a checkbox input.
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"type": "input:checkbox",
|
|
147
|
+
"label": "Checkbox",
|
|
148
|
+
"bind": "checkbox"
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### **Toggle**
|
|
153
|
+
|
|
154
|
+
The `toggle` input is a toggle input.
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"type": "input:toggle",
|
|
159
|
+
"label": "Toggle",
|
|
160
|
+
"bind": "toggle"
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### **Submit**
|
|
165
|
+
|
|
166
|
+
The `submit` input is a submit input.
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"type": "input:submit",
|
|
171
|
+
"label": "Submit"
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## **Event Handling**
|
|
176
|
+
|
|
177
|
+
```html
|
|
178
|
+
|
|
179
|
+
<twintag-form id="yourform" options='{"variant":"beta","resetOnSubmit":true}' config='[{"type":"input:toggle","label":"Test","bind":"test","options":{"optionalField":true}},{"type":"input:submit","label":"Submit"}]'></twintag-form>
|
|
180
|
+
|
|
181
|
+
<button id="btn">Submit</button>
|
|
182
|
+
|
|
183
|
+
<script>
|
|
184
|
+
const form = document.getElementById('yourform');
|
|
185
|
+
const btn = document.getElementById('btn');
|
|
186
|
+
|
|
187
|
+
// If there are no errors, the form will emit a custom event with the data on submit
|
|
188
|
+
form.addEventListener('twintag-form-valid', (e) => {
|
|
189
|
+
console.log(e.detail); // { test: true }
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// If there are errors, the form will emit a custom event with the errors
|
|
193
|
+
form.addEventListener('twintag-form-invalid', (e) => {
|
|
194
|
+
console.log(e.detail); // { test: 'Test is required' }
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// You can validate the form outside the component:
|
|
198
|
+
btn.addEventListener('click', () => {
|
|
199
|
+
const submitEvent = new Event('twintag-form-validate');
|
|
200
|
+
form.shadowRoot.querySelector('form').dispatchEvent(submitEvent);
|
|
201
|
+
});
|
|
202
|
+
</script>
|
|
203
|
+
```
|
package/dist/index.es.js
CHANGED
|
@@ -5700,7 +5700,7 @@ const Rw = ih({
|
|
|
5700
5700
|
{
|
|
5701
5701
|
id: m,
|
|
5702
5702
|
type: "text",
|
|
5703
|
-
placeholder: "Write here...",
|
|
5703
|
+
placeholder: (v == null ? void 0 : v.placeholder) || "Write here...",
|
|
5704
5704
|
className: E(),
|
|
5705
5705
|
...u.register(f, {
|
|
5706
5706
|
required: v != null && v.optionalField ? !1 : `${s} is required`
|
|
@@ -5717,7 +5717,7 @@ const Rw = ih({
|
|
|
5717
5717
|
{
|
|
5718
5718
|
id: m,
|
|
5719
5719
|
className: E(),
|
|
5720
|
-
placeholder: "Write here...",
|
|
5720
|
+
placeholder: (v == null ? void 0 : v.placeholder) || "Write here...",
|
|
5721
5721
|
...u.register(f, {
|
|
5722
5722
|
required: v != null && v.optionalField ? !1 : `${s} is required`
|
|
5723
5723
|
})
|
|
@@ -26719,7 +26719,7 @@ const fA = ({ useForm: u, label: s, bind: f, options: v }) => {
|
|
|
26719
26719
|
children: _.name
|
|
26720
26720
|
},
|
|
26721
26721
|
$
|
|
26722
|
-
)) : /* @__PURE__ */ ot.jsx("span", { children: "
|
|
26722
|
+
)) : /* @__PURE__ */ ot.jsx("span", { className: "block max-w-full overflow-hidden text-ellipsis whitespace-nowrap", children: (v == null ? void 0 : v.placeholder) || "No file selected" }) }),
|
|
26723
26723
|
/* @__PURE__ */ ot.jsx(cA, { className: "h-6 w-6 min-w-[1.5rem]" })
|
|
26724
26724
|
]
|
|
26725
26725
|
}
|