@insticc/genericform 1.0.11 → 2.0.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/build/Demo.js +559 -0
- package/build/Demo2.js +495 -0
- package/build/FormFields/CustomAccordion.js +105 -0
- package/build/FormFields/CustomCheckbox.js +38 -62
- package/build/FormFields/CustomCheckboxGroup.js +87 -0
- package/build/FormFields/CustomComponent.js +42 -0
- package/build/FormFields/CustomDatePicker.js +51 -68
- package/build/FormFields/CustomDropdown.js +103 -26
- package/build/FormFields/CustomInput.js +51 -46
- package/build/FormFields/CustomJson.js +148 -0
- package/build/FormFields/CustomLabel.js +8 -14
- package/build/FormFields/CustomMultiDropdown.js +88 -0
- package/build/FormFields/CustomNumberInput.js +47 -44
- package/build/FormFields/CustomRadioGroup.js +91 -0
- package/build/FormFields/CustomSearch.js +56 -30
- package/build/FormFields/CustomSeparator.js +24 -0
- package/build/FormFields/CustomTextArea.js +52 -46
- package/build/FormFields/CustomToggle.js +73 -0
- package/build/FormFields/defaults.js +32 -0
- package/build/index.css +450 -12
- package/build/index.js +739 -385
- package/package.json +28 -14
- package/build/FormFields/CustomRadioButton.js +0 -57
- package/build/FormFields/MultipleCheckbox.js +0 -92
- package/build/FormFields/MultipleDropdown.js +0 -76
- package/build/FormFields/MultipleRadioButton.js +0 -90
- package/build/FormFields/YearDatePicker.js +0 -115
package/build/Demo.js
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _index = _interopRequireDefault(require("./index"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /**
|
|
16
|
+
* @file Demo.jsx
|
|
17
|
+
* Full GenericForm demo — every field type + every key scenario.
|
|
18
|
+
*
|
|
19
|
+
* Mount anywhere: <Demo />
|
|
20
|
+
*/
|
|
21
|
+
// ── Shared option sets ────────────────────────────────────────────────────────
|
|
22
|
+
var COUNTRIES = [{
|
|
23
|
+
value: "PT",
|
|
24
|
+
text: "Portugal"
|
|
25
|
+
}, {
|
|
26
|
+
value: "ES",
|
|
27
|
+
text: "Spain"
|
|
28
|
+
}, {
|
|
29
|
+
value: "FR",
|
|
30
|
+
text: "France"
|
|
31
|
+
}, {
|
|
32
|
+
value: "DE",
|
|
33
|
+
text: "Germany"
|
|
34
|
+
}];
|
|
35
|
+
var ROLES = [{
|
|
36
|
+
id: "admin",
|
|
37
|
+
label: "Administrator"
|
|
38
|
+
}, {
|
|
39
|
+
id: "editor",
|
|
40
|
+
label: "Editor"
|
|
41
|
+
}, {
|
|
42
|
+
id: "viewer",
|
|
43
|
+
label: "Viewer"
|
|
44
|
+
}];
|
|
45
|
+
var TAGS = [{
|
|
46
|
+
name: "react",
|
|
47
|
+
text: "React"
|
|
48
|
+
}, {
|
|
49
|
+
name: "vue",
|
|
50
|
+
text: "Vue"
|
|
51
|
+
}, {
|
|
52
|
+
name: "svelte",
|
|
53
|
+
text: "Svelte"
|
|
54
|
+
}, {
|
|
55
|
+
name: "solid",
|
|
56
|
+
text: "SolidJS"
|
|
57
|
+
}];
|
|
58
|
+
|
|
59
|
+
// ── Demo ──────────────────────────────────────────────────────────────────────
|
|
60
|
+
var Demo = function Demo() {
|
|
61
|
+
var _useState = (0, _react.useState)(null),
|
|
62
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
63
|
+
lastSubmit = _useState2[0],
|
|
64
|
+
setLastSubmit = _useState2[1];
|
|
65
|
+
var _useState3 = (0, _react.useState)([{
|
|
66
|
+
title: "Alice Johnson",
|
|
67
|
+
description: "alice@example.com"
|
|
68
|
+
}, {
|
|
69
|
+
title: "Bob Smith",
|
|
70
|
+
description: "bob@example.com"
|
|
71
|
+
}]),
|
|
72
|
+
_useState4 = _slicedToArray(_useState3, 1),
|
|
73
|
+
searchResults = _useState4[0];
|
|
74
|
+
|
|
75
|
+
// Checkbox group state (controlled externally, as the field expects)
|
|
76
|
+
var _useState5 = (0, _react.useState)([]),
|
|
77
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
78
|
+
interests = _useState6[0],
|
|
79
|
+
setInterests = _useState6[1];
|
|
80
|
+
var fields = [
|
|
81
|
+
// ── Section header ─────────────────────────────────────────────────────
|
|
82
|
+
{
|
|
83
|
+
name: "sep1",
|
|
84
|
+
type: "separator"
|
|
85
|
+
}, {
|
|
86
|
+
name: "lbl1",
|
|
87
|
+
type: "label",
|
|
88
|
+
displayName: "① Text inputs"
|
|
89
|
+
}, {
|
|
90
|
+
name: "firstName",
|
|
91
|
+
type: "text",
|
|
92
|
+
displayName: "First name",
|
|
93
|
+
required: false,
|
|
94
|
+
inline: true,
|
|
95
|
+
value: ""
|
|
96
|
+
}, {
|
|
97
|
+
name: "lastName",
|
|
98
|
+
type: "text",
|
|
99
|
+
displayName: "Last name",
|
|
100
|
+
required: false,
|
|
101
|
+
inline: true,
|
|
102
|
+
value: ""
|
|
103
|
+
}, {
|
|
104
|
+
name: "email",
|
|
105
|
+
type: "email",
|
|
106
|
+
displayName: "Email",
|
|
107
|
+
required: false,
|
|
108
|
+
value: "",
|
|
109
|
+
validate: function validate(v) {
|
|
110
|
+
return v && !v.includes("@demo") ? "Use a @demo address for this example" : null;
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
name: "age",
|
|
114
|
+
type: "int",
|
|
115
|
+
displayName: "Age",
|
|
116
|
+
value: "",
|
|
117
|
+
min: 0,
|
|
118
|
+
max: 120
|
|
119
|
+
}, {
|
|
120
|
+
name: "score",
|
|
121
|
+
type: "number",
|
|
122
|
+
displayName: "Score (0–100)",
|
|
123
|
+
value: "",
|
|
124
|
+
min: 0,
|
|
125
|
+
max: 100,
|
|
126
|
+
step: 0.5
|
|
127
|
+
}, {
|
|
128
|
+
name: "bio",
|
|
129
|
+
type: "textArea",
|
|
130
|
+
displayName: "Biography",
|
|
131
|
+
value: "",
|
|
132
|
+
rows: 4,
|
|
133
|
+
maxLength: 300,
|
|
134
|
+
tooltip: "Max 300 characters"
|
|
135
|
+
},
|
|
136
|
+
// ── Select ────────────────────────────────────────────────────────────
|
|
137
|
+
{
|
|
138
|
+
name: "sep2",
|
|
139
|
+
type: "separator"
|
|
140
|
+
}, {
|
|
141
|
+
name: "lbl2",
|
|
142
|
+
type: "label",
|
|
143
|
+
displayName: "② Select / dropdown"
|
|
144
|
+
},
|
|
145
|
+
// select with { value, text } options — returns full object
|
|
146
|
+
{
|
|
147
|
+
name: "country",
|
|
148
|
+
type: "select",
|
|
149
|
+
displayName: "Country (value/text)",
|
|
150
|
+
required: false,
|
|
151
|
+
value: "",
|
|
152
|
+
options: COUNTRIES,
|
|
153
|
+
onChange: function onChange(val, fd) {
|
|
154
|
+
return console.log("country full option →", fd);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
// select with { id, label } options
|
|
158
|
+
{
|
|
159
|
+
name: "role",
|
|
160
|
+
type: "select",
|
|
161
|
+
displayName: "Role (id/label)",
|
|
162
|
+
value: "",
|
|
163
|
+
options: ROLES
|
|
164
|
+
},
|
|
165
|
+
// select with { name, text } options
|
|
166
|
+
{
|
|
167
|
+
name: "framework",
|
|
168
|
+
type: "select",
|
|
169
|
+
displayName: "Framework (name/text)",
|
|
170
|
+
value: "",
|
|
171
|
+
options: TAGS
|
|
172
|
+
},
|
|
173
|
+
// multi-select
|
|
174
|
+
{
|
|
175
|
+
name: "langs",
|
|
176
|
+
type: "multipleDropdown",
|
|
177
|
+
displayName: "Languages (multi)",
|
|
178
|
+
value: [],
|
|
179
|
+
options: [{
|
|
180
|
+
value: "js",
|
|
181
|
+
text: "JavaScript"
|
|
182
|
+
}, {
|
|
183
|
+
value: "ts",
|
|
184
|
+
text: "TypeScript"
|
|
185
|
+
}, {
|
|
186
|
+
value: "py",
|
|
187
|
+
text: "Python"
|
|
188
|
+
}, {
|
|
189
|
+
value: "go",
|
|
190
|
+
text: "Go"
|
|
191
|
+
}]
|
|
192
|
+
},
|
|
193
|
+
// ── Date / time ───────────────────────────────────────────────────────
|
|
194
|
+
{
|
|
195
|
+
name: "sep3",
|
|
196
|
+
type: "separator"
|
|
197
|
+
}, {
|
|
198
|
+
name: "lbl3",
|
|
199
|
+
type: "label",
|
|
200
|
+
displayName: "③ Date / time pickers"
|
|
201
|
+
}, {
|
|
202
|
+
name: "dob",
|
|
203
|
+
type: "date",
|
|
204
|
+
displayName: "Date of birth",
|
|
205
|
+
value: ""
|
|
206
|
+
}, {
|
|
207
|
+
name: "meeting",
|
|
208
|
+
type: "datetime",
|
|
209
|
+
displayName: "Meeting at",
|
|
210
|
+
value: ""
|
|
211
|
+
}, {
|
|
212
|
+
name: "alarm",
|
|
213
|
+
type: "time",
|
|
214
|
+
displayName: "Alarm time",
|
|
215
|
+
value: ""
|
|
216
|
+
}, {
|
|
217
|
+
name: "startYear",
|
|
218
|
+
type: "year",
|
|
219
|
+
displayName: "Start year",
|
|
220
|
+
value: "",
|
|
221
|
+
minYear: 2000,
|
|
222
|
+
maxYear: 2030
|
|
223
|
+
},
|
|
224
|
+
// ── Boolean controls ──────────────────────────────────────────────────
|
|
225
|
+
{
|
|
226
|
+
name: "sep4",
|
|
227
|
+
type: "separator"
|
|
228
|
+
}, {
|
|
229
|
+
name: "lbl4",
|
|
230
|
+
type: "label",
|
|
231
|
+
displayName: "④ Boolean controls"
|
|
232
|
+
}, {
|
|
233
|
+
name: "terms",
|
|
234
|
+
type: "checkbox",
|
|
235
|
+
displayName: "I accept the terms",
|
|
236
|
+
value: false,
|
|
237
|
+
required: false
|
|
238
|
+
}, {
|
|
239
|
+
name: "newsletter",
|
|
240
|
+
type: "toggle",
|
|
241
|
+
displayName: "Subscribe to newsletter",
|
|
242
|
+
value: false
|
|
243
|
+
},
|
|
244
|
+
// ── Radio ─────────────────────────────────────────────────────────────
|
|
245
|
+
{
|
|
246
|
+
name: "sep5",
|
|
247
|
+
type: "separator"
|
|
248
|
+
}, {
|
|
249
|
+
name: "lbl5",
|
|
250
|
+
type: "label",
|
|
251
|
+
displayName: "⑤ Radio buttons"
|
|
252
|
+
},
|
|
253
|
+
// Radio group (controlled by options)
|
|
254
|
+
{
|
|
255
|
+
name: "priority",
|
|
256
|
+
type: "radioGroup",
|
|
257
|
+
displayName: "Priority",
|
|
258
|
+
value: "medium",
|
|
259
|
+
options: [{
|
|
260
|
+
value: "low",
|
|
261
|
+
text: "Low"
|
|
262
|
+
}, {
|
|
263
|
+
value: "medium",
|
|
264
|
+
text: "Medium"
|
|
265
|
+
}, {
|
|
266
|
+
value: "high",
|
|
267
|
+
text: "High"
|
|
268
|
+
}]
|
|
269
|
+
},
|
|
270
|
+
// Radio group inline
|
|
271
|
+
{
|
|
272
|
+
name: "size",
|
|
273
|
+
type: "radioGroupInline",
|
|
274
|
+
displayName: "Size",
|
|
275
|
+
value: "md",
|
|
276
|
+
options: [{
|
|
277
|
+
value: "sm",
|
|
278
|
+
text: "Small"
|
|
279
|
+
}, {
|
|
280
|
+
value: "md",
|
|
281
|
+
text: "Medium"
|
|
282
|
+
}, {
|
|
283
|
+
value: "lg",
|
|
284
|
+
text: "Large"
|
|
285
|
+
}]
|
|
286
|
+
},
|
|
287
|
+
// ── Checkbox groups ───────────────────────────────────────────────────
|
|
288
|
+
{
|
|
289
|
+
name: "sep6",
|
|
290
|
+
type: "separator"
|
|
291
|
+
}, {
|
|
292
|
+
name: "lbl6",
|
|
293
|
+
type: "label",
|
|
294
|
+
displayName: "⑥ Checkbox groups"
|
|
295
|
+
},
|
|
296
|
+
// checkboxGroup — option-level onChange
|
|
297
|
+
{
|
|
298
|
+
name: "perms",
|
|
299
|
+
type: "checkboxGroup",
|
|
300
|
+
displayName: "Permissions",
|
|
301
|
+
value: ["read"],
|
|
302
|
+
options: [{
|
|
303
|
+
name: "read",
|
|
304
|
+
label: "Read"
|
|
305
|
+
}, {
|
|
306
|
+
name: "write",
|
|
307
|
+
label: "Write"
|
|
308
|
+
}, {
|
|
309
|
+
name: "delete",
|
|
310
|
+
label: "Delete"
|
|
311
|
+
}]
|
|
312
|
+
}, {
|
|
313
|
+
name: "interests",
|
|
314
|
+
type: "checkboxGroup",
|
|
315
|
+
displayName: "Interests",
|
|
316
|
+
value: [],
|
|
317
|
+
options: [{
|
|
318
|
+
name: "tech",
|
|
319
|
+
label: "Technology"
|
|
320
|
+
}, {
|
|
321
|
+
name: "sports",
|
|
322
|
+
label: "Sports"
|
|
323
|
+
}, {
|
|
324
|
+
name: "music",
|
|
325
|
+
label: "Music"
|
|
326
|
+
}]
|
|
327
|
+
// onOptionChange: setInterests // !warnnig updating state cause re-rendering
|
|
328
|
+
},
|
|
329
|
+
// ── JSON ──────────────────────────────────────────────────────────────
|
|
330
|
+
{
|
|
331
|
+
name: "sep7",
|
|
332
|
+
type: "separator"
|
|
333
|
+
}, {
|
|
334
|
+
name: "lbl7",
|
|
335
|
+
type: "label",
|
|
336
|
+
displayName: "⑦ JSON editor"
|
|
337
|
+
}, {
|
|
338
|
+
name: "config",
|
|
339
|
+
type: "json",
|
|
340
|
+
displayName: "Config object",
|
|
341
|
+
datatype: "object",
|
|
342
|
+
value: "",
|
|
343
|
+
allowModeSwitch: false,
|
|
344
|
+
rows: 6,
|
|
345
|
+
showHelp: true,
|
|
346
|
+
helpText: "Enter a valid JSON object"
|
|
347
|
+
}, {
|
|
348
|
+
name: "tags",
|
|
349
|
+
type: "json",
|
|
350
|
+
displayName: "Tags (string)",
|
|
351
|
+
datatype: "string",
|
|
352
|
+
value: "",
|
|
353
|
+
allowModeSwitch: true,
|
|
354
|
+
rows: 4
|
|
355
|
+
},
|
|
356
|
+
// ── Accordion ─────────────────────────────────────────────────────────
|
|
357
|
+
{
|
|
358
|
+
name: "sep8",
|
|
359
|
+
type: "separator"
|
|
360
|
+
}, {
|
|
361
|
+
name: "lbl8",
|
|
362
|
+
type: "label",
|
|
363
|
+
displayName: "⑧ Accordion"
|
|
364
|
+
}, {
|
|
365
|
+
name: "advanced",
|
|
366
|
+
type: "accordion",
|
|
367
|
+
defaultOpen: false,
|
|
368
|
+
sections: [{
|
|
369
|
+
title: "Advanced settings",
|
|
370
|
+
icon: "⚙️",
|
|
371
|
+
content: /*#__PURE__*/React.createElement("div", {
|
|
372
|
+
style: {
|
|
373
|
+
display: "flex",
|
|
374
|
+
flexDirection: "column",
|
|
375
|
+
gap: 8
|
|
376
|
+
}
|
|
377
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
378
|
+
style: {
|
|
379
|
+
fontSize: "0.9rem"
|
|
380
|
+
}
|
|
381
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
382
|
+
type: "checkbox",
|
|
383
|
+
style: {
|
|
384
|
+
marginRight: 6
|
|
385
|
+
}
|
|
386
|
+
}), "Enable experimental features"), /*#__PURE__*/React.createElement("label", {
|
|
387
|
+
style: {
|
|
388
|
+
fontSize: "0.9rem"
|
|
389
|
+
}
|
|
390
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
391
|
+
type: "checkbox",
|
|
392
|
+
style: {
|
|
393
|
+
marginRight: 6
|
|
394
|
+
}
|
|
395
|
+
}), "Verbose logging"))
|
|
396
|
+
}, {
|
|
397
|
+
title: "Danger zone",
|
|
398
|
+
icon: "⚠️",
|
|
399
|
+
content: /*#__PURE__*/React.createElement("p", {
|
|
400
|
+
style: {
|
|
401
|
+
color: "#db2828",
|
|
402
|
+
fontSize: "0.9rem"
|
|
403
|
+
}
|
|
404
|
+
}, "Destructive actions go here.")
|
|
405
|
+
}]
|
|
406
|
+
},
|
|
407
|
+
// ── Custom component ──────────────────────────────────────────────────
|
|
408
|
+
{
|
|
409
|
+
name: "sep9",
|
|
410
|
+
type: "separator"
|
|
411
|
+
}, {
|
|
412
|
+
name: "lbl9",
|
|
413
|
+
type: "label",
|
|
414
|
+
displayName: "⑨ Custom component"
|
|
415
|
+
}, {
|
|
416
|
+
name: "avatar",
|
|
417
|
+
type: "component",
|
|
418
|
+
displayName: "Avatar preview",
|
|
419
|
+
component: /*#__PURE__*/React.createElement("div", {
|
|
420
|
+
style: {
|
|
421
|
+
width: 64,
|
|
422
|
+
height: 64,
|
|
423
|
+
borderRadius: "50%",
|
|
424
|
+
background: "#2185d0",
|
|
425
|
+
display: "flex",
|
|
426
|
+
alignItems: "center",
|
|
427
|
+
justifyContent: "center",
|
|
428
|
+
color: "#fff",
|
|
429
|
+
fontSize: 24,
|
|
430
|
+
fontWeight: 600
|
|
431
|
+
}
|
|
432
|
+
}, "A")
|
|
433
|
+
},
|
|
434
|
+
// ── Conditional (hide as function) ────────────────────────────────────
|
|
435
|
+
{
|
|
436
|
+
name: "sep10",
|
|
437
|
+
type: "separator"
|
|
438
|
+
}, {
|
|
439
|
+
name: "lbl10",
|
|
440
|
+
type: "label",
|
|
441
|
+
displayName: "⑩ Conditional visibility (hide a field when newsletter is off)"
|
|
442
|
+
}, {
|
|
443
|
+
name: "newsletterFreq",
|
|
444
|
+
type: "radioGroupInline",
|
|
445
|
+
displayName: "Frequency",
|
|
446
|
+
value: "weekly",
|
|
447
|
+
options: [{
|
|
448
|
+
value: "daily",
|
|
449
|
+
text: "Daily"
|
|
450
|
+
}, {
|
|
451
|
+
value: "weekly",
|
|
452
|
+
text: "Weekly"
|
|
453
|
+
}, {
|
|
454
|
+
value: "monthly",
|
|
455
|
+
text: "Monthly"
|
|
456
|
+
}],
|
|
457
|
+
hide: function hide(formData) {
|
|
458
|
+
return !formData.newsletter;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
// ── Validation showcase ───────────────────────────────────────────────
|
|
462
|
+
{
|
|
463
|
+
name: "sep11",
|
|
464
|
+
type: "separator"
|
|
465
|
+
}, {
|
|
466
|
+
name: "lbl11",
|
|
467
|
+
type: "label",
|
|
468
|
+
displayName: "⑪ Validation (minLength, maxLength, custom)"
|
|
469
|
+
}, {
|
|
470
|
+
name: "username",
|
|
471
|
+
type: "text",
|
|
472
|
+
displayName: "Username",
|
|
473
|
+
value: "",
|
|
474
|
+
required: false,
|
|
475
|
+
minLength: 3,
|
|
476
|
+
maxLength: 20,
|
|
477
|
+
tooltip: "3–20 characters, no spaces",
|
|
478
|
+
validate: function validate(v) {
|
|
479
|
+
return v && /\s/.test(v) ? "No spaces allowed" : null;
|
|
480
|
+
}
|
|
481
|
+
}, {
|
|
482
|
+
name: "website",
|
|
483
|
+
type: "text",
|
|
484
|
+
displayName: "Website URL",
|
|
485
|
+
value: "",
|
|
486
|
+
validate: function validate(v) {
|
|
487
|
+
return v && !v.startsWith("https://") ? "Must start with https://" : null;
|
|
488
|
+
}
|
|
489
|
+
}];
|
|
490
|
+
|
|
491
|
+
// ── Custom action buttons ──────────────────────────────────────────────────
|
|
492
|
+
var customActions = [{
|
|
493
|
+
label: "Reset",
|
|
494
|
+
className: "ufg-button-secondary",
|
|
495
|
+
onClick: function onClick() {
|
|
496
|
+
return alert("Reset clicked");
|
|
497
|
+
}
|
|
498
|
+
}];
|
|
499
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
500
|
+
style: {
|
|
501
|
+
maxWidth: 800,
|
|
502
|
+
margin: "2rem auto",
|
|
503
|
+
fontFamily: "sans-serif"
|
|
504
|
+
}
|
|
505
|
+
}, /*#__PURE__*/React.createElement("h1", {
|
|
506
|
+
style: {
|
|
507
|
+
fontSize: "1.4rem",
|
|
508
|
+
marginBottom: "0.5rem"
|
|
509
|
+
}
|
|
510
|
+
}, "GenericForm \u2014 full demo"), /*#__PURE__*/React.createElement("p", {
|
|
511
|
+
style: {
|
|
512
|
+
color: "#666",
|
|
513
|
+
marginBottom: "1.5rem",
|
|
514
|
+
fontSize: "0.9rem"
|
|
515
|
+
}
|
|
516
|
+
}, "Every field type, conditional visibility, validation, custom actions, and onSubmit."), /*#__PURE__*/React.createElement(_index["default"], {
|
|
517
|
+
title: "Demo form",
|
|
518
|
+
fields: fields,
|
|
519
|
+
submitText: "Submit demo",
|
|
520
|
+
cancelText: "Clear",
|
|
521
|
+
customActions: customActions,
|
|
522
|
+
validateOnChange: true,
|
|
523
|
+
validateOnSubmit: true,
|
|
524
|
+
onSubmit: function onSubmit(data) {
|
|
525
|
+
console.log("Submitted:", data);
|
|
526
|
+
setLastSubmit(data);
|
|
527
|
+
},
|
|
528
|
+
onCancel: function onCancel() {
|
|
529
|
+
return setLastSubmit(null);
|
|
530
|
+
}
|
|
531
|
+
// Date handlers
|
|
532
|
+
,
|
|
533
|
+
onChangeTime: function onChangeTime(date, name) {
|
|
534
|
+
return console.log("date:", name, date);
|
|
535
|
+
},
|
|
536
|
+
onChangeYear: function onChangeYear(date, name) {
|
|
537
|
+
return console.log("year:", name, date);
|
|
538
|
+
}
|
|
539
|
+
// Search
|
|
540
|
+
,
|
|
541
|
+
handleSearchChange: function handleSearchChange() {},
|
|
542
|
+
handleResultSelect: function handleResultSelect() {}
|
|
543
|
+
}), lastSubmit && /*#__PURE__*/React.createElement("div", {
|
|
544
|
+
style: {
|
|
545
|
+
marginTop: "2rem",
|
|
546
|
+
padding: "1rem",
|
|
547
|
+
background: "#f0f8f0",
|
|
548
|
+
borderRadius: 8,
|
|
549
|
+
border: "1px solid #b2dfb2"
|
|
550
|
+
}
|
|
551
|
+
}, /*#__PURE__*/React.createElement("strong", null, "Last submitted data:"), /*#__PURE__*/React.createElement("pre", {
|
|
552
|
+
style: {
|
|
553
|
+
marginTop: 8,
|
|
554
|
+
fontSize: "0.8rem",
|
|
555
|
+
overflow: "auto"
|
|
556
|
+
}
|
|
557
|
+
}, JSON.stringify(lastSubmit, null, 2))));
|
|
558
|
+
};
|
|
559
|
+
var _default = exports["default"] = Demo;
|