-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react' | ||
import { codeToHtml } from 'shiki' | ||
import { Highlight, themes } from 'prism-react-renderer' | ||
import useCopyToClipboard from '@hooks/useCopyToClipboard' | ||
import { | ||
CopyOutlined, | ||
CheckCircleTwoTone | ||
} from '@ant-design/icons'; | ||
import styles from './index.module.less' | ||
|
||
const ShiCode = ({ preCode }) => { | ||
const [copyToClipboard, copyResult] = useCopyToClipboard() | ||
const handleClickCopy = () => { | ||
copyToClipboard(preCode); | ||
} | ||
|
||
return ( | ||
<div className="rounded-md bg-cyan-800 text-zinc-50"> | ||
<header className="grid grid-cols-6 gap-3 items-center px-4 py-3"> | ||
<div className="flex gap-1.5"> | ||
<div className="rounded-full h-3 w-3 bg-red-500"></div> | ||
<div className="rounded-full h-3 w-3 bg-yellow-500"></div> | ||
<div className="rounded-full h-3 w-3 bg-green-500"></div> | ||
</div> | ||
<div className="col-span-4 flex justify-center"> | ||
<div className="bg-transparent text-center text-gray-400 text-sm font-medium focus:outline-none">Untitled</div> | ||
</div> | ||
</header> | ||
<div className="relative px-4 pb-4"> | ||
<div className="absolute top-2 right-5 size-4 text-gray-400"> | ||
{copyResult?.state === 'success' ? <CheckCircleTwoTone className="size-4 text-base" twoToneColor="#52c41a" /> : <CopyOutlined className="size-4 text-base" onClick={handleClickCopy}/>} | ||
</div> | ||
|
||
<Highlight theme={themes.dracula} className={styles.wrapper} code={preCode?.trim()} language="jsx"> | ||
{({ style, tokens, getLineProps, getTokenProps }) => ( | ||
<pre className={styles.pre} style={style}> | ||
{tokens.map((line, i) => ( | ||
<div className={styles.line} key={i} {...getLineProps({ line })}> | ||
<span className={styles['line-no']}>{i + 1}</span> | ||
{line.map((token, key) => ( | ||
<span key={key} {...getTokenProps({ token })} /> | ||
))} | ||
</div> | ||
))} | ||
</pre> | ||
)} | ||
</Highlight> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default ShiCode |
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,25 @@ | ||
.warpper { | ||
font-family: sans-serif; | ||
text-align: center; | ||
} | ||
|
||
.pre { | ||
text-align: left; | ||
padding: 0.5em; | ||
overflow: auto; | ||
& .token-line { | ||
line-height: 1.3em; | ||
height: 1.3em; | ||
} | ||
} | ||
|
||
.line { | ||
padding-right: 0.5em; | ||
} | ||
|
||
.line-no { | ||
text-align: right; | ||
padding-right: 1em; | ||
user-select: none; | ||
opacity: 0.5; | ||
} |
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