Skip to content

Commit 5cde74a

Browse files
Merge pull request #32 from moveyourdigital/issue-23-implement-simple-image
Adds support to SimpleImage
2 parents 7cbc87a + 1928144 commit 5cde74a

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The package ships with the following renderers, but you can include your custom
5050
- Header
5151
- Paragraph
5252
- Image
53+
- SimpleImage
5354
- Embed
5455
- List
5556
- Table

src/renderers/image/__snapshots__/index.test.tsx.snap

+12
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ exports[`<Image /> when receives a Image block without actions renders a <figure
2828
</figcaption>
2929
</figure>
3030
`;
31+
32+
exports[`<Image /> when receives a SimpleImage block renders a <figure> block with <img> and <figcaption> 1`] = `
33+
<figure>
34+
<img
35+
alt="Deep in the universe"
36+
src="https://cdn.directions.pt/uploads/2020/08/681-2000x1300-2.jpg"
37+
/>
38+
<figcaption>
39+
Deep in the universe
40+
</figcaption>
41+
</figure>
42+
`;

src/renderers/image/index.test.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,18 @@ describe('<Image />', () => {
3636
expect(create(<Image data={data} />).toJSON()).toMatchSnapshot();
3737
});
3838
});
39+
40+
describe('when receives a SimpleImage block', () => {
41+
const data: ImageBlockData = {
42+
url: 'https://cdn.directions.pt/uploads/2020/08/681-2000x1300-2.jpg',
43+
caption: 'Deep in the universe',
44+
withBorder: false,
45+
stretched: false,
46+
withBackground: false,
47+
};
48+
49+
it('renders a <figure> block with <img> and <figcaption>', () => {
50+
expect(create(<Image data={data} />).toJSON()).toMatchSnapshot();
51+
});
52+
});
3953
});

src/renderers/image/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import HTMLReactParser from 'html-react-parser';
33
import { RenderFn } from '../..';
44

55
export interface ImageBlockData {
6-
file: {
6+
file?: {
77
url: string;
88
name?: string;
99
};
10+
url?: string
1011
caption: string;
1112
withBorder: boolean;
1213
withBackground: boolean;
@@ -50,6 +51,7 @@ const Image: RenderFn<ImageBlockData, ImageBlockConfig> = ({
5051
return (
5152
<figure {...figureprops}>
5253
{data?.file?.url && <img src={data.file.url} alt={data.caption || data.file.name} />}
54+
{data?.url && <img src={data.url} alt={data.caption} />}
5355
{data?.caption && <figcaption>{HTMLReactParser(data.caption)}</figcaption>}
5456
</figure>
5557
);

0 commit comments

Comments
 (0)