@douglasneuroinformatics/libui 3.7.3 → 3.7.5
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/components.d.ts +1 -1
- package/dist/components.js +16 -16
- package/dist/components.js.map +1 -1
- package/dist/douglasneuroinformatics-libui-3.7.5.tgz +0 -0
- package/package.json +1 -1
- package/src/components/Form/BooleanField/BooleanFieldCheckbox.tsx +1 -1
- package/src/components/Form/Form.stories.tsx +37 -3
- package/src/components/Form/Form.tsx +3 -13
- package/src/components/Form/NumberRecordField.tsx +7 -2
- package/src/components/Form/RecordArrayField.tsx +6 -2
- package/dist/douglasneuroinformatics-libui-3.7.3.tgz +0 -0
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douglasneuroinformatics/libui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.7.
|
|
4
|
+
"version": "3.7.5",
|
|
5
5
|
"packageManager": "pnpm@9.14.2",
|
|
6
6
|
"description": "Generic UI components for DNP projects, built using React and Tailwind CSS",
|
|
7
7
|
"author": "Joshua Unrau",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
/* eslint-disable perfectionist/sort-objects */
|
|
2
3
|
|
|
3
4
|
import { useEffect, useState } from 'react';
|
|
@@ -18,8 +19,8 @@ const $ExampleFormData = z.object({
|
|
|
18
19
|
booleanRadio: z.boolean().optional(),
|
|
19
20
|
recordArray: z.array(
|
|
20
21
|
z.object({
|
|
21
|
-
recordArrayStringInput: z.string()
|
|
22
|
-
showRecordArrayDynamicField: z.boolean()
|
|
22
|
+
recordArrayStringInput: z.string(),
|
|
23
|
+
showRecordArrayDynamicField: z.boolean(),
|
|
23
24
|
recordArrayDynamicField: z.string().optional()
|
|
24
25
|
})
|
|
25
26
|
),
|
|
@@ -46,6 +47,11 @@ const $ExampleFormData = z.object({
|
|
|
46
47
|
type ExampleFormSchemaType = typeof $ExampleFormData;
|
|
47
48
|
type ExampleFormData = z.TypeOf<typeof $ExampleFormData>;
|
|
48
49
|
|
|
50
|
+
const $SimpleExampleFormData = z.object({
|
|
51
|
+
name: z.string()
|
|
52
|
+
});
|
|
53
|
+
type SimpleExampleFormSchemaType = typeof $SimpleExampleFormData;
|
|
54
|
+
|
|
49
55
|
export default {
|
|
50
56
|
component: Form,
|
|
51
57
|
decorators: [
|
|
@@ -399,6 +405,18 @@ export const WithInitialValues: StoryObj<typeof Form> = {
|
|
|
399
405
|
numberSlider: 45,
|
|
400
406
|
numberRadio: 3,
|
|
401
407
|
numberSelect: 4,
|
|
408
|
+
numberRecord: {
|
|
409
|
+
q1: 1,
|
|
410
|
+
q2: 2,
|
|
411
|
+
q3: 3
|
|
412
|
+
},
|
|
413
|
+
recordArray: [
|
|
414
|
+
{
|
|
415
|
+
recordArrayStringInput: 'A',
|
|
416
|
+
showRecordArrayDynamicField: true,
|
|
417
|
+
recordArrayDynamicField: 'B'
|
|
418
|
+
}
|
|
419
|
+
],
|
|
402
420
|
stringSelect: 'a',
|
|
403
421
|
setListbox: new Set(['a', 'b']),
|
|
404
422
|
setSelect: new Set(['c', 'd']),
|
|
@@ -420,7 +438,6 @@ export const WithDynamicInitialValues: StoryObj<typeof Form> = {
|
|
|
420
438
|
decorators: [
|
|
421
439
|
(Story) => {
|
|
422
440
|
const [initialValues, setInitialValues] = useState<FormTypes.PartialNullableData<ExampleFormData>>({});
|
|
423
|
-
|
|
424
441
|
useEffect(() => {
|
|
425
442
|
setTimeout(() => {
|
|
426
443
|
setInitialValues({
|
|
@@ -471,3 +488,20 @@ export const WithDynamicInitialValues: StoryObj<typeof Form> = {
|
|
|
471
488
|
}
|
|
472
489
|
]
|
|
473
490
|
};
|
|
491
|
+
|
|
492
|
+
export const WithPreventReset: StoryObj<typeof Form<SimpleExampleFormSchemaType>> = {
|
|
493
|
+
args: {
|
|
494
|
+
content: {
|
|
495
|
+
name: {
|
|
496
|
+
kind: 'string',
|
|
497
|
+
label: 'Name',
|
|
498
|
+
variant: 'input'
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
preventResetValuesOnReset: true,
|
|
502
|
+
onSubmit: (data) => {
|
|
503
|
+
alert(JSON.stringify(data, (_key, value) => (value instanceof Set ? [...value] : (value as unknown)), 2));
|
|
504
|
+
},
|
|
505
|
+
validationSchema: $SimpleExampleFormData
|
|
506
|
+
}
|
|
507
|
+
};
|
|
@@ -64,8 +64,9 @@ const Form = <TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TS
|
|
|
64
64
|
const { resolvedLanguage, t } = useTranslation('libui');
|
|
65
65
|
const [rootErrors, setRootErrors] = useState<string[]>([]);
|
|
66
66
|
const [errors, setErrors] = useState<FormErrors<TData>>({});
|
|
67
|
-
const [values, setValues] = useState<PartialFormDataType<TData>>(
|
|
68
|
-
|
|
67
|
+
const [values, setValues] = useState<PartialFormDataType<TData>>(
|
|
68
|
+
initialValues ? getInitialValues(initialValues) : {}
|
|
69
|
+
);
|
|
69
70
|
|
|
70
71
|
const handleError = (error: z.ZodError<TData>) => {
|
|
71
72
|
const fieldErrors: FormErrors<TData> = {};
|
|
@@ -127,17 +128,6 @@ const Form = <TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TS
|
|
|
127
128
|
revalidate();
|
|
128
129
|
}, [resolvedLanguage]);
|
|
129
130
|
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
if (initialValues) {
|
|
132
|
-
setValues(getInitialValues(initialValues));
|
|
133
|
-
}
|
|
134
|
-
setIsInitialSetValuesComplete(true);
|
|
135
|
-
}, [initialValues]);
|
|
136
|
-
|
|
137
|
-
if (!isInitialSetValuesComplete) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
131
|
return (
|
|
142
132
|
<form
|
|
143
133
|
autoComplete="off"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
NumberRecordFieldValue,
|
|
@@ -27,8 +27,13 @@ export const NumberRecordField = <T extends NumberRecordFieldValue = NumberRecor
|
|
|
27
27
|
setValue: setRecordValue,
|
|
28
28
|
value: recordValue
|
|
29
29
|
}: NumberRecordFieldProps<T>) => {
|
|
30
|
+
const isFirstRenderRef = useRef(true);
|
|
31
|
+
|
|
30
32
|
useEffect(() => {
|
|
31
|
-
|
|
33
|
+
if ((isFirstRenderRef.current && !recordValue) || !isFirstRenderRef.current) {
|
|
34
|
+
setRecordValue({});
|
|
35
|
+
}
|
|
36
|
+
isFirstRenderRef.current = false;
|
|
32
37
|
}, [options]);
|
|
33
38
|
|
|
34
39
|
if (!recordValue) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { memo, useEffect } from 'react';
|
|
1
|
+
import { memo, useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
import type { RecordArrayFieldValue, RecordArrayFormField } from '@douglasneuroinformatics/libui-form-types';
|
|
4
4
|
import { MinusCircleIcon, PlusCircleIcon } from 'lucide-react';
|
|
@@ -25,12 +25,16 @@ export const RecordArrayField = memo(function RecordArrayField({
|
|
|
25
25
|
setValue: setArrayValue,
|
|
26
26
|
value: arrayValue
|
|
27
27
|
}: RecordArrayFieldProps) {
|
|
28
|
+
const isFirstRenderRef = useRef(true);
|
|
28
29
|
const { t } = useTranslation('libui');
|
|
29
30
|
|
|
30
31
|
const createNewRecord = () => Object.fromEntries(Object.keys(fieldset).map((fieldName) => [fieldName, undefined]));
|
|
31
32
|
|
|
32
33
|
useEffect(() => {
|
|
33
|
-
|
|
34
|
+
if ((isFirstRenderRef.current && !arrayValue) || !isFirstRenderRef.current) {
|
|
35
|
+
setArrayValue([createNewRecord()]);
|
|
36
|
+
}
|
|
37
|
+
isFirstRenderRef.current = false;
|
|
34
38
|
}, [fieldset]);
|
|
35
39
|
|
|
36
40
|
if (!arrayValue) {
|
|
Binary file
|