Skip to content

Commit f5e5e21

Browse files
authored
Merge pull request #7 from aromalanil/fullscreen-support
🌊 Added Fullscreen support
2 parents 229666e + cb79d62 commit f5e5e21

File tree

5 files changed

+109
-38
lines changed

5 files changed

+109
-38
lines changed

package-lock.json

+22-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "markdown-editor",
3-
"version": "1.8.1",
3+
"version": "1.9.1",
44
"description": "A react app to preview and edit Markdown",
55
"private": true,
66
"author": {
@@ -20,6 +20,8 @@
2020
"prismjs": "^1.21.0",
2121
"react": "^16.13.1",
2222
"react-dom": "^16.13.1",
23+
"react-full-screen": "^0.3.1",
24+
"react-icons": "^3.11.0",
2325
"react-scripts": "3.4.1",
2426
"react-split": "^2.0.7"
2527
},

src/App.scss

+25-6
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@ body {
4040
width: 0%;
4141
}
4242

43-
.btn {
43+
.btn{
44+
display:flex;
45+
align-items: center;
46+
justify-content: center;
4447
cursor: pointer;
45-
font-size: 0.9rem;
46-
padding: 0.4rem 1rem;
47-
font-weight: 600;
48-
border-radius: 0.2rem;
48+
font-size: 1.1rem;
49+
border-radius: 0.3rem;
50+
display: inline-block;
4951
color: var(--nav-item-color);
5052
background-color: var(--primary-color);
5153
transition: color, background-color var(--color-transition);
5254
border: none;
5355
transition: filter 200ms ease;
5456
margin: 0 0.5rem;
57+
padding:0.4rem .4rem .15rem;
5558
&:hover {
5659
filter: brightness(1.1);
5760
}
@@ -238,10 +241,19 @@ body {
238241
.html-div {
239242
background-color: var(--body-color);
240243
transition: background-color var(--color-transition);
241-
margin-top: 2rem;
242244
overflow-y: scroll;
245+
max-height: 100%;
246+
}
247+
.preview-fullscreen {
248+
padding: 1rem;
249+
margin-top: 0;
243250
}
244251
}
252+
.fullscreen {
253+
max-height: 100%;
254+
margin-top: 2rem;
255+
padding-bottom: 1rem;
256+
}
245257

246258
.gutter {
247259
height: 100% !important;
@@ -373,6 +385,13 @@ body {
373385
flex-direction: column;
374386
position: relative;
375387
}
388+
.fullscreen {
389+
margin-top: 0;
390+
padding-bottom: 0;
391+
}
392+
#preview {
393+
padding-top: 2rem;
394+
}
376395
.gutter {
377396
height: 10px !important;
378397
width: 100% !important;

src/components/MarkdownEdit.jsx

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import React, { useEffect, useState,useRef } from "react";
1+
import React, { useEffect, useState, useRef } from "react";
22
import Snackbar from "@material-ui/core/Snackbar";
33
import { Alert, AlertTitle } from "@material-ui/lab";
44
import placeholder from "../data/placeholder";
5+
import { MdContentCopy as CopyIcon } from "react-icons/md";
6+
import { MdDelete as CleanIcon } from "react-icons/md";
7+
import { Tooltip } from "@material-ui/core";
58

69
function MarkdownEdit({ content, changeContent }) {
710
const [open, setOpen] = useState(false);
8-
const editorRef =useRef(null);
11+
const editorRef = useRef(null);
912

1013
useEffect(() => {
11-
if(content===''){
12-
localStorage.setItem("markdown",placeholder);
14+
if (content === "") {
15+
localStorage.setItem("markdown", placeholder);
16+
} else {
17+
localStorage.setItem("markdown", content);
1318
}
14-
else{
15-
localStorage.setItem("markdown",content);
16-
}
17-
}, [content])
19+
}, [content]);
1820

1921
const handleEditorChange = (event) => {
2022
event.preventDefault();
@@ -40,29 +42,31 @@ function MarkdownEdit({ content, changeContent }) {
4042
<div className="section-title">
4143
<h3>Markdown</h3>
4244
<div className="right-section">
43-
<button onClick={handleCopyButton} className="btn">
44-
Copy
45-
</button>
46-
<button onClick={handleClearButton} className="btn">
47-
Clear
48-
</button>
45+
<Tooltip title="Copy to Clipboard">
46+
<button onClick={handleCopyButton} className="btn">
47+
<CopyIcon />
48+
</button>
49+
</Tooltip>
50+
<Tooltip title="Clean">
51+
<button onClick={handleClearButton} className="btn">
52+
<CleanIcon />
53+
</button>
54+
</Tooltip>
4955
</div>
5056
</div>
5157
<textarea
5258
className="editable"
5359
value={content}
5460
onChange={handleEditorChange}
5561
id="editor"
56-
ref={editorRef}
57-
></textarea>
62+
ref={editorRef}></textarea>
5863

5964
<Snackbar open={open} autoHideDuration={2000} onClose={handleClose}>
6065
<Alert
6166
onClose={handleClose}
6267
severity="success"
6368
elevation={6}
64-
variant="filled"
65-
>
69+
variant="filled">
6670
<AlertTitle>Copied</AlertTitle>
6771
The markdown is copied to your clipboard
6872
</Alert>

src/components/MarkdownPreview.jsx

+37-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,57 @@
11
import React, { useState, useEffect } from "react";
22
import * as marked from "marked";
3-
import Prism from 'prismjs';
4-
import '../utils/prism-imports';
5-
//css for Prism is imported in ThemeSelector
3+
import Prism from "prismjs"; //css for Prism is imported in ThemeSelector
4+
import "../utils/prism-imports";
5+
import { FullScreen, useFullScreenHandle } from "react-full-screen";
6+
import { CgSoftwareDownload as SaveIcon } from "react-icons/cg";
7+
import { RiFullscreenFill as FullScreenIcon } from "react-icons/ri";
8+
import { Tooltip } from "@material-ui/core";
69

710
function MarkdownPreview({ content }) {
811
const [html, setHtml] = useState(getHtml(content));
12+
const handle = useFullScreenHandle();
913

10-
useEffect(()=>{
14+
useEffect(() => {
1115
Prism.highlightAll();
12-
})
16+
});
1317

1418
useEffect(() => {
1519
setHtml(getHtml(content));
1620
}, [content]);
1721

22+
const handleFullScreen = () =>
23+
handle.active ? handle.exit() : handle.enter();
24+
25+
const handleSaveClick = () => {
26+
let link = document.createElement("a");
27+
link.href = `data:text/html,${html}`;
28+
link.download = "export.html";
29+
link.click();
30+
};
31+
1832
return (
1933
<div className="markdown-preview scroll">
2034
<div className="section-title">
2135
<h3>Preview</h3>
22-
<a href={`data:text/html,${html}`} download="export.html" className="btn">
23-
Save
24-
</a>
36+
<div className="right-section">
37+
<Tooltip title="FullScreen" title="Download HTML">
38+
<button className="btn" onClick={handleSaveClick}>
39+
<SaveIcon />
40+
</button>
41+
</Tooltip>
42+
<Tooltip title="FullScreen">
43+
<button className="btn" onClick={handleFullScreen}>
44+
<FullScreenIcon />
45+
</button>
46+
</Tooltip>
47+
</div>
2548
</div>
26-
<div
27-
id="preview"
28-
className="html-div"
29-
dangerouslySetInnerHTML={{ __html: html }}></div>
49+
<FullScreen handle={handle}>
50+
<div
51+
id="preview"
52+
className={`html-div ${handle.active ? "preview-fullscreen" : ""}`}
53+
dangerouslySetInnerHTML={{ __html: html }}></div>
54+
</FullScreen>
3055
</div>
3156
);
3257
}

0 commit comments

Comments
 (0)