@uibit/form 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UIBit Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Form
2
+
3
+ [Interactive Demonstration](https://rawlings.github.io/uibit/components/form)
4
+
5
+ Form provides a composable, declarative wrapper around standard HTML `<form>` elements. It adds multi-step wizard navigation, asynchronous submission lifecycle states, and unsaved changes tracking to simplify form construction.
6
+
7
+ ## Value Delivery
8
+
9
+ - **Progressive Enhancement** – Operates as a wrapper around native forms, falling back to default browser submission behavior if JavaScript has not loaded.
10
+ - **Asynchronous Lifecycles** – Intercepts submissions to perform fetch requests, exposing state attributes (idle, pending, success, error) to allow custom interface feedback.
11
+ - **Automated Multi-step Wizards** – Groups inputs within standard `<fieldset>` tags into structured wizard steps with navigation buttons and step validation.
12
+ - **Safe Navigation** – Tracks changes across all internal fields, warning users before they navigate away with unsaved details.
13
+
14
+ ## Ideal Applications
15
+
16
+ - **Onboarding flows** – Multi-step registration forms or surveys.
17
+ - **Data editing screens** – Safe updates of profile records, settings panels, or metadata grids.
18
+ - **Transactional submittals** – Fast user checkouts or feedback collection points.
19
+
20
+ ## Further Information
21
+
22
+ Detailed design guidelines, customizable attributes, and integration examples are available on our documentation site.
23
+
24
+ ## Changelog
25
+
26
+ Please see the [Changelog](CHANGELOG.md) for version history.
@@ -0,0 +1,407 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/form.ts",
8
+ "declarations": [
9
+ {
10
+ "kind": "class",
11
+ "description": "A declarative form wrapper that wraps a native `<form>` and adds wizards,\nsubmit lifecycle states, and dirty checking.",
12
+ "name": "Form",
13
+ "slots": [
14
+ {
15
+ "description": "Default slot where the native `<form>` element is placed.",
16
+ "name": ""
17
+ },
18
+ {
19
+ "description": "Custom success template displayed upon successful submission.",
20
+ "name": "success"
21
+ },
22
+ {
23
+ "description": "Custom error template displayed upon failed submission.",
24
+ "name": "error"
25
+ }
26
+ ],
27
+ "members": [
28
+ {
29
+ "kind": "field",
30
+ "name": "warnUnsaved",
31
+ "type": {
32
+ "text": "boolean"
33
+ },
34
+ "default": "false",
35
+ "description": "Opt-in warning prompt if the user tries to leave the page with unsaved changes.",
36
+ "attribute": "warn-unsaved"
37
+ },
38
+ {
39
+ "kind": "field",
40
+ "name": "step",
41
+ "type": {
42
+ "text": "number"
43
+ },
44
+ "default": "1",
45
+ "description": "Active wizard step (1-indexed). Only active if multiple fieldsets exist.",
46
+ "attribute": "step",
47
+ "reflects": true
48
+ },
49
+ {
50
+ "kind": "field",
51
+ "name": "stepsCount",
52
+ "type": {
53
+ "text": "number"
54
+ },
55
+ "default": "0",
56
+ "description": "The total number of steps/fieldsets detected in the form.",
57
+ "attribute": "steps-count",
58
+ "reflects": true
59
+ },
60
+ {
61
+ "kind": "field",
62
+ "name": "_stepTitles",
63
+ "type": {
64
+ "text": "string[]"
65
+ },
66
+ "privacy": "private",
67
+ "default": "[]"
68
+ },
69
+ {
70
+ "kind": "field",
71
+ "name": "_maxVisitedStep",
72
+ "type": {
73
+ "text": "number"
74
+ },
75
+ "privacy": "private",
76
+ "default": "1"
77
+ },
78
+ {
79
+ "kind": "field",
80
+ "name": "dirty",
81
+ "type": {
82
+ "text": "boolean"
83
+ },
84
+ "default": "false",
85
+ "description": "Tracks whether the form has unsaved changes.",
86
+ "attribute": "dirty",
87
+ "reflects": true
88
+ },
89
+ {
90
+ "kind": "field",
91
+ "name": "status",
92
+ "type": {
93
+ "text": "'idle' | 'pending' | 'success' | 'error'"
94
+ },
95
+ "default": "'idle'",
96
+ "description": "Submission state: 'idle', 'pending', 'success', or 'error'.",
97
+ "attribute": "status",
98
+ "reflects": true
99
+ },
100
+ {
101
+ "kind": "field",
102
+ "name": "_slottedFormEl",
103
+ "type": {
104
+ "text": "HTMLFormElement | null"
105
+ },
106
+ "privacy": "private",
107
+ "default": "null"
108
+ },
109
+ {
110
+ "kind": "field",
111
+ "name": "_initialValues",
112
+ "privacy": "private",
113
+ "default": "new Map<Element, any>()"
114
+ },
115
+ {
116
+ "kind": "field",
117
+ "name": "_observer",
118
+ "type": {
119
+ "text": "MutationObserver | undefined"
120
+ },
121
+ "privacy": "private"
122
+ },
123
+ {
124
+ "kind": "field",
125
+ "name": "_formListenersCleanups",
126
+ "type": {
127
+ "text": "Array<() => void>"
128
+ },
129
+ "privacy": "private",
130
+ "default": "[]"
131
+ },
132
+ {
133
+ "kind": "method",
134
+ "name": "_cleanupFormListeners",
135
+ "privacy": "private"
136
+ },
137
+ {
138
+ "kind": "method",
139
+ "name": "_initializeForm",
140
+ "privacy": "private"
141
+ },
142
+ {
143
+ "kind": "method",
144
+ "name": "_detectSlottedForm",
145
+ "privacy": "private"
146
+ },
147
+ {
148
+ "kind": "method",
149
+ "name": "_detectSteps",
150
+ "privacy": "private"
151
+ },
152
+ {
153
+ "kind": "method",
154
+ "name": "_updateStepVisibility",
155
+ "privacy": "private"
156
+ },
157
+ {
158
+ "kind": "method",
159
+ "name": "_getFormElements",
160
+ "privacy": "private",
161
+ "return": {
162
+ "type": {
163
+ "text": "Array<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>"
164
+ }
165
+ }
166
+ },
167
+ {
168
+ "kind": "method",
169
+ "name": "_captureInitialValues",
170
+ "privacy": "private"
171
+ },
172
+ {
173
+ "kind": "method",
174
+ "name": "_getElementValue",
175
+ "privacy": "private",
176
+ "return": {
177
+ "type": {
178
+ "text": "any"
179
+ }
180
+ },
181
+ "parameters": [
182
+ {
183
+ "name": "el",
184
+ "type": {
185
+ "text": "HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement"
186
+ }
187
+ }
188
+ ]
189
+ },
190
+ {
191
+ "kind": "method",
192
+ "name": "_onFormInput",
193
+ "privacy": "private"
194
+ },
195
+ {
196
+ "kind": "method",
197
+ "name": "_checkDirty",
198
+ "privacy": "private"
199
+ },
200
+ {
201
+ "kind": "method",
202
+ "name": "_onBeforeUnload",
203
+ "privacy": "private",
204
+ "parameters": [
205
+ {
206
+ "name": "e",
207
+ "type": {
208
+ "text": "BeforeUnloadEvent"
209
+ }
210
+ }
211
+ ]
212
+ },
213
+ {
214
+ "kind": "method",
215
+ "name": "_onSlotChange",
216
+ "privacy": "private"
217
+ },
218
+ {
219
+ "kind": "method",
220
+ "name": "nextStep"
221
+ },
222
+ {
223
+ "kind": "method",
224
+ "name": "prevStep"
225
+ },
226
+ {
227
+ "kind": "method",
228
+ "name": "goToStep",
229
+ "parameters": [
230
+ {
231
+ "name": "stepNum",
232
+ "type": {
233
+ "text": "number"
234
+ }
235
+ }
236
+ ]
237
+ },
238
+ {
239
+ "kind": "field",
240
+ "name": "_isResetting",
241
+ "type": {
242
+ "text": "boolean"
243
+ },
244
+ "privacy": "private",
245
+ "default": "false"
246
+ },
247
+ {
248
+ "kind": "method",
249
+ "name": "reset"
250
+ },
251
+ {
252
+ "kind": "method",
253
+ "name": "submit"
254
+ },
255
+ {
256
+ "kind": "method",
257
+ "name": "_onSubmit",
258
+ "privacy": "private",
259
+ "parameters": [
260
+ {
261
+ "name": "e",
262
+ "type": {
263
+ "text": "Event"
264
+ }
265
+ }
266
+ ]
267
+ },
268
+ {
269
+ "kind": "method",
270
+ "name": "_onFormClick",
271
+ "privacy": "private",
272
+ "parameters": [
273
+ {
274
+ "name": "e",
275
+ "type": {
276
+ "text": "Event"
277
+ }
278
+ }
279
+ ]
280
+ }
281
+ ],
282
+ "attributes": [
283
+ {
284
+ "name": "warn-unsaved",
285
+ "type": {
286
+ "text": "boolean"
287
+ },
288
+ "default": "false",
289
+ "description": "Opt-in warning prompt if the user tries to leave the page with unsaved changes.",
290
+ "fieldName": "warnUnsaved"
291
+ },
292
+ {
293
+ "name": "step",
294
+ "type": {
295
+ "text": "number"
296
+ },
297
+ "default": "1",
298
+ "description": "Active wizard step (1-indexed). Only active if multiple fieldsets exist.",
299
+ "fieldName": "step"
300
+ },
301
+ {
302
+ "name": "steps-count",
303
+ "type": {
304
+ "text": "number"
305
+ },
306
+ "default": "0",
307
+ "description": "The total number of steps/fieldsets detected in the form.",
308
+ "fieldName": "stepsCount"
309
+ },
310
+ {
311
+ "name": "dirty",
312
+ "type": {
313
+ "text": "boolean"
314
+ },
315
+ "default": "false",
316
+ "description": "Tracks whether the form has unsaved changes.",
317
+ "fieldName": "dirty"
318
+ },
319
+ {
320
+ "name": "status",
321
+ "type": {
322
+ "text": "'idle' | 'pending' | 'success' | 'error'"
323
+ },
324
+ "default": "'idle'",
325
+ "description": "Submission state: 'idle', 'pending', 'success', or 'error'.",
326
+ "fieldName": "status"
327
+ }
328
+ ],
329
+ "superclass": {
330
+ "name": "UIBitElement",
331
+ "package": "@uibit/core"
332
+ },
333
+ "tagName": "uibit-form",
334
+ "customElement": true
335
+ }
336
+ ],
337
+ "exports": [
338
+ {
339
+ "kind": "js",
340
+ "name": "Form",
341
+ "declaration": {
342
+ "name": "Form",
343
+ "module": "src/form.ts"
344
+ }
345
+ },
346
+ {
347
+ "kind": "custom-element-definition",
348
+ "name": "uibit-form",
349
+ "declaration": {
350
+ "name": "Form",
351
+ "module": "src/form.ts"
352
+ }
353
+ }
354
+ ]
355
+ },
356
+ {
357
+ "kind": "javascript-module",
358
+ "path": "src/index.ts",
359
+ "declarations": [],
360
+ "exports": [
361
+ {
362
+ "kind": "js",
363
+ "name": "*",
364
+ "declaration": {
365
+ "name": "*",
366
+ "module": "src/form"
367
+ }
368
+ },
369
+ {
370
+ "kind": "js",
371
+ "name": "*",
372
+ "declaration": {
373
+ "name": "*",
374
+ "module": "src/types"
375
+ }
376
+ }
377
+ ]
378
+ },
379
+ {
380
+ "kind": "javascript-module",
381
+ "path": "src/styles.ts",
382
+ "declarations": [
383
+ {
384
+ "kind": "variable",
385
+ "name": "styles",
386
+ "default": "css` :host { display: block; position: relative; font-size: var(--uibit-component-font-size, var(--uibit-font-size-base, 1rem)); font-weight: var(--uibit-component-font-weight, var(--uibit-font-weight-normal, 400)); line-height: var(--uibit-component-line-height, var(--uibit-line-height-relaxed, 1.625)); --uibit-form-wizard-margin: var(--uibit-form-wizard-margin-val, 2rem); } /* Premium Minimalist Stepper Header (Split Layout) */ .wizard-header { margin-bottom: var(--uibit-form-wizard-margin, 2rem); display: flex; justify-content: space-between; align-items: center; width: 100%; height: 1.5rem; } .wizard-meta { display: flex; align-items: center; gap: 0.75rem; } .wizard-controls { display: flex; align-items: center; gap: 0.25rem; } .wizard-back-btn, .wizard-next-btn { display: inline-flex; align-items: center; justify-content: center; background: transparent; border: none; padding: 0.25rem; cursor: pointer; color: #6b7280; border-radius: 999rem; transition: color 150ms ease, background-color 150ms ease, transform 150ms ease, opacity 150ms ease; } .wizard-back-btn:hover, .wizard-next-btn:hover { color: #111827; background-color: #f3f4f6; } .wizard-back-btn:active, .wizard-next-btn:active { transform: scale(0.95); } .wizard-back-btn:focus-visible, .wizard-next-btn:focus-visible { outline: 0.125rem solid #000000; } .wizard-step-info { font-size: var(--uibit-font-size-xs, 0.75rem); font-weight: 500; color: #9ca3af; display: inline-flex; align-items: center; gap: 0.25rem; user-select: none; } .wizard-step-num { color: #111827; font-weight: 600; } .wizard-step-sep { opacity: 0.5; } .wizard-step-total { opacity: 0.8; } ::slotted([slot^=\"step-title-\"]), .wizard-step-title { font-family: var(--uibit-font-family, Inter, sans-serif); font-size: var(--uibit-font-size-sm, 0.875rem); font-weight: 650; color: #111827; letter-spacing: -0.01em; user-select: none; } /* Stabilized layout hidden state */ .disabled-control { opacity: 0; pointer-events: none; visibility: hidden; } /* Premium inline error banner */ .error-banner { padding: 1rem 0; font-size: var(--uibit-font-size-sm, 0.875rem); color: #111827; margin-bottom: 0.5rem; } /* State content wrappers */ .state-content { display: none; } :host([status=\"pending\"]) .state-content[data-state=\"pending\"] { display: block; } :host([status=\"success\"]) .state-content[data-state=\"success\"] { display: block; } /* Correctly hide the slotted form element on success and pending states */ :host([status=\"success\"]) ::slotted(form), :host([status=\"pending\"]) ::slotted(form) { display: none !important; } `"
387
+ }
388
+ ],
389
+ "exports": [
390
+ {
391
+ "kind": "js",
392
+ "name": "styles",
393
+ "declaration": {
394
+ "name": "styles",
395
+ "module": "src/styles.ts"
396
+ }
397
+ }
398
+ ]
399
+ },
400
+ {
401
+ "kind": "javascript-module",
402
+ "path": "src/types.ts",
403
+ "declarations": [],
404
+ "exports": []
405
+ }
406
+ ]
407
+ }
package/dist/form.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ import type { PropertyValues } from 'lit';
2
+ import { UIBitElement } from '@uibit/core';
3
+ /**
4
+ * A declarative form wrapper that wraps a native `<form>` and adds wizards,
5
+ * submit lifecycle states, and dirty checking.
6
+ *
7
+ * @slot - Default slot where the native `<form>` element is placed.
8
+ * @slot success - Custom success template displayed upon successful submission.
9
+ * @slot error - Custom error template displayed upon failed submission.
10
+ */
11
+ export declare class Form extends UIBitElement {
12
+ static styles: import("lit").CSSResult;
13
+ /** Opt-in warning prompt if the user tries to leave the page with unsaved changes. */
14
+ warnUnsaved: boolean;
15
+ /** Active wizard step (1-indexed). Only active if multiple fieldsets exist. */
16
+ step: number;
17
+ /** The total number of steps/fieldsets detected in the form. */
18
+ stepsCount: number;
19
+ private _stepTitles;
20
+ private _maxVisitedStep;
21
+ /** Tracks whether the form has unsaved changes. */
22
+ dirty: boolean;
23
+ /** Submission state: 'idle', 'pending', 'success', or 'error'. */
24
+ status: 'idle' | 'pending' | 'success' | 'error';
25
+ private _slottedFormEl;
26
+ private _initialValues;
27
+ private _observer?;
28
+ private _formListenersCleanups;
29
+ connectedCallback(): void;
30
+ disconnectedCallback(): void;
31
+ firstUpdated(changedProperties: PropertyValues): void;
32
+ private _cleanupFormListeners;
33
+ private _initializeForm;
34
+ private _detectSlottedForm;
35
+ private _detectSteps;
36
+ private _updateStepVisibility;
37
+ private _getFormElements;
38
+ private _captureInitialValues;
39
+ private _getElementValue;
40
+ private _onFormInput;
41
+ private _checkDirty;
42
+ private _onBeforeUnload;
43
+ private _onSlotChange;
44
+ nextStep(): void;
45
+ prevStep(): void;
46
+ goToStep(stepNum: number): void;
47
+ private _isResetting;
48
+ reset(): void;
49
+ submit(): Promise<void>;
50
+ private _onSubmit;
51
+ private _onFormClick;
52
+ protected willUpdate(changedProperties: PropertyValues): void;
53
+ render(): import("lit").TemplateResult<1>;
54
+ }
55
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;AAI/D;;;;;;;GAOG;AACH,qBACa,IAAK,SAAQ,YAAY;IACpC,MA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