@@ -39,31 +39,27 @@ const transformCode = <T extends ReactElement<PropsWithChildren>>(
3939 // being an empty string, so we need to remove it
4040 const lines = content . split ( '\n' ) ;
4141
42- const extraStyle = language . length === 0 ? { fontFamily : 'monospace' } : { } ;
42+ const extraClasses = classNames ( { 'plain-text' : language . length === 0 } ) ;
4343
4444 return (
45- < code style = { extraStyle } >
46- { lines
47- . flatMap ( ( line , lineIndex ) => {
48- const columns = line . split ( ' ' ) ;
49-
50- return [
51- < span key = { lineIndex } className = "line" >
52- { columns . map ( ( column , columnIndex ) => (
53- < Fragment key = { columnIndex } >
54- < span > { column } </ span >
55- { columnIndex < columns . length - 1 && < span > </ span > }
56- </ Fragment >
57- ) ) }
58- </ span > ,
59- // Add a break line so the text content is formatted correctly
60- // when copying to clipboard
61- '\n' ,
62- ] ;
63- } )
64- // Here we remove that empty line from before and
65- // the last flatMap entry which is an `\n`
66- . slice ( 0 , - 2 ) }
45+ < code className = { extraClasses } >
46+ { lines . flatMap ( ( line , lineIndex ) => {
47+ const columns = line . split ( ' ' ) ;
48+
49+ return [
50+ < span key = { lineIndex } className = "line" >
51+ { columns . map ( ( column , columnIndex ) => (
52+ < Fragment key = { columnIndex } >
53+ < span > { column } </ span >
54+ { columnIndex < columns . length - 1 && < span > </ span > }
55+ </ Fragment >
56+ ) ) }
57+ </ span > ,
58+ // Add a break line so the text content is formatted correctly
59+ // when copying to clipboard
60+ '\n' ,
61+ ] ;
62+ } ) }
6763 </ code >
6864 ) ;
6965} ;
@@ -89,8 +85,11 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
8985 const containerRef = useRef < HTMLPreElement > ( null ) ;
9086
9187 const handleCopy = ( ) => copy ( containerRef . current ?. textContent ) ;
88+
9289 const ButtonIcon = copied ? DocumentDuplicateIcon : CodeBracketIcon ;
9390
91+ const hideFooter = className ?. includes ( 'no-footer' ) ;
92+
9493 return (
9594 < div className = { styles . root } >
9695 < pre
@@ -100,9 +99,11 @@ const BaseCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
10099 >
101100 { transformCode ( children as ReactElement < PropsWithChildren > , language ) }
102101 </ pre >
103- { language && (
102+
103+ { ! language || hideFooter || (
104104 < div className = { styles . footer } >
105105 < span className = { styles . language } > { language } </ span >
106+
106107 < BaseButton
107108 as = { as }
108109 className = { styles . action }
0 commit comments