@twintag/twintag-form 0.2.0 → 0.3.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.
- package/.turbo/turbo-build.log +35 -27
- package/CHANGELOG.md +12 -0
- package/README.md +103 -89
- package/dist/index.es.js +6786 -6803
- package/dist/index.umd.js +43 -43
- package/dist/lib/__stories__/Form.stories.d.ts +7 -0
- package/dist/lib/__stories__/Form.stories.d.ts.map +1 -0
- package/dist/lib/components/Input/checkbox.d.ts +2 -2
- package/dist/lib/components/Input/checkbox.d.ts.map +1 -1
- package/dist/lib/components/Input/file.d.ts +2 -2
- package/dist/lib/components/Input/file.d.ts.map +1 -1
- package/dist/lib/components/Input/index.d.ts +2 -0
- package/dist/lib/components/Input/index.d.ts.map +1 -1
- package/dist/lib/components/Input/simple.d.ts +2 -2
- package/dist/lib/components/Input/simple.d.ts.map +1 -1
- package/dist/lib/components/Input/submit.d.ts +2 -2
- package/dist/lib/components/Input/submit.d.ts.map +1 -1
- package/dist/lib/components/Input/textarea.d.ts +2 -2
- package/dist/lib/components/Input/textarea.d.ts.map +1 -1
- package/dist/lib/components/Input/toggle.d.ts +2 -2
- package/dist/lib/components/Input/toggle.d.ts.map +1 -1
- package/dist/lib/components/Label/index.d.ts +9 -0
- package/dist/lib/components/Label/index.d.ts.map +1 -0
- package/dist/lib/components/index.d.ts +5 -0
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/index.d.ts +6 -4
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/styles.d.ts +1 -0
- package/dist/lib/styles.d.ts.map +1 -1
- package/dist/twind.config.d.ts.map +1 -1
- package/dist/webcomponent.es.js +6779 -6793
- package/dist/webcomponent.umd.js +43 -43
- package/lib/__stories__/Form.stories.tsx +38 -0
- package/lib/components/Form/index.tsx +1 -1
- package/lib/components/Input/checkbox.tsx +7 -4
- package/lib/components/Input/file.tsx +12 -5
- package/lib/components/Input/index.tsx +2 -2
- package/lib/components/Input/simple.tsx +10 -11
- package/lib/components/Input/submit.tsx +7 -5
- package/lib/components/Input/textarea.tsx +14 -11
- package/lib/components/Input/toggle.tsx +23 -18
- package/lib/components/Label/index.tsx +22 -0
- package/lib/components/index.tsx +5 -0
- package/lib/index.tsx +3 -3
- package/lib/styles.ts +12 -8
- package/package.json +2 -4
- package/scripts/build.js +5 -0
- package/tsconfig.json +1 -1
- package/twind.config.ts +5 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,50 +1,58 @@
|
|
|
1
1
|
|
|
2
|
-
> @twintag/twintag-form@0.
|
|
2
|
+
> @twintag/twintag-form@0.3.1 build /home/runner/work/twintag-templates/twintag-templates/packages/twintag-form
|
|
3
3
|
> tsc && node ./scripts/build.js
|
|
4
4
|
|
|
5
|
-
[36mvite v4.
|
|
6
|
-
[36mvite v4.
|
|
5
|
+
[36mvite v4.3.9 [32mbuilding for production...[36m[39m
|
|
6
|
+
[36mvite v4.3.9 [32mbuilding for production...[36m[39m
|
|
7
7
|
transforming...
|
|
8
8
|
transforming...
|
|
9
|
-
[32m✓[39m
|
|
9
|
+
[32m✓[39m 681 modules transformed.
|
|
10
10
|
[1m[33m[plugin:typescript][39m[22m [33m@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.[39m
|
|
11
|
-
[32m✓[39m
|
|
11
|
+
[32m✓[39m 662 modules transformed.
|
|
12
12
|
[1m[33m[plugin:typescript][39m[22m [33m@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.[39m
|
|
13
13
|
rendering chunks...
|
|
14
14
|
computing gzip size...
|
|
15
15
|
[2mdist/[22m[32mlib/webcomponent.d.ts [39m[1m[2m 0.05 kB[22m[1m[22m
|
|
16
|
-
[2mdist/[22m[32mlib/components/
|
|
16
|
+
[2mdist/[22m[32mlib/components/index.d.ts [39m[1m[2m 0.15 kB[22m[1m[22m
|
|
17
|
+
[2mdist/[22m[32mlib/components/Input/index.d.ts [39m[1m[2m 0.28 kB[22m[1m[22m
|
|
18
|
+
[2mdist/[22m[32mlib/__stories__/Form.stories.d.ts [39m[1m[2m 0.28 kB[22m[1m[22m
|
|
17
19
|
[2mdist/[22m[32mtwind.config.d.ts [39m[1m[2m 0.29 kB[22m[1m[22m
|
|
18
20
|
[2mdist/[22m[32mlib/components/Form/index.d.ts [39m[1m[2m 0.30 kB[22m[1m[22m
|
|
19
|
-
[2mdist/[22m[32mlib/components/
|
|
20
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
21
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
22
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
23
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
24
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
21
|
+
[2mdist/[22m[32mlib/components/Label/index.d.ts [39m[1m[2m 0.31 kB[22m[1m[22m
|
|
22
|
+
[2mdist/[22m[32mlib/components/Input/submit.d.ts [39m[1m[2m 0.39 kB[22m[1m[22m
|
|
23
|
+
[2mdist/[22m[32mlib/components/Input/file.d.ts [39m[1m[2m 0.40 kB[22m[1m[22m
|
|
24
|
+
[2mdist/[22m[32mlib/components/Input/simple.d.ts [39m[1m[2m 0.41 kB[22m[1m[22m
|
|
25
|
+
[2mdist/[22m[32mlib/components/Input/toggle.d.ts [39m[1m[2m 0.41 kB[22m[1m[22m
|
|
26
|
+
[2mdist/[22m[32mlib/components/Input/textarea.d.ts [39m[1m[2m 0.41 kB[22m[1m[22m
|
|
27
|
+
[2mdist/[22m[32mlib/components/Input/checkbox.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
25
28
|
[2mdist/[22m[32mlib/components/Form/register.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
26
|
-
[2mdist/[22m[32mlib/index.d.ts [39m[1m[2m 0.44 kB[22m[1m[22m
|
|
27
29
|
[2mdist/[22m[32mlib/types/index.d.ts [39m[1m[2m 0.45 kB[22m[1m[22m
|
|
28
|
-
[2mdist/[22m[32mlib/
|
|
29
|
-
[2mdist/[22m[
|
|
30
|
+
[2mdist/[22m[32mlib/index.d.ts [39m[1m[2m 0.46 kB[22m[1m[22m
|
|
31
|
+
[2mdist/[22m[32mlib/styles.d.ts [39m[1m[2m 3.24 kB[22m[1m[22m
|
|
32
|
+
[2mdist/[22m[36mwebcomponent.es.js [39m[1m[33m1,009.45 kB[39m[22m[2m │ gzip: 240.02 kB[22m
|
|
30
33
|
[1m[33m[plugin:typescript][39m[22m [33m@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.[39m
|
|
31
34
|
rendering chunks...
|
|
32
35
|
computing gzip size...
|
|
33
|
-
[2mdist/[22m[36mindex.es.js [39m[1m[
|
|
36
|
+
[2mdist/[22m[36mindex.es.js [39m[1m[33m893.03 kB[39m[22m[2m │ gzip: 208.16 kB[22m
|
|
34
37
|
[1m[33m[plugin:typescript][39m[22m [33m@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.[39m
|
|
35
38
|
[2mdist/[22m[32mlib/webcomponent.d.ts [39m[1m[2m 0.05 kB[22m[1m[22m
|
|
36
|
-
[2mdist/[22m[32mlib/components/
|
|
39
|
+
[2mdist/[22m[32mlib/components/index.d.ts [39m[1m[2m 0.15 kB[22m[1m[22m
|
|
40
|
+
[2mdist/[22m[32mlib/components/Input/index.d.ts [39m[1m[2m 0.28 kB[22m[1m[22m
|
|
41
|
+
[2mdist/[22m[32mlib/__stories__/Form.stories.d.ts [39m[1m[2m 0.28 kB[22m[1m[22m
|
|
37
42
|
[2mdist/[22m[32mtwind.config.d.ts [39m[1m[2m 0.29 kB[22m[1m[22m
|
|
38
43
|
[2mdist/[22m[32mlib/components/Form/index.d.ts [39m[1m[2m 0.30 kB[22m[1m[22m
|
|
39
|
-
[2mdist/[22m[32mlib/components/
|
|
40
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
41
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
42
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
43
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
44
|
-
[2mdist/[22m[32mlib/components/Input/
|
|
44
|
+
[2mdist/[22m[32mlib/components/Label/index.d.ts [39m[1m[2m 0.31 kB[22m[1m[22m
|
|
45
|
+
[2mdist/[22m[32mlib/components/Input/submit.d.ts [39m[1m[2m 0.39 kB[22m[1m[22m
|
|
46
|
+
[2mdist/[22m[32mlib/components/Input/file.d.ts [39m[1m[2m 0.40 kB[22m[1m[22m
|
|
47
|
+
[2mdist/[22m[32mlib/components/Input/simple.d.ts [39m[1m[2m 0.41 kB[22m[1m[22m
|
|
48
|
+
[2mdist/[22m[32mlib/components/Input/toggle.d.ts [39m[1m[2m 0.41 kB[22m[1m[22m
|
|
49
|
+
[2mdist/[22m[32mlib/components/Input/textarea.d.ts [39m[1m[2m 0.41 kB[22m[1m[22m
|
|
50
|
+
[2mdist/[22m[32mlib/components/Input/checkbox.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
45
51
|
[2mdist/[22m[32mlib/components/Form/register.d.ts [39m[1m[2m 0.42 kB[22m[1m[22m
|
|
46
|
-
[2mdist/[22m[32mlib/index.d.ts [39m[1m[2m 0.44 kB[22m[1m[22m
|
|
47
52
|
[2mdist/[22m[32mlib/types/index.d.ts [39m[1m[2m 0.45 kB[22m[1m[22m
|
|
48
|
-
[2mdist/[22m[32mlib/
|
|
49
|
-
[2mdist/[22m[
|
|
50
|
-
[2mdist/[22m[
|
|
53
|
+
[2mdist/[22m[32mlib/index.d.ts [39m[1m[2m 0.46 kB[22m[1m[22m
|
|
54
|
+
[2mdist/[22m[32mlib/styles.d.ts [39m[1m[2m 3.24 kB[22m[1m[22m
|
|
55
|
+
[2mdist/[22m[36mwebcomponent.umd.js [39m[1m[33m622.35 kB[39m[22m[2m │ gzip: 194.56 kB[22m
|
|
56
|
+
[32m✓ built in 24.15s[39m
|
|
57
|
+
[2mdist/[22m[36mindex.umd.js [39m[1m[33m556.28 kB[39m[22m[2m │ gzip: 172.27 kB[22m
|
|
58
|
+
[32m✓ built in 24.46s[39m
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -5,17 +5,18 @@
|
|
|
5
5
|
- [Introduction](#introduction)
|
|
6
6
|
- [Framework Agnostic](#framework-agnostic)
|
|
7
7
|
- [Parameters](#parameters)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
18
|
- [Event Handling](#event-handling)
|
|
19
|
+
- [CSS](#css)
|
|
19
20
|
|
|
20
21
|
## **Introduction**
|
|
21
22
|
|
|
@@ -26,44 +27,44 @@ Twintag Form provides a web component that allows you to create a form based on
|
|
|
26
27
|
Twintag Form exposes a web component that can be used in any framework or vanilla JS.
|
|
27
28
|
|
|
28
29
|
```html
|
|
29
|
-
<twintag-form options=
|
|
30
|
+
<twintag-form options="..." config="[...]"></twintag-form>
|
|
30
31
|
```
|
|
31
32
|
|
|
32
33
|
## **Parameters**
|
|
33
34
|
|
|
34
35
|
The form component receives the following parameters:
|
|
35
36
|
|
|
36
|
-
| Parameter | Type
|
|
37
|
-
|
|
|
38
|
-
| `config`
|
|
39
|
-
| `options` | `object` | Options to customize the form
|
|
37
|
+
| Parameter | Type | Description |
|
|
38
|
+
| --------- | -------- | --------------------------------------- |
|
|
39
|
+
| `config` | `array` | Array that contains the form structure. |
|
|
40
|
+
| `options` | `object` | Options to customize the form |
|
|
40
41
|
|
|
41
42
|
### **Config**
|
|
42
43
|
|
|
43
44
|
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
|
|
|
45
|
-
| Property
|
|
46
|
-
|
|
|
47
|
-
| `input:<subtype>` | `string` | Type of the input.
|
|
48
|
-
| `label`
|
|
49
|
-
| `bind`
|
|
46
|
+
| Property | Type | Description |
|
|
47
|
+
| ----------------- | -------- | -------------------------------------------------------------- |
|
|
48
|
+
| `input:<subtype>` | `string` | Type of the input. |
|
|
49
|
+
| `label` | `string` | Name of the form. |
|
|
50
|
+
| `bind` | `string` | Unique identifier for the form. (Optional for `Submit` inputs) |
|
|
50
51
|
|
|
51
52
|
```json
|
|
52
53
|
[
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
{
|
|
55
|
+
"type": "input:simple",
|
|
56
|
+
"label": "Email",
|
|
57
|
+
"bind": "email"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"type": "input:textarea",
|
|
61
|
+
"label": "Message",
|
|
62
|
+
"bind": "message"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "input:submit",
|
|
66
|
+
"label": "Submit"
|
|
67
|
+
}
|
|
67
68
|
]
|
|
68
69
|
```
|
|
69
70
|
|
|
@@ -71,10 +72,10 @@ The `config` object contains the form structure. It is organized by the index of
|
|
|
71
72
|
|
|
72
73
|
Twintag Form provides some options to customize the form:
|
|
73
74
|
|
|
74
|
-
| Option
|
|
75
|
-
|
|
|
76
|
-
| `variant`
|
|
77
|
-
| `resetOnSubmit` | `boolean`
|
|
75
|
+
| Option | Type | Description |
|
|
76
|
+
| --------------- | ------------ | ------------------------------------------------------------------------- |
|
|
77
|
+
| `variant` | `alpha/beta` | Variant of the form. |
|
|
78
|
+
| `resetOnSubmit` | `boolean` | If `true`, the form will be reset after submitting. (`false` per default) |
|
|
78
79
|
|
|
79
80
|
### **Inputs**
|
|
80
81
|
|
|
@@ -82,22 +83,22 @@ Twintag Form provides some options to customize the form:
|
|
|
82
83
|
|
|
83
84
|
Each input can be customized with the following options:
|
|
84
85
|
|
|
85
|
-
| Option
|
|
86
|
-
|
|
|
87
|
-
| `variant`
|
|
88
|
-
| `placeholder`
|
|
89
|
-
| `optionalField` | `boolean`
|
|
86
|
+
| Option | Type | Description |
|
|
87
|
+
| --------------- | ------------ | ------------------------------------------------------------ |
|
|
88
|
+
| `variant` | `alpha/beta` | Variant of the input. |
|
|
89
|
+
| `placeholder` | `string` | Placeholder of the input. |
|
|
90
|
+
| `optionalField` | `boolean` | If `true`, the field will be optional. (`false` per default) |
|
|
90
91
|
|
|
91
92
|
```json
|
|
92
93
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
"type": "input:simple",
|
|
95
|
+
"label": "Email",
|
|
96
|
+
"bind": "email",
|
|
97
|
+
"options": {
|
|
98
|
+
"variant": "alpha",
|
|
99
|
+
"placeholder": "Enter your email",
|
|
100
|
+
"optionalField": true
|
|
101
|
+
}
|
|
101
102
|
}
|
|
102
103
|
```
|
|
103
104
|
|
|
@@ -107,9 +108,9 @@ The `simple` input is a simple text input.
|
|
|
107
108
|
|
|
108
109
|
```json
|
|
109
110
|
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
"type": "input:simple",
|
|
112
|
+
"label": "Email",
|
|
113
|
+
"bind": "email"
|
|
113
114
|
}
|
|
114
115
|
```
|
|
115
116
|
|
|
@@ -119,9 +120,9 @@ The `textarea` input is a textarea input.
|
|
|
119
120
|
|
|
120
121
|
```json
|
|
121
122
|
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
"type": "input:textarea",
|
|
124
|
+
"label": "Message",
|
|
125
|
+
"bind": "message"
|
|
125
126
|
}
|
|
126
127
|
```
|
|
127
128
|
|
|
@@ -131,9 +132,9 @@ The `file` input is a file input.
|
|
|
131
132
|
|
|
132
133
|
```json
|
|
133
134
|
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
"type": "input:file",
|
|
136
|
+
"label": "File",
|
|
137
|
+
"bind": "file"
|
|
137
138
|
}
|
|
138
139
|
```
|
|
139
140
|
|
|
@@ -143,9 +144,9 @@ The `checkbox` input is a checkbox input.
|
|
|
143
144
|
|
|
144
145
|
```json
|
|
145
146
|
{
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
"type": "input:checkbox",
|
|
148
|
+
"label": "Checkbox",
|
|
149
|
+
"bind": "checkbox"
|
|
149
150
|
}
|
|
150
151
|
```
|
|
151
152
|
|
|
@@ -155,9 +156,9 @@ The `toggle` input is a toggle input.
|
|
|
155
156
|
|
|
156
157
|
```json
|
|
157
158
|
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
"type": "input:toggle",
|
|
160
|
+
"label": "Toggle",
|
|
161
|
+
"bind": "toggle"
|
|
161
162
|
}
|
|
162
163
|
```
|
|
163
164
|
|
|
@@ -167,37 +168,50 @@ The `submit` input is a submit input.
|
|
|
167
168
|
|
|
168
169
|
```json
|
|
169
170
|
{
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
"type": "input:submit",
|
|
172
|
+
"label": "Submit"
|
|
172
173
|
}
|
|
173
174
|
```
|
|
174
175
|
|
|
175
176
|
## **Event Handling**
|
|
176
177
|
|
|
177
178
|
```html
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
<twintag-form
|
|
180
|
+
id="yourform"
|
|
181
|
+
options='{"variant":"beta","resetOnSubmit":true}'
|
|
182
|
+
config='[{"type":"input:toggle","label":"Test","bind":"test","options":{"optionalField":true}},{"type":"input:submit","label":"Submit"}]'
|
|
183
|
+
></twintag-form>
|
|
180
184
|
|
|
181
185
|
<button id="btn">Submit</button>
|
|
182
186
|
|
|
183
187
|
<script>
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
188
|
+
const form = document.getElementById('yourform');
|
|
189
|
+
const btn = document.getElementById('btn');
|
|
190
|
+
|
|
191
|
+
// If there are no errors, the form will emit a custom event with the data on submit
|
|
192
|
+
form.addEventListener('twintag-form-valid', (e) => {
|
|
193
|
+
console.log(e.detail); // { test: true }
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// If there are errors, the form will emit a custom event with the errors
|
|
197
|
+
form.addEventListener('twintag-form-invalid', (e) => {
|
|
198
|
+
console.log(e.detail); // { test: 'Test is required' }
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// You can validate the form outside the component:
|
|
202
|
+
btn.addEventListener('click', () => {
|
|
203
|
+
const submitEvent = new Event('twintag-form-validate');
|
|
204
|
+
form.shadowRoot.querySelector('form').dispatchEvent(submitEvent);
|
|
205
|
+
});
|
|
202
206
|
</script>
|
|
203
|
-
```
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## **CSS**
|
|
210
|
+
|
|
211
|
+
The form component exposes the following CSS variables:
|
|
212
|
+
|
|
213
|
+
| Variable | Description |
|
|
214
|
+
| ------------- | ------------------------ |
|
|
215
|
+
| `--clr-label` | Color of the labels. |
|
|
216
|
+
| `--clr-input` | Color of the inputs. |
|
|
217
|
+
| `--ff-text` | Font family of the text. |
|