Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 21ac3ba

Browse files
committedMar 20, 2020
allow to customize image size and alignment on post editor
1 parent 78f0614 commit 21ac3ba

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed
 

‎src/components/ImageViewer.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { theme } from '@zoonk/utils';
2+
3+
interface ImageViewerProps {
4+
src?: string;
5+
height?: string;
6+
width?: string;
7+
align?: 'center' | 'left' | 'right';
8+
alt?: string;
9+
title?: string;
10+
}
11+
12+
const ImageViewer = ({
13+
src,
14+
height,
15+
width,
16+
align,
17+
alt,
18+
title,
19+
}: ImageViewerProps) => {
20+
const float = align === 'left' || align === 'right' ? align : 'none';
21+
22+
if (!src) return null;
23+
24+
return (
25+
<div style={{ float, textAlign: align, margin: theme.spacing(0, 1) }}>
26+
<img
27+
src={src}
28+
title={title}
29+
alt={alt}
30+
style={{ maxWidth: width || '100%', height: height || 'auto' }}
31+
/>
32+
</div>
33+
);
34+
};
35+
36+
export default ImageViewer;

‎src/components/PostForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const PostForm = ({
9090
// Append an image to the current content.
9191
const insertImage = useCallback(
9292
(url: string) => {
93-
const img = `![post](${url} "")`;
93+
const img = `[[ img src="${url}" align="center" alt="post" title="" ]]`;
9494
const newContent = `${content}\n${img}`;
9595
setContent(newContent);
9696
},

‎src/components/ShortcodeRenderer.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import dynamic from 'next/dynamic';
22

33
const GoogleDriveViewer = dynamic(() => import('./GoogleDriveViewer'));
4+
const ImageViewer = dynamic(() => import('./ImageViewer'));
45
const PDFViewer = dynamic(() => import('./PDFViewer'));
56
const VimeoPlayer = dynamic(() => import('./VimeoPlayer'));
67
const YoutubePlayer = dynamic(() => import('./YoutubePlayer'));
78

89
interface ShortcodeRendererProps {
9-
identifier: 'drive' | 'pdf' | 'vimeo' | 'youtube';
10-
attributes: {
11-
[key: string]: string;
12-
};
10+
identifier: 'drive' | 'img' | 'pdf' | 'vimeo' | 'youtube';
11+
attributes: any;
1312
}
1413

1514
/**
@@ -21,17 +20,17 @@ const ShortcodeRenderer = ({
2120
identifier,
2221
attributes,
2322
}: ShortcodeRendererProps) => {
24-
const { id, url } = attributes;
25-
2623
switch (identifier) {
2724
case 'drive':
28-
return <GoogleDriveViewer id={id} />;
25+
return <GoogleDriveViewer {...attributes} />;
26+
case 'img':
27+
return <ImageViewer {...attributes} />;
2928
case 'pdf':
30-
return <PDFViewer url={url} />;
29+
return <PDFViewer {...attributes} />;
3130
case 'vimeo':
32-
return <VimeoPlayer id={id} />;
31+
return <VimeoPlayer {...attributes} />;
3332
case 'youtube':
34-
return <YoutubePlayer id={id} />;
33+
return <YoutubePlayer {...attributes} />;
3534
default:
3635
return null;
3736
}

‎src/locale/en.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ const translate: TranslationFn = (key, args) => {
8282
formatting_drive: 'Google Drive',
8383
formatting_header_example: '# Title',
8484
formatting_header: 'Header',
85-
formatting_image_example: '![alt text](photo.png "photo title")',
85+
formatting_image_example:
86+
'[[ img src="photo.png" width="200px" height="200px" align="right" alt="text" title="title" ]]',
8687
formatting_image: 'Image',
8788
formatting_italic_example: '_italic text_',
8889
formatting_italic: 'Italic',

‎src/locale/pt.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ const translate: TranslationFn = (key, args) => {
8585
formatting_drive: 'Google Drive',
8686
formatting_header_example: '# Título',
8787
formatting_header: 'Cabeçalho',
88-
formatting_image_example: '![descrição](foto.png "título")',
88+
formatting_image_example:
89+
'[[ img src="foto.png" width="200px" align="right" alt="texto" title="título" ]]',
8990
formatting_image: 'Imagem',
9091
formatting_italic_example: '_texto em itálico_',
9192
formatting_italic: 'Itálico',

0 commit comments

Comments
 (0)
This repository has been archived.