Merge pull request #31152 from SonilPro/'code-snippet-wrap-long-lines'

code snippet support for wrap long lines
This commit is contained in:
Fredrik Adelöw
2025-12-13 19:59:29 +01:00
committed by GitHub
3 changed files with 16 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core-components': patch
---
added support for wrapLongLines option in CodeSnippet
+1
View File
@@ -188,6 +188,7 @@ export interface CodeSnippetProps {
showCopyCodeButton?: boolean;
showLineNumbers?: boolean;
text: string;
wrapLongLines?: boolean;
}
// Warning: (ae-forgotten-export) The symbol "Props_12" needs to be exported by the entry point index.d.ts
@@ -57,6 +57,14 @@ export interface CodeSnippetProps {
* Array of line numbers to highlight
*/
highlightedNumbers?: number[];
/**
* Whether to style the `<code>` block with `white-space: pre-wrap` or `white-space: pre`
*
* @remarks
*
* Default: false (`white-space: pre`)
*/
wrapLongLines?: boolean;
/**
* Custom styles applied to code
*
@@ -79,6 +87,7 @@ export function CodeSnippet(props: CodeSnippetProps) {
language,
showLineNumbers = false,
highlightedNumbers,
wrapLongLines,
customStyle,
showCopyCodeButton = false,
} = props;
@@ -94,6 +103,7 @@ export function CodeSnippet(props: CodeSnippetProps) {
style={mode}
showLineNumbers={showLineNumbers}
wrapLines
wrapLongLines={wrapLongLines}
lineNumberStyle={{ color: theme.palette.textVerySubtle }}
lineProps={(lineNumber: number) =>
highlightedNumbers?.includes(lineNumber)