@availity/mui-controlled-form 1.1.3 → 1.2.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/CHANGELOG.md +22 -0
- package/dist/index.d.mts +28 -9
- package/dist/index.d.ts +28 -9
- package/dist/index.js +135 -130
- package/dist/index.mjs +147 -142
- package/package.json +5 -4
- package/src/lib/AsyncAutocomplete.stories.tsx +59 -33
- package/src/lib/AsyncAutocomplete.tsx +19 -9
- package/src/lib/CodesAutocomplete.tsx +47 -42
- package/src/lib/OrganizationAutocomplete.tsx +36 -42
- package/src/lib/ProviderAutocomplete.tsx +44 -44
- package/src/lib/Types.tsx +8 -0
- package/src/lib/utils.tsx +1 -0
package/dist/index.mjs
CHANGED
|
@@ -29,10 +29,30 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
32
52
|
|
|
33
53
|
// src/lib/AsyncAutocomplete.tsx
|
|
34
54
|
import { AsyncAutocomplete } from "@availity/mui-autocomplete";
|
|
35
|
-
import { Controller } from "react-hook-form";
|
|
55
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
36
56
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
37
57
|
var ControlledAsyncAutocomplete = (_a) => {
|
|
38
58
|
var _b = _a, {
|
|
@@ -42,7 +62,9 @@ var ControlledAsyncAutocomplete = (_a) => {
|
|
|
42
62
|
rules = {},
|
|
43
63
|
shouldUnregister,
|
|
44
64
|
value,
|
|
45
|
-
FieldProps
|
|
65
|
+
FieldProps,
|
|
66
|
+
defaultToFirstOption,
|
|
67
|
+
defaultToOnlyOption
|
|
46
68
|
} = _b, rest = __objRest(_b, [
|
|
47
69
|
"name",
|
|
48
70
|
"onBlur",
|
|
@@ -50,19 +72,17 @@ var ControlledAsyncAutocomplete = (_a) => {
|
|
|
50
72
|
"rules",
|
|
51
73
|
"shouldUnregister",
|
|
52
74
|
"value",
|
|
53
|
-
"FieldProps"
|
|
75
|
+
"FieldProps",
|
|
76
|
+
"defaultToFirstOption",
|
|
77
|
+
"defaultToOnlyOption"
|
|
54
78
|
]);
|
|
79
|
+
const { setValue } = useFormContext();
|
|
55
80
|
return /* @__PURE__ */ jsx(
|
|
56
81
|
Controller,
|
|
57
82
|
{
|
|
58
83
|
name,
|
|
59
84
|
defaultValue: rest.defaultValue,
|
|
60
|
-
rules: __spreadValues({
|
|
61
|
-
onBlur,
|
|
62
|
-
onChange,
|
|
63
|
-
shouldUnregister,
|
|
64
|
-
value
|
|
65
|
-
}, rules),
|
|
85
|
+
rules: __spreadValues({ onBlur, onChange, shouldUnregister, value }, rules),
|
|
66
86
|
shouldUnregister,
|
|
67
87
|
render: ({ field: { onChange: onChange2, value: value2, onBlur: onBlur2, ref }, fieldState: { error } }) => /* @__PURE__ */ jsx(
|
|
68
88
|
AsyncAutocomplete,
|
|
@@ -85,7 +105,17 @@ var ControlledAsyncAutocomplete = (_a) => {
|
|
|
85
105
|
onChange2(value3);
|
|
86
106
|
},
|
|
87
107
|
onBlur: onBlur2,
|
|
88
|
-
value: value2 || null
|
|
108
|
+
value: value2 || null,
|
|
109
|
+
loadOptions: (offset, limit, inputValue) => __async(void 0, null, function* () {
|
|
110
|
+
const { options, hasMore, offset: returnedOffsetValue } = yield rest.loadOptions(offset, limit, inputValue);
|
|
111
|
+
if (defaultToFirstOption && offset === 0) {
|
|
112
|
+
setValue(name, rest.multiple ? [options[0]] : options[0]);
|
|
113
|
+
}
|
|
114
|
+
if (defaultToOnlyOption && offset === 0 && options.length === 1) {
|
|
115
|
+
setValue(name, rest.multiple ? [options[0]] : options[0]);
|
|
116
|
+
}
|
|
117
|
+
return { options, hasMore, offset: returnedOffsetValue };
|
|
118
|
+
})
|
|
89
119
|
})
|
|
90
120
|
)
|
|
91
121
|
}
|
|
@@ -207,9 +237,8 @@ var ControlledCheckbox = (_a) => {
|
|
|
207
237
|
};
|
|
208
238
|
|
|
209
239
|
// src/lib/CodesAutocomplete.tsx
|
|
210
|
-
import {
|
|
211
|
-
import {
|
|
212
|
-
import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
240
|
+
import { fetchCodes, handleGetCodesOptionLabel } from "@availity/mui-autocomplete";
|
|
241
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
213
242
|
var ControlledCodesAutocomplete = (_a) => {
|
|
214
243
|
var _b = _a, {
|
|
215
244
|
name,
|
|
@@ -219,7 +248,12 @@ var ControlledCodesAutocomplete = (_a) => {
|
|
|
219
248
|
rules = {},
|
|
220
249
|
shouldUnregister,
|
|
221
250
|
value,
|
|
222
|
-
FieldProps
|
|
251
|
+
FieldProps,
|
|
252
|
+
apiConfig = {},
|
|
253
|
+
queryOptions,
|
|
254
|
+
queryKey = "codes-autocomplete",
|
|
255
|
+
list,
|
|
256
|
+
watchParams
|
|
223
257
|
} = _b, rest = __objRest(_b, [
|
|
224
258
|
"name",
|
|
225
259
|
"defaultValue",
|
|
@@ -228,52 +262,44 @@ var ControlledCodesAutocomplete = (_a) => {
|
|
|
228
262
|
"rules",
|
|
229
263
|
"shouldUnregister",
|
|
230
264
|
"value",
|
|
231
|
-
"FieldProps"
|
|
265
|
+
"FieldProps",
|
|
266
|
+
"apiConfig",
|
|
267
|
+
"queryOptions",
|
|
268
|
+
"queryKey",
|
|
269
|
+
"list",
|
|
270
|
+
"watchParams"
|
|
232
271
|
]);
|
|
272
|
+
const handleLoadOptions = (offset, limit, inputValue) => __async(void 0, null, function* () {
|
|
273
|
+
const resp = yield fetchCodes(__spreadProps(__spreadValues({}, apiConfig), {
|
|
274
|
+
params: __spreadProps(__spreadValues({}, apiConfig.params), { list, offset, limit, q: inputValue })
|
|
275
|
+
}));
|
|
276
|
+
return resp;
|
|
277
|
+
});
|
|
233
278
|
return /* @__PURE__ */ jsx4(
|
|
234
|
-
|
|
235
|
-
{
|
|
279
|
+
ControlledAsyncAutocomplete,
|
|
280
|
+
__spreadProps(__spreadValues({
|
|
236
281
|
name,
|
|
237
282
|
defaultValue,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
shouldUnregister,
|
|
242
|
-
value
|
|
243
|
-
}, rules),
|
|
283
|
+
onBlur,
|
|
284
|
+
onChange,
|
|
285
|
+
rules,
|
|
244
286
|
shouldUnregister,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
/* @__PURE__ */ jsx4("br", {}),
|
|
255
|
-
FieldProps == null ? void 0 : FieldProps.helperText
|
|
256
|
-
] }) : FieldProps == null ? void 0 : FieldProps.helperText,
|
|
257
|
-
inputRef: ref
|
|
258
|
-
}),
|
|
259
|
-
onChange: (event, value3, reason) => {
|
|
260
|
-
if (reason === "clear") {
|
|
261
|
-
onChange2(null);
|
|
262
|
-
}
|
|
263
|
-
onChange2(value3);
|
|
264
|
-
},
|
|
265
|
-
onBlur: onBlur2,
|
|
266
|
-
value: value2 || null
|
|
267
|
-
})
|
|
268
|
-
)
|
|
269
|
-
}
|
|
287
|
+
value,
|
|
288
|
+
FieldProps,
|
|
289
|
+
getOptionLabel: handleGetCodesOptionLabel,
|
|
290
|
+
queryKey,
|
|
291
|
+
queryOptions: __spreadValues({ enabled: !!list }, queryOptions),
|
|
292
|
+
watchParams: __spreadValues({ list }, watchParams)
|
|
293
|
+
}, rest), {
|
|
294
|
+
loadOptions: handleLoadOptions
|
|
295
|
+
})
|
|
270
296
|
);
|
|
271
297
|
};
|
|
272
298
|
|
|
273
299
|
// src/lib/Datepicker.tsx
|
|
274
300
|
import { Datepicker } from "@availity/mui-datepicker";
|
|
275
|
-
import { Controller as
|
|
276
|
-
import { Fragment as
|
|
301
|
+
import { Controller as Controller4 } from "react-hook-form";
|
|
302
|
+
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
277
303
|
var ControlledDatepicker = (_a) => {
|
|
278
304
|
var _b = _a, {
|
|
279
305
|
name,
|
|
@@ -295,7 +321,7 @@ var ControlledDatepicker = (_a) => {
|
|
|
295
321
|
"FieldProps"
|
|
296
322
|
]);
|
|
297
323
|
return /* @__PURE__ */ jsx5(
|
|
298
|
-
|
|
324
|
+
Controller4,
|
|
299
325
|
{
|
|
300
326
|
name,
|
|
301
327
|
defaultValue,
|
|
@@ -313,7 +339,7 @@ var ControlledDatepicker = (_a) => {
|
|
|
313
339
|
required: typeof rules.required === "object" ? rules.required.value : !!rules.required
|
|
314
340
|
}, FieldProps), {
|
|
315
341
|
error: !!error,
|
|
316
|
-
helperText: error ? /* @__PURE__ */
|
|
342
|
+
helperText: error ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
317
343
|
error.message,
|
|
318
344
|
/* @__PURE__ */ jsx5("br", {}),
|
|
319
345
|
FieldProps == null ? void 0 : FieldProps.helperText
|
|
@@ -333,7 +359,7 @@ var ControlledDatepicker = (_a) => {
|
|
|
333
359
|
|
|
334
360
|
// src/lib/Input.tsx
|
|
335
361
|
import { Input } from "@availity/mui-form-utils";
|
|
336
|
-
import { Controller as
|
|
362
|
+
import { Controller as Controller5 } from "react-hook-form";
|
|
337
363
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
338
364
|
var ControlledInput = (_a) => {
|
|
339
365
|
var _b = _a, {
|
|
@@ -356,7 +382,7 @@ var ControlledInput = (_a) => {
|
|
|
356
382
|
"value"
|
|
357
383
|
]);
|
|
358
384
|
return /* @__PURE__ */ jsx6(
|
|
359
|
-
|
|
385
|
+
Controller5,
|
|
360
386
|
{
|
|
361
387
|
name,
|
|
362
388
|
defaultValue,
|
|
@@ -381,9 +407,8 @@ var ControlledInput = (_a) => {
|
|
|
381
407
|
};
|
|
382
408
|
|
|
383
409
|
// src/lib/OrganizationAutocomplete.tsx
|
|
384
|
-
import {
|
|
385
|
-
import {
|
|
386
|
-
import { Fragment as Fragment5, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
410
|
+
import { handleGetOrgOptionLabel, fetchOrgs } from "@availity/mui-autocomplete";
|
|
411
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
387
412
|
var ControlledOrganizationAutocomplete = (_a) => {
|
|
388
413
|
var _b = _a, {
|
|
389
414
|
name,
|
|
@@ -393,7 +418,9 @@ var ControlledOrganizationAutocomplete = (_a) => {
|
|
|
393
418
|
rules = {},
|
|
394
419
|
shouldUnregister,
|
|
395
420
|
value,
|
|
396
|
-
FieldProps
|
|
421
|
+
FieldProps,
|
|
422
|
+
queryKey = "org-autocomplete",
|
|
423
|
+
apiConfig = {}
|
|
397
424
|
} = _b, rest = __objRest(_b, [
|
|
398
425
|
"name",
|
|
399
426
|
"defaultValue",
|
|
@@ -402,52 +429,36 @@ var ControlledOrganizationAutocomplete = (_a) => {
|
|
|
402
429
|
"rules",
|
|
403
430
|
"shouldUnregister",
|
|
404
431
|
"value",
|
|
405
|
-
"FieldProps"
|
|
432
|
+
"FieldProps",
|
|
433
|
+
"queryKey",
|
|
434
|
+
"apiConfig"
|
|
406
435
|
]);
|
|
436
|
+
const handleLoadOptions = (offset, limit) => __async(void 0, null, function* () {
|
|
437
|
+
const resp = yield fetchOrgs(__spreadProps(__spreadValues({}, apiConfig), { params: __spreadProps(__spreadValues({ dropdown: true }, apiConfig.params), { offset, limit }) }));
|
|
438
|
+
return resp;
|
|
439
|
+
});
|
|
407
440
|
return /* @__PURE__ */ jsx7(
|
|
408
|
-
|
|
409
|
-
{
|
|
441
|
+
ControlledAsyncAutocomplete,
|
|
442
|
+
__spreadProps(__spreadValues({
|
|
410
443
|
name,
|
|
411
444
|
defaultValue,
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
shouldUnregister,
|
|
416
|
-
value
|
|
417
|
-
}, rules),
|
|
445
|
+
onBlur,
|
|
446
|
+
onChange,
|
|
447
|
+
rules,
|
|
418
448
|
shouldUnregister,
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
helperText: (error == null ? void 0 : error.message) ? /* @__PURE__ */ jsxs5(Fragment5, { children: [
|
|
427
|
-
error.message,
|
|
428
|
-
/* @__PURE__ */ jsx7("br", {}),
|
|
429
|
-
FieldProps == null ? void 0 : FieldProps.helperText
|
|
430
|
-
] }) : FieldProps == null ? void 0 : FieldProps.helperText,
|
|
431
|
-
inputRef: ref
|
|
432
|
-
}),
|
|
433
|
-
onChange: (event, value3, reason) => {
|
|
434
|
-
if (reason === "clear") {
|
|
435
|
-
onChange2(null);
|
|
436
|
-
}
|
|
437
|
-
onChange2(value3);
|
|
438
|
-
},
|
|
439
|
-
onBlur: onBlur2,
|
|
440
|
-
value: value2 || null
|
|
441
|
-
})
|
|
442
|
-
)
|
|
443
|
-
}
|
|
449
|
+
value,
|
|
450
|
+
FieldProps,
|
|
451
|
+
getOptionLabel: handleGetOrgOptionLabel,
|
|
452
|
+
queryKey
|
|
453
|
+
}, rest), {
|
|
454
|
+
loadOptions: handleLoadOptions
|
|
455
|
+
})
|
|
444
456
|
);
|
|
445
457
|
};
|
|
446
458
|
|
|
447
459
|
// src/lib/ProviderAutocomplete.tsx
|
|
448
|
-
import {
|
|
449
|
-
import {
|
|
450
|
-
import { Fragment as Fragment6, jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
460
|
+
import { handleGetProviderOptionLabel, fetchProviders } from "@availity/mui-autocomplete";
|
|
461
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
451
462
|
var ControlledProviderAutocomplete = (_a) => {
|
|
452
463
|
var _b = _a, {
|
|
453
464
|
name,
|
|
@@ -457,7 +468,10 @@ var ControlledProviderAutocomplete = (_a) => {
|
|
|
457
468
|
rules = {},
|
|
458
469
|
shouldUnregister,
|
|
459
470
|
value,
|
|
460
|
-
FieldProps
|
|
471
|
+
FieldProps,
|
|
472
|
+
apiConfig = {},
|
|
473
|
+
customerId,
|
|
474
|
+
queryKey = "prov-autocomplete"
|
|
461
475
|
} = _b, rest = __objRest(_b, [
|
|
462
476
|
"name",
|
|
463
477
|
"defaultValue",
|
|
@@ -466,52 +480,43 @@ var ControlledProviderAutocomplete = (_a) => {
|
|
|
466
480
|
"rules",
|
|
467
481
|
"shouldUnregister",
|
|
468
482
|
"value",
|
|
469
|
-
"FieldProps"
|
|
483
|
+
"FieldProps",
|
|
484
|
+
"apiConfig",
|
|
485
|
+
"customerId",
|
|
486
|
+
"queryKey"
|
|
470
487
|
]);
|
|
488
|
+
const handleLoadOptions = (offset, limit, inputValue) => __async(void 0, null, function* () {
|
|
489
|
+
const resp = yield fetchProviders(customerId, __spreadProps(__spreadValues({}, apiConfig), {
|
|
490
|
+
params: __spreadProps(__spreadValues({}, apiConfig.params), { offset, limit, q: inputValue })
|
|
491
|
+
}));
|
|
492
|
+
return resp;
|
|
493
|
+
});
|
|
471
494
|
return /* @__PURE__ */ jsx8(
|
|
472
|
-
|
|
473
|
-
{
|
|
495
|
+
ControlledAsyncAutocomplete,
|
|
496
|
+
__spreadProps(__spreadValues({
|
|
474
497
|
name,
|
|
475
498
|
defaultValue,
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
shouldUnregister,
|
|
480
|
-
value
|
|
481
|
-
}, rules),
|
|
499
|
+
onBlur,
|
|
500
|
+
onChange,
|
|
501
|
+
rules,
|
|
482
502
|
shouldUnregister,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
/* @__PURE__ */ jsx8("br", {}),
|
|
493
|
-
FieldProps == null ? void 0 : FieldProps.helperText
|
|
494
|
-
] }) : FieldProps == null ? void 0 : FieldProps.helperText
|
|
495
|
-
}),
|
|
496
|
-
onChange: (event, value3, reason) => {
|
|
497
|
-
if (reason === "clear") {
|
|
498
|
-
onChange2(null);
|
|
499
|
-
}
|
|
500
|
-
onChange2(value3);
|
|
501
|
-
},
|
|
502
|
-
onBlur: onBlur2,
|
|
503
|
-
value: value2 || null
|
|
504
|
-
})
|
|
505
|
-
)
|
|
506
|
-
}
|
|
503
|
+
value,
|
|
504
|
+
FieldProps,
|
|
505
|
+
getOptionLabel: handleGetProviderOptionLabel,
|
|
506
|
+
queryOptions: { enabled: !!customerId },
|
|
507
|
+
queryKey,
|
|
508
|
+
watchParams: { customerId }
|
|
509
|
+
}, rest), {
|
|
510
|
+
loadOptions: handleLoadOptions
|
|
511
|
+
})
|
|
507
512
|
);
|
|
508
513
|
};
|
|
509
514
|
|
|
510
515
|
// src/lib/RadioGroup.tsx
|
|
511
516
|
import { RadioGroup } from "@availity/mui-form-utils";
|
|
512
|
-
import { Controller as
|
|
517
|
+
import { Controller as Controller6 } from "react-hook-form";
|
|
513
518
|
import { FormControl, FormLabel, FormHelperText } from "@availity/mui-form-utils";
|
|
514
|
-
import { Fragment as
|
|
519
|
+
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
515
520
|
var ControlledRadioGroup = (_a) => {
|
|
516
521
|
var _b = _a, {
|
|
517
522
|
name,
|
|
@@ -537,7 +542,7 @@ var ControlledRadioGroup = (_a) => {
|
|
|
537
542
|
"value"
|
|
538
543
|
]);
|
|
539
544
|
return /* @__PURE__ */ jsx9(
|
|
540
|
-
|
|
545
|
+
Controller6,
|
|
541
546
|
{
|
|
542
547
|
name,
|
|
543
548
|
defaultValue,
|
|
@@ -545,7 +550,7 @@ var ControlledRadioGroup = (_a) => {
|
|
|
545
550
|
shouldUnregister,
|
|
546
551
|
render: (_a2) => {
|
|
547
552
|
var _b2 = _a2, { field: _c } = _b2, _d = _c, { disabled } = _d, field = __objRest(_d, ["disabled"]), { fieldState: { error } } = _b2;
|
|
548
|
-
return /* @__PURE__ */
|
|
553
|
+
return /* @__PURE__ */ jsxs4(
|
|
549
554
|
FormControl,
|
|
550
555
|
{
|
|
551
556
|
error: !!error,
|
|
@@ -554,7 +559,7 @@ var ControlledRadioGroup = (_a) => {
|
|
|
554
559
|
children: [
|
|
555
560
|
/* @__PURE__ */ jsx9(FormLabel, { children: label }),
|
|
556
561
|
/* @__PURE__ */ jsx9(RadioGroup, __spreadValues(__spreadValues({}, field), rest)),
|
|
557
|
-
/* @__PURE__ */ jsx9(FormHelperText, { children: (error == null ? void 0 : error.message) ? /* @__PURE__ */
|
|
562
|
+
/* @__PURE__ */ jsx9(FormHelperText, { children: (error == null ? void 0 : error.message) ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
558
563
|
error.message,
|
|
559
564
|
/* @__PURE__ */ jsx9("br", {}),
|
|
560
565
|
helperText
|
|
@@ -569,7 +574,7 @@ var ControlledRadioGroup = (_a) => {
|
|
|
569
574
|
|
|
570
575
|
// src/lib/Select.tsx
|
|
571
576
|
import { Select } from "@availity/mui-form-utils";
|
|
572
|
-
import { Controller as
|
|
577
|
+
import { Controller as Controller7 } from "react-hook-form";
|
|
573
578
|
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
574
579
|
var ControlledSelect = (_a) => {
|
|
575
580
|
var _b = _a, {
|
|
@@ -592,7 +597,7 @@ var ControlledSelect = (_a) => {
|
|
|
592
597
|
"value"
|
|
593
598
|
]);
|
|
594
599
|
return /* @__PURE__ */ jsx10(
|
|
595
|
-
|
|
600
|
+
Controller7,
|
|
596
601
|
{
|
|
597
602
|
name,
|
|
598
603
|
defaultValue,
|
|
@@ -618,8 +623,8 @@ var ControlledSelect = (_a) => {
|
|
|
618
623
|
|
|
619
624
|
// src/lib/TextField.tsx
|
|
620
625
|
import { TextField } from "@availity/mui-textfield";
|
|
621
|
-
import { Controller as
|
|
622
|
-
import { Fragment as
|
|
626
|
+
import { Controller as Controller8 } from "react-hook-form";
|
|
627
|
+
import { Fragment as Fragment5, jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
623
628
|
var ControlledTextField = (_a) => {
|
|
624
629
|
var _b = _a, {
|
|
625
630
|
name,
|
|
@@ -643,7 +648,7 @@ var ControlledTextField = (_a) => {
|
|
|
643
648
|
"value"
|
|
644
649
|
]);
|
|
645
650
|
return /* @__PURE__ */ jsx11(
|
|
646
|
-
|
|
651
|
+
Controller8,
|
|
647
652
|
{
|
|
648
653
|
name,
|
|
649
654
|
defaultValue,
|
|
@@ -670,7 +675,7 @@ var ControlledTextField = (_a) => {
|
|
|
670
675
|
}),
|
|
671
676
|
inputRef: ref,
|
|
672
677
|
error: !!error,
|
|
673
|
-
helperText: (error == null ? void 0 : error.message) ? /* @__PURE__ */
|
|
678
|
+
helperText: (error == null ? void 0 : error.message) ? /* @__PURE__ */ jsxs5(Fragment5, { children: [
|
|
674
679
|
error.message,
|
|
675
680
|
/* @__PURE__ */ jsx11("br", {}),
|
|
676
681
|
helperText
|
|
@@ -686,7 +691,7 @@ var ControlledTextField = (_a) => {
|
|
|
686
691
|
import {
|
|
687
692
|
FormProvider,
|
|
688
693
|
useForm,
|
|
689
|
-
useFormContext
|
|
694
|
+
useFormContext as useFormContext2
|
|
690
695
|
} from "react-hook-form";
|
|
691
696
|
export {
|
|
692
697
|
ControlledAsyncAutocomplete,
|
|
@@ -702,5 +707,5 @@ export {
|
|
|
702
707
|
ControlledTextField,
|
|
703
708
|
FormProvider,
|
|
704
709
|
useForm,
|
|
705
|
-
useFormContext
|
|
710
|
+
useFormContext2 as useFormContext
|
|
706
711
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-controlled-form",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Availity MUI/react-hook-form controlled form components - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@availity/mui-autocomplete": "^1.0.
|
|
43
|
+
"@availity/mui-autocomplete": "^1.0.10",
|
|
44
44
|
"@availity/mui-checkbox": "^1.0.1",
|
|
45
|
-
"@availity/mui-datepicker": "^1.0.
|
|
45
|
+
"@availity/mui-datepicker": "^1.0.7",
|
|
46
46
|
"@availity/mui-form-utils": "^1.1.0",
|
|
47
|
-
"@availity/mui-textfield": "^1.1.
|
|
47
|
+
"@availity/mui-textfield": "^1.1.2",
|
|
48
48
|
"react-hook-form": "^7.54.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"yup": "^1.6.1"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
+
"@availity/api-axios": "^8.0.7",
|
|
68
69
|
"@mui/material": "^6.4.5",
|
|
69
70
|
"react": ">=16.3.0"
|
|
70
71
|
},
|
|
@@ -13,54 +13,31 @@ const meta: Meta<typeof ControlledAsyncAutocomplete> = {
|
|
|
13
13
|
title: 'Form Components/Controlled Form/Autocomplete/ControlledAsyncAutocomplete',
|
|
14
14
|
component: ControlledAsyncAutocomplete,
|
|
15
15
|
tags: ['autodocs'],
|
|
16
|
-
argTypes: {...AllControllerPropertiesCategorized, ...AsyncAutocompletePropsCategorized}
|
|
16
|
+
argTypes: { ...AllControllerPropertiesCategorized, ...AsyncAutocompletePropsCategorized },
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export default meta;
|
|
20
20
|
|
|
21
21
|
const api = new AvApi({ name: 'example' } as ApiConfig);
|
|
22
22
|
|
|
23
|
-
type Option = {
|
|
24
|
-
label: string;
|
|
25
|
-
value: number;
|
|
26
|
-
};
|
|
23
|
+
type Option = { label: string; value: number };
|
|
27
24
|
|
|
28
|
-
type ExampleResponse = {
|
|
29
|
-
totalCount: number;
|
|
30
|
-
options: Option[];
|
|
31
|
-
count: number;
|
|
32
|
-
};
|
|
25
|
+
type ExampleResponse = { totalCount: number; options: Option[]; count: number };
|
|
33
26
|
|
|
34
27
|
const getResults = async (offset: number, limit: number) => {
|
|
35
28
|
// const offset = page * limit;
|
|
36
29
|
const resp = await api.post<ExampleResponse>({ offset, limit }, { params: {} });
|
|
37
30
|
|
|
38
|
-
return {
|
|
39
|
-
totalCount: resp.data.totalCount,
|
|
40
|
-
offset,
|
|
41
|
-
limit,
|
|
42
|
-
options: resp.data.options,
|
|
43
|
-
count: resp.data.count,
|
|
44
|
-
};
|
|
31
|
+
return { totalCount: resp.data.totalCount, offset, limit, options: resp.data.options, count: resp.data.count };
|
|
45
32
|
};
|
|
46
33
|
|
|
47
34
|
const loadOptions = async (offset: number, limit: number) => {
|
|
48
35
|
const { options, totalCount } = await getResults(offset, limit);
|
|
49
36
|
|
|
50
|
-
return {
|
|
51
|
-
options,
|
|
52
|
-
hasMore: offset + limit < totalCount,
|
|
53
|
-
offset,
|
|
54
|
-
};
|
|
37
|
+
return { options, hasMore: offset + limit < totalCount, offset };
|
|
55
38
|
};
|
|
56
39
|
|
|
57
|
-
const client = new QueryClient({
|
|
58
|
-
defaultOptions: {
|
|
59
|
-
queries: {
|
|
60
|
-
refetchOnWindowFocus: false,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
});
|
|
40
|
+
const client = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false } } });
|
|
64
41
|
|
|
65
42
|
export const _ControlledAsyncAutoComplete: StoryObj<typeof ControlledAsyncAutocomplete> = {
|
|
66
43
|
render: (args) => {
|
|
@@ -72,15 +49,20 @@ export const _ControlledAsyncAutoComplete: StoryObj<typeof ControlledAsyncAutoco
|
|
|
72
49
|
<form onSubmit={methods.handleSubmit((data) => data)}>
|
|
73
50
|
<ControlledAsyncAutocomplete {...args} />
|
|
74
51
|
<Grid container direction="row" justifyContent="space-between" marginTop={1}>
|
|
75
|
-
<Button
|
|
52
|
+
<Button
|
|
53
|
+
disabled={!methods?.formState?.isSubmitSuccessful}
|
|
54
|
+
children="Reset"
|
|
55
|
+
color="secondary"
|
|
56
|
+
onClick={() => methods.reset()}
|
|
57
|
+
/>
|
|
76
58
|
<Button type="submit" disabled={methods?.formState?.isSubmitSuccessful} children="Submit" />
|
|
77
59
|
</Grid>
|
|
78
|
-
{
|
|
60
|
+
{methods?.formState?.isSubmitSuccessful ? (
|
|
79
61
|
<Paper sx={{ padding: '1.5rem', marginTop: '1.5rem' }}>
|
|
80
62
|
<Typography variant="h2">Submitted Values</Typography>
|
|
81
63
|
<pre data-testid="result">{JSON.stringify(methods.getValues(), null, 2)}</pre>
|
|
82
64
|
</Paper>
|
|
83
|
-
) : null
|
|
65
|
+
) : null}
|
|
84
66
|
</form>
|
|
85
67
|
</FormProvider>
|
|
86
68
|
</QueryClientProvider>
|
|
@@ -93,6 +75,50 @@ export const _ControlledAsyncAutoComplete: StoryObj<typeof ControlledAsyncAutoco
|
|
|
93
75
|
loadOptions,
|
|
94
76
|
limit: 10,
|
|
95
77
|
queryKey: 'example',
|
|
96
|
-
rules: { required:'This is required.' },
|
|
78
|
+
rules: { required: 'This is required.' },
|
|
79
|
+
defaultToFirstOption: true,
|
|
80
|
+
disableClearable: true,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const _ControlledAsyncAutoCompleteDefaultToOnlyOption: StoryObj<typeof ControlledAsyncAutocomplete> = {
|
|
85
|
+
render: (args) => {
|
|
86
|
+
const methods = useForm();
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<QueryClientProvider client={client}>
|
|
90
|
+
<FormProvider {...methods}>
|
|
91
|
+
<form onSubmit={methods.handleSubmit((data) => data)}>
|
|
92
|
+
<ControlledAsyncAutocomplete {...args} />
|
|
93
|
+
<Grid container direction="row" justifyContent="space-between" marginTop={1}>
|
|
94
|
+
<Button
|
|
95
|
+
disabled={!methods?.formState?.isSubmitSuccessful}
|
|
96
|
+
children="Reset"
|
|
97
|
+
color="secondary"
|
|
98
|
+
onClick={() => methods.reset()}
|
|
99
|
+
/>
|
|
100
|
+
<Button type="submit" disabled={methods?.formState?.isSubmitSuccessful} children="Submit" />
|
|
101
|
+
</Grid>
|
|
102
|
+
{methods?.formState?.isSubmitSuccessful ? (
|
|
103
|
+
<Paper sx={{ padding: '1.5rem', marginTop: '1.5rem' }}>
|
|
104
|
+
<Typography variant="h2">Submitted Values</Typography>
|
|
105
|
+
<pre data-testid="result">{JSON.stringify(methods.getValues(), null, 2)}</pre>
|
|
106
|
+
</Paper>
|
|
107
|
+
) : null}
|
|
108
|
+
</form>
|
|
109
|
+
</FormProvider>
|
|
110
|
+
</QueryClientProvider>
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
args: {
|
|
114
|
+
name: 'controlledAsyncAutocomplete',
|
|
115
|
+
FieldProps: { label: 'Async Select', helperText: 'Helper Text', fullWidth: false, required: true },
|
|
116
|
+
getOptionLabel: (val: Option) => val.label,
|
|
117
|
+
loadOptions,
|
|
118
|
+
limit: 1,
|
|
119
|
+
queryKey: 'example2',
|
|
120
|
+
rules: { required: 'This is required.' },
|
|
121
|
+
defaultToOnlyOption: true,
|
|
122
|
+
disableClearable: true,
|
|
97
123
|
},
|
|
98
124
|
};
|