|
1 | | -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import ReactMarkdown from 'react-markdown'; |
3 | 3 | 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'; |
5 | 12 | import css from '@styled-system/css'; |
6 | 13 | import { Code } from './Code'; |
7 | 14 |
|
8 | 15 | export const Markdown = ({ source }) => { |
9 | 16 | const { state } = useOvermind(); |
| 17 | + const [modalOpen, setModalOpen] = useState(false); |
10 | 18 | const privateSandbox = |
11 | 19 | state.editor.currentSandbox.privacy === 1 || |
12 | 20 | state.editor.currentSandbox.privacy === 2; |
13 | 21 |
|
14 | 22 | const image = props => |
15 | 23 | 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} |
19 | 94 | css={css({ |
20 | | - maxWidth: '100%', |
| 95 | + backgroundColor: 'sideBar.border', |
21 | 96 | })} |
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> |
27 | 102 | ); |
28 | 103 |
|
29 | 104 | return ( |
|
0 commit comments