@douglasneuroinformatics/libui 3.6.0 → 3.6.2

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.6.0",
4
+ "version": "3.6.2",
5
5
  "packageManager": "pnpm@9.12.1",
6
6
  "description": "Generic UI components for DNP projects, built using React and Tailwind CSS",
7
7
  "author": "Joshua Unrau",
@@ -18,7 +18,7 @@ describe('FileDropzone', () => {
18
18
  }}
19
19
  />
20
20
  );
21
- expect(screen.getByTestId('dropzoneText')).contains(String, "Drag'n'drop files or click on box to upload");
21
+ expect(screen.getByTestId('dropzone-title')).contains(String, 'Drag and drop files or click on box to upload');
22
22
  });
23
23
 
24
24
  it('should have file', () => {
@@ -64,6 +64,6 @@ describe('FileDropzone', () => {
64
64
  }
65
65
  });
66
66
 
67
- expect(screen.getByTestId('dropzoneText')).contain(String, 'testfile.csv');
67
+ expect(screen.getByTestId('dropzone-title')).contain(String, 'testfile.csv');
68
68
  });
69
69
  });
@@ -1,18 +1,33 @@
1
1
  import { useCallback } from 'react';
2
2
 
3
+ import { UploadIcon } from 'lucide-react';
3
4
  import { type FileRejection, useDropzone } from 'react-dropzone';
4
5
 
5
6
  import { useTranslation } from '@/hooks/useTranslation';
7
+ import { cn } from '@/utils';
6
8
 
7
9
  export type FileDropzoneProps = {
8
10
  acceptedFileTypes: {
9
11
  [key: string]: string[];
10
12
  };
13
+ className?: string;
14
+ description?: string;
11
15
  file: File | null;
12
16
  setFile: (file: File) => void;
17
+ titles?: {
18
+ dragActive: string;
19
+ dragInactive: string;
20
+ };
13
21
  };
14
22
 
15
- export const FileDropzone = ({ acceptedFileTypes, file, setFile }: FileDropzoneProps) => {
23
+ export const FileDropzone = ({
24
+ acceptedFileTypes,
25
+ className,
26
+ description,
27
+ file,
28
+ setFile,
29
+ titles
30
+ }: FileDropzoneProps) => {
16
31
  const { t } = useTranslation();
17
32
 
18
33
  const handleDrop = useCallback(
@@ -30,22 +45,31 @@ export const FileDropzone = ({ acceptedFileTypes, file, setFile }: FileDropzoneP
30
45
  onDrop: handleDrop
31
46
  });
32
47
 
33
- return (
34
- <div data-testid="dropzone" {...getRootProps()}>
35
- <p className="mt-1 border border-dashed p-4 text-center text-sm" data-testid="dropzoneText">
36
- {file
37
- ? file.name
38
- : isDragActive
39
- ? t({
40
- en: 'File to upload',
41
- fr: 'fichier à télécharger'
42
- })
43
- : t({
44
- en: "Drag'n'drop files or click on box to upload",
45
- fr: 'Glissez-déposez les fichiers ou cliquez sur la case pour les télécharger'
46
- })}
47
- </p>
48
+ const dragActiveTitle =
49
+ titles?.dragActive ??
50
+ t({
51
+ en: 'File to upload',
52
+ fr: 'fichier à télécharger'
53
+ });
48
54
 
55
+ const dragInactiveTitle =
56
+ titles?.dragInactive ??
57
+ t({
58
+ en: 'Drag and drop files or click on box to upload',
59
+ fr: 'Glissez-déposez les fichiers ou cliquez sur la case pour les télécharger'
60
+ });
61
+
62
+ return (
63
+ <div className={cn('border border-dashed p-4', className)} data-testid="dropzone" {...getRootProps()}>
64
+ <div className="flex flex-col items-center gap-3">
65
+ <UploadIcon style={{ height: 24, strokeWidth: 2, width: 24 }} />
66
+ <div className="flex flex-col items-center gap-1 text-center">
67
+ <h3 className="text-lg font-semibold tracking-tight" data-testid="dropzone-title">
68
+ {file ? file.name : isDragActive ? dragActiveTitle : dragInactiveTitle}
69
+ </h3>
70
+ {description && <p className="text-sm text-muted-foreground">{description}</p>}
71
+ </div>
72
+ </div>
49
73
  <input {...getInputProps()} />
50
74
  </div>
51
75
  );
@@ -1,5 +1,4 @@
1
- import { useEffect, useState } from 'react';
2
- import * as React from 'react';
1
+ import { useEffect, useLayoutEffect, useState } from 'react';
3
2
 
4
3
  import type {
5
4
  FormContent,
@@ -122,7 +121,7 @@ const Form = <TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TS
122
121
  revalidate();
123
122
  }, [resolvedLanguage]);
124
123
 
125
- useEffect(() => {
124
+ useLayoutEffect(() => {
126
125
  if (initialValues) {
127
126
  setValues(getInitialValues(initialValues));
128
127
  }