Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Attachments and OEmbed margins #25713

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ActionButton } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const AttachmentAction: FC<ComponentProps<typeof ActionButton> & { icon: string }> = (props) => (
<ActionButton mi='x2' mini ghost {...props} />
);

export default AttachmentAction;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const Author: FC<ComponentProps<typeof Box>> = (props) => (
const AttachmentAuthor: FC<ComponentProps<typeof Box>> = (props) => (
<Box display='flex' flexDirection='row' alignItems='center' mbe='x4' {...props} />
);

export default Author;
export default AttachmentAuthor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React, { ReactElement } from 'react';

import BaseAvatar from '../../../avatar/BaseAvatar';

const AttachmentAuthorAvatar = ({ url }: { url: string }): ReactElement => <BaseAvatar url={url} size='x24' />;

export default AttachmentAuthorAvatar;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const AttachmentAuthorName: FC<ComponentProps<typeof Box>> = (props) => <Box withTruncatedText fontScale='p2m' mi='x8' {...props} />;

export default AttachmentAuthorName;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import React, { FC } from 'react';

import Attachment from './Attachment';

const Block: FC<{ pre?: JSX.Element | string | undefined; color?: string | undefined }> = ({ pre, color = 'neutral-600', children }) => (
const AttachmentBlock: FC<{ pre?: JSX.Element | string | undefined; color?: string | undefined }> = ({
pre,
color = 'neutral-600',
children,
}) => (
<Attachment>
{pre}
<Box
Expand All @@ -19,4 +23,4 @@ const Block: FC<{ pre?: JSX.Element | string | undefined; color?: string | undef
</Attachment>
);

export default Block;
export default AttachmentBlock;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { ComponentProps, FC } from 'react';

import Action from './Action';
import Action from './AttachmentAction';

const Collapse: FC<Omit<ComponentProps<typeof Action>, 'icon'> & { collapsed?: boolean }> = ({ collapsed = false, ...props }) => {
const AttachmentCollapse: FC<Omit<ComponentProps<typeof Action>, 'icon'> & { collapsed?: boolean }> = ({ collapsed = false, ...props }) => {
const t = useTranslation();
return <Action title={collapsed ? t('Uncollapse') : t('Collapse')} icon={!collapsed ? 'chevron-down' : 'chevron-left'} {...props} />;
};

export default Collapse;
export default AttachmentCollapse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const AttachmentContent: FC<ComponentProps<typeof Box>> = ({ ...props }) => <Box rcx-attachment__content width='full' mb='x4' {...props} />;

export default AttachmentContent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, ReactElement } from 'react';

const AttachmentDescription = ({ ...props }: ComponentProps<typeof Box>): ReactElement => (
<Box rcx-attachment__description mbe='x4' {...props} />
);

export default AttachmentDescription;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box } from '@rocket.chat/fuselage';
import React, { FC, ComponentProps } from 'react';

const Details: FC<ComponentProps<typeof Box>> = ({ ...props }) => (
const AttachmentDetails: FC<ComponentProps<typeof Box>> = ({ ...props }) => (
<Box rcx-attachment__details fontScale='p2' color='info' bg='neutral-100' pi='x16' pb='x16' {...props} />
);

export default Details;
export default AttachmentDetails;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { ComponentProps, FC } from 'react';

import Action from './Action';
import Action from './AttachmentAction';

const Download: FC<Omit<ComponentProps<typeof Action>, 'icon'> & { title?: string | undefined; href: string }> = ({
const AttachmentDownload: FC<Omit<ComponentProps<typeof Action>, 'icon'> & { title?: string | undefined; href: string }> = ({
title,
href,
...props
Expand All @@ -23,4 +23,4 @@ const Download: FC<Omit<ComponentProps<typeof Action>, 'icon'> & { title?: strin
);
};

export default Download;
export default AttachmentDownload;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const AttachmentInner: FC<ComponentProps<typeof Box>> = ({ ...props }) => <Box {...props} />;

export default AttachmentInner;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box } from '@rocket.chat/fuselage';
import React, { FC, ComponentProps } from 'react';

const Row: FC<ComponentProps<typeof Box>> = (props) => (
const AttachmentRow: FC<ComponentProps<typeof Box>> = (props) => (
<Box mi='neg-x2' mbe='x2' rcx-message-attachment display='flex' alignItems='center' {...props} />
);

export default Row;
export default AttachmentRow;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

import { useFormatMemorySize } from '../../../../hooks/useFormatMemorySize';
import Title from './Title';
import Title from './AttachmentTitle';

const Size: FC<ComponentProps<typeof Box> & { size: number }> = ({ size, ...props }) => {
const AttachmentSize: FC<ComponentProps<typeof Box> & { size: number }> = ({ size, ...props }) => {
const format = useFormatMemorySize();
return (
<Title flexShrink={0} {...props}>
Expand All @@ -13,4 +13,4 @@ const Size: FC<ComponentProps<typeof Box> & { size: number }> = ({ size, ...prop
);
};

export default Size;
export default AttachmentSize;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const AttachmentText: FC<ComponentProps<typeof Box>> = (props) => <Box mbe='x4' mi='x2' fontScale='p2' color='default' {...props}></Box>;

export default AttachmentText;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Box, Avatar } from '@rocket.chat/fuselage';
import React, { FC, memo } from 'react';

const Thumb: FC<{ url: string }> = ({ url }) => (
const AttachmentThumb: FC<{ url: string }> = ({ url }) => (
<Box mis='x8'>
<Avatar {...({ url, size: 'x48' } as any)} />
</Box>
);

export default memo(Thumb);
export default memo(AttachmentThumb);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ComponentProps, FC } from 'react';

const AttachmentTitle: FC<ComponentProps<typeof Box>> = (props) => (
<Box withTruncatedText mi='x2' fontScale='c1' color='hint' {...props}></Box>
);

export default AttachmentTitle;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { FC } from 'react';

import Title from './Title';
import Title from './AttachmentTitle';

const TitleLink: FC<{ link: string; title?: string | undefined }> = ({ link, title }) => (
const AttachmentTitleLink: FC<{ link: string; title?: string | undefined }> = ({ link, title }) => (
<Title is='a' href={`${link}?download`} color={undefined} target='_blank' download={title} rel='noopener noreferrer'>
{title}
</Title>
);

export default TitleLink;
export default AttachmentTitleLink;

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
import Image from '../components/Image';
import Attachment from './Attachment';
import Author from './Author';
import AuthorAvatar from './AuthorAvatar';
import AuthorName from './AuthorName';
import Block from './Block';
import Collapse from './Collapse';
import Content from './Content';
import Details from './Details';
import Download from './Download';
import Inner from './Inner';
import Row from './Row';
import Size from './Size';
import Text from './Text';
import Thumb from './Thumb';
import Title from './Title';
import TitleLink from './TitleLink';

export default Object.assign(Attachment, {
Image,
Row,
Title,
Text,
TitleLink,
Size,
Thumb,
Collapse,
Download,
Content,
Details,
Inner,
Block,
Author,
AuthorAvatar,
AuthorName,
});
export default Attachment;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import React, { FC, ReactNode, ComponentProps } from 'react';

import MarkdownText from '../../MarkdownText';
import { ActionAttachment } from './ActionAttachtment';
import Attachment from './Attachment';
import AttachmentAuthor from './Attachment/AttachmentAuthor';
import AttachmentAuthorAvatar from './Attachment/AttachmentAuthorAvatar';
import AttachmentAuthorName from './Attachment/AttachmentAuthorName';
import AttachmentBlock from './Attachment/AttachmentBlock';
import AttachmentContent from './Attachment/AttachmentContent';
import AttachmentRow from './Attachment/AttachmentRow';
import AttachmentText from './Attachment/AttachmentText';
import AttachmentThumb from './Attachment/AttachmentThumb';
import AttachmentTitle from './Attachment/AttachmentTitle';
import FieldsAttachment from './FieldsAttachment';
import AttachmentImage from './components/Image';
import { useCollapse } from './hooks/useCollapse';

const applyMarkdownIfRequires = (
Expand All @@ -18,19 +27,19 @@ const DefaultAttachment: FC<MessageAttachmentDefault> = (attachment) => {
const [collapsed, collapse] = useCollapse(!!attachment.collapsed);

return (
<Attachment.Block
<AttachmentBlock
color={attachment.color}
pre={
attachment.pretext && (
<Attachment.Text>{applyMarkdownIfRequires(attachment.mrkdwn_in, 'pretext', attachment.pretext)}</Attachment.Text>
<AttachmentText>{applyMarkdownIfRequires(attachment.mrkdwn_in, 'pretext', attachment.pretext)}</AttachmentText>
)
}
>
<Attachment.Content>
<AttachmentContent>
{attachment.author_name && (
<Attachment.Author>
{attachment.author_icon && <Attachment.AuthorAvatar url={attachment.author_icon} />}
<Attachment.AuthorName
<AttachmentAuthor>
{attachment.author_icon && <AttachmentAuthorAvatar url={attachment.author_icon} />}
<AttachmentAuthorName
{...(attachment.author_link && {
is: 'a',
href: attachment.author_link,
Expand All @@ -39,12 +48,12 @@ const DefaultAttachment: FC<MessageAttachmentDefault> = (attachment) => {
})}
>
{attachment.author_name}
</Attachment.AuthorName>
</Attachment.Author>
</AttachmentAuthorName>
</AttachmentAuthor>
)}
{attachment.title && (
<Attachment.Row>
<Attachment.Title
<AttachmentRow>
<AttachmentTitle
{...(attachment.title_link && {
is: 'a',
href: attachment.title_link,
Expand All @@ -53,14 +62,14 @@ const DefaultAttachment: FC<MessageAttachmentDefault> = (attachment) => {
})}
>
{attachment.title}
</Attachment.Title>{' '}
</AttachmentTitle>{' '}
{collapse}
</Attachment.Row>
</AttachmentRow>
)}
{!collapsed && (
<>
{attachment.text && (
<Attachment.Text>{applyMarkdownIfRequires(attachment.mrkdwn_in, 'text', attachment.text, 'document')}</Attachment.Text>
<AttachmentText>{applyMarkdownIfRequires(attachment.mrkdwn_in, 'text', attachment.text, 'document')}</AttachmentText>
)}
{/* {attachment.fields && <FieldsAttachment fields={attachment.mrkdwn_in?.includes('fields') ? attachment.fields.map(({ value, ...rest }) => ({ ...rest, value: <MarkdownText withRichContent={null} content={value} /> })) : attachment.fields} />} */}
{attachment.fields && (
Expand All @@ -80,14 +89,14 @@ const DefaultAttachment: FC<MessageAttachmentDefault> = (attachment) => {
})}
/>
)}
{attachment.image_url && <Attachment.Image {...(attachment.image_dimensions as any)} src={attachment.image_url} />}
{attachment.image_url && <AttachmentImage {...(attachment.image_dimensions as any)} src={attachment.image_url} />}
{/* DEPRECATED */}
{isActionAttachment(attachment) && <ActionAttachment {...attachment} />}
</>
)}
</Attachment.Content>
{attachment.thumb_url && <Attachment.Thumb url={attachment.thumb_url} />}
</Attachment.Block>
</AttachmentContent>
{attachment.thumb_url && <AttachmentThumb url={attachment.thumb_url} />}
</AttachmentBlock>
);
};

Expand Down
Loading