@sb1/ffe-file-upload-react 100.8.3 → 100.9.0
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/README.md +110 -16
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,32 +1,126 @@
|
|
|
1
1
|
# @sb1/ffe-file-upload-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Beskrivelse
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Filopplastingskomponent med dropzone, validering og filliste. Filer vises i tre tilstander:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Laster** - Viser skeleton
|
|
8
|
+
- **Ferdig** - Viser filnavn med slett-knapp
|
|
9
|
+
- **Feil** - Viser feilmelding
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## Installasjon
|
|
12
|
+
|
|
13
|
+
```bash
|
|
10
14
|
npm install --save @sb1/ffe-file-upload-react
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
##
|
|
17
|
+
## Bruk
|
|
14
18
|
|
|
15
|
-
Full
|
|
19
|
+
Full dokumentasjon: https://sparebank1.github.io/designsystem/
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
Make sure you import the less-files.
|
|
21
|
+
Avhengig av `@sb1/ffe-icons-react`, `@sb1/ffe-buttons-react` og `@sb1/ffe-form-react`. Importer CSS:
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
```css
|
|
24
|
+
@import url('@sb1/ffe-file-upload/css/ffe-file-upload.css');
|
|
25
|
+
@import url('@sb1/ffe-icons/css/ffe-icons.css');
|
|
26
|
+
@import url('@sb1/ffe-buttons/css/ffe-buttons.css');
|
|
27
|
+
@import url('@sb1/ffe-form/css/ffe-form.css');
|
|
28
|
+
```
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
## Eksempler
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
### Grunnleggende eksempel
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import {
|
|
36
|
+
FileUpload,
|
|
37
|
+
getFileContent,
|
|
38
|
+
getUniqueFileName,
|
|
39
|
+
} from '@sb1/ffe-file-upload-react';
|
|
40
|
+
import { useState } from 'react';
|
|
41
|
+
|
|
42
|
+
type FileItem = {
|
|
43
|
+
name: string;
|
|
44
|
+
document?: { content: unknown };
|
|
45
|
+
error?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function FileUploadExample() {
|
|
49
|
+
const [files, setFiles] = useState<Record<string, FileItem>>({});
|
|
50
|
+
|
|
51
|
+
const uploadFiles = async (fileList: FileList | null) => {
|
|
52
|
+
if (!fileList) return;
|
|
53
|
+
|
|
54
|
+
for (const file of Array.from(fileList)) {
|
|
55
|
+
const name = getUniqueFileName(file.name, files);
|
|
56
|
+
setFiles(prev => ({ ...prev, [name]: { name } }));
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const content = await getFileContent(file);
|
|
60
|
+
// Erstatt med faktisk API-kall
|
|
61
|
+
await fetch('/api/upload', {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
body: JSON.stringify({ name, content }),
|
|
64
|
+
});
|
|
65
|
+
setFiles(prev => ({
|
|
66
|
+
...prev,
|
|
67
|
+
[name]: { name, document: { content } },
|
|
68
|
+
}));
|
|
69
|
+
} catch {
|
|
70
|
+
setFiles(prev => ({
|
|
71
|
+
...prev,
|
|
72
|
+
[name]: { name, error: 'Opplasting feilet' },
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const deleteFile = (file: FileItem) => {
|
|
79
|
+
setFiles(prev => {
|
|
80
|
+
const next = { ...prev };
|
|
81
|
+
delete next[file.name];
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<FileUpload
|
|
88
|
+
id="dokumenter"
|
|
89
|
+
label="Velg filer"
|
|
90
|
+
title="Last opp dokumenter"
|
|
91
|
+
infoText="Legg ved relevant dokumentasjon."
|
|
92
|
+
uploadTitle="Dra filene hit"
|
|
93
|
+
uploadMicroText="Eller"
|
|
94
|
+
uploadSubText="PDF, JPG eller PNG, maks 50 MB"
|
|
95
|
+
files={files}
|
|
96
|
+
onFilesSelected={uploadFiles}
|
|
97
|
+
onFilesDropped={uploadFiles}
|
|
98
|
+
onFileDeleted={deleteFile}
|
|
99
|
+
cancelText="Avbryt"
|
|
100
|
+
deleteText="Slett"
|
|
101
|
+
accept=".pdf,.jpg,.png"
|
|
102
|
+
multiple={true}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Hjelpefunksjoner
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { getFileContent, getUniqueFileName } from '@sb1/ffe-file-upload-react';
|
|
112
|
+
|
|
113
|
+
// Les filinnhold som base64 data URL
|
|
114
|
+
const content = await getFileContent(file);
|
|
115
|
+
|
|
116
|
+
// Generer unikt filnavn (legger til -1, -2 etc. ved duplikater)
|
|
117
|
+
const uniqueName = getUniqueFileName('dokument.pdf', existingFiles);
|
|
28
118
|
```
|
|
29
119
|
|
|
30
|
-
|
|
120
|
+
## Utvikling
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm install && npm run build && npm start
|
|
124
|
+
```
|
|
31
125
|
|
|
32
|
-
|
|
126
|
+
Storybook kjører på http://localhost:6006/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-file-upload-react",
|
|
3
|
-
"version": "100.
|
|
3
|
+
"version": "100.9.0",
|
|
4
4
|
"description": "Upload file button with validation and list of uploaded files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ffe"
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"test:watch": "ffe-buildtool jest --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@sb1/ffe-buttons-react": "^100.
|
|
32
|
-
"@sb1/ffe-file-upload": "^100.
|
|
33
|
-
"@sb1/ffe-form": "^100.
|
|
34
|
-
"@sb1/ffe-icons-react": "^100.
|
|
31
|
+
"@sb1/ffe-buttons-react": "^100.9.0",
|
|
32
|
+
"@sb1/ffe-file-upload": "^100.9.0",
|
|
33
|
+
"@sb1/ffe-form": "^100.9.0",
|
|
34
|
+
"@sb1/ffe-icons-react": "^100.9.0",
|
|
35
35
|
"classnames": "^2.3.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@sb1/ffe-buildtool": "^100.
|
|
38
|
+
"@sb1/ffe-buildtool": "^100.9.0",
|
|
39
39
|
"react": "^18.2.0",
|
|
40
40
|
"react-dom": "^18.2.0"
|
|
41
41
|
},
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "41f20cf10bec5ebe53036c282690983d2114fb45"
|
|
49
49
|
}
|