feat(code): add min-width to code block

This commit is contained in:
unix
2020-03-23 08:54:20 +08:00
parent 2d2d9d33de
commit 4e76051c2a
4 changed files with 16 additions and 17 deletions

View File

@@ -6,6 +6,7 @@ interface Props {
bash?: boolean
darkBash?: boolean
block?: boolean
minWidth?: string
className?: string
}
@@ -19,7 +20,7 @@ const defaultProps = {
export type CodeProps = Props & typeof defaultProps & React.HTMLAttributes<any>
const Code: React.FC<React.PropsWithChildren<CodeProps>> = React.memo(({
children, block, bash, darkBash, className, ...props
children, block, bash, darkBash, className, minWidth, ...props
}) => {
const theme = useTheme()
const isBash = bash || darkBash
@@ -34,10 +35,17 @@ const Code: React.FC<React.PropsWithChildren<CodeProps>> = React.memo(({
<>
<pre className={classes} {...props}><code>{children}</code></pre>
<style jsx>{`
code {
min-width: ${minWidth ? minWidth : 'unset'};
}
pre {
line-height: 1.5;
padding: ${theme.layout.gapHalf};
text-align: left;
white-space: pre;
overflow: auto;
min-width: ${minWidth ? minWidth : 'unset'};
}
pre :global(p) {