Skip to content

Commit

Permalink
Merge branch 'feat-003-tiptap'
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
EvitanRelta committed Jun 12, 2022
2 parents 56008cf + ab90377 commit ef28c59
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const Body = ({ showMarkdown, mdText, onTextChange, theme }: Props) => {
>
<TextEditor theme={theme} onTextChange={onTextChange} />
</div>
{showMarkdown && <MarkdownTextContainer mdText={mdText} />}
{showMarkdown && (
<MarkdownTextContainer mdText={mdText} theme={theme} />
)}
</div>
</div>
)
Expand Down
27 changes: 27 additions & 0 deletions src/components/Body/CopyClipboardButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import { IconButton } from '@mui/material'

const CopyClipboardButton = ({ onClick }) => {
return (
<div
style={{
marginTop: 6,
padding: 2,
paddingTop: 6,
borderRadius: 5,
display: 'inline',
}}
>
<IconButton
onClick={onClick}
color='inherit'
size='small'
sx={{ transform: 'scaleX(-1) scale(0.8)' }}
>
<ContentCopyIcon />
</IconButton>
</div>
)
}

export default CopyClipboardButton
60 changes: 55 additions & 5 deletions src/components/Body/MarkdownTextContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,70 @@
import Button from '@mui/material/Button'
import { useState } from 'react'
import CopyClipboardButton from './CopyClipboardButton'

type Props = {
mdText: string
theme: 'light' | 'dark'
}

const MarkdownTextContainer = ({ mdText }: Props) => {
const MarkdownTextContainer = ({ mdText, theme }: Props) => {
const [isHovering, setIsHovering] = useState(false)

const [showCopiedPopup, setShowCopiedPopup] = useState(false)

const onCopy = () => {
navigator.clipboard.writeText(mdText)
popUpCopied()
}

const popUpCopied = () => {
setShowCopiedPopup(true)
setTimeout(() => setShowCopiedPopup(false), 1000)
}

const copyButtonColor = theme === 'dark' ? '#2a2a2a' : '#F5F5F5'

return (
<pre
<div
style={{
border: '1px solid #d0cccc',
width: '50%',
border: '1px solid #d0cccc',
padding: '20px',
paddingTop: 15,
paddingRight: 8,
margin: '10px',
overflowX: 'auto',
}}
onMouseLeave={() => setIsHovering(false)}
onMouseEnter={() => setIsHovering(true)}
>
{mdText}
</pre>
{isHovering && (
<div
style={{
margin: 0,
right: 20,
top: 120,
position: 'absolute',
backgroundColor: copyButtonColor,
borderRadius: 7,
paddingBottom: 1,
}}
>
{showCopiedPopup ? (
<Button
sx={{
display: 'inline',
}}
>
Copied
</Button>
) : (
<CopyClipboardButton onClick={onCopy} />
)}
</div>
)}
<pre style={{ marginTop: 15, display: 'inline' }}>{mdText}</pre>
</div>
)
}

Expand Down

0 comments on commit ef28c59

Please sign in to comment.