|
| 1 | +import { |
| 2 | + MessageGenericPreview, |
| 3 | + MessageGenericPreviewContent, |
| 4 | + MessageGenericPreviewDescription, |
| 5 | + MessageGenericPreviewImage, |
| 6 | + MessageGenericPreviewTitle, |
| 7 | + MessageGenericPreviewFooter, |
| 8 | + MessageGenericPreviewThumb, |
| 9 | + Box, |
| 10 | +} from '@rocket.chat/fuselage'; |
| 11 | +import * as UiKit from '@rocket.chat/ui-kit'; |
| 12 | +import { |
| 13 | + isPreviewBlockWithThumb, |
| 14 | + isPreviewBlockWithPreview, |
| 15 | +} from '@rocket.chat/ui-kit'; |
| 16 | +import React, { memo, ReactElement } from 'react'; |
| 17 | + |
| 18 | +import { BlockProps } from '../utils/BlockProps'; |
| 19 | +import ContextBlock from './ContextBlock'; |
| 20 | + |
| 21 | +type PreviewBlockProps = BlockProps<UiKit.PreviewBlock>; |
| 22 | + |
| 23 | +const PreviewBlock = ({ |
| 24 | + block, |
| 25 | + surfaceRenderer, |
| 26 | +}: PreviewBlockProps): ReactElement => ( |
| 27 | + <Box> |
| 28 | + <MessageGenericPreview> |
| 29 | + {isPreviewBlockWithPreview(block) && block.preview?.dimensions && ( |
| 30 | + <MessageGenericPreviewImage |
| 31 | + width={block.preview.dimensions.width} |
| 32 | + height={block.preview.dimensions.height} |
| 33 | + url={block.preview.url} |
| 34 | + /> |
| 35 | + )} |
| 36 | + <MessageGenericPreviewContent |
| 37 | + thumb={ |
| 38 | + isPreviewBlockWithThumb(block) ? ( |
| 39 | + <MessageGenericPreviewThumb> |
| 40 | + <MessageGenericPreviewImage |
| 41 | + height={192} |
| 42 | + width={368} |
| 43 | + url={block.thumb.url} |
| 44 | + /> |
| 45 | + </MessageGenericPreviewThumb> |
| 46 | + ) : undefined |
| 47 | + } |
| 48 | + > |
| 49 | + {Array.isArray(block.title) ? ( |
| 50 | + <MessageGenericPreviewTitle |
| 51 | + externalUrl={ |
| 52 | + isPreviewBlockWithPreview(block) ? block.externalUrl : undefined |
| 53 | + } |
| 54 | + > |
| 55 | + {block.title.map((title) => |
| 56 | + surfaceRenderer.renderTextObject( |
| 57 | + title, |
| 58 | + 0, |
| 59 | + UiKit.BlockContext.NONE |
| 60 | + ) |
| 61 | + )} |
| 62 | + </MessageGenericPreviewTitle> |
| 63 | + ) : null} |
| 64 | + {Array.isArray(block.description) ? ( |
| 65 | + <MessageGenericPreviewDescription clamp> |
| 66 | + {block.description.map((description) => |
| 67 | + surfaceRenderer.renderTextObject( |
| 68 | + description, |
| 69 | + 0, |
| 70 | + UiKit.BlockContext.NONE |
| 71 | + ) |
| 72 | + )} |
| 73 | + </MessageGenericPreviewDescription> |
| 74 | + ) : null} |
| 75 | + {block.footer && ( |
| 76 | + <MessageGenericPreviewFooter> |
| 77 | + <ContextBlock |
| 78 | + block={block.footer} |
| 79 | + surfaceRenderer={surfaceRenderer} |
| 80 | + context={UiKit.BlockContext.BLOCK} |
| 81 | + index={0} |
| 82 | + /> |
| 83 | + </MessageGenericPreviewFooter> |
| 84 | + )} |
| 85 | + </MessageGenericPreviewContent> |
| 86 | + </MessageGenericPreview> |
| 87 | + </Box> |
| 88 | +); |
| 89 | + |
| 90 | +export default memo(PreviewBlock); |
0 commit comments