From 653e885266d58875ed755dfd4bea6d7d02b6e6c6 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Wed, 27 Apr 2022 16:43:03 -0700 Subject: [PATCH] Fix collapsed corners for link previews and image attachments Co-authored-by: Scott Nonnenberg --- stylesheets/_modules.scss | 22 +-- ts/components/conversation/AttachmentList.tsx | 7 +- ts/components/conversation/Image.stories.tsx | 40 ++-- ts/components/conversation/Image.tsx | 68 +++---- .../conversation/ImageGrid.stories.tsx | 1 + ts/components/conversation/ImageGrid.tsx | 83 +++++++- .../conversation/Message.stories.tsx | 187 ++++++++++-------- ts/components/conversation/Message.tsx | 26 ++- .../conversation/StagedLinkPreview.tsx | 7 +- 9 files changed, 260 insertions(+), 181 deletions(-) diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index a9003c1c6..b48528051 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -779,7 +779,7 @@ width: calc(100% + 24px); outline: none; - margin-top: -10px; + margin-top: -8px; margin-bottom: 5px; overflow: hidden; @@ -2589,30 +2589,10 @@ button.ConversationDetails__action-button { left: 6px; } -.module-image--soft-corners { - border-radius: 4px; -} - .module-image--cropped { overflow: hidden; } -.module-image--curved-top-left { - border-top-left-radius: 18px; -} -.module-image--curved-top-right { - border-top-right-radius: 18px; -} -.module-image--curved-bottom-left { - border-bottom-left-radius: 18px; -} -.module-image--curved-bottom-right { - border-bottom-right-radius: 18px; -} -.module-image--small-curved-top-left { - border-top-left-radius: 10px; -} - .module-image__border-overlay { @include button-reset; diff --git a/ts/components/conversation/AttachmentList.tsx b/ts/components/conversation/AttachmentList.tsx index a39d399e5..3d18c5aaf 100644 --- a/ts/components/conversation/AttachmentList.tsx +++ b/ts/components/conversation/AttachmentList.tsx @@ -3,7 +3,7 @@ import React from 'react'; -import { Image } from './Image'; +import { CurveType, Image } from './Image'; import { StagedGenericAttachment } from './StagedGenericAttachment'; import { StagedPlaceholderAttachment } from './StagedPlaceholderAttachment'; import type { LocalizerType } from '../../types/Util'; @@ -109,7 +109,10 @@ export const AttachmentList = ({ i18n={i18n} attachment={attachment} isDownloaded={isDownloaded} - softCorners + curveBottomLeft={CurveType.Tiny} + curveBottomRight={CurveType.Tiny} + curveTopLeft={CurveType.Tiny} + curveTopRight={CurveType.Tiny} playIconOverlay={isVideo} height={IMAGE_HEIGHT} width={IMAGE_WIDTH} diff --git a/ts/components/conversation/Image.stories.tsx b/ts/components/conversation/Image.stories.tsx index 3b425598f..1fcad17ba 100644 --- a/ts/components/conversation/Image.stories.tsx +++ b/ts/components/conversation/Image.stories.tsx @@ -9,7 +9,7 @@ import { storiesOf } from '@storybook/react'; import { pngUrl } from '../../storybook/Fixtures'; import type { Props } from './Image'; -import { Image } from './Image'; +import { CurveType, Image } from './Image'; import { IMAGE_PNG } from '../../types/MIME'; import type { ThemeType } from '../../types/Util'; import { setupI18n } from '../../util/setupI18n'; @@ -34,16 +34,22 @@ const createProps = (overrideProps: Partial = {}): Props => ({ blurHash: text('blurHash', overrideProps.blurHash || ''), bottomOverlay: boolean('bottomOverlay', overrideProps.bottomOverlay || false), closeButton: boolean('closeButton', overrideProps.closeButton || false), - curveBottomLeft: boolean( + curveBottomLeft: number( 'curveBottomLeft', - overrideProps.curveBottomLeft || false + overrideProps.curveBottomLeft || CurveType.None ), - curveBottomRight: boolean( + curveBottomRight: number( 'curveBottomRight', - overrideProps.curveBottomRight || false + overrideProps.curveBottomRight || CurveType.None + ), + curveTopLeft: number( + 'curveTopLeft', + overrideProps.curveTopLeft || CurveType.None + ), + curveTopRight: number( + 'curveTopRight', + overrideProps.curveTopRight || CurveType.None ), - curveTopLeft: boolean('curveTopLeft', overrideProps.curveTopLeft || false), - curveTopRight: boolean('curveTopRight', overrideProps.curveTopRight || false), darkOverlay: boolean('darkOverlay', overrideProps.darkOverlay || false), height: number('height', overrideProps.height || 100), i18n, @@ -57,11 +63,6 @@ const createProps = (overrideProps: Partial = {}): Props => ({ 'playIconOverlay', overrideProps.playIconOverlay || false ), - smallCurveTopLeft: boolean( - 'smallCurveTopLeft', - overrideProps.smallCurveTopLeft || false - ), - softCorners: boolean('softCorners', overrideProps.softCorners || false), tabIndex: number('tabIndex', overrideProps.tabIndex || 0), theme: text('theme', overrideProps.theme || 'light') as ThemeType, url: text('url', 'url' in overrideProps ? overrideProps.url || null : pngUrl), @@ -145,10 +146,10 @@ story.add('Pending w/blurhash', () => { story.add('Curved Corners', () => { const props = createProps({ - curveBottomLeft: true, - curveBottomRight: true, - curveTopLeft: true, - curveTopRight: true, + curveBottomLeft: CurveType.Normal, + curveBottomRight: CurveType.Normal, + curveTopLeft: CurveType.Normal, + curveTopRight: CurveType.Normal, }); return ; @@ -156,7 +157,7 @@ story.add('Curved Corners', () => { story.add('Small Curve Top Left', () => { const props = createProps({ - smallCurveTopLeft: true, + curveTopLeft: CurveType.Small, }); return ; @@ -164,7 +165,10 @@ story.add('Small Curve Top Left', () => { story.add('Soft Corners', () => { const props = createProps({ - softCorners: true, + curveBottomLeft: CurveType.Tiny, + curveBottomRight: CurveType.Tiny, + curveTopLeft: CurveType.Tiny, + curveTopRight: CurveType.Tiny, }); return ; diff --git a/ts/components/conversation/Image.tsx b/ts/components/conversation/Image.tsx index 0d62045d0..b1dfe9b9a 100644 --- a/ts/components/conversation/Image.tsx +++ b/ts/components/conversation/Image.tsx @@ -13,6 +13,13 @@ import { defaultBlurHash, } from '../../types/Attachment'; +export enum CurveType { + None = 0, + Tiny = 4, + Small = 10, + Normal = 18, +} + export type Props = { alt: string; attachment: AttachmentType; @@ -32,16 +39,13 @@ export type Props = { noBackground?: boolean; bottomOverlay?: boolean; closeButton?: boolean; - curveBottomLeft?: boolean; - curveBottomRight?: boolean; - curveTopLeft?: boolean; - curveTopRight?: boolean; - - smallCurveTopLeft?: boolean; + curveBottomLeft?: CurveType; + curveBottomRight?: CurveType; + curveTopLeft?: CurveType; + curveTopRight?: CurveType; darkOverlay?: boolean; playIconOverlay?: boolean; - softCorners?: boolean; blurHash?: string; i18n: LocalizerType; @@ -158,8 +162,6 @@ export class Image extends React.Component { onError, overlayText, playIconOverlay, - smallCurveTopLeft, - softCorners, tabIndex, theme, url, @@ -176,25 +178,25 @@ export class Image extends React.Component { const resolvedBlurHash = blurHash || defaultBlurHash(theme); - const overlayClassName = classNames('module-image__border-overlay', { - 'module-image__border-overlay--with-border': !noBorder, - 'module-image__border-overlay--with-click-handler': canClick, - 'module-image--curved-top-left': curveTopLeft, - 'module-image--curved-top-right': curveTopRight, - 'module-image--curved-bottom-left': curveBottomLeft, - 'module-image--curved-bottom-right': curveBottomRight, - 'module-image--small-curved-top-left': smallCurveTopLeft, - 'module-image--soft-corners': softCorners, - 'module-image__border-overlay--dark': darkOverlay, - 'module-image--not-downloaded': imgNotDownloaded, - }); + const curveStyles = { + borderTopLeftRadius: curveTopLeft || CurveType.None, + borderTopRightRadius: curveTopRight || CurveType.None, + borderBottomLeftRadius: curveBottomLeft || CurveType.None, + borderBottomRightRadius: curveBottomRight || CurveType.None, + }; const overlay = canClick ? ( // Not sure what this button does. // eslint-disable-next-line jsx-a11y/control-has-associated-label