@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@douglasneuroinformatics/libui",
3
3
  "type": "module",
4
- "version": "3.7.4",
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().optional(),
22
- showRecordArrayDynamicField: z.boolean().optional(),
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
- setRecordValue({});
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
- setArrayValue([createNewRecord()]);
34
+ if ((isFirstRenderRef.current && !arrayValue) || !isFirstRenderRef.current) {
35
+ setArrayValue([createNewRecord()]);
36
+ }
37
+ isFirstRenderRef.current = false;
34
38
  }, [fieldset]);
35
39
 
36
40
  if (!arrayValue) {