@oslokommune/punkt-react 19.3.0 → 19.4.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 +13 -0
- package/dist/components/card/Card.d.ts +2 -1
- package/dist/components/consent/Consent.d.ts +6 -38
- package/dist/components/datepicker/types.d.ts +1 -1
- package/dist/components/fileupload/extensions/Comments.d.ts +2 -1
- package/dist/components/fileupload/extensions/Remove.d.ts +2 -1
- package/dist/components/fileupload/extensions/Rename.d.ts +2 -1
- package/dist/components/fileupload/hooks/index.d.ts +1 -0
- package/dist/components/fileupload/hooks/useImageObjectUrl.d.ts +1 -0
- package/dist/components/fileupload/hooks.d.ts +1 -0
- package/dist/components/fileupload/types.d.ts +2 -0
- package/dist/components/header-menu/HeaderMenu.d.ts +3 -2
- package/dist/components/messagebox/Messagebox.d.ts +2 -1
- package/dist/components/modal/Modal.d.ts +2 -1
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1986 -1955
- package/dist/shared-strings/nb.d.ts +34 -0
- package/dist/shared-types/consent.d.ts +69 -0
- package/dist/shared-types/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/components/alert/Alert.test.tsx +5 -5
- package/src/components/alert/Alert.tsx +2 -4
- package/src/components/breadcrumbs/Breadcrumbs.tsx +15 -12
- package/src/components/calendar/Calendar.core.test.tsx +22 -16
- package/src/components/calendar/CalendarNav.tsx +11 -6
- package/src/components/calendar/useCalendarState.ts +42 -55
- package/src/components/card/Card.tsx +17 -5
- package/src/components/combobox/ComboboxTags.tsx +3 -3
- package/src/components/combobox/Listbox.tsx +7 -5
- package/src/components/combobox/useComboboxState.ts +22 -18
- package/src/components/consent/Consent.test.tsx +6 -0
- package/src/components/consent/Consent.tsx +30 -55
- package/src/components/datepicker/DatepickerInputs.tsx +3 -9
- package/src/components/datepicker/types.ts +1 -1
- package/src/components/datepicker/useDatepickerState.ts +22 -17
- package/src/components/fileupload/DropZone.tsx +10 -10
- package/src/components/fileupload/FileUpload.tsx +9 -14
- package/src/components/fileupload/Subcomponents.tsx +78 -84
- package/src/components/fileupload/extensions/Comments.tsx +56 -50
- package/src/components/fileupload/extensions/Remove.tsx +8 -3
- package/src/components/fileupload/extensions/Rename.tsx +12 -8
- package/src/components/fileupload/hooks/index.ts +1 -0
- package/src/components/fileupload/hooks/useImageObjectUrl.ts +15 -0
- package/src/components/fileupload/hooks/useOperationState.ts +9 -16
- package/src/components/fileupload/hooks.ts +1 -0
- package/src/components/fileupload/types.ts +7 -1
- package/src/components/formAttribute.test.tsx +1 -0
- package/src/components/header/HeaderGlobal.tsx +8 -2
- package/src/components/header/HeaderService.test.tsx +5 -2
- package/src/components/header/HeaderService.tsx +5 -5
- package/src/components/header-menu/HeaderMenu.tsx +8 -3
- package/src/components/headerUserMenu/UserMenu.tsx +3 -2
- package/src/components/inputwrapper/InputWrapper.tsx +20 -27
- package/src/components/loader/Loader.tsx +12 -9
- package/src/components/messagebox/Messagebox.tsx +6 -2
- package/src/components/modal/Modal.tsx +13 -9
- package/src/components/searchinput/SearchInput.tsx +10 -6
- package/src/components/tabs/Tabs.test.tsx +1 -1
- package/src/components/tabs/Tabs.tsx +30 -35
- package/src/components/tag/Tag.tsx +7 -6
- package/src/components/textarea/Textarea.test.tsx +9 -0
- package/src/components/textarea/Textarea.tsx +6 -10
- package/src/components/textinput/Textinput.tsx +3 -9
- package/src/components/timepicker/useTimepickerState.ts +25 -21
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { RefObject, useEffect, useState } from 'react'
|
|
1
|
+
import { RefObject, useContext, useEffect, useState } from 'react'
|
|
2
2
|
|
|
3
|
+
import { formatString } from 'shared-strings'
|
|
3
4
|
import { getDisplayFilename, trapTabInside } from 'shared-utils/fileupload'
|
|
4
5
|
|
|
5
6
|
import { PktButton } from '../button/Button'
|
|
@@ -7,7 +8,14 @@ import { PktIcon } from '../icon/Icon'
|
|
|
7
8
|
import { PktProgressbar } from '../progressbar/Progressbar'
|
|
8
9
|
import { PktModal } from '../modal/Modal'
|
|
9
10
|
import { Truncate } from './Truncate'
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
PktFileUploadContext,
|
|
13
|
+
TFileAndTransfer,
|
|
14
|
+
TQueueItemOperation,
|
|
15
|
+
TQueueOperationContext,
|
|
16
|
+
TTransferItemInProgress,
|
|
17
|
+
} from './types'
|
|
18
|
+
import { useImageObjectUrl } from './hooks'
|
|
11
19
|
import { formatFileSize } from './utils'
|
|
12
20
|
|
|
13
21
|
const CancelTransferButton = (props: {
|
|
@@ -15,23 +23,29 @@ const CancelTransferButton = (props: {
|
|
|
15
23
|
label?: string
|
|
16
24
|
ariaLabel?: string
|
|
17
25
|
disabled?: boolean
|
|
18
|
-
}) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
}) => {
|
|
27
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
28
|
+
return (
|
|
29
|
+
<button
|
|
30
|
+
type="button"
|
|
31
|
+
onClick={props.onClick}
|
|
32
|
+
disabled={props.disabled}
|
|
33
|
+
className="pkt-fileupload__queue-display__item__cancel-button"
|
|
34
|
+
aria-label={props.ariaLabel || strings.cancelUpload}
|
|
35
|
+
>
|
|
36
|
+
{props.label || strings.cancel}
|
|
37
|
+
</button>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
29
40
|
|
|
30
|
-
const LoadingText = () =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
const LoadingText = () => {
|
|
42
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
43
|
+
return (
|
|
44
|
+
<span className="pkt-fileupload__queue-display__item__loading-text" aria-label={strings.uploadingFile}>
|
|
45
|
+
{strings.uploading}
|
|
46
|
+
</span>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
35
49
|
|
|
36
50
|
export const TransferInProgress = ({
|
|
37
51
|
cancelTransfer,
|
|
@@ -42,6 +56,7 @@ export const TransferInProgress = ({
|
|
|
42
56
|
cancelTransfer: () => void
|
|
43
57
|
disabled?: boolean
|
|
44
58
|
}) => {
|
|
59
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
45
60
|
const showProgressBar = transferItem.showProgress ?? transferItem.progress !== 0
|
|
46
61
|
|
|
47
62
|
return (
|
|
@@ -51,7 +66,7 @@ export const TransferInProgress = ({
|
|
|
51
66
|
className="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
|
|
52
67
|
aria-hidden="true"
|
|
53
68
|
/>
|
|
54
|
-
<p className="pkt-fileupload__queue-display__item__title" aria-label=
|
|
69
|
+
<p className="pkt-fileupload__queue-display__item__title" aria-label={strings.filename}>
|
|
55
70
|
<Truncate>{getDisplayFilename(transferItem)}</Truncate>
|
|
56
71
|
<span className="pkt-fileupload__queue-display__item__filesize">
|
|
57
72
|
{' '}
|
|
@@ -83,10 +98,7 @@ const TitleWithSize = ({ transferItem }: { transferItem: TFileAndTransfer }) =>
|
|
|
83
98
|
<p className="pkt-fileupload__queue-display__item__title">
|
|
84
99
|
<Truncate>{getDisplayFilename(transferItem)}</Truncate>
|
|
85
100
|
{transferItem.file && (
|
|
86
|
-
<span className="pkt-fileupload__queue-display__item__filesize">
|
|
87
|
-
{' '}
|
|
88
|
-
({formatFileSize(transferItem.file.size)})
|
|
89
|
-
</span>
|
|
101
|
+
<span className="pkt-fileupload__queue-display__item__filesize"> ({formatFileSize(transferItem.file.size)})</span>
|
|
90
102
|
)}
|
|
91
103
|
</p>
|
|
92
104
|
)
|
|
@@ -101,6 +113,7 @@ const TransferErrorWithProgress = ({
|
|
|
101
113
|
onRemove: () => void
|
|
102
114
|
disabled?: boolean
|
|
103
115
|
}) => {
|
|
116
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
104
117
|
// Use lastProgress to show where the upload failed (default to 100% if not available)
|
|
105
118
|
const progressValue = (transferItem.lastProgress ?? 1) * 100
|
|
106
119
|
|
|
@@ -114,8 +127,8 @@ const TransferErrorWithProgress = ({
|
|
|
114
127
|
<TitleWithSize transferItem={transferItem} />
|
|
115
128
|
<CancelTransferButton
|
|
116
129
|
onClick={onRemove}
|
|
117
|
-
label=
|
|
118
|
-
ariaLabel=
|
|
130
|
+
label={strings.removeFailed}
|
|
131
|
+
ariaLabel={strings.removeFailedFile}
|
|
119
132
|
disabled={disabled}
|
|
120
133
|
/>
|
|
121
134
|
<PktProgressbar
|
|
@@ -141,25 +154,28 @@ const TransferErrorIndeterminate = ({
|
|
|
141
154
|
transferItem: TFileAndTransfer
|
|
142
155
|
onRemove: () => void
|
|
143
156
|
disabled?: boolean
|
|
144
|
-
}) =>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
)
|
|
157
|
+
}) => {
|
|
158
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
159
|
+
return (
|
|
160
|
+
<>
|
|
161
|
+
<PktIcon
|
|
162
|
+
className="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
|
|
163
|
+
name="alert-error"
|
|
164
|
+
aria-hidden="true"
|
|
165
|
+
/>
|
|
166
|
+
<TitleWithSize transferItem={transferItem} />
|
|
167
|
+
<CancelTransferButton
|
|
168
|
+
onClick={onRemove}
|
|
169
|
+
label={strings.removeFailed}
|
|
170
|
+
ariaLabel={strings.removeFailedFile}
|
|
171
|
+
disabled={disabled}
|
|
172
|
+
/>
|
|
173
|
+
{transferItem.errorMessage && (
|
|
174
|
+
<span className="pkt-fileupload__queue-display__item__error-message">{transferItem.errorMessage}</span>
|
|
175
|
+
)}
|
|
176
|
+
</>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
163
179
|
|
|
164
180
|
// Main error component - chooses display based on showProgress
|
|
165
181
|
export const TransferError = ({
|
|
@@ -232,33 +248,16 @@ export const ThumbnailRenderer = ({
|
|
|
232
248
|
queueItemOperations?: Array<TQueueItemOperation>
|
|
233
249
|
onPreviewClick?: () => void
|
|
234
250
|
}) => {
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
useEffect(() => {
|
|
240
|
-
setThumbnailLoadFailed(false)
|
|
241
|
-
|
|
242
|
-
// Check if the file is an image
|
|
243
|
-
if (file.type.startsWith('image/')) {
|
|
244
|
-
// Create an object URL for the file
|
|
245
|
-
const url = URL.createObjectURL(file)
|
|
246
|
-
setThumbnailUrl(url)
|
|
247
|
-
|
|
248
|
-
// Cleanup: revoke the object URL when component unmounts
|
|
249
|
-
return () => {
|
|
250
|
-
URL.revokeObjectURL(url)
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
setThumbnailUrl(null)
|
|
255
|
-
}, [file])
|
|
251
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
252
|
+
const thumbnailUrl = useImageObjectUrl(transferItem.file)
|
|
253
|
+
const [failedUrl, setFailedUrl] = useState<string | null>(null)
|
|
254
|
+
const thumbnailLoadFailed = !!thumbnailUrl && failedUrl === thumbnailUrl
|
|
256
255
|
|
|
257
256
|
const img = (thumbnailUrl && !thumbnailLoadFailed && (
|
|
258
257
|
<img
|
|
259
258
|
src={thumbnailUrl}
|
|
260
259
|
alt={transferItem.attributes['targetFilename']}
|
|
261
|
-
onError={() =>
|
|
260
|
+
onError={() => setFailedUrl(thumbnailUrl)}
|
|
262
261
|
/>
|
|
263
262
|
)) || <PktIcon name="document-text" className="pkt-fileupload__queue-display__item__icon pkt-icon--medium" />
|
|
264
263
|
|
|
@@ -273,7 +272,7 @@ export const ThumbnailRenderer = ({
|
|
|
273
272
|
>
|
|
274
273
|
<PktButton
|
|
275
274
|
className="pkt-fileupload__queue-display__item__thumbnail__image-wrapper"
|
|
276
|
-
aria-label={
|
|
275
|
+
aria-label={formatString(strings.previewImage, { filename: transferItem.attributes['targetFilename'] })}
|
|
277
276
|
type="button"
|
|
278
277
|
skin="secondary"
|
|
279
278
|
onClick={onPreviewClick}
|
|
@@ -313,21 +312,12 @@ export const ImagePreviewModal = ({
|
|
|
313
312
|
onNavigate,
|
|
314
313
|
modalRef,
|
|
315
314
|
}: IImagePreviewModal) => {
|
|
316
|
-
const
|
|
317
|
-
const [imageLoadFailed, setImageLoadFailed] = useState(false)
|
|
315
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
318
316
|
const currentImage = images[currentIndex]
|
|
319
317
|
const hasMultipleImages = images.length > 1
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (currentImage && currentImage.file.type.startsWith('image/')) {
|
|
325
|
-
const url = URL.createObjectURL(currentImage.file)
|
|
326
|
-
setImageUrl(url)
|
|
327
|
-
return () => URL.revokeObjectURL(url)
|
|
328
|
-
}
|
|
329
|
-
setImageUrl(null)
|
|
330
|
-
}, [currentImage])
|
|
318
|
+
const imageUrl = useImageObjectUrl(currentImage?.file)
|
|
319
|
+
const [failedUrl, setFailedUrl] = useState<string | null>(null)
|
|
320
|
+
const imageLoadFailed = !!imageUrl && failedUrl === imageUrl
|
|
331
321
|
|
|
332
322
|
useEffect(() => {
|
|
333
323
|
if (!isOpen) return
|
|
@@ -376,7 +366,7 @@ export const ImagePreviewModal = ({
|
|
|
376
366
|
size="medium"
|
|
377
367
|
className="pkt-fileupload__image-preview__nav pkt-fileupload__image-preview__nav--prev"
|
|
378
368
|
onClick={() => onNavigate('prev')}
|
|
379
|
-
aria-label={
|
|
369
|
+
aria-label={formatString(strings.previewPrevious, { index: currentIndex, total: images.length })}
|
|
380
370
|
/>
|
|
381
371
|
)}
|
|
382
372
|
|
|
@@ -384,9 +374,13 @@ export const ImagePreviewModal = ({
|
|
|
384
374
|
{imageUrl && !imageLoadFailed ? (
|
|
385
375
|
<img
|
|
386
376
|
src={imageUrl}
|
|
387
|
-
alt={
|
|
377
|
+
alt={formatString(strings.previewImageAlt, {
|
|
378
|
+
filename: currentImage.attributes['targetFilename'],
|
|
379
|
+
index: currentIndex + 1,
|
|
380
|
+
total: images.length,
|
|
381
|
+
})}
|
|
388
382
|
className="pkt-fileupload__image-preview__image"
|
|
389
|
-
onError={() =>
|
|
383
|
+
onError={() => setFailedUrl(imageUrl)}
|
|
390
384
|
/>
|
|
391
385
|
) : (
|
|
392
386
|
<PktIcon name="picture" className="pkt-fileupload__queue-display__item__icon pkt-icon--medium" />
|
|
@@ -407,7 +401,7 @@ export const ImagePreviewModal = ({
|
|
|
407
401
|
size="medium"
|
|
408
402
|
className="pkt-fileupload__image-preview__nav pkt-fileupload__image-preview__nav--next"
|
|
409
403
|
onClick={() => onNavigate('next')}
|
|
410
|
-
aria-label={
|
|
404
|
+
aria-label={formatString(strings.previewNext, { index: currentIndex + 2, total: images.length })}
|
|
411
405
|
/>
|
|
412
406
|
)}
|
|
413
407
|
</div>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useContext, useLayoutEffect, useRef } from 'react'
|
|
2
2
|
|
|
3
|
+
import { formatString, type TPktStrings } from 'shared-strings'
|
|
4
|
+
|
|
3
5
|
import { PktButton } from '../../button/Button'
|
|
4
6
|
import { PktIcon } from '../../icon/Icon'
|
|
5
7
|
import { PktTextarea } from '../../textarea/Textarea'
|
|
@@ -12,7 +14,7 @@ export interface IComment {
|
|
|
12
14
|
timestamp: string
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
const formatTimestamp = (iso: string): string => {
|
|
17
|
+
const formatTimestamp = (iso: string, strings: TPktStrings['fileupload']): string => {
|
|
16
18
|
const date = new Date(iso)
|
|
17
19
|
if (Number.isNaN(date.getTime())) return iso
|
|
18
20
|
const day = String(date.getDate()).padStart(2, '0')
|
|
@@ -20,7 +22,10 @@ const formatTimestamp = (iso: string): string => {
|
|
|
20
22
|
const year = date.getFullYear()
|
|
21
23
|
const hours = String(date.getHours()).padStart(2, '0')
|
|
22
24
|
const minutes = String(date.getMinutes()).padStart(2, '0')
|
|
23
|
-
return
|
|
25
|
+
return formatString(strings.commentTimestamp, {
|
|
26
|
+
date: `${day}.${month}.${year}`,
|
|
27
|
+
time: `${hours}:${minutes}`,
|
|
28
|
+
})
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
const AddComment = ({
|
|
@@ -36,6 +41,7 @@ const AddComment = ({
|
|
|
36
41
|
onAddComment: (comment: IComment) => void
|
|
37
42
|
existingComment?: IComment
|
|
38
43
|
}) => {
|
|
44
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
39
45
|
const inputRef = useRef<HTMLTextAreaElement>(null)
|
|
40
46
|
const isEditing = !!existingComment
|
|
41
47
|
|
|
@@ -56,10 +62,10 @@ const AddComment = ({
|
|
|
56
62
|
<>
|
|
57
63
|
<PktTextarea
|
|
58
64
|
autoFocus
|
|
59
|
-
label={isEditing ?
|
|
65
|
+
label={isEditing ? strings.editComment : strings.addComment}
|
|
60
66
|
name={`comment-${fileItem.fileId}`}
|
|
61
67
|
className="pkt-fileupload__queue-display__item__comment-input"
|
|
62
|
-
placeholder=
|
|
68
|
+
placeholder={strings.commentPlaceholder}
|
|
63
69
|
rows={2}
|
|
64
70
|
id={`comment-${fileItem.fileId}`}
|
|
65
71
|
ref={inputRef}
|
|
@@ -68,10 +74,10 @@ const AddComment = ({
|
|
|
68
74
|
/>
|
|
69
75
|
|
|
70
76
|
<PktButton skin="secondary" size="small" disabled={disabled} onClick={handleAddComment}>
|
|
71
|
-
{isEditing ?
|
|
77
|
+
{isEditing ? strings.saveComment : strings.addComment}
|
|
72
78
|
</PktButton>
|
|
73
79
|
<PktButton skin="tertiary" size="small" disabled={disabled} onClick={closeOperationUi}>
|
|
74
|
-
|
|
80
|
+
{strings.cancel}
|
|
75
81
|
</PktButton>
|
|
76
82
|
</>
|
|
77
83
|
)
|
|
@@ -87,62 +93,59 @@ const ShowComment = ({
|
|
|
87
93
|
disabled: boolean
|
|
88
94
|
onDeleteComment: () => void
|
|
89
95
|
onEditComment: () => void
|
|
90
|
-
}) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
96
|
+
}) => {
|
|
97
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
98
|
+
return (
|
|
99
|
+
<div className="pkt-fileupload__queue-display__item__comments">
|
|
100
|
+
<div className="pkt-fileupload__queue-display__item__comment">
|
|
101
|
+
<div className="pkt-fileupload__queue-display__item__comment__content">
|
|
102
|
+
<span className="pkt-fileupload__queue-display__item__comment__text" aria-label={strings.commentText}>
|
|
103
|
+
{comment.text}
|
|
104
|
+
</span>
|
|
105
|
+
<time className="pkt-fileupload__queue-display__item__comment__time">
|
|
106
|
+
{formatTimestamp(comment.timestamp, strings)}
|
|
107
|
+
</time>
|
|
108
|
+
</div>
|
|
109
|
+
<div className="pkt-fileupload__queue-display__item__comment__actions">
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
className="pkt-fileupload__queue-display__item__comment__action"
|
|
113
|
+
onClick={onEditComment}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
aria-label={strings.editComment}
|
|
116
|
+
>
|
|
117
|
+
<PktIcon name="edit" />
|
|
118
|
+
</button>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
className="pkt-fileupload__queue-display__item__comment__action"
|
|
122
|
+
onClick={onDeleteComment}
|
|
123
|
+
disabled={disabled}
|
|
124
|
+
aria-label={strings.deleteComment}
|
|
125
|
+
>
|
|
126
|
+
<PktIcon name="trash-can" />
|
|
127
|
+
</button>
|
|
128
|
+
</div>
|
|
120
129
|
</div>
|
|
121
130
|
</div>
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
)
|
|
132
|
+
}
|
|
124
133
|
|
|
125
134
|
const CommentHiddenInput = ({ comments }: { comments: IComment[] | undefined }) => {
|
|
126
135
|
const context = useContext(PktFileUploadContext)
|
|
127
|
-
return (
|
|
128
|
-
<input
|
|
129
|
-
type="hidden"
|
|
130
|
-
name={`${context.name}-comments`}
|
|
131
|
-
value={comments ? JSON.stringify(comments) : ''}
|
|
132
|
-
/>
|
|
133
|
-
)
|
|
136
|
+
return <input type="hidden" name={`${context.name}-comments`} value={comments ? JSON.stringify(comments) : ''} />
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
const getComments = (context: TQueueOperationContext): IComment[] =>
|
|
137
140
|
context.getAttribute<IComment[]>(COMMENTS_ATTRIBUTE) ?? []
|
|
138
141
|
|
|
139
|
-
export const addCommentOperation: TQueueItemOperation
|
|
142
|
+
export const addCommentOperation = (strings: TPktStrings['fileupload']): TQueueItemOperation => ({
|
|
140
143
|
id: 'comment',
|
|
141
144
|
title: (fileItem) => {
|
|
142
145
|
const comments = (fileItem.attributes?.[COMMENTS_ATTRIBUTE] as IComment[] | undefined) ?? []
|
|
143
|
-
return comments.length > 0 ? '' :
|
|
146
|
+
return comments.length > 0 ? '' : strings.addComment
|
|
144
147
|
},
|
|
145
|
-
ariaLabel:
|
|
148
|
+
ariaLabel: strings.addComment,
|
|
146
149
|
renderExtendedUI: (context) => {
|
|
147
150
|
const existingComment = getComments(context)[0]
|
|
148
151
|
return (
|
|
@@ -171,6 +174,9 @@ export const addCommentOperation: TQueueItemOperation = {
|
|
|
171
174
|
)
|
|
172
175
|
},
|
|
173
176
|
renderHidden: (context) => (
|
|
174
|
-
<CommentHiddenInput
|
|
177
|
+
<CommentHiddenInput
|
|
178
|
+
key={`comments${context.file.fileId}`}
|
|
179
|
+
comments={context.getAttribute<IComment[]>(COMMENTS_ATTRIBUTE)}
|
|
180
|
+
/>
|
|
175
181
|
),
|
|
176
|
-
}
|
|
182
|
+
})
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { TPktStrings } from 'shared-strings'
|
|
2
|
+
|
|
1
3
|
import type { TFileId, TQueueItemOperation } from '@/components/fileupload/types'
|
|
2
4
|
|
|
3
|
-
export const removeFileOperation = (
|
|
5
|
+
export const removeFileOperation = (
|
|
6
|
+
onFileRemoved: (fileId: TFileId) => void,
|
|
7
|
+
strings: TPktStrings['fileupload'],
|
|
8
|
+
): TQueueItemOperation => ({
|
|
4
9
|
id: 'remove',
|
|
5
|
-
title:
|
|
6
|
-
ariaLabel:
|
|
10
|
+
title: strings.remove,
|
|
11
|
+
ariaLabel: strings.removeFile,
|
|
7
12
|
onClick: ({ file }) => onFileRemoved(file.fileId),
|
|
8
13
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useContext, useId, useRef } from 'react'
|
|
2
2
|
|
|
3
|
+
import type { TPktStrings } from 'shared-strings'
|
|
3
4
|
import { getDisplayFilename } from 'shared-utils/fileupload'
|
|
4
5
|
|
|
5
6
|
import { PktButton } from '../../button/Button'
|
|
@@ -13,6 +14,7 @@ interface IRenameFileProps {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const RenameFile = ({ initialValue, disabled, onSave, onCancel }: IRenameFileProps) => {
|
|
17
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
16
18
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
17
19
|
const inputId = useId()
|
|
18
20
|
|
|
@@ -21,7 +23,7 @@ const RenameFile = ({ initialValue, disabled, onSave, onCancel }: IRenameFilePro
|
|
|
21
23
|
return (
|
|
22
24
|
<>
|
|
23
25
|
<label htmlFor={inputId} className="pkt-sr-only">
|
|
24
|
-
|
|
26
|
+
{strings.renameInputLabel}
|
|
25
27
|
</label>
|
|
26
28
|
<input
|
|
27
29
|
id={inputId}
|
|
@@ -45,10 +47,10 @@ const RenameFile = ({ initialValue, disabled, onSave, onCancel }: IRenameFilePro
|
|
|
45
47
|
}}
|
|
46
48
|
/>
|
|
47
49
|
<PktButton skin="secondary" size="small" disabled={disabled} onClick={save}>
|
|
48
|
-
|
|
50
|
+
{strings.save}
|
|
49
51
|
</PktButton>
|
|
50
52
|
<PktButton skin="tertiary" size="small" disabled={disabled} onClick={onCancel}>
|
|
51
|
-
|
|
53
|
+
{strings.cancel}
|
|
52
54
|
</PktButton>
|
|
53
55
|
</>
|
|
54
56
|
)
|
|
@@ -62,10 +64,10 @@ const RenameHiddenInput = ({ targetFilename }: { targetFilename: string }) => {
|
|
|
62
64
|
const resolveCurrentName = (context: TQueueOperationContext) =>
|
|
63
65
|
context.getAttribute<string>('targetFilename') || getDisplayFilename(context.file, '')
|
|
64
66
|
|
|
65
|
-
export const renameFileOperation: TQueueItemOperation
|
|
67
|
+
export const renameFileOperation = (strings: TPktStrings['fileupload']): TQueueItemOperation => ({
|
|
66
68
|
id: 'rename',
|
|
67
|
-
title:
|
|
68
|
-
ariaLabel:
|
|
69
|
+
title: strings.rename,
|
|
70
|
+
ariaLabel: strings.renameFile,
|
|
69
71
|
renderInlineUI: (context) => (
|
|
70
72
|
<RenameFile
|
|
71
73
|
initialValue={resolveCurrentName(context)}
|
|
@@ -78,5 +80,7 @@ export const renameFileOperation: TQueueItemOperation = {
|
|
|
78
80
|
onCancel={context.close}
|
|
79
81
|
/>
|
|
80
82
|
),
|
|
81
|
-
renderHidden: (context) =>
|
|
82
|
-
}
|
|
83
|
+
renderHidden: (context) => (
|
|
84
|
+
<RenameHiddenInput key={`rename${context.file.fileId}`} targetFilename={resolveCurrentName(context)} />
|
|
85
|
+
),
|
|
86
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useFileAttributes } from './useFileAttributes'
|
|
2
2
|
export { useImagePreview } from './useImagePreview'
|
|
3
|
+
export { useImageObjectUrl } from './useImageObjectUrl'
|
|
3
4
|
export { useOperationState } from './useOperationState'
|
|
4
5
|
export { useRequiredFormValidation } from './useRequiredFormValidation'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useImageObjectUrl = (file: File | undefined): string | null => {
|
|
4
|
+
const [entry, setEntry] = useState<{ file: File; url: string } | null>(null)
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!file?.type.startsWith('image/')) return
|
|
8
|
+
const url = URL.createObjectURL(file)
|
|
9
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
10
|
+
setEntry({ file, url })
|
|
11
|
+
return () => URL.revokeObjectURL(url)
|
|
12
|
+
}, [file])
|
|
13
|
+
|
|
14
|
+
return entry && entry.file === file ? entry.url : null
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import { TFileId, TQueueItemOperation } from '../types'
|
|
4
4
|
|
|
@@ -9,21 +9,14 @@ export const useOperationState = (queueItemOperations: TQueueItemOperation[]) =>
|
|
|
9
9
|
// the stored id would re-activate a freshly-added operation with the same id
|
|
10
10
|
// (e.g. an extension re-mounted). Drop any stale entries on list changes so the
|
|
11
11
|
// activation state can never refer to an operation that no longer exists.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else {
|
|
21
|
-
changed = true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return changed ? next : prev
|
|
25
|
-
})
|
|
26
|
-
}, [queueItemOperations])
|
|
12
|
+
const [prevOperations, setPrevOperations] = useState(queueItemOperations)
|
|
13
|
+
if (queueItemOperations !== prevOperations) {
|
|
14
|
+
setPrevOperations(queueItemOperations)
|
|
15
|
+
const validIds = new Set(queueItemOperations.map((op) => op.id))
|
|
16
|
+
const entries = Object.entries(activatedIds)
|
|
17
|
+
const kept = entries.filter(([, opId]) => validIds.has(opId))
|
|
18
|
+
if (kept.length !== entries.length) setActivatedIds(Object.fromEntries(kept))
|
|
19
|
+
}
|
|
27
20
|
|
|
28
21
|
const getActivated = useCallback(
|
|
29
22
|
(fileId: TFileId): TQueueItemOperation | undefined => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Re-export all hooks from the hooks folder
|
|
2
2
|
export { useFileAttributes } from './hooks/useFileAttributes'
|
|
3
3
|
export { useImagePreview } from './hooks/useImagePreview'
|
|
4
|
+
export { useImageObjectUrl } from './hooks/useImageObjectUrl'
|
|
4
5
|
export { useOperationState } from './hooks/useOperationState'
|
|
5
6
|
export { useRequiredFormValidation } from './hooks/useRequiredFormValidation'
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
TFileUploadStrategy,
|
|
8
8
|
TTransferProgress,
|
|
9
9
|
} from 'shared-types'
|
|
10
|
+
import type { TPktStrings } from 'shared-strings'
|
|
10
11
|
|
|
11
12
|
import { uuidish } from '../../utils/stringutils'
|
|
12
13
|
|
|
@@ -37,7 +38,12 @@ export class FileItem implements IFileItem {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/** Internal context used by queue item operations and hidden inputs. */
|
|
40
|
-
export type TPktFileUploadContext = {
|
|
41
|
+
export type TPktFileUploadContext = {
|
|
42
|
+
name?: string
|
|
43
|
+
multiple: boolean
|
|
44
|
+
id?: string
|
|
45
|
+
strings: TPktStrings['fileupload']
|
|
46
|
+
}
|
|
41
47
|
export const PktFileUploadContext = createContext<TPktFileUploadContext>({} as TPktFileUploadContext)
|
|
42
48
|
|
|
43
49
|
/** The value type for `PktFileUpload` (`value` / `defaultValue`). */
|
|
@@ -410,10 +410,16 @@ export const PktHeaderGlobal = forwardRef(
|
|
|
410
410
|
id={MENU_ID}
|
|
411
411
|
>
|
|
412
412
|
{localeData ? (
|
|
413
|
-
<PktHeaderMenu
|
|
413
|
+
<PktHeaderMenu
|
|
414
|
+
data={effectiveData}
|
|
415
|
+
locale={locale}
|
|
416
|
+
open
|
|
417
|
+
mobileBreakpoint={mobileBreakpoint}
|
|
418
|
+
strings={strings}
|
|
419
|
+
/>
|
|
414
420
|
) : (
|
|
415
421
|
<nav className="pkt-header-menu pkt-header-menu--open">
|
|
416
|
-
<p className="pkt-header-menu__error">
|
|
422
|
+
<p className="pkt-header-menu__error">{headerStrings.menuLoadError}</p>
|
|
417
423
|
</nav>
|
|
418
424
|
)}
|
|
419
425
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@testing-library/jest-dom'
|
|
2
2
|
|
|
3
|
-
import { fireEvent, render, screen } from '@testing-library/react'
|
|
3
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
4
4
|
import { resetPktStrings, setPktStrings } from 'shared-strings'
|
|
5
5
|
import { vi } from 'vitest'
|
|
6
6
|
|
|
@@ -134,7 +134,10 @@ describe('PktHeaderService', () => {
|
|
|
134
134
|
})
|
|
135
135
|
|
|
136
136
|
describe('strings', () => {
|
|
137
|
-
afterEach(() =>
|
|
137
|
+
afterEach(() => {
|
|
138
|
+
cleanup()
|
|
139
|
+
resetPktStrings()
|
|
140
|
+
})
|
|
138
141
|
|
|
139
142
|
it('labels the logo link from the string catalogue', () => {
|
|
140
143
|
const { container } = render(<PktHeaderService serviceName="Svc" />)
|