Skip to content

Commit 7699d02

Browse files
fix(richtext-lexical): use thumbnail component for uploads (#12540)
### What? Fix the broken thumbnail for non-images for uploads in the richtext-lexical editor. **Before:** ![before](https://github.com/user-attachments/assets/dbe5ffb7-9032-435b-8684-3c8bf53ae5bd) **After:** ![after](https://github.com/user-attachments/assets/1c4af50e-2216-4ada-aff0-7a5e5559ac64) ### Why? As described in #6867, the thumbnail in the richtext-lexical editor is always trying to render an thumbnail image. This leads to a broken image as soon as a non-image is added. ### How? The fix was done by using the `<Thumbnail />` component from `@payloadcms/ui` Fixes #6867 --------- Co-authored-by: German Jablonski <43938777+GermanJablo@users.noreply.github.com>
1 parent b714e6b commit 7699d02

File tree

2 files changed

+13
-14
lines changed
  • packages
    • richtext-lexical/src/features/upload/client/component
    • ui/src/graphics/File

2 files changed

+13
-14
lines changed

packages/richtext-lexical/src/features/upload/client/component/index.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
55
import { getTranslation } from '@payloadcms/translations'
66
import {
77
Button,
8-
File,
98
formatDrawerSlug,
9+
Thumbnail,
1010
useConfig,
1111
useEditDepth,
1212
usePayloadAPI,
1313
useTranslation,
1414
} from '@payloadcms/ui'
1515
import { $getNodeByKey } from 'lexical'
16+
import { isImage } from 'payload/shared'
1617
import React, { useCallback, useId, useReducer, useRef, useState } from 'react'
1718

1819
import type { BaseClientFeatureProps } from '../../../typesClient.js'
@@ -142,18 +143,11 @@ const Component: React.FC<ElementProps> = (props) => {
142143
<div className={baseClass} contentEditable={false} ref={uploadRef}>
143144
<div className={`${baseClass}__card`}>
144145
<div className={`${baseClass}__topRow`}>
145-
{/* TODO: migrate to use @payloadcms/ui/elements/Thumbnail component */}
146146
<div className={`${baseClass}__thumbnail`}>
147-
{thumbnailSRC ? (
148-
<img
149-
alt={data?.filename}
150-
data-lexical-upload-id={value}
151-
data-lexical-upload-relation-to={relationTo}
152-
src={thumbnailSRC}
153-
/>
154-
) : (
155-
<File />
156-
)}
147+
<Thumbnail
148+
collectionSlug={relationTo}
149+
fileSrc={isImage(data?.mimeType) ? thumbnailSRC : null}
150+
/>
157151
</div>
158152
<div className={`${baseClass}__topRowRightPanel`}>
159153
<div className={`${baseClass}__collectionLabel`}>

packages/ui/src/graphics/File/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import React from 'react'
22

33
export const File: React.FC = () => (
4-
<svg height="150" viewBox="0 0 150 150" width="150" xmlns="http://www.w3.org/2000/svg">
5-
<rect fill="#333333" height="150" transform="translate(0 0.5)" width="150" />
4+
<svg
5+
height="150"
6+
style={{ backgroundColor: '#333333' }}
7+
viewBox="0 0 150 150"
8+
width="150"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
611
<path d="M82.8876 50.5H55.5555V100.5H94.4444V61.9818H82.8876V50.5Z" fill="white" />
712
<path d="M82.8876 61.9818H94.4444L82.8876 50.5V61.9818Z" fill="#9A9A9A" />
813
</svg>

0 commit comments

Comments
 (0)