docusaurus-theme-openapi-docs 0.0.0-beta.643 → 0.0.0-beta.645
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/theme/ApiDemoPanel/ApiCodeBlock/Container/_Container.scss +6 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Container/index.js +29 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/Element.js +30 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/String.js +131 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +88 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/_CopyButton.scss +44 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/index.js +74 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/_ExitButton.scss +16 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/index.js +47 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/_ExpandButton.scss +42 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +180 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Line/_Line.scss +46 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Line/index.js +47 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/_WordWrapButton.scss +10 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/index.js +44 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/index.js +40 -0
- package/lib/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +19 -1
- package/lib/theme/ApiDemoPanel/CodeTabs/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Curl/index.js +5 -2
- package/lib/theme/DiscriminatorTabs/_DiscriminatorTabs.scss +4 -0
- package/lib/theme/ParamsItem/_ParamsItem.scss +14 -1
- package/lib/theme/ParamsItem/index.js +9 -4
- package/lib/theme/SchemaItem/_SchemaItem.scss +20 -3
- package/lib/theme/SchemaItem/index.js +21 -10
- package/lib/theme/styles.scss +10 -0
- package/package.json +5 -3
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Container/_Container.scss +6 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Container/index.js +29 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/Element.js +30 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/String.js +131 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +88 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/_CopyButton.scss +44 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/index.js +74 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/_ExitButton.scss +16 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/index.js +47 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/_ExpandButton.scss +42 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +180 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Line/_Line.scss +46 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Line/index.js +47 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/_WordWrapButton.scss +10 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/index.js +44 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/index.js +40 -0
- package/src/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +19 -1
- package/src/theme/ApiDemoPanel/CodeTabs/index.js +1 -1
- package/src/theme/ApiDemoPanel/Curl/index.tsx +5 -3
- package/src/theme/DiscriminatorTabs/_DiscriminatorTabs.scss +4 -0
- package/src/theme/ParamsItem/_ParamsItem.scss +14 -1
- package/src/theme/ParamsItem/index.js +9 -4
- package/src/theme/SchemaItem/_SchemaItem.scss +20 -3
- package/src/theme/SchemaItem/index.js +21 -10
- package/src/theme/styles.scss +10 -0
- package/src/theme-openapi.d.ts +4 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { ThemeClassNames, usePrismTheme } from "@docusaurus/theme-common";
|
|
11
|
+
import { getPrismCssVariables } from "@docusaurus/theme-common/internal";
|
|
12
|
+
import clsx from "clsx";
|
|
13
|
+
|
|
14
|
+
export default function CodeBlockContainer({ as: As, ...props }) {
|
|
15
|
+
const prismTheme = usePrismTheme();
|
|
16
|
+
const prismCssVariables = getPrismCssVariables(prismTheme);
|
|
17
|
+
return (
|
|
18
|
+
<As
|
|
19
|
+
// Polymorphic components are hard to type, without `oneOf` generics
|
|
20
|
+
{...props}
|
|
21
|
+
style={prismCssVariables}
|
|
22
|
+
className={clsx(
|
|
23
|
+
"openapi-demo__code-block-container",
|
|
24
|
+
props.className,
|
|
25
|
+
ThemeClassNames.common.codeBlock
|
|
26
|
+
)}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import Container from "@theme/ApiDemoPanel/ApiCodeBlock/Container";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
|
|
13
|
+
// <pre> tags in markdown map to CodeBlocks. They may contain JSX children. When
|
|
14
|
+
// the children is not a simple string, we just return a styled block without
|
|
15
|
+
// actually highlighting.
|
|
16
|
+
export default function CodeBlockJSX({ children, className }) {
|
|
17
|
+
return (
|
|
18
|
+
<Container
|
|
19
|
+
as="pre"
|
|
20
|
+
tabIndex={0}
|
|
21
|
+
className={clsx(
|
|
22
|
+
"openapi-demo__code-block-standalone",
|
|
23
|
+
"thin-scrollbar",
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
>
|
|
27
|
+
<code className="openapi-demo__code-block-lines">{children}</code>
|
|
28
|
+
</Container>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { useThemeConfig, usePrismTheme } from "@docusaurus/theme-common";
|
|
11
|
+
import {
|
|
12
|
+
parseCodeBlockTitle,
|
|
13
|
+
parseLanguage,
|
|
14
|
+
parseLines,
|
|
15
|
+
containsLineNumbers,
|
|
16
|
+
useCodeWordWrap,
|
|
17
|
+
} from "@docusaurus/theme-common/internal";
|
|
18
|
+
import Container from "@theme/ApiDemoPanel/ApiCodeBlock/Container";
|
|
19
|
+
import CopyButton from "@theme/ApiDemoPanel/ApiCodeBlock/CopyButton";
|
|
20
|
+
import ExpandButton from "@theme/ApiDemoPanel/ApiCodeBlock/ExpandButton";
|
|
21
|
+
import Line from "@theme/ApiDemoPanel/ApiCodeBlock/Line";
|
|
22
|
+
import WordWrapButton from "@theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton";
|
|
23
|
+
import clsx from "clsx";
|
|
24
|
+
import Highlight, { defaultProps } from "prism-react-renderer";
|
|
25
|
+
|
|
26
|
+
export default function CodeBlockString({
|
|
27
|
+
children,
|
|
28
|
+
className: blockClassName = "",
|
|
29
|
+
metastring,
|
|
30
|
+
title: titleProp,
|
|
31
|
+
showLineNumbers: showLineNumbersProp,
|
|
32
|
+
language: languageProp,
|
|
33
|
+
}) {
|
|
34
|
+
const {
|
|
35
|
+
prism: { defaultLanguage, magicComments },
|
|
36
|
+
} = useThemeConfig();
|
|
37
|
+
const language =
|
|
38
|
+
languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage;
|
|
39
|
+
const prismTheme = usePrismTheme();
|
|
40
|
+
const wordWrap = useCodeWordWrap();
|
|
41
|
+
// We still parse the metastring in case we want to support more syntax in the
|
|
42
|
+
// future. Note that MDX doesn't strip quotes when parsing metastring:
|
|
43
|
+
// "title=\"xyz\"" => title: "\"xyz\""
|
|
44
|
+
const title = parseCodeBlockTitle(metastring) || titleProp;
|
|
45
|
+
const { lineClassNames, code } = parseLines(children, {
|
|
46
|
+
metastring,
|
|
47
|
+
language,
|
|
48
|
+
magicComments,
|
|
49
|
+
});
|
|
50
|
+
const showLineNumbers =
|
|
51
|
+
showLineNumbersProp ?? containsLineNumbers(metastring);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Container
|
|
55
|
+
as="div"
|
|
56
|
+
className={clsx(
|
|
57
|
+
blockClassName,
|
|
58
|
+
language &&
|
|
59
|
+
!blockClassName.includes(`language-${language}`) &&
|
|
60
|
+
`language-${language}`
|
|
61
|
+
)}
|
|
62
|
+
>
|
|
63
|
+
{title && <div className="openapi-demo__code-block-title">{title}</div>}
|
|
64
|
+
<div className="openapi-demo__code-block-content">
|
|
65
|
+
<Highlight
|
|
66
|
+
{...defaultProps}
|
|
67
|
+
theme={prismTheme}
|
|
68
|
+
code={code}
|
|
69
|
+
language={language ?? "text"}
|
|
70
|
+
>
|
|
71
|
+
{({ className, tokens, getLineProps, getTokenProps }) => (
|
|
72
|
+
<pre
|
|
73
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
74
|
+
tabIndex={0}
|
|
75
|
+
ref={wordWrap.codeBlockRef}
|
|
76
|
+
className={clsx(
|
|
77
|
+
className,
|
|
78
|
+
"openapi-demo__code-block",
|
|
79
|
+
"thin-scrollbar"
|
|
80
|
+
)}
|
|
81
|
+
>
|
|
82
|
+
<code
|
|
83
|
+
className={clsx(
|
|
84
|
+
"openapi-demo__code-block-lines",
|
|
85
|
+
showLineNumbers && "openapi-demo__code-block-lines-numbering"
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
88
|
+
{tokens.map((line, i) => (
|
|
89
|
+
<Line
|
|
90
|
+
key={i}
|
|
91
|
+
line={line}
|
|
92
|
+
getLineProps={getLineProps}
|
|
93
|
+
getTokenProps={getTokenProps}
|
|
94
|
+
classNames={lineClassNames[i]}
|
|
95
|
+
showLineNumbers={showLineNumbers}
|
|
96
|
+
/>
|
|
97
|
+
))}
|
|
98
|
+
</code>
|
|
99
|
+
</pre>
|
|
100
|
+
)}
|
|
101
|
+
</Highlight>
|
|
102
|
+
<div className="openapi-demo__code-block-btn-group">
|
|
103
|
+
{(wordWrap.isEnabled || wordWrap.isCodeScrollable) && (
|
|
104
|
+
<WordWrapButton
|
|
105
|
+
className="openapi-demo__code-block-code-btn"
|
|
106
|
+
onClick={() => wordWrap.toggle()}
|
|
107
|
+
isEnabled={wordWrap.isEnabled}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
<CopyButton
|
|
111
|
+
className="openapi-demo__code-block-code-btn"
|
|
112
|
+
code={code}
|
|
113
|
+
/>
|
|
114
|
+
<ExpandButton
|
|
115
|
+
className={clsx(
|
|
116
|
+
"openapi-demo__code-block-code-btn",
|
|
117
|
+
"openapi-demo__expand-btn"
|
|
118
|
+
)}
|
|
119
|
+
code={code}
|
|
120
|
+
language={language}
|
|
121
|
+
showLineNumbers={showLineNumbers}
|
|
122
|
+
blockClassName={blockClassName}
|
|
123
|
+
title={title}
|
|
124
|
+
lineClassNames={lineClassNames}
|
|
125
|
+
wordWrap={wordWrap}
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</Container>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
.openapi-demo__code-block-content {
|
|
2
|
+
position: relative;
|
|
3
|
+
/* rtl:ignore */
|
|
4
|
+
direction: ltr;
|
|
5
|
+
border-radius: inherit;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.openapi-demo__code-block-title {
|
|
9
|
+
border-bottom: 1px solid var(--ifm-color-emphasis-300);
|
|
10
|
+
font-size: var(--ifm-code-font-size);
|
|
11
|
+
font-weight: 500;
|
|
12
|
+
padding: 0.75rem var(--ifm-pre-padding);
|
|
13
|
+
border-top-left-radius: inherit;
|
|
14
|
+
border-top-right-radius: inherit;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.openapi-demo__code-block {
|
|
18
|
+
--ifm-pre-background: var(--prism-background-color);
|
|
19
|
+
margin: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.openapi-demo__code-block-title
|
|
24
|
+
+ .openapi-demo__code-block-content
|
|
25
|
+
.openapi-demo__code-block {
|
|
26
|
+
border-top-left-radius: 0;
|
|
27
|
+
border-top-right-radius: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.openapi-demo__code-block-standalone {
|
|
31
|
+
padding: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.openapi-demo__code-block-lines {
|
|
35
|
+
font: inherit;
|
|
36
|
+
/* rtl:ignore */
|
|
37
|
+
float: left;
|
|
38
|
+
min-width: 100%;
|
|
39
|
+
padding: var(--ifm-pre-padding);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.openapi-demo__code-block-lines-numbering {
|
|
43
|
+
// This causes max-height to unset
|
|
44
|
+
// display: table;
|
|
45
|
+
padding: var(--ifm-pre-padding) 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@media print {
|
|
49
|
+
.openapi-demo__code-block-lines {
|
|
50
|
+
white-space: pre-wrap;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.openapi-demo__code-block-btn-group {
|
|
55
|
+
display: flex;
|
|
56
|
+
column-gap: 0.2rem;
|
|
57
|
+
position: absolute;
|
|
58
|
+
right: calc(var(--ifm-pre-padding) / 2);
|
|
59
|
+
top: calc(var(--ifm-pre-padding) / 2);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.openapi-demo__code-block-btn-group button {
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
background: var(--prism-background-color);
|
|
66
|
+
color: var(--prism-color);
|
|
67
|
+
border: 1px solid var(--ifm-color-emphasis-300);
|
|
68
|
+
border-radius: var(--ifm-global-radius);
|
|
69
|
+
padding: 0.4rem;
|
|
70
|
+
line-height: 0;
|
|
71
|
+
transition: opacity 200ms ease-in-out;
|
|
72
|
+
opacity: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.openapi-demo__code-block-btn-group button:focus-visible,
|
|
76
|
+
.openapi-demo__code-block-btn-group button:hover {
|
|
77
|
+
opacity: 1 !important;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.theme-code-block:hover .openapi-demo__code-block-btn-group button {
|
|
81
|
+
opacity: 0.4;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@media screen and (max-width: 996px) {
|
|
85
|
+
.openapi-demo__expand-btn {
|
|
86
|
+
display: none !important;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.theme-code-block:hover {
|
|
2
|
+
.openapi-demo__code-block-copy-btn--copied {
|
|
3
|
+
opacity: 1 !important;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.openapi-demo__code-block-copy-btn-icons {
|
|
8
|
+
position: relative;
|
|
9
|
+
width: 1.125rem;
|
|
10
|
+
height: 1.125rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.openapi-demo__code-block-copy-btn-icon,
|
|
14
|
+
.openapi-demo__code-block-copy-btn-icon--success {
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
fill: currentColor;
|
|
19
|
+
opacity: inherit;
|
|
20
|
+
width: inherit;
|
|
21
|
+
height: inherit;
|
|
22
|
+
transition: all 0.15s ease;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.openapi-demo__code-block-copy-btn-icon--success {
|
|
26
|
+
top: 50%;
|
|
27
|
+
left: 50%;
|
|
28
|
+
transform: translate(-50%, -50%) scale(0.33);
|
|
29
|
+
opacity: 0;
|
|
30
|
+
color: #00d600;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.openapi-demo__code-block-copy-btn--copied {
|
|
34
|
+
.openapi-demo__code-block-copy-btn-icon {
|
|
35
|
+
transform: scale(0.33);
|
|
36
|
+
opacity: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.openapi-demo__code-block-copy-btn-icon--success {
|
|
40
|
+
transform: translate(-50%, -50%) scale(1);
|
|
41
|
+
opacity: 1;
|
|
42
|
+
transition-delay: 0.075s;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React, { useCallback, useState, useRef, useEffect } from "react";
|
|
9
|
+
|
|
10
|
+
import { translate } from "@docusaurus/Translate";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
// @ts-expect-error: TODO, we need to make theme-classic have type: module
|
|
13
|
+
import copy from "copy-text-to-clipboard";
|
|
14
|
+
|
|
15
|
+
export default function CopyButton({ code, className }) {
|
|
16
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
17
|
+
const copyTimeout = useRef(undefined);
|
|
18
|
+
const handleCopyCode = useCallback(() => {
|
|
19
|
+
copy(code);
|
|
20
|
+
setIsCopied(true);
|
|
21
|
+
copyTimeout.current = window.setTimeout(() => {
|
|
22
|
+
setIsCopied(false);
|
|
23
|
+
}, 1000);
|
|
24
|
+
}, [code]);
|
|
25
|
+
useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
|
|
26
|
+
return (
|
|
27
|
+
<button
|
|
28
|
+
type="button"
|
|
29
|
+
aria-label={
|
|
30
|
+
isCopied
|
|
31
|
+
? translate({
|
|
32
|
+
id: "theme.CodeBlock.copied",
|
|
33
|
+
message: "Copied",
|
|
34
|
+
description: "The copied button label on code blocks",
|
|
35
|
+
})
|
|
36
|
+
: translate({
|
|
37
|
+
id: "theme.CodeBlock.copyButtonAriaLabel",
|
|
38
|
+
message: "Copy code to clipboard",
|
|
39
|
+
description: "The ARIA label for copy code blocks button",
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
title={translate({
|
|
43
|
+
id: "theme.CodeBlock.copy",
|
|
44
|
+
message: "Copy",
|
|
45
|
+
description: "The copy button label on code blocks",
|
|
46
|
+
})}
|
|
47
|
+
className={clsx(
|
|
48
|
+
"clean-btn",
|
|
49
|
+
className,
|
|
50
|
+
"openapi-demo__code-block-copy-btn",
|
|
51
|
+
isCopied && "openapi-demo__code-block-copy-btn--copied"
|
|
52
|
+
)}
|
|
53
|
+
onClick={handleCopyCode}
|
|
54
|
+
>
|
|
55
|
+
<span
|
|
56
|
+
className="openapi-demo__code-block-copy-btn-icons"
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
>
|
|
59
|
+
<svg
|
|
60
|
+
className="openapi-demo__code-block-copy-btn-icon"
|
|
61
|
+
viewBox="0 0 24 24"
|
|
62
|
+
>
|
|
63
|
+
<path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
|
|
64
|
+
</svg>
|
|
65
|
+
<svg
|
|
66
|
+
className="openapi-demo__code-block-copy-btn-icon--success"
|
|
67
|
+
viewBox="0 0 24 24"
|
|
68
|
+
>
|
|
69
|
+
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
|
|
70
|
+
</svg>
|
|
71
|
+
</span>
|
|
72
|
+
</button>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.openapi-demo__code-block-exit-btn-icons {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 1.125rem;
|
|
4
|
+
height: 1.125rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.openapi-demo__code-block-exit-btn-icon {
|
|
8
|
+
position: absolute;
|
|
9
|
+
top: 0;
|
|
10
|
+
left: 0;
|
|
11
|
+
fill: currentColor;
|
|
12
|
+
opacity: inherit;
|
|
13
|
+
width: inherit;
|
|
14
|
+
height: inherit;
|
|
15
|
+
transition: all 0.15s ease;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { translate } from "@docusaurus/Translate";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
|
|
13
|
+
export default function ExitButton({ className, handler }) {
|
|
14
|
+
return (
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
aria-label={translate({
|
|
18
|
+
id: "theme.CodeBlock.exitButtonAriaLabel",
|
|
19
|
+
message: "Exit expanded view",
|
|
20
|
+
description: "The ARIA label for exit expanded view button",
|
|
21
|
+
})}
|
|
22
|
+
title={translate({
|
|
23
|
+
id: "theme.CodeBlock.copy",
|
|
24
|
+
message: "Copy",
|
|
25
|
+
description: "The exit button label on code blocks",
|
|
26
|
+
})}
|
|
27
|
+
className={clsx(
|
|
28
|
+
"clean-btn",
|
|
29
|
+
"openapi-demo__code-block-exit-btn",
|
|
30
|
+
className
|
|
31
|
+
)}
|
|
32
|
+
onClick={handler}
|
|
33
|
+
>
|
|
34
|
+
<span
|
|
35
|
+
className="openapi-demo__code-block-exit-btn-icons"
|
|
36
|
+
aria-hidden="true"
|
|
37
|
+
>
|
|
38
|
+
<svg
|
|
39
|
+
className="openapi-demo__code-block-exit-btn-icon"
|
|
40
|
+
viewBox="0 0 384 512"
|
|
41
|
+
>
|
|
42
|
+
<path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z" />
|
|
43
|
+
</svg>
|
|
44
|
+
</span>
|
|
45
|
+
</button>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.theme-code-block:hover .openapi-demo__code-block-expand-btn--copied {
|
|
2
|
+
opacity: 1 !important;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.openapi-demo__code-block-expand-btn-icons {
|
|
6
|
+
position: relative;
|
|
7
|
+
width: 1.125rem;
|
|
8
|
+
height: 1.125rem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.openapi-demo__code-block-expand-btn-icon,
|
|
12
|
+
.openapi-demo__code-block-expand-btn-icon--success {
|
|
13
|
+
position: absolute;
|
|
14
|
+
top: 0;
|
|
15
|
+
left: 0;
|
|
16
|
+
fill: currentColor;
|
|
17
|
+
opacity: inherit;
|
|
18
|
+
width: inherit;
|
|
19
|
+
height: inherit;
|
|
20
|
+
transition: all 0.15s ease;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.openapi-demo__code-block-expand-btn-icon--success {
|
|
24
|
+
top: 50%;
|
|
25
|
+
left: 50%;
|
|
26
|
+
transform: translate(-50%, -50%) scale(0.33);
|
|
27
|
+
opacity: 0;
|
|
28
|
+
color: #00d600;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.openapi-demo__code-block-expand-btn--copied
|
|
32
|
+
.openapi-demo__code-block-expand-btn-icon {
|
|
33
|
+
transform: scale(0.33);
|
|
34
|
+
opacity: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.openapi-demo__code-block-expand-btn--copied
|
|
38
|
+
.openapi-demo__code-block-expand-btn-icon--success {
|
|
39
|
+
transform: translate(-50%, -50%) scale(1);
|
|
40
|
+
opacity: 1;
|
|
41
|
+
transition-delay: 0.075s;
|
|
42
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React, { useEffect } from "react";
|
|
9
|
+
|
|
10
|
+
import { usePrismTheme } from "@docusaurus/theme-common";
|
|
11
|
+
import { translate } from "@docusaurus/Translate";
|
|
12
|
+
import Container from "@theme/ApiDemoPanel/ApiCodeBlock/Container";
|
|
13
|
+
import CopyButton from "@theme/ApiDemoPanel/ApiCodeBlock/CopyButton";
|
|
14
|
+
import ExitButton from "@theme/ApiDemoPanel/ApiCodeBlock/ExitButton";
|
|
15
|
+
import Line from "@theme/ApiDemoPanel/ApiCodeBlock/Line";
|
|
16
|
+
import clsx from "clsx";
|
|
17
|
+
import Highlight, { defaultProps } from "prism-react-renderer";
|
|
18
|
+
import Modal from "react-modal";
|
|
19
|
+
|
|
20
|
+
export default function ExpandButton({
|
|
21
|
+
code,
|
|
22
|
+
className,
|
|
23
|
+
language,
|
|
24
|
+
showLineNumbers,
|
|
25
|
+
blockClassName,
|
|
26
|
+
title,
|
|
27
|
+
lineClassNames,
|
|
28
|
+
}) {
|
|
29
|
+
const prismTheme = usePrismTheme();
|
|
30
|
+
|
|
31
|
+
function openModal() {
|
|
32
|
+
setIsOpen(true);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function closeModal() {
|
|
36
|
+
setIsOpen(false);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const [modalIsOpen, setIsOpen] = React.useState(false);
|
|
40
|
+
|
|
41
|
+
const customStyles = {
|
|
42
|
+
overlay: { backgroundColor: "rgba(0, 0, 0, 0.9)", zIndex: "201" },
|
|
43
|
+
content: {
|
|
44
|
+
top: "50%",
|
|
45
|
+
left: "50%",
|
|
46
|
+
right: "auto",
|
|
47
|
+
bottom: "auto",
|
|
48
|
+
padding: "none",
|
|
49
|
+
border: "thin solid var(--ifm-toc-border-color)",
|
|
50
|
+
borderRadius: "var(--ifm-global-radius)",
|
|
51
|
+
transform: "translate(-50%, -50%)",
|
|
52
|
+
maxWidth: "95%",
|
|
53
|
+
width: "min-content",
|
|
54
|
+
overflow: "auto",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
Modal.setAppElement("body");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
aria-label={
|
|
66
|
+
modalIsOpen
|
|
67
|
+
? translate({
|
|
68
|
+
id: "theme.CodeBlock.expanded",
|
|
69
|
+
message: "Expanded",
|
|
70
|
+
description: "The expanded button label on code blocks",
|
|
71
|
+
})
|
|
72
|
+
: translate({
|
|
73
|
+
id: "theme.CodeBlock.expandButtonAriaLabel",
|
|
74
|
+
message: "Expand code to fullscreen",
|
|
75
|
+
description: "The ARIA label for expand code blocks button",
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
title={translate({
|
|
79
|
+
id: "theme.CodeBlock.expand",
|
|
80
|
+
message: "Expand",
|
|
81
|
+
description: "The expand button label on code blocks",
|
|
82
|
+
})}
|
|
83
|
+
className={clsx(
|
|
84
|
+
"clean-btn",
|
|
85
|
+
className,
|
|
86
|
+
"openapi-demo__code-block-expand-btn",
|
|
87
|
+
modalIsOpen && "openapi-demo__code-block-expand-btn--copied"
|
|
88
|
+
)}
|
|
89
|
+
onClick={openModal}
|
|
90
|
+
>
|
|
91
|
+
<span
|
|
92
|
+
className="openapi-demo__code-block-expand-btn-icons"
|
|
93
|
+
aria-hidden="true"
|
|
94
|
+
>
|
|
95
|
+
<svg
|
|
96
|
+
className="openapi-demo__code-block-expand-btn-icon"
|
|
97
|
+
viewBox="0 0 448 512"
|
|
98
|
+
>
|
|
99
|
+
<path d="M32 32C14.3 32 0 46.3 0 64v96c0 17.7 14.3 32 32 32s32-14.3 32-32V96h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H64V352zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32h64v64c0 17.7 14.3 32 32 32s32-14.3 32-32V64c0-17.7-14.3-32-32-32H320zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H320c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V352z" />
|
|
100
|
+
</svg>
|
|
101
|
+
<svg
|
|
102
|
+
className="openapi-demo__code-block-expand-btn-icon--success"
|
|
103
|
+
viewBox="0 0 24 24"
|
|
104
|
+
>
|
|
105
|
+
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
|
|
106
|
+
</svg>
|
|
107
|
+
</span>
|
|
108
|
+
</button>
|
|
109
|
+
<Modal
|
|
110
|
+
isOpen={modalIsOpen}
|
|
111
|
+
onRequestClose={closeModal}
|
|
112
|
+
style={customStyles}
|
|
113
|
+
contentLabel="Code Snippet"
|
|
114
|
+
>
|
|
115
|
+
<Container
|
|
116
|
+
as="div"
|
|
117
|
+
className={clsx(
|
|
118
|
+
"openapi-demo__code-block-container",
|
|
119
|
+
language &&
|
|
120
|
+
!blockClassName.includes(`language-${language}`) &&
|
|
121
|
+
`language-${language}`
|
|
122
|
+
)}
|
|
123
|
+
>
|
|
124
|
+
{title && (
|
|
125
|
+
<div className="openapi-demo__code-block-title">{title}</div>
|
|
126
|
+
)}
|
|
127
|
+
<div className="openapi-demo__code-block-content">
|
|
128
|
+
<Highlight
|
|
129
|
+
{...defaultProps}
|
|
130
|
+
theme={prismTheme}
|
|
131
|
+
code={code}
|
|
132
|
+
language={language ?? "text"}
|
|
133
|
+
>
|
|
134
|
+
{({ className, tokens, getLineProps, getTokenProps }) => (
|
|
135
|
+
<pre
|
|
136
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
137
|
+
tabIndex={0}
|
|
138
|
+
className={clsx(
|
|
139
|
+
className,
|
|
140
|
+
"openapi-demo__code-block",
|
|
141
|
+
"thin-scrollbar"
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
<code
|
|
145
|
+
className={clsx(
|
|
146
|
+
"openapi-demo__code-block-lines",
|
|
147
|
+
showLineNumbers &&
|
|
148
|
+
"openapi-demo__code-block-lines-numbers"
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
{tokens.map((line, i) => (
|
|
152
|
+
<Line
|
|
153
|
+
key={i}
|
|
154
|
+
line={line}
|
|
155
|
+
getLineProps={getLineProps}
|
|
156
|
+
getTokenProps={getTokenProps}
|
|
157
|
+
classNames={lineClassNames[i]}
|
|
158
|
+
showLineNumbers={showLineNumbers}
|
|
159
|
+
/>
|
|
160
|
+
))}
|
|
161
|
+
</code>
|
|
162
|
+
</pre>
|
|
163
|
+
)}
|
|
164
|
+
</Highlight>
|
|
165
|
+
<div className="openapi-demo__code-block-btn-group">
|
|
166
|
+
<CopyButton
|
|
167
|
+
className="openapi-demo__code-block-code-btn"
|
|
168
|
+
code={code}
|
|
169
|
+
/>
|
|
170
|
+
<ExitButton
|
|
171
|
+
className="openapi-dmeo__code-block-code-btn"
|
|
172
|
+
handler={closeModal}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
</Container>
|
|
177
|
+
</Modal>
|
|
178
|
+
</>
|
|
179
|
+
);
|
|
180
|
+
}
|