@oslokommune/punkt-react 15.0.4 → 15.2.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/CHANGELOG.md +49 -0
- package/dist/index.d.ts +173 -0
- package/dist/punkt-react.es.js +8216 -7134
- package/dist/punkt-react.umd.js +435 -435
- package/package.json +4 -4
- package/src/components/fileupload/DropZone.tsx +236 -0
- package/src/components/fileupload/FileUpload.test.tsx +584 -0
- package/src/components/fileupload/FileUpload.tsx +425 -0
- package/src/components/fileupload/QueueDisplay.test.tsx +222 -0
- package/src/components/fileupload/QueueDisplay.tsx +155 -0
- package/src/components/fileupload/QueueItemContent.tsx +200 -0
- package/src/components/fileupload/Subcomponents.tsx +363 -0
- package/src/components/fileupload/Truncate.test.tsx +256 -0
- package/src/components/fileupload/Truncate.tsx +137 -0
- package/src/components/fileupload/extensions/Comments.tsx +188 -0
- package/src/components/fileupload/extensions/Remove.tsx +10 -0
- package/src/components/fileupload/extensions/Rename.tsx +79 -0
- package/src/components/fileupload/hooks/index.ts +3 -0
- package/src/components/fileupload/hooks/useFileAttributes.ts +46 -0
- package/src/components/fileupload/hooks/useImagePreview.ts +42 -0
- package/src/components/fileupload/hooks/useOperationState.ts +30 -0
- package/src/components/fileupload/hooks.ts +4 -0
- package/src/components/fileupload/texts.ts +20 -0
- package/src/components/fileupload/types.ts +94 -0
- package/src/components/fileupload/utils.ts +56 -0
- package/src/components/index.ts +1 -0
- package/src/components/interfaces.ts +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for the FileUpload component
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a file size string (e.g. "5MB", "500KB") to bytes.
|
|
7
|
+
* Also accepts raw numbers (returned as-is).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* parseFileSize("5MB") // 5242880
|
|
11
|
+
* parseFileSize("500KB") // 512000
|
|
12
|
+
* parseFileSize("1GB") // 1073741824
|
|
13
|
+
* parseFileSize(1024) // 1024
|
|
14
|
+
*/
|
|
15
|
+
export const parseFileSize = (size: string | number): number => {
|
|
16
|
+
if (typeof size === 'number') return size
|
|
17
|
+
|
|
18
|
+
const match = size.trim().match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)$/i)
|
|
19
|
+
if (!match) {
|
|
20
|
+
console.warn(
|
|
21
|
+
`PktFileUpload: Invalid maxFileSize format "${size}". Use format like "5MB", "500KB", or a number in bytes.`,
|
|
22
|
+
)
|
|
23
|
+
return 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const value = parseFloat(match[1])
|
|
27
|
+
const unit = match[2].toUpperCase()
|
|
28
|
+
|
|
29
|
+
switch (unit) {
|
|
30
|
+
case 'B':
|
|
31
|
+
return value
|
|
32
|
+
case 'KB':
|
|
33
|
+
return value * 1024
|
|
34
|
+
case 'MB':
|
|
35
|
+
return value * 1024 * 1024
|
|
36
|
+
case 'GB':
|
|
37
|
+
return value * 1024 * 1024 * 1024
|
|
38
|
+
default:
|
|
39
|
+
return value
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Format bytes to a human-readable string (e.g. "5 MB", "500 KB").
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* formatFileSize(5242880) // "5 MB"
|
|
48
|
+
* formatFileSize(512000) // "500 KB"
|
|
49
|
+
* formatFileSize(500) // "500 B"
|
|
50
|
+
*/
|
|
51
|
+
export const formatFileSize = (bytes: number): string => {
|
|
52
|
+
if (bytes < 1024) return `${bytes} B`
|
|
53
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`
|
|
54
|
+
if (bytes < 1024 * 1024 * 1024) return `${Math.round(bytes / (1024 * 1024))} MB`
|
|
55
|
+
return `${Math.round(bytes / (1024 * 1024 * 1024))} GB`
|
|
56
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { PktCheckbox } from './checkbox/Checkbox'
|
|
|
10
10
|
export { PktCombobox } from './combobox/Combobox'
|
|
11
11
|
export { PktConsent } from './consent/Consent'
|
|
12
12
|
export { PktDatepicker } from './datepicker/Datepicker'
|
|
13
|
+
export { PktFileUpload } from './fileupload/FileUpload'
|
|
13
14
|
export { PktFooter } from './footer/Footer'
|
|
14
15
|
export { PktFooterSimple } from './footerSimple/FooterSimple'
|
|
15
16
|
export { PktHeader } from './header/Header'
|
|
@@ -8,6 +8,7 @@ export type { IPktCard } from './card/Card'
|
|
|
8
8
|
export type { IPktCheckbox } from './checkbox/Checkbox'
|
|
9
9
|
export type { IPktCombobox } from './combobox/Combobox'
|
|
10
10
|
export type { IPktDatepicker } from './datepicker/Datepicker'
|
|
11
|
+
export type { IPktFileUpload } from './fileupload/FileUpload'
|
|
11
12
|
export type { IPktFooter } from './footer/Footer'
|
|
12
13
|
export type { IPktFooterSimple } from './footerSimple/FooterSimple'
|
|
13
14
|
export type { IPktHeader } from './header/Header'
|