-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add markown editor preview (#29)
- Loading branch information
1 parent
2681a97
commit caacd67
Showing
9 changed files
with
92 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState } from "react"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { useAppContext } from "~/store"; | ||
import { Eye } from "lucide-react"; | ||
|
||
import Editor from "./Editor"; | ||
import EditorControls from "./EditorControls"; | ||
import Preview from "./Preview"; | ||
import TagInput from "./TagInput"; | ||
|
||
export const EditorWrapper = () => { | ||
const { currentNote, currentTrashedNote } = useAppContext(); | ||
const [showPreview, setShowPreview] = useState(false); | ||
|
||
return ( | ||
<> | ||
{(currentNote ?? currentTrashedNote) && ( | ||
<div className="flex h-full flex-col"> | ||
{!showPreview && <Editor />} | ||
{showPreview && <Preview />} | ||
<div className="fixed bottom-[3.75rem] right-2.5 p-2"> | ||
<Button | ||
id="editor-preview-btn" | ||
name="editor-preview-btn" | ||
type="button" | ||
variant="ghost" | ||
size="icon" | ||
onClick={() => | ||
setShowPreview((prevShowPreview) => !prevShowPreview) | ||
} | ||
className="rounded-full text-muted-foreground" | ||
> | ||
<Eye className="h-[1.2rem] w-[1.2rem]" /> | ||
</Button> | ||
</div> | ||
<div className="flex items-center border-t border-muted"> | ||
<TagInput /> | ||
<EditorControls /> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default EditorWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import MarkdownPreview from "@uiw/react-markdown-preview"; | ||
import { useAppContext } from "~/store"; | ||
import rehypeSanitize from "rehype-sanitize"; | ||
|
||
const rehypePlugins = [rehypeSanitize]; | ||
|
||
export const Preview = () => { | ||
const { currentNote, currentTrashedNote } = useAppContext(); | ||
|
||
return ( | ||
<div className="editor-container h-full w-full overflow-y-auto"> | ||
<div className="h-full w-full"> | ||
<MarkdownPreview | ||
source={currentNote?.content ?? currentTrashedNote?.content ?? ""} | ||
className="pb-40 pl-[22px] pr-[18px] pt-4" | ||
rehypePlugins={rehypePlugins} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Preview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters