mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-29 12:45:32 +08:00
chore: remove deprecated props
This commit is contained in:
@@ -1,18 +1,13 @@
|
|||||||
import React, { useMemo } from 'react'
|
import React from 'react'
|
||||||
import withDefaults from '../utils/with-defaults'
|
import withDefaults from '../utils/with-defaults'
|
||||||
import useWarning from '../utils/use-warning'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bash?: boolean
|
|
||||||
darkBash?: boolean
|
|
||||||
block?: boolean
|
block?: boolean
|
||||||
width?: string
|
width?: string
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
bash: false,
|
|
||||||
darkBash: false,
|
|
||||||
block: false,
|
block: false,
|
||||||
className: '',
|
className: '',
|
||||||
}
|
}
|
||||||
@@ -23,27 +18,15 @@ export type CodeProps = Props & typeof defaultProps & NativeAttrs
|
|||||||
const Code: React.FC<React.PropsWithChildren<CodeProps>> = ({
|
const Code: React.FC<React.PropsWithChildren<CodeProps>> = ({
|
||||||
children,
|
children,
|
||||||
block,
|
block,
|
||||||
bash,
|
|
||||||
darkBash,
|
|
||||||
className,
|
className,
|
||||||
width,
|
width,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
if (bash) {
|
if (!block) return <code {...props}>{children}</code>
|
||||||
useWarning('Props "bash" is deprecated. Use `Snippet` instead of it.', 'code')
|
|
||||||
}
|
|
||||||
if (darkBash) {
|
|
||||||
useWarning('Props "darkBash" is deprecated. Use `Snippet` instead of it.', 'code')
|
|
||||||
}
|
|
||||||
|
|
||||||
const isBash = bash || darkBash
|
|
||||||
const isBlock = isBash || block
|
|
||||||
if (!isBlock) return <code {...props}>{children}</code>
|
|
||||||
const classes = useMemo(() => `${darkBash ? 'dark' : ''} ${className}`, [className, darkBash])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<pre className={classes} {...props}>
|
<pre className={className} {...props}>
|
||||||
<code>{children}</code>
|
<code>{children}</code>
|
||||||
</pre>
|
</pre>
|
||||||
<style jsx>{`
|
<style jsx>{`
|
||||||
@@ -60,13 +43,6 @@ const Code: React.FC<React.PropsWithChildren<CodeProps>> = ({
|
|||||||
.dark code {
|
.dark code {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre:before {
|
|
||||||
content: '$ ';
|
|
||||||
display: ${isBash ? 'inline-block' : 'none'};
|
|
||||||
font-weight: 500;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
`}</style>
|
`}</style>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user