feat(snippet): add component

This commit is contained in:
unix
2020-04-03 06:35:35 +08:00
parent 101a4c8395
commit 1120d9dd92
12 changed files with 380 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
import React, { useMemo } from 'react'
import withDefaults from '../utils/with-defaults'
import useTheme from '../styles/use-theme'
import useWarning from '../utils/use-warning'
interface Props {
bash?: boolean
@@ -23,7 +23,13 @@ export type CodeProps = Props & typeof defaultProps & NativeAttrs
const Code: React.FC<React.PropsWithChildren<CodeProps>> = React.memo(({
children, block, bash, darkBash, className, width, ...props
}) => {
const theme = useTheme()
if (bash) {
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>
@@ -37,17 +43,10 @@ const Code: React.FC<React.PropsWithChildren<CodeProps>> = React.memo(({
<pre className={classes} {...props}><code>{children}</code></pre>
<style jsx>{`
pre {
line-height: 1.5;
padding: ${theme.layout.gapHalf};
text-align: left;
width: ${width ? width : 'initial'};
max-width: 100%;
}
pre :global(p) {
margin: 0;
}
.dark {
color: white;
background: black;