From 9fe12a7f31fd6f9991636cade360c50b8d3a3493 Mon Sep 17 00:00:00 2001 From: Zishan Ahmad Date: Tue, 27 Feb 2024 16:03:58 +0530 Subject: [PATCH] added MessageGenericPreview component added PreviewBlock fixed link visibility styling remaining --- .../components/Markup/elements/BoldSpan.js | 13 +++ .../MessageGenericPreview.js | 28 ++++++ .../MessageGenericPreviewContent.js | 32 +++++++ .../MessageGenericPreviewCoverImage.js | 34 ++++++++ .../MessageGenericPreviewDescription.js | 28 ++++++ .../MessageGenericPreviewFooter.js | 25 ++++++ .../MessageGenericPreviewThumb.js | 17 ++++ .../MessageGenericPreviewTitle.js | 40 +++++++++ .../components/MessageGenericPreview/index.js | 7 ++ .../components/uiKit/blocks/PreviewBlock.js | 85 +++++++++++++++++++ .../uiKit/surfaces/FuselageSurfaceRenderer.js | 22 +++-- 11 files changed, 319 insertions(+), 12 deletions(-) create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreview.js create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreviewContent.js create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreviewCoverImage.js create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreviewDescription.js create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreviewFooter.js create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreviewThumb.js create mode 100644 packages/react/src/components/MessageGenericPreview/MessageGenericPreviewTitle.js create mode 100644 packages/react/src/components/MessageGenericPreview/index.js diff --git a/packages/react/src/components/Markup/elements/BoldSpan.js b/packages/react/src/components/Markup/elements/BoldSpan.js index a921fba6a..36f1ee945 100644 --- a/packages/react/src/components/Markup/elements/BoldSpan.js +++ b/packages/react/src/components/Markup/elements/BoldSpan.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import PlainSpan from './PlainSpan'; import ItalicSpan from './ItalicSpan'; import StrikeSpan from './StrikeSpan'; +import LinkSpan from './LinkSpan'; const BoldSpan = ({ contents }) => ( @@ -16,6 +17,18 @@ const BoldSpan = ({ contents }) => ( case 'ITALIC': return ; + case 'LINK': + return ( + + ); default: return null; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreview.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreview.js new file mode 100644 index 000000000..7e100dd9f --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreview.js @@ -0,0 +1,28 @@ +import React from 'react'; +import { css } from '@emotion/react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreview = (props, className = '', style = {}) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreview' + ); + const messageGenericPreviewStyles = css` + display: flex; + overflow: hidden; + flex-direction: column; + padding: 0.75rem; + border: 1px solid #ccc; + border-radius: 5px; + background-color: #cbced1; + `; + return ( +
+ ); +}; + +export default MessageGenericPreview; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewContent.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewContent.js new file mode 100644 index 000000000..67d780a3a --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewContent.js @@ -0,0 +1,32 @@ +import React from 'react'; +import { css } from '@emotion/react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreviewContent = ({ + className = '', + style = {}, + thumb, + ...props +}) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreviewContent' + ); + + const MessageGenericPreviewContentCss = css` + display: flex; + flex-direction: row; + `; + + return ( +
+ {thumb} +
+
+ ); +}; + +export default MessageGenericPreviewContent; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewCoverImage.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewCoverImage.js new file mode 100644 index 000000000..d0e1fe5f6 --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewCoverImage.js @@ -0,0 +1,34 @@ +import React from 'react'; +import { css } from '@emotion/react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreviewCoverImage = ({ + className = '', + style = {}, + url, + width, + height, + ...props +}) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreviewCoverImage' + ); + + const previewCoverImageCss = css` + background-image: url(${url}); + max-width: 100%; + `; + + return ( +
+
+
+ ); +}; + +export default MessageGenericPreviewCoverImage; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewDescription.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewDescription.js new file mode 100644 index 000000000..6725848bf --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewDescription.js @@ -0,0 +1,28 @@ +import React from 'react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreviewDescription = ({ + children, + clamp = false, + className = '', + style = {}, + ...props +}) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreviewDescription' + ); + + return ( +
+ {children} +
+ ); +}; + +export default MessageGenericPreviewDescription; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewFooter.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewFooter.js new file mode 100644 index 000000000..79dc2c890 --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewFooter.js @@ -0,0 +1,25 @@ +import React from 'react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreviewFooter = ({ + children, + className = '', + style = {}, + ...props +}) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreviewFooter' + ); + + return ( +
+ {children} +
+ ); +}; + +export default MessageGenericPreviewFooter; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewThumb.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewThumb.js new file mode 100644 index 000000000..66a8b1cf4 --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewThumb.js @@ -0,0 +1,17 @@ +import React from 'react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreviewThumb = (className = '', style = {}, ...props) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreviewThumb' + ); + return ( +
+ ); +}; + +export default MessageGenericPreviewThumb; diff --git a/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewTitle.js b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewTitle.js new file mode 100644 index 000000000..c2980037e --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/MessageGenericPreviewTitle.js @@ -0,0 +1,40 @@ +import React from 'react'; +import useComponentOverrides from '../../theme/useComponentOverrides'; + +const MessageGenericPreviewTitle = ({ + externalUrl, + children, + className = '', + style = {}, + ...props +}) => { + const { classNames, styleOverrides } = useComponentOverrides( + 'MessageGenericPreviewTitle' + ); + + if (externalUrl) { + return ( + + {children} + + ); + } + return ( + + {children} + + ); +}; + +export default MessageGenericPreviewTitle; diff --git a/packages/react/src/components/MessageGenericPreview/index.js b/packages/react/src/components/MessageGenericPreview/index.js new file mode 100644 index 000000000..07df81c7c --- /dev/null +++ b/packages/react/src/components/MessageGenericPreview/index.js @@ -0,0 +1,7 @@ +export { default as MessageGenericPreview } from './MessageGenericPreview'; +export { default as MessageGenericPreviewCoverImage } from './MessageGenericPreviewCoverImage'; +export { default as MessageGenericPreviewThumb } from './MessageGenericPreviewThumb'; +export { default as MessageGenericPreviewTitle } from './MessageGenericPreviewTitle'; +export { default as MessageGenericPreviewContent } from './MessageGenericPreviewContent'; +export { default as MessageGenericPreviewDescription } from './MessageGenericPreviewDescription'; +export { default as MessageGenericPreviewFooter } from './MessageGenericPreviewFooter'; diff --git a/packages/react/src/components/uiKit/blocks/PreviewBlock.js b/packages/react/src/components/uiKit/blocks/PreviewBlock.js index 07329cfc0..c7878b390 100644 --- a/packages/react/src/components/uiKit/blocks/PreviewBlock.js +++ b/packages/react/src/components/uiKit/blocks/PreviewBlock.js @@ -1,3 +1,88 @@ +import * as UiKit from '@rocket.chat/ui-kit'; +import { + isPreviewBlockWithThumb, + isPreviewBlockWithPreview, +} from '@rocket.chat/ui-kit'; +import React, { memo } from 'react'; +import { Box } from '../../Box'; +import { + MessageGenericPreviewCoverImage, + MessageGenericPreview, + MessageGenericPreviewThumb, + MessageGenericPreviewContent, + MessageGenericPreviewTitle, + MessageGenericPreviewDescription, + MessageGenericPreviewFooter, +} from '../../MessageGenericPreview'; + +import ContextBlock from './ContextBlock'; + +const PreviewBlock = ({ block, surfaceRenderer }) => ( + + + {isPreviewBlockWithPreview(block) && block.preview?.dimensions && ( + + )} + + + + ) : undefined + } + > + {Array.isArray(block.title) ? ( + + {block.title.map((title, index) => + surfaceRenderer.renderTextObject( + title, + index, + UiKit.BlockContext.NONE + ) + )} + + ) : null} + {Array.isArray(block.description) ? ( + + {block.description.map((description) => + surfaceRenderer.renderTextObject( + description, + 0, + UiKit.BlockContext.NONE + ) + )} + + ) : null} + {block.footer && ( + + + + )} + + + +); + +export default memo(PreviewBlock); + // import { // MessageGenericPreview, // MessageGenericPreviewContent, diff --git a/packages/react/src/components/uiKit/surfaces/FuselageSurfaceRenderer.js b/packages/react/src/components/uiKit/surfaces/FuselageSurfaceRenderer.js index bb08b0f88..a301ba51a 100644 --- a/packages/react/src/components/uiKit/surfaces/FuselageSurfaceRenderer.js +++ b/packages/react/src/components/uiKit/surfaces/FuselageSurfaceRenderer.js @@ -6,7 +6,7 @@ import ContextBlock from '../blocks/ContextBlock'; import DividerBlock from '../blocks/DividerBlock'; import ImageBlock from '../blocks/ImageBlock'; import InputBlock from '../blocks/InputBlock'; -// import PreviewBlock from '../blocks/PreviewBlock'; +import PreviewBlock from '../blocks/PreviewBlock'; import SectionBlock from '../blocks/SectionBlock'; import ButtonElement from '../elements/ButtonElement'; import DatePickerElement from '../elements/DatePickerElement'; @@ -79,18 +79,16 @@ export class FuselageSurfaceRenderer extends UiKit.SurfaceRenderer { if (context !== UiKit.BlockContext.BLOCK) { return null; } - return null; - // TODO: Implement this without fuselage. - // return ( - // - // ); + return ( + + ); } context(block, context, index) {