fix(snippet): fix typo of copy type (#461)

This commit is contained in:
witt
2021-02-17 19:22:42 +08:00
committed by GitHub
parent cfd0a48688
commit f898ade9d3
4 changed files with 9 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ import { getStyles } from './styles'
import SnippetIcon from './snippet-icon'
import useClipboard from '../utils/use-clipboard'
import useToasts from '../use-toasts'
import useWarning from 'components/utils/use-warning'
interface Props {
text?: string | string[]
@@ -59,6 +60,10 @@ const Snippet: React.FC<React.PropsWithChildren<SnippetProps>> = ({
const ref = useRef<HTMLPreElement>(null)
const isMultiLine = text && Array.isArray(text)
if (copyType === 'slient') {
useWarning('"slient" is deprecated, use "silent" instead of it.', 'Snippet')
}
const style = useMemo(() => getStyles(type, theme.palette, filled), [
type,
theme.palette,
@@ -79,7 +84,7 @@ const Snippet: React.FC<React.PropsWithChildren<SnippetProps>> = ({
const clickHandler = () => {
if (!childText || !showCopyIcon) return
copy(childText)
if (copyType === 'slient') return
if (copyType === 'silent' || copyType === 'slient') return
setToast({ text: toastText, type: toastType })
}

View File

@@ -41,7 +41,7 @@ const cardTypes = tuple(
'cyan',
)
const copyTypes = tuple('default', 'slient', 'prevent')
const copyTypes = tuple('default', 'silent', 'prevent', 'slient')
const triggerTypes = tuple('hover', 'click')

View File

@@ -106,7 +106,7 @@ Display a snippet of copyable code for the command line.
| **type** | snippet types | [SnippetTypes](#snippettypes) | [SnippetTypes](#snippettypes) | `default` |
| **filled** | filled style | `boolean` | - | `false` |
| **width** | set CSS string | `string` | - | `initial` |
| **copy** | function of copy button | `CopyTypes` | `'default', 'slient', 'prevent'` | `default` |
| **copy** | function of copy button | `CopyTypes` | `'default', 'silent', 'prevent'` | `default` |
| **symbol** | symbol snippet | `string` | - | `$` |
| **toastText** | toast text | `string` | - | `Copied to clipboard!` |
| **toastType** | toast type | `NormalTypes` | [NormalTypes](#normaltypes) | `success` |

View File

@@ -90,7 +90,7 @@ export const meta = {
| **type** | 组件类型 | [SnippetTypes](#snippettypes) | [SnippetTypes](#snippettypes) | `default` |
| **filled** | 填充风格的样式 | `boolean` | - | `false` |
| **width** | 设置 CSS 宽度 | `string` | - | `initial` |
| **copy** | 拷贝按钮的工作方式 | `CopyTypes` | `'default', 'slient', 'prevent'` | `default` |
| **copy** | 拷贝按钮的工作方式 | `CopyTypes` | `'default', 'silent', 'prevent'` | `default` |
| **symbol** | 组件左侧显示的字符 | `string` | - | `$` |
| **toastText** | 拷贝提示的字符 | `string` | - | `Copied to clipboard!` |
| **toastType** | 拷贝提示的类型 | `NormalTypes` | [NormalTypes](#normaltypes) | `success` |