diff --git a/apps/docs/components/CodeBlock/CodeBlock.tsx b/apps/docs/components/CodeBlock/CodeBlock.tsx index 9172f204075..fede6a38d1c 100644 --- a/apps/docs/components/CodeBlock/CodeBlock.tsx +++ b/apps/docs/components/CodeBlock/CodeBlock.tsx @@ -48,6 +48,11 @@ const CodeBlock: FC = ({ }, 1000) } + // check the length of the string inside the tag + // if it's fewer than 70 characters, add a white-space: pre so it doesn't wrap + const shortCodeBlockClasses = + typeof children === 'string' && children.length < 70 ? 'short-inline-codeblock' : '' + let lang = language ? language : className ? className.replace('language-', '') : 'js' // force jsx to be js highlighted if (lang === 'jsx') lang = 'js' @@ -65,76 +70,78 @@ const CodeBlock: FC = ({ const showLineNumbers = !hideLineNumbers return ( -
+ <> {title && (
{title.replace(/%20/g, ' ')}
)} {className ? ( - { - if (linesToHighlight.includes(lineNumber)) { - return { - style: { display: 'block', backgroundColor: 'var(--colors-scale6)' }, +
+ { + if (linesToHighlight.includes(lineNumber)) { + return { + style: { display: 'block', backgroundColor: 'var(--colors-scale6)' }, + } } - } - return {} - }} - lineNumberContainerStyle={{ - paddingTop: '128px', - }} - lineNumberStyle={{ - minWidth: '44px', - paddingLeft: '4px', - paddingRight: '4px', - marginRight: '12px', - color: '#828282', - textAlign: 'center', - fontSize: large ? 14 : 12, - paddingTop: '4px', - paddingBottom: '4px', - }} - > - {(value || children)?.trimEnd()} - - ) : ( - {value || children} - )} - {!hideCopy && (value || children) && className ? ( -
- - - + + + +
+ ) : null}
- ) : null} -
+ ) : ( + {value || children} + )} + ) }