forked from quant-speed-AI/Scoring-System
创赢未来评分系统 - 初始化提交(移除大文件)
This commit is contained in:
42
miniprogram/src/components/MarkdownReader/CodeBlock.tsx
Normal file
42
miniprogram/src/components/MarkdownReader/CodeBlock.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import React, { useState } from 'react'
|
||||
import { View, Text, ScrollView } from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { AtIcon } from 'taro-ui'
|
||||
import './index.scss'
|
||||
|
||||
interface Props {
|
||||
code: string
|
||||
language?: string
|
||||
}
|
||||
|
||||
const CodeBlock: React.FC<Props> = ({ code, language }) => {
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
const handleCopy = (e) => {
|
||||
e.stopPropagation()
|
||||
Taro.setClipboardData({
|
||||
data: code,
|
||||
success: () => {
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='markdown-code-block'>
|
||||
<View className='code-header'>
|
||||
<Text className='language'>{language || 'text'}</Text>
|
||||
<View className='copy-btn' onClick={handleCopy}>
|
||||
<AtIcon value='copy' size='14' color='#ccc' />
|
||||
<Text className='copy-text'>{copied ? '已复制' : '复制'}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<ScrollView scrollX scrollY className='code-content'>
|
||||
<Text userSelect className='code-text'>{code}</Text>
|
||||
</ScrollView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export default CodeBlock
|
||||
Reference in New Issue
Block a user