@douglasneuroinformatics/libui 3.7.4 → 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.js +12 -4
- 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/Form.stories.tsx +15 -3
- package/src/components/Form/NumberRecordField.tsx +7 -2
- package/src/components/Form/RecordArrayField.tsx +6 -2
- package/dist/douglasneuroinformatics-libui-3.7.4.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
|
),
|
|
@@ -404,6 +405,18 @@ export const WithInitialValues: StoryObj<typeof Form> = {
|
|
|
404
405
|
numberSlider: 45,
|
|
405
406
|
numberRadio: 3,
|
|
406
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
|
+
],
|
|
407
420
|
stringSelect: 'a',
|
|
408
421
|
setListbox: new Set(['a', 'b']),
|
|
409
422
|
setSelect: new Set(['c', 'd']),
|
|
@@ -425,7 +438,6 @@ export const WithDynamicInitialValues: StoryObj<typeof Form> = {
|
|
|
425
438
|
decorators: [
|
|
426
439
|
(Story) => {
|
|
427
440
|
const [initialValues, setInitialValues] = useState<FormTypes.PartialNullableData<ExampleFormData>>({});
|
|
428
|
-
|
|
429
441
|
useEffect(() => {
|
|
430
442
|
setTimeout(() => {
|
|
431
443
|
setInitialValues({
|
|
@@ -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
|