-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CodeBlocks): add live code editor support (#791)
issue #777
- Loading branch information
1 parent
ffe90dc
commit 7f81d99
Showing
15 changed files
with
818 additions
and
1,187 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,15 @@ | ||
.code { | ||
@apply relative; | ||
@apply m-0 p-5; | ||
.container { | ||
@apply flex flex-wrap flex-col md:flex-row; | ||
@apply m-0 p-0; | ||
} | ||
|
||
.editor, | ||
.preview { | ||
@apply flex-auto; | ||
@apply w-full md:w-1/2; | ||
} | ||
|
||
.error { | ||
@apply w-full; | ||
@apply bg-red-100 text-red-700; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import { classNames } from '@components/utils'; | ||
import type { Language } from 'prism-react-renderer'; | ||
import React from 'react'; | ||
import { | ||
LiveEditor, | ||
LiveError, | ||
LivePreview, | ||
LiveProvider, | ||
} from 'react-live-runner'; | ||
import styles from './LiveCode.module.css'; | ||
import { normalizeCode } from './utils'; | ||
import theme from './monokai'; | ||
|
||
interface Props { | ||
code?: string; | ||
className?: string; | ||
language?: string; | ||
children?: string; | ||
} | ||
|
||
const LiveCode = ({ code, className }: Props): JSX.Element => ( | ||
<pre className={classNames(className, styles.code)}> | ||
{normalizeCode(code)} | ||
</pre> | ||
const scope = { | ||
...React, | ||
}; | ||
|
||
const LiveCode = ({ language, children }: Props): JSX.Element => ( | ||
<div className={styles.container}> | ||
<LiveProvider | ||
scope={scope} | ||
code={children} | ||
language={language as Language} | ||
theme={theme} | ||
> | ||
<LiveEditor padding="1.25rem" className={styles.editor} /> | ||
<LivePreview className={styles.preview} /> | ||
<LiveError className={styles.error} /> | ||
</LiveProvider> | ||
</div> | ||
); | ||
|
||
export default LiveCode; |
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
Oops, something went wrong.
7f81d99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
blog – ./
blog-sabertaz.vercel.app
blog.tazimi.dev
blog-git-main-sabertaz.vercel.app