-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fuselage): add message generic preview cover image (#863)
* refactor(fuselage): add external url to message generic preview image * refactor: add image preview variation * creating new component for imageLinkPreview * refactor: update tests and pass onError and alt * refactor; remove external link from image preview * refactor: add props spread * refactor: rename components * refactor: extend html and anchor attributes on preview title * removing unused props Co-authored-by: Hugo Costa <[email protected]> Co-authored-by: gabriellsh <[email protected]>
- Loading branch information
1 parent
b82cace
commit f1f19f0
Showing
8 changed files
with
136 additions
and
17 deletions.
There are no files selected for viewing
38 changes: 35 additions & 3 deletions
38
...s/fuselage/src/components/Message/MessageGenericPreview/MessageGenericPreview.stories.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...age/src/components/Message/MessageGenericPreview/MessageGenericPreviewCoverImage.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { MessageGenericPreviewCoverImage } from './MessageGenericPreviewCoverImage'; | ||
|
||
describe('MessageGenericPreviewCoverImage', () => { | ||
it('renders without crashing', () => { | ||
render(<MessageGenericPreviewCoverImage url='' width={200} height={200} />); | ||
}); | ||
|
||
it('should render div with background image', () => { | ||
render( | ||
<MessageGenericPreviewCoverImage url='test' width={200} height={200} /> | ||
); | ||
const previewImage = screen.getByTestId('preview-image'); | ||
|
||
expect(previewImage).toHaveStyle({ | ||
background: 'test', | ||
}); | ||
expect(previewImage).toHaveClass('rcx-message-generic-preview__preview'); | ||
expect(previewImage).not.toHaveClass( | ||
'rcx-message-generic-preview__preview--image' | ||
); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
...fuselage/src/components/Message/MessageGenericPreview/MessageGenericPreviewCoverImage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
|
||
import { prependClassName } from '../../../helpers/prependClassName'; | ||
|
||
type MessageGenericPreviewCoverImageProps = { | ||
url: string; | ||
width: number; | ||
height: number; | ||
className?: string; | ||
}; | ||
|
||
export const MessageGenericPreviewCoverImage = ({ | ||
url, | ||
width, | ||
height, | ||
className, | ||
...props | ||
}: MessageGenericPreviewCoverImageProps) => ( | ||
<div | ||
className={prependClassName( | ||
className, | ||
'rcx-message-generic-preview__preview' | ||
)} | ||
style={{ backgroundImage: `url(${url})`, maxWidth: '100%' }} | ||
data-testid='preview-image' | ||
{...props} | ||
> | ||
<div style={{ paddingTop: `${(height / width) * 100}%` }} /> | ||
</div> | ||
); |
18 changes: 18 additions & 0 deletions
18
...fuselage/src/components/Message/MessageGenericPreview/MessageGenericPreviewImage.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { MessageGenericPreviewImage } from './MessageGenericPreviewImage'; | ||
|
||
describe('MessageGenericPreviewImage', () => { | ||
it('renders without crashing', () => { | ||
render(<MessageGenericPreviewImage url='' />); | ||
}); | ||
|
||
it('should render image', () => { | ||
render(<MessageGenericPreviewImage url='test' />); | ||
const previewImage = screen.getByRole('img'); | ||
|
||
expect(previewImage).toBeInTheDocument(); | ||
expect(previewImage).toHaveAttribute('src', 'test'); | ||
}); | ||
}); |
25 changes: 14 additions & 11 deletions
25
...ages/fuselage/src/components/Message/MessageGenericPreview/MessageGenericPreviewImage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import type { ImgHTMLAttributes } from 'react'; | ||
import React from 'react'; | ||
|
||
import { prependClassName } from '../../../helpers/prependClassName'; | ||
|
||
type MessageGenericPreviewImageProps = { | ||
url: string; | ||
width: number; | ||
height: number; | ||
}; | ||
className?: string; | ||
} & ImgHTMLAttributes<HTMLImageElement>; | ||
|
||
export const MessageGenericPreviewImage = ({ | ||
url, | ||
width, | ||
height, | ||
className, | ||
...props | ||
}: MessageGenericPreviewImageProps) => ( | ||
<div | ||
className='rcx-message-generic-preview__preview' | ||
style={{ backgroundImage: `url(${url})`, maxWidth: '100%' }} | ||
<img | ||
src={url} | ||
className={prependClassName( | ||
className, | ||
'rcx-message-generic-preview__image' | ||
)} | ||
alt='' | ||
{...props} | ||
> | ||
<div style={{ paddingTop: `${(height / width) * 100}%` }} /> | ||
</div> | ||
/> | ||
); |
5 changes: 3 additions & 2 deletions
5
...ages/fuselage/src/components/Message/MessageGenericPreview/MessageGenericPreviewTitle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters