@redocly/theme 0.33.2 → 0.33.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ export interface CodeBlockProps {
15
15
  codeBlockRef?: (instance: HTMLPreElement | null) => void;
16
16
  codeBlockMaxHeight?: string;
17
17
  hideCodeColors?: boolean;
18
+ wrapContents?: boolean;
18
19
  }
19
20
  export interface Sample {
20
21
  lang: string;
@@ -37,4 +38,4 @@ export interface ExternalSource {
37
38
  properties?: any;
38
39
  operation?: any;
39
40
  }
40
- export declare function CodeBlock({ lang, source, externalSource, header, dataTestId, codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, }: CodeBlockProps): JSX.Element;
41
+ export declare function CodeBlock({ lang, source, externalSource, header, dataTestId, codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, wrapContents, }: CodeBlockProps): JSX.Element;
@@ -32,7 +32,7 @@ const styled_components_1 = __importDefault(require("styled-components"));
32
32
  const utils_1 = require("../../utils");
33
33
  const Feedback_1 = require("../../components/Feedback");
34
34
  const CodeBlock_1 = require("../../components/CodeBlock");
35
- function CodeBlock({ lang, source, externalSource, header, dataTestId = 'source-code', codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, }) {
35
+ function CodeBlock({ lang, source, externalSource, header, dataTestId = 'source-code', codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, wrapContents = false, }) {
36
36
  var _a;
37
37
  const [sourceCode, setSourceCode] = (0, react_1.useState)(source !== null && source !== void 0 ? source : '');
38
38
  const highlightedCode = highlightedHtml || (0, utils_1.highlight)(sourceCode, lang);
@@ -59,7 +59,7 @@ function CodeBlock({ lang, source, externalSource, header, dataTestId = 'source-
59
59
  __html: withLineNumbers
60
60
  ? (0, utils_1.addLineNumbers)(highlightedCode, startLineNumber)
61
61
  : highlightedCode,
62
- }, "data-cy": dataTestId, hideCodeColors: hideCodeColors, maxHeight: codeBlockMaxHeight, withControls: true }),
62
+ }, "data-cy": dataTestId, hideCodeColors: hideCodeColors, maxHeight: codeBlockMaxHeight, withControls: true, wrapContents: wrapContents }),
63
63
  reportDialog.visible && (react_1.default.createElement(Feedback_1.ReportDialog, Object.assign({}, reportDialog.props, { location: sourceCode, lang: lang }))))));
64
64
  }
65
65
  exports.CodeBlock = CodeBlock;
@@ -2,4 +2,5 @@ export declare const CodeBlockContainer: import("styled-components").StyledCompo
2
2
  withControls?: boolean | undefined;
3
3
  maxHeight?: string | undefined;
4
4
  hideCodeColors?: boolean | undefined;
5
+ wrapContents?: boolean | undefined;
5
6
  }, never>;
@@ -40,7 +40,7 @@ exports.CodeBlockContainer = styled_components_1.default.pre.attrs(({ className
40
40
  background-color: var(--code-block-background-color);
41
41
  color: var(--code-block-text-color);
42
42
  font-size: var(--code-block-font-size);
43
- white-space: var(--code-wrap, pre);
43
+ white-space: ${({ wrapContents }) => (wrapContents ? 'pre-wrap' : 'var(--code-wrap, pre)')};
44
44
  max-height: ${({ maxHeight }) => maxHeight ? maxHeight : 'var(--code-block-max-height, 600px);'};
45
45
  word-break: var(--code-block-word-break, initial);
46
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.33.2",
3
+ "version": "0.33.3",
4
4
  "description": "Shared UI components lib",
5
5
  "keywords": [
6
6
  "theme",
@@ -22,6 +22,7 @@ export interface CodeBlockProps {
22
22
  codeBlockRef?: (instance: HTMLPreElement | null) => void;
23
23
  codeBlockMaxHeight?: string;
24
24
  hideCodeColors?: boolean;
25
+ wrapContents?: boolean;
25
26
  }
26
27
 
27
28
  export interface Sample {
@@ -61,6 +62,7 @@ export function CodeBlock({
61
62
  codeBlockMaxHeight,
62
63
  tabs,
63
64
  hideCodeColors,
65
+ wrapContents = false,
64
66
  }: CodeBlockProps): JSX.Element {
65
67
  const [sourceCode, setSourceCode] = useState<string>(source ?? '');
66
68
 
@@ -109,6 +111,7 @@ export function CodeBlock({
109
111
  hideCodeColors={hideCodeColors}
110
112
  maxHeight={codeBlockMaxHeight}
111
113
  withControls={true}
114
+ wrapContents={wrapContents}
112
115
  />
113
116
  {reportDialog.visible && (
114
117
  <ReportDialog
@@ -5,7 +5,12 @@ import { generateCodeBlockTokens } from '@theme/utils';
5
5
  export const CodeBlockContainer = styled.pre.attrs<{ className?: string }>(({ className }) => ({
6
6
  'data-component-name': 'CodeBlock/CodeBlockContainer',
7
7
  className,
8
- }))<{ withControls?: boolean; maxHeight?: string; hideCodeColors?: boolean }>`
8
+ }))<{
9
+ withControls?: boolean;
10
+ maxHeight?: string;
11
+ hideCodeColors?: boolean;
12
+ wrapContents?: boolean;
13
+ }>`
9
14
  && {
10
15
  overflow-x: auto;
11
16
  font-family: var(--code-block-font-family);
@@ -16,7 +21,7 @@ export const CodeBlockContainer = styled.pre.attrs<{ className?: string }>(({ cl
16
21
  background-color: var(--code-block-background-color);
17
22
  color: var(--code-block-text-color);
18
23
  font-size: var(--code-block-font-size);
19
- white-space: var(--code-wrap, pre);
24
+ white-space: ${({ wrapContents }) => (wrapContents ? 'pre-wrap' : 'var(--code-wrap, pre)')};
20
25
  max-height: ${({ maxHeight }) =>
21
26
  maxHeight ? maxHeight : 'var(--code-block-max-height, 600px);'};
22
27
  word-break: var(--code-block-word-break, initial);