@oslokommune/punkt-react 15.4.1 → 15.4.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "15.4.1",
3
+ "version": "15.4.2",
4
4
  "description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo Origo",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@lit-labs/ssr-dom-shim": "^1.2.1",
41
41
  "@lit/react": "^1.0.7",
42
- "@oslokommune/punkt-elements": "^15.4.0",
42
+ "@oslokommune/punkt-elements": "^15.4.2",
43
43
  "classnames": "^2.5.1",
44
44
  "prettier": "^3.3.3",
45
45
  "react-hook-form": "^7.53.0"
@@ -50,7 +50,7 @@
50
50
  "@eslint/eslintrc": "^3.3.3",
51
51
  "@eslint/js": "^9.37.0",
52
52
  "@oslokommune/punkt-assets": "^15.0.0",
53
- "@oslokommune/punkt-css": "^15.4.0",
53
+ "@oslokommune/punkt-css": "^15.4.2",
54
54
  "@testing-library/jest-dom": "^6.5.0",
55
55
  "@testing-library/react": "^16.0.1",
56
56
  "@testing-library/user-event": "^14.5.2",
@@ -109,5 +109,5 @@
109
109
  "url": "https://github.com/oslokommune/punkt/issues"
110
110
  },
111
111
  "license": "MIT",
112
- "gitHead": "38243fb5d8d7bef2cacf6ba5c79cb4ec4478edcf"
112
+ "gitHead": "1186b7601af17e09107f3f8e55410af0fea62248"
113
113
  }
@@ -208,9 +208,12 @@ export const ThumbnailRenderer = ({
208
208
  onPreviewClick?: () => void
209
209
  }) => {
210
210
  const [thumbnailUrl, setThumbnailUrl] = useState<string | null>(null)
211
+ const [thumbnailLoadFailed, setThumbnailLoadFailed] = useState(false)
211
212
  const file = transferItem.file
212
213
 
213
214
  useEffect(() => {
215
+ setThumbnailLoadFailed(false)
216
+
214
217
  // Check if the file is an image
215
218
  if (file.type.startsWith('image/')) {
216
219
  // Create an object URL for the file
@@ -222,16 +225,27 @@ export const ThumbnailRenderer = ({
222
225
  URL.revokeObjectURL(url)
223
226
  }
224
227
  }
228
+
229
+ setThumbnailUrl(null)
225
230
  }, [file])
226
231
 
227
- const img = (thumbnailUrl && <img src={thumbnailUrl} alt={transferItem.attributes['targetFilename']} />) || (
228
- <PktIcon name="document-text" className="pkt-fileupload__queue-display__item__icon pkt-icon--medium" />
229
- )
232
+ const img = (thumbnailUrl && !thumbnailLoadFailed && (
233
+ <img
234
+ src={thumbnailUrl}
235
+ alt={transferItem.attributes['targetFilename']}
236
+ onError={() => setThumbnailLoadFailed(true)}
237
+ />
238
+ )) || <PktIcon name="document-text" className="pkt-fileupload__queue-display__item__icon pkt-icon--medium" />
230
239
 
231
240
  const showExpandButton = !!onPreviewClick
241
+ const hasThumbnailPreview = !!thumbnailUrl && !thumbnailLoadFailed
232
242
 
233
243
  return (
234
- <div className="pkt-fileupload__queue-display__item__thumbnail">
244
+ <div
245
+ className={`pkt-fileupload__queue-display__item__thumbnail${
246
+ hasThumbnailPreview ? '' : ' pkt-fileupload__queue-display__item__thumbnail--fallback'
247
+ }`}
248
+ >
235
249
  <PktButton
236
250
  className="pkt-fileupload__queue-display__item__thumbnail__image-wrapper"
237
251
  aria-label={`Forhåndsvis bilde ${transferItem.attributes['targetFilename']}`}
@@ -268,10 +282,13 @@ interface IImagePreviewModal {
268
282
  export const ImagePreviewModal = forwardRef(
269
283
  ({ isOpen, images, currentIndex, onClose, onNavigate }: IImagePreviewModal, ref: ForwardedRef<HTMLDialogElement>) => {
270
284
  const [imageUrl, setImageUrl] = useState<string | null>(null)
285
+ const [imageLoadFailed, setImageLoadFailed] = useState(false)
271
286
  const currentImage = images[currentIndex]
272
287
  const hasMultipleImages = images.length > 1
273
288
 
274
289
  useEffect(() => {
290
+ setImageLoadFailed(false)
291
+
275
292
  if (currentImage && currentImage.file.type.startsWith('image/')) {
276
293
  const url = URL.createObjectURL(currentImage.file)
277
294
  setImageUrl(url)
@@ -328,12 +345,15 @@ export const ImagePreviewModal = forwardRef(
328
345
  )}
329
346
 
330
347
  <div className="pkt-fileupload__image-preview__content">
331
- {imageUrl && (
348
+ {imageUrl && !imageLoadFailed ? (
332
349
  <img
333
350
  src={imageUrl}
334
351
  alt={`${currentImage.attributes['targetFilename']} - ${currentIndex + 1} av ${images.length}`}
335
352
  className="pkt-fileupload__image-preview__image"
353
+ onError={() => setImageLoadFailed(true)}
336
354
  />
355
+ ) : (
356
+ <PktIcon name="picture" className="pkt-fileupload__queue-display__item__icon pkt-icon--medium" />
337
357
  )}
338
358
  </div>
339
359