@redocly/theme 0.33.1 → 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.
- package/lib/components/CodeBlock/CodeBlock.d.ts +2 -1
- package/lib/components/CodeBlock/CodeBlock.js +2 -2
- package/lib/components/CodeBlock/CodeBlockContainer.d.ts +1 -0
- package/lib/components/CodeBlock/CodeBlockContainer.js +1 -1
- package/lib/components/CodeBlock/CodeBlockControls.js +2 -1
- package/package.json +1 -1
- package/src/components/CodeBlock/CodeBlock.tsx +3 -0
- package/src/components/CodeBlock/CodeBlockContainer.tsx +7 -2
- package/src/components/CodeBlock/CodeBlockControls.tsx +2 -1
|
@@ -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;
|
|
@@ -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
|
|
|
@@ -47,7 +47,7 @@ function CodeBlockControls({ children, className, title, controls, tabs, }) {
|
|
|
47
47
|
exports.CodeBlockControls = CodeBlockControls;
|
|
48
48
|
const ContainerWraper = styled_components_1.default.div `
|
|
49
49
|
display: flex;
|
|
50
|
-
justify-content:
|
|
50
|
+
justify-content: right;
|
|
51
51
|
min-height: 30px;
|
|
52
52
|
padding: var(--code-block-controls-padding);
|
|
53
53
|
background-color: var(--code-block-controls-background-color);
|
|
@@ -61,6 +61,7 @@ const Title = styled_components_1.default.span `
|
|
|
61
61
|
display: flex;
|
|
62
62
|
align-items: center;
|
|
63
63
|
color: var(--code-block-controls-text-color);
|
|
64
|
+
width: 100%;
|
|
64
65
|
`;
|
|
65
66
|
const ControlsWrapper = styled_components_1.default.div `
|
|
66
67
|
display: flex;
|
package/package.json
CHANGED
|
@@ -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
|
-
}))<{
|
|
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);
|
|
@@ -193,7 +193,7 @@ export function CodeBlockControls({
|
|
|
193
193
|
|
|
194
194
|
const ContainerWraper = styled.div`
|
|
195
195
|
display: flex;
|
|
196
|
-
justify-content:
|
|
196
|
+
justify-content: right;
|
|
197
197
|
min-height: 30px;
|
|
198
198
|
padding: var(--code-block-controls-padding);
|
|
199
199
|
background-color: var(--code-block-controls-background-color);
|
|
@@ -208,6 +208,7 @@ const Title = styled.span`
|
|
|
208
208
|
display: flex;
|
|
209
209
|
align-items: center;
|
|
210
210
|
color: var(--code-block-controls-text-color);
|
|
211
|
+
width: 100%;
|
|
211
212
|
`;
|
|
212
213
|
|
|
213
214
|
const ControlsWrapper = styled.div`
|