Skip to content

Commit 92c2c82

Browse files
authored
style forbidden images and add modal (codesandbox#3809)
1 parent 438e26a commit 92c2c82

File tree

1 file changed

+86
-11
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Dialog

1 file changed

+86
-11
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Dialog/Markdown.tsx

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,104 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import ReactMarkdown from 'react-markdown';
33
import { useOvermind } from 'app/overmind';
4-
import { Text, Element, Link } from '@codesandbox/components';
4+
import Modal from 'react-modal';
5+
import {
6+
Text,
7+
Element,
8+
Link,
9+
Button,
10+
IconButton,
11+
} from '@codesandbox/components';
512
import css from '@styled-system/css';
613
import { Code } from './Code';
714

815
export const Markdown = ({ source }) => {
916
const { state } = useOvermind();
17+
const [modalOpen, setModalOpen] = useState(false);
1018
const privateSandbox =
1119
state.editor.currentSandbox.privacy === 1 ||
1220
state.editor.currentSandbox.privacy === 2;
1321

1422
const image = props =>
1523
privateSandbox ? (
16-
<img
17-
{...props}
18-
alt={props.alt}
24+
<>
25+
<Button
26+
padding={0}
27+
margin={0}
28+
marginTop={2}
29+
variant="link"
30+
onClick={() => setModalOpen(true)}
31+
css={css({
32+
maxWidth: '100%',
33+
border: 'none',
34+
})}
35+
>
36+
<img
37+
{...props}
38+
alt={props.alt}
39+
css={css({
40+
maxWidth: '100%',
41+
borderRadius: 'small',
42+
})}
43+
/>
44+
</Button>
45+
<Modal
46+
isOpen={modalOpen}
47+
style={{
48+
content: {
49+
border: 'none',
50+
padding: 0,
51+
background: 'transparent',
52+
top: '50%',
53+
left: '50%',
54+
right: 'auto',
55+
bottom: 'auto',
56+
marginRight: '-50%',
57+
transform: 'translate(-50%, -50%)',
58+
},
59+
overlay: {
60+
zIndex: 10,
61+
backgroundColor: 'rgba(0, 0, 0, 0.4)',
62+
},
63+
}}
64+
contentLabel={props.alt}
65+
onRequestClose={() => setModalOpen(false)}
66+
>
67+
<IconButton
68+
name="cross"
69+
size={10}
70+
title="Close Modal"
71+
onClick={() => setModalOpen(false)}
72+
css={{
73+
position: 'absolute',
74+
right: 4,
75+
top: 4,
76+
color: 'white',
77+
}}
78+
/>
79+
<img
80+
{...props}
81+
alt={props.alt}
82+
css={css({
83+
maxWidth: '100%',
84+
borderRadius: 'small',
85+
maxHeight: '80vh',
86+
})}
87+
/>
88+
</Modal>
89+
</>
90+
) : (
91+
<Element
92+
paddingY={4}
93+
marginY={2}
1994
css={css({
20-
maxWidth: '100%',
95+
backgroundColor: 'sideBar.border',
2196
})}
22-
/>
23-
) : (
24-
<Text marginY={4} variant="muted" block align="center">
25-
You cannot use images in comments on public sandboxes.
26-
</Text>
97+
>
98+
<Text size={3} variant="muted" block align="center">
99+
Images are not shown in public sandboxes
100+
</Text>
101+
</Element>
27102
);
28103

29104
return (

0 commit comments

Comments
 (0)