@form-eng/chakra 1.1.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/dist/index.js ADDED
@@ -0,0 +1,832 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ CheckboxGroup: () => CheckboxGroup_default,
33
+ DateControl: () => DateControl_default,
34
+ DocumentLinksStrings: () => import_core.DocumentLinksStrings,
35
+ Dropdown: () => Dropdown_default,
36
+ DynamicFragment: () => DynamicFragment_default,
37
+ FieldClassName: () => import_core.FieldClassName,
38
+ FormLoading: () => FormLoading,
39
+ GetFieldDataTestId: () => import_core.GetFieldDataTestId,
40
+ MultiSelect: () => MultiSelect_default,
41
+ Number: () => Number_default,
42
+ RadioGroup: () => RadioGroup_default,
43
+ ReadOnly: () => ReadOnly_default,
44
+ ReadOnlyText: () => ReadOnlyText,
45
+ SimpleDropdown: () => SimpleDropdown_default,
46
+ Slider: () => Slider_default,
47
+ StatusMessage: () => StatusMessage,
48
+ Textarea: () => Textarea_default,
49
+ Textbox: () => Textbox_default,
50
+ Toggle: () => Toggle_default,
51
+ createChakraFieldRegistry: () => createChakraFieldRegistry,
52
+ formatDateTime: () => import_core.formatDateTime,
53
+ getFieldState: () => import_core.getFieldState
54
+ });
55
+ module.exports = __toCommonJS(index_exports);
56
+
57
+ // src/fields/Textbox.tsx
58
+ var import_react = require("@chakra-ui/react");
59
+
60
+ // src/components/ReadOnlyText.tsx
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ var ReadOnlyText = (props) => {
63
+ const { value, fieldName, ellipsifyTextCharacters } = props;
64
+ const cutoff = (ellipsifyTextCharacters || 0) - 3;
65
+ const displayValue = value ? ellipsifyTextCharacters && value.length > ellipsifyTextCharacters ? `${value.substring(0, cutoff)}...` : value : "-";
66
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
67
+ "span",
68
+ {
69
+ id: `${fieldName}-read-only`,
70
+ className: "fe-read-only-text",
71
+ title: value,
72
+ children: displayValue
73
+ }
74
+ );
75
+ };
76
+
77
+ // src/helpers.ts
78
+ var import_core = require("@form-eng/core");
79
+
80
+ // src/fields/Textbox.tsx
81
+ var import_jsx_runtime2 = require("react/jsx-runtime");
82
+ var Textbox = (props) => {
83
+ const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, placeholder, setFieldValue } = props;
84
+ const onChange = (event) => {
85
+ setFieldValue(fieldName, event.target.value, false, 3e3);
86
+ };
87
+ if (readOnly) {
88
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
89
+ ReadOnlyText,
90
+ {
91
+ fieldName,
92
+ value,
93
+ ellipsifyTextCharacters: config?.ellipsifyTextCharacters
94
+ }
95
+ );
96
+ }
97
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
98
+ import_react.Input,
99
+ {
100
+ type: "text",
101
+ autoComplete: "off",
102
+ value: value ?? "",
103
+ onChange,
104
+ placeholder: placeholder ?? config?.placeHolder,
105
+ "aria-invalid": !!error,
106
+ "aria-required": required,
107
+ "data-field-type": "Textbox",
108
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
109
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId)
110
+ }
111
+ );
112
+ };
113
+ var Textbox_default = Textbox;
114
+
115
+ // src/fields/Number.tsx
116
+ var import_core2 = require("@form-eng/core");
117
+ var import_react2 = require("@chakra-ui/react");
118
+ var import_jsx_runtime3 = require("react/jsx-runtime");
119
+ var NumberField = (props) => {
120
+ const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
121
+ const onChange = (event) => {
122
+ const number = Number(event.target.value);
123
+ if (!isNaN(number)) {
124
+ setFieldValue(fieldName, number, false, 1500);
125
+ }
126
+ };
127
+ if (readOnly) {
128
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ReadOnlyText, { fieldName, value: String(value) });
129
+ }
130
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
131
+ import_react2.Input,
132
+ {
133
+ type: "number",
134
+ autoComplete: "off",
135
+ value: !(0, import_core2.isNull)(value) ? String(value) : "",
136
+ onChange,
137
+ "aria-invalid": !!error,
138
+ "aria-required": required,
139
+ "data-field-type": "Number",
140
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
141
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId)
142
+ }
143
+ );
144
+ };
145
+ var Number_default = NumberField;
146
+
147
+ // src/fields/Toggle.tsx
148
+ var import_core3 = require("@form-eng/core");
149
+ var import_jsx_runtime4 = require("react/jsx-runtime");
150
+ var Toggle = (props) => {
151
+ const { fieldName, programName, entityType, entityId, value, readOnly, error, required, label, setFieldValue } = props;
152
+ const onChange = (event) => {
153
+ setFieldValue(fieldName, event.target.checked);
154
+ };
155
+ if (readOnly) {
156
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ReadOnlyText, { fieldName, value: (0, import_core3.convertBooleanToYesOrNoText)(value) });
157
+ }
158
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
159
+ "label",
160
+ {
161
+ style: {
162
+ display: "inline-flex",
163
+ alignItems: "center",
164
+ gap: "8px",
165
+ cursor: "pointer"
166
+ },
167
+ "data-field-type": "Toggle",
168
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
169
+ children: [
170
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
171
+ "input",
172
+ {
173
+ type: "checkbox",
174
+ role: "switch",
175
+ checked: !!value,
176
+ onChange,
177
+ "aria-invalid": !!error,
178
+ "aria-required": required,
179
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId),
180
+ style: { accentColor: "var(--chakra-colors-blue-500, #3182CE)" }
181
+ }
182
+ ),
183
+ label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "var(--chakra-fontSizes-md, 16px)" }, children: label })
184
+ ]
185
+ }
186
+ );
187
+ };
188
+ var Toggle_default = Toggle;
189
+
190
+ // src/fields/Dropdown.tsx
191
+ var import_react3 = require("@chakra-ui/react");
192
+ var import_react4 = __toESM(require("react"));
193
+ var import_jsx_runtime5 = require("react/jsx-runtime");
194
+ var Dropdown = (props) => {
195
+ const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, options, placeholder, setFieldValue } = props;
196
+ const onChange = (event) => {
197
+ setFieldValue(fieldName, event.target.value);
198
+ };
199
+ import_react4.default.useEffect(() => {
200
+ if (!value && !readOnly && config?.setDefaultKeyIfOnlyOneOption && options?.length === 1) {
201
+ setFieldValue(fieldName, String(options[0].value));
202
+ }
203
+ }, [options]);
204
+ if (readOnly) {
205
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ReadOnlyText, { fieldName, value });
206
+ }
207
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
208
+ import_react3.NativeSelect.Root,
209
+ {
210
+ "data-field-type": "Dropdown",
211
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
212
+ children: [
213
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
214
+ import_react3.NativeSelect.Field,
215
+ {
216
+ value: value ?? "",
217
+ onChange,
218
+ "aria-invalid": !!error,
219
+ "aria-required": required,
220
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId),
221
+ children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: placeholder ?? config?.placeHolder ?? "" }),
223
+ options?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: String(option.value), disabled: option.disabled, children: option.label }, String(option.value)))
224
+ ]
225
+ }
226
+ ),
227
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react3.NativeSelect.Indicator, {})
228
+ ]
229
+ }
230
+ );
231
+ };
232
+ var Dropdown_default = Dropdown;
233
+
234
+ // src/fields/SimpleDropdown.tsx
235
+ var import_react5 = require("@chakra-ui/react");
236
+ var import_jsx_runtime6 = require("react/jsx-runtime");
237
+ var SimpleDropdown = (props) => {
238
+ const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, placeholder, setFieldValue } = props;
239
+ const simpleOptions = config?.dropdownOptions ?? [];
240
+ const onChange = (event) => {
241
+ setFieldValue(fieldName, event.target.value);
242
+ };
243
+ if (readOnly) {
244
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ReadOnlyText, { fieldName, value });
245
+ }
246
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
247
+ import_react5.NativeSelect.Root,
248
+ {
249
+ "data-field-type": "SimpleDropdown",
250
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
251
+ children: [
252
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
253
+ import_react5.NativeSelect.Field,
254
+ {
255
+ value: value ?? "",
256
+ onChange,
257
+ "aria-invalid": !!error,
258
+ "aria-required": required,
259
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId),
260
+ children: [
261
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "", children: placeholder ?? config?.placeHolder ?? "" }),
262
+ simpleOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: option, children: option }, option))
263
+ ]
264
+ }
265
+ ),
266
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react5.NativeSelect.Indicator, {})
267
+ ]
268
+ }
269
+ );
270
+ };
271
+ var SimpleDropdown_default = SimpleDropdown;
272
+
273
+ // src/fields/MultiSelect.tsx
274
+ var import_jsx_runtime7 = require("react/jsx-runtime");
275
+ var MultiSelect = (props) => {
276
+ const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options, setFieldValue } = props;
277
+ const selectedValues = value ?? [];
278
+ const onChange = (event) => {
279
+ const selected = Array.from(event.target.selectedOptions, (opt) => opt.value);
280
+ setFieldValue(fieldName, selected, false, 1500);
281
+ };
282
+ if (readOnly) {
283
+ return selectedValues.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
284
+ "ul",
285
+ {
286
+ style: { listStyle: "none", padding: 0, margin: 0 },
287
+ "data-field-type": "MultiSelect",
288
+ "data-field-state": "readonly",
289
+ children: selectedValues.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { style: { padding: "2px 0" }, children: v }, i))
290
+ }
291
+ ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "fe-read-only-text", children: "-" });
292
+ }
293
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
294
+ "select",
295
+ {
296
+ multiple: true,
297
+ style: {
298
+ width: "100%",
299
+ minHeight: "80px",
300
+ padding: "8px",
301
+ borderWidth: "1px",
302
+ borderStyle: "solid",
303
+ borderColor: error ? "var(--chakra-colors-red-500, #E53E3E)" : "var(--chakra-colors-gray-200, #E2E8F0)",
304
+ borderRadius: "var(--chakra-radii-md, 6px)",
305
+ fontSize: "var(--chakra-fontSizes-md, 16px)",
306
+ background: "var(--chakra-colors-white, #FFFFFF)"
307
+ },
308
+ value: selectedValues,
309
+ onChange,
310
+ "aria-invalid": !!error,
311
+ "aria-required": required,
312
+ "data-field-type": "MultiSelect",
313
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
314
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId),
315
+ children: options?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: String(option.value), disabled: option.disabled, children: option.label }, String(option.value)))
316
+ }
317
+ );
318
+ };
319
+ var MultiSelect_default = MultiSelect;
320
+
321
+ // src/fields/DateControl.tsx
322
+ var import_core4 = require("@form-eng/core");
323
+ var import_react6 = require("@chakra-ui/react");
324
+ var import_jsx_runtime8 = require("react/jsx-runtime");
325
+ var DateControl = (props) => {
326
+ const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
327
+ const onChange = (event) => {
328
+ const date = new Date(event.target.value);
329
+ if (!isNaN(date.getTime())) {
330
+ setFieldValue(fieldName, date.toISOString());
331
+ }
332
+ };
333
+ const onClear = () => {
334
+ setFieldValue(fieldName, null);
335
+ };
336
+ const dateInputValue = value ? new Date(value).toISOString().split("T")[0] : "";
337
+ if (readOnly) {
338
+ return value ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
339
+ "time",
340
+ {
341
+ className: "fe-read-only-date",
342
+ dateTime: value,
343
+ "data-field-type": "DateControl",
344
+ "data-field-state": "readonly",
345
+ children: (0, import_core.formatDateTime)(value, { hideTimestamp: true })
346
+ }
347
+ ) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "fe-read-only-text", children: "-" });
348
+ }
349
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
350
+ "div",
351
+ {
352
+ style: { display: "flex", alignItems: "center", gap: "8px" },
353
+ "data-field-type": "DateControl",
354
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
355
+ children: [
356
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
357
+ import_react6.Input,
358
+ {
359
+ type: "date",
360
+ value: dateInputValue,
361
+ onChange,
362
+ "aria-invalid": !!error,
363
+ "aria-required": required,
364
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId)
365
+ }
366
+ ),
367
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
368
+ "button",
369
+ {
370
+ type: "button",
371
+ onClick: onClear,
372
+ title: import_core4.FormStrings.clickToClear,
373
+ "aria-label": `${fieldName} ${import_core4.FormStrings.clear}`,
374
+ style: {
375
+ background: "none",
376
+ border: "none",
377
+ cursor: "pointer",
378
+ fontSize: "18px",
379
+ color: "var(--chakra-colors-gray-500, #718096)",
380
+ padding: "4px 8px"
381
+ },
382
+ children: "\xD7"
383
+ }
384
+ )
385
+ ]
386
+ }
387
+ );
388
+ };
389
+ var DateControl_default = DateControl;
390
+
391
+ // src/fields/Slider.tsx
392
+ var import_jsx_runtime9 = require("react/jsx-runtime");
393
+ var Slider = (props) => {
394
+ const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, setFieldValue } = props;
395
+ const onChange = (event) => {
396
+ setFieldValue(fieldName, Number(event.target.value));
397
+ };
398
+ if (readOnly) {
399
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ReadOnlyText, { fieldName, value: String(value) });
400
+ }
401
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
402
+ "div",
403
+ {
404
+ style: { display: "flex", alignItems: "center", gap: "12px" },
405
+ "data-field-type": "Slider",
406
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
407
+ children: [
408
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
409
+ "input",
410
+ {
411
+ type: "range",
412
+ style: {
413
+ flex: 1,
414
+ accentColor: "var(--chakra-colors-blue-500, #3182CE)"
415
+ },
416
+ value: value ?? 0,
417
+ onChange,
418
+ max: config?.max ?? 100,
419
+ min: config?.min ?? 0,
420
+ step: config?.step ?? 1,
421
+ "aria-invalid": !!error,
422
+ "aria-required": required,
423
+ "aria-valuenow": value ?? 0,
424
+ "aria-valuemin": config?.min ?? 0,
425
+ "aria-valuemax": config?.max ?? 100,
426
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId)
427
+ }
428
+ ),
429
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("output", { style: { minWidth: "32px", textAlign: "center", fontSize: "var(--chakra-fontSizes-md, 16px)" }, children: String(value) })
430
+ ]
431
+ }
432
+ );
433
+ };
434
+ var Slider_default = Slider;
435
+
436
+ // src/fields/RadioGroup.tsx
437
+ var import_jsx_runtime10 = require("react/jsx-runtime");
438
+ var RadioGroup = (props) => {
439
+ const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options, setFieldValue } = props;
440
+ const onChange = (event) => {
441
+ setFieldValue(fieldName, event.target.value);
442
+ };
443
+ if (readOnly) {
444
+ const label = options?.find((o) => String(o.value) === String(value))?.label ?? value;
445
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ReadOnlyText, { fieldName, value: label });
446
+ }
447
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
448
+ "div",
449
+ {
450
+ role: "radiogroup",
451
+ style: { display: "flex", flexDirection: "column", gap: "8px" },
452
+ "aria-invalid": !!error,
453
+ "aria-required": required,
454
+ "data-field-type": "RadioGroup",
455
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
456
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId),
457
+ children: options?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
458
+ "label",
459
+ {
460
+ style: {
461
+ display: "flex",
462
+ alignItems: "center",
463
+ gap: "8px",
464
+ cursor: option.disabled ? "not-allowed" : "pointer",
465
+ opacity: option.disabled ? 0.5 : 1,
466
+ fontSize: "var(--chakra-fontSizes-md, 16px)"
467
+ },
468
+ children: [
469
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
470
+ "input",
471
+ {
472
+ type: "radio",
473
+ name: fieldName,
474
+ value: String(option.value),
475
+ checked: String(value) === String(option.value),
476
+ onChange,
477
+ disabled: option.disabled,
478
+ style: { accentColor: "var(--chakra-colors-blue-500, #3182CE)" }
479
+ }
480
+ ),
481
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: option.label })
482
+ ]
483
+ },
484
+ String(option.value)
485
+ ))
486
+ }
487
+ );
488
+ };
489
+ var RadioGroup_default = RadioGroup;
490
+
491
+ // src/fields/CheckboxGroup.tsx
492
+ var import_jsx_runtime11 = require("react/jsx-runtime");
493
+ var CheckboxGroup = (props) => {
494
+ const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options, setFieldValue } = props;
495
+ const selected = Array.isArray(value) ? value : [];
496
+ const onChange = (optionValue) => (event) => {
497
+ const next = event.target.checked ? [...selected, optionValue] : selected.filter((v) => v !== optionValue);
498
+ setFieldValue(fieldName, next);
499
+ };
500
+ if (readOnly) {
501
+ const labels = options?.filter((o) => selected.includes(String(o.value))).map((o) => o.label).join(", ");
502
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ReadOnlyText, { fieldName, value: labels ?? "" });
503
+ }
504
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
505
+ "div",
506
+ {
507
+ style: { display: "flex", flexDirection: "column", gap: "8px" },
508
+ "aria-invalid": !!error,
509
+ "aria-required": required,
510
+ "data-field-type": "CheckboxGroup",
511
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
512
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId),
513
+ children: options?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
514
+ "label",
515
+ {
516
+ style: {
517
+ display: "flex",
518
+ alignItems: "center",
519
+ gap: "8px",
520
+ cursor: option.disabled ? "not-allowed" : "pointer",
521
+ opacity: option.disabled ? 0.5 : 1,
522
+ fontSize: "var(--chakra-fontSizes-md, 16px)"
523
+ },
524
+ children: [
525
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
526
+ "input",
527
+ {
528
+ type: "checkbox",
529
+ value: String(option.value),
530
+ checked: selected.includes(String(option.value)),
531
+ onChange: onChange(String(option.value)),
532
+ disabled: option.disabled,
533
+ style: { accentColor: "var(--chakra-colors-blue-500, #3182CE)" }
534
+ }
535
+ ),
536
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { children: option.label })
537
+ ]
538
+ },
539
+ String(option.value)
540
+ ))
541
+ }
542
+ );
543
+ };
544
+ var CheckboxGroup_default = CheckboxGroup;
545
+
546
+ // src/fields/Textarea.tsx
547
+ var import_core6 = require("@form-eng/core");
548
+ var import_react7 = require("@chakra-ui/react");
549
+ var import_react8 = __toESM(require("react"));
550
+
551
+ // src/components/StatusMessage.tsx
552
+ var import_core5 = require("@form-eng/core");
553
+ var import_jsx_runtime12 = require("react/jsx-runtime");
554
+ var StatusMessage = (props) => {
555
+ const { id, error, errorCount, savePending, saving } = props;
556
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "fe-status-message", children: error ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { id, role: "alert", style: { color: "var(--chakra-colors-red-500, #E53E3E)" }, children: error.message || "Error" }) : savePending ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { id, role: "alert", style: { color: "var(--chakra-colors-orange-500, #DD6B20)" }, children: [
557
+ import_core5.FormStrings.autoSavePending,
558
+ " (",
559
+ errorCount,
560
+ " ",
561
+ import_core5.FormStrings.remaining,
562
+ ")"
563
+ ] }) : saving ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { id, role: "status", style: { color: "var(--chakra-colors-gray-500, #718096)" }, children: import_core5.FormStrings.saving }) : null });
564
+ };
565
+
566
+ // src/fields/Textarea.tsx
567
+ var import_jsx_runtime13 = require("react/jsx-runtime");
568
+ var Textarea = (props) => {
569
+ const {
570
+ error,
571
+ fieldName,
572
+ programName,
573
+ entityType,
574
+ entityId,
575
+ config,
576
+ readOnly,
577
+ required,
578
+ savePending,
579
+ saving,
580
+ value,
581
+ label,
582
+ setFieldValue
583
+ } = props;
584
+ const [modalValue, setModalValue] = (0, import_react8.useState)();
585
+ const [modalVisible, setModalVisible] = (0, import_react8.useState)(false);
586
+ const [confirmVisible, setConfirmVisible] = (0, import_react8.useState)(false);
587
+ const dialogRef = import_react8.default.useRef(null);
588
+ const confirmRef = import_react8.default.useRef(null);
589
+ const onChange = (event) => {
590
+ const newValue = event.target.value;
591
+ modalVisible ? setModalValue(newValue) : setFieldValue(fieldName, newValue, false, 3e3);
592
+ };
593
+ const onExpand = () => {
594
+ setModalVisible(true);
595
+ setModalValue(value ? `${value}` : "");
596
+ dialogRef.current?.showModal();
597
+ };
598
+ const onSave = () => {
599
+ setFieldValue(fieldName, modalValue, false);
600
+ setConfirmVisible(false);
601
+ setModalVisible(false);
602
+ dialogRef.current?.close();
603
+ confirmRef.current?.close();
604
+ config?.saveCallback?.();
605
+ };
606
+ const onCancel = () => {
607
+ if (confirmVisible) {
608
+ setConfirmVisible(false);
609
+ setModalVisible(false);
610
+ dialogRef.current?.close();
611
+ confirmRef.current?.close();
612
+ } else if (modalValue !== value) {
613
+ setConfirmVisible(true);
614
+ confirmRef.current?.showModal();
615
+ } else {
616
+ setModalVisible(false);
617
+ dialogRef.current?.close();
618
+ }
619
+ };
620
+ if (readOnly) {
621
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
622
+ ReadOnlyText,
623
+ {
624
+ fieldName,
625
+ value: value ? `${value}` : "",
626
+ ellipsifyTextCharacters: config?.ellipsifyTextCharacters
627
+ }
628
+ );
629
+ }
630
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
631
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
632
+ "div",
633
+ {
634
+ "data-field-type": "Textarea",
635
+ "data-field-state": (0, import_core.getFieldState)({ error, required, readOnly }),
636
+ children: [
637
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
638
+ import_react7.Textarea,
639
+ {
640
+ autoComplete: "off",
641
+ value: modalVisible ? `${modalValue}` : value ? `${value}` : "",
642
+ onChange,
643
+ rows: config?.numberOfRows ?? 4,
644
+ "aria-invalid": !!error,
645
+ "aria-required": required,
646
+ "data-testid": (0, import_core.GetFieldDataTestId)(fieldName, programName, entityType, entityId)
647
+ }
648
+ ),
649
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
650
+ "button",
651
+ {
652
+ type: "button",
653
+ onClick: onExpand,
654
+ "aria-label": import_core6.FormStrings.openExpandedTextEditor,
655
+ style: {
656
+ marginTop: "4px",
657
+ background: "none",
658
+ border: "none",
659
+ cursor: "pointer",
660
+ color: "var(--chakra-colors-blue-500, #3182CE)",
661
+ fontSize: "var(--chakra-fontSizes-sm, 14px)",
662
+ padding: "2px 0"
663
+ },
664
+ children: import_core6.FormStrings.expand
665
+ }
666
+ )
667
+ ]
668
+ }
669
+ ),
670
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("dialog", { ref: dialogRef, style: { padding: "24px", borderRadius: "8px", border: "1px solid var(--chakra-colors-gray-200, #E2E8F0)", maxWidth: "640px", width: "100%" }, "aria-label": `${label} editor`, children: [
671
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("header", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "16px" }, children: [
672
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("h2", { style: { margin: 0, fontSize: "18px" }, children: [
673
+ label,
674
+ required && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { style: { color: "var(--chakra-colors-red-500, #E53E3E)" }, children: " *" })
675
+ ] }),
676
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
677
+ "button",
678
+ {
679
+ type: "button",
680
+ onClick: onCancel,
681
+ "aria-label": import_core6.FormStrings.closeExpandedTextEditor,
682
+ style: { background: "none", border: "none", cursor: "pointer", fontSize: "20px" },
683
+ children: "\xD7"
684
+ }
685
+ )
686
+ ] }),
687
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
688
+ import_react7.Textarea,
689
+ {
690
+ autoComplete: "off",
691
+ value: modalVisible ? `${modalValue}` : value ? `${value}` : "",
692
+ onChange,
693
+ rows: 12,
694
+ "aria-invalid": !!error
695
+ }
696
+ ) }),
697
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("footer", { style: { display: "flex", justifyContent: "flex-end", alignItems: "center", gap: "8px" }, children: [
698
+ config?.renderExtraModalFooter && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { children: config.renderExtraModalFooter() }),
699
+ (savePending || saving) && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StatusMessage, { savePending: !error ? savePending : void 0, saving, error }),
700
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
701
+ "button",
702
+ {
703
+ type: "button",
704
+ onClick: onCancel,
705
+ style: { padding: "6px 16px", borderRadius: "6px", border: "1px solid var(--chakra-colors-gray-200, #E2E8F0)", background: "white", cursor: "pointer" },
706
+ children: import_core6.FormStrings.cancel
707
+ }
708
+ ),
709
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
710
+ "button",
711
+ {
712
+ type: "button",
713
+ onClick: onSave,
714
+ disabled: !config?.saveCallback && modalValue === value,
715
+ style: { padding: "6px 16px", borderRadius: "6px", border: "none", background: "var(--chakra-colors-blue-500, #3182CE)", color: "white", cursor: "pointer" },
716
+ "data-testid": `${programName}-${entityType}-${entityId}-save-note`,
717
+ children: import_core6.FormStrings.save
718
+ }
719
+ )
720
+ ] })
721
+ ] }),
722
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("dialog", { ref: confirmRef, style: { padding: "24px", borderRadius: "8px", border: "1px solid var(--chakra-colors-gray-200, #E2E8F0)" }, children: [
723
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h2", { style: { margin: "0 0 8px 0", fontSize: "18px" }, children: import_core6.FormStrings.unsavedChanges }),
724
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { children: import_core6.FormStrings.saveChangesTo(label) }),
725
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("footer", { style: { display: "flex", justifyContent: "flex-end", gap: "8px", marginTop: "16px" }, children: [
726
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
727
+ "button",
728
+ {
729
+ type: "button",
730
+ onClick: onCancel,
731
+ style: { padding: "6px 16px", borderRadius: "6px", border: "1px solid var(--chakra-colors-gray-200, #E2E8F0)", background: "white", cursor: "pointer" },
732
+ children: import_core6.FormStrings.dontSave
733
+ }
734
+ ),
735
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
736
+ "button",
737
+ {
738
+ type: "button",
739
+ onClick: onSave,
740
+ style: { padding: "6px 16px", borderRadius: "6px", border: "none", background: "var(--chakra-colors-blue-500, #3182CE)", color: "white", cursor: "pointer" },
741
+ children: import_core6.FormStrings.save
742
+ }
743
+ )
744
+ ] })
745
+ ] })
746
+ ] });
747
+ };
748
+ var Textarea_default = Textarea;
749
+
750
+ // src/fields/DynamicFragment.tsx
751
+ var import_jsx_runtime14 = require("react/jsx-runtime");
752
+ var DynamicFragment = (props) => {
753
+ const { value } = props;
754
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { type: "hidden", value });
755
+ };
756
+ var DynamicFragment_default = DynamicFragment;
757
+
758
+ // src/fields/readonly/ReadOnly.tsx
759
+ var import_jsx_runtime15 = require("react/jsx-runtime");
760
+ var ReadOnly = (props) => {
761
+ const { fieldName, value, config } = props;
762
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ReadOnlyText, { fieldName, value, ...config });
763
+ };
764
+ var ReadOnly_default = ReadOnly;
765
+
766
+ // src/components/FormLoading.tsx
767
+ var import_core7 = require("@form-eng/core");
768
+ var import_jsx_runtime16 = require("react/jsx-runtime");
769
+ var FormLoading = (props) => {
770
+ const { loadingShimmerCount, loadingFieldShimmerHeight, inPanel, hideTitleShimmer } = props;
771
+ const count = loadingShimmerCount || import_core7.FormConstants.loadingShimmerCount;
772
+ const height = loadingFieldShimmerHeight || import_core7.FormConstants.loadingFieldShimmerHeight;
773
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
774
+ "div",
775
+ {
776
+ className: `fe-form-loading ${inPanel ? "fe-form-loading--panel" : ""}`,
777
+ role: "status",
778
+ "aria-label": "Loading form",
779
+ children: [...Array(count)].map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { style: { marginBottom: 16 }, children: [
780
+ !hideTitleShimmer && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "fe-skeleton", style: { width: "33%", height: 16, marginBottom: 8, background: "var(--chakra-colors-gray-200, #E2E8F0)", borderRadius: 4 } }),
781
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "fe-skeleton", style: { width: "100%", height, background: "var(--chakra-colors-gray-200, #E2E8F0)", borderRadius: 4 } })
782
+ ] }, `fe-loading-${i}`))
783
+ }
784
+ );
785
+ };
786
+
787
+ // src/registry.ts
788
+ var import_core8 = require("@form-eng/core");
789
+ var import_react9 = __toESM(require("react"));
790
+ function createChakraFieldRegistry() {
791
+ return {
792
+ [import_core8.ComponentTypes.Textbox]: import_react9.default.createElement(Textbox_default),
793
+ [import_core8.ComponentTypes.Number]: import_react9.default.createElement(Number_default),
794
+ [import_core8.ComponentTypes.Toggle]: import_react9.default.createElement(Toggle_default),
795
+ [import_core8.ComponentTypes.Dropdown]: import_react9.default.createElement(Dropdown_default),
796
+ [import_core8.ComponentTypes.SimpleDropdown]: import_react9.default.createElement(SimpleDropdown_default),
797
+ [import_core8.ComponentTypes.MultiSelect]: import_react9.default.createElement(MultiSelect_default),
798
+ [import_core8.ComponentTypes.DateControl]: import_react9.default.createElement(DateControl_default),
799
+ [import_core8.ComponentTypes.Slider]: import_react9.default.createElement(Slider_default),
800
+ [import_core8.ComponentTypes.RadioGroup]: import_react9.default.createElement(RadioGroup_default),
801
+ [import_core8.ComponentTypes.CheckboxGroup]: import_react9.default.createElement(CheckboxGroup_default),
802
+ [import_core8.ComponentTypes.Textarea]: import_react9.default.createElement(Textarea_default),
803
+ [import_core8.ComponentTypes.Fragment]: import_react9.default.createElement(DynamicFragment_default),
804
+ [import_core8.ComponentTypes.ReadOnly]: import_react9.default.createElement(ReadOnly_default)
805
+ };
806
+ }
807
+ // Annotate the CommonJS export names for ESM import in node:
808
+ 0 && (module.exports = {
809
+ CheckboxGroup,
810
+ DateControl,
811
+ DocumentLinksStrings,
812
+ Dropdown,
813
+ DynamicFragment,
814
+ FieldClassName,
815
+ FormLoading,
816
+ GetFieldDataTestId,
817
+ MultiSelect,
818
+ Number,
819
+ RadioGroup,
820
+ ReadOnly,
821
+ ReadOnlyText,
822
+ SimpleDropdown,
823
+ Slider,
824
+ StatusMessage,
825
+ Textarea,
826
+ Textbox,
827
+ Toggle,
828
+ createChakraFieldRegistry,
829
+ formatDateTime,
830
+ getFieldState
831
+ });
832
+ //# sourceMappingURL=index.js.map