docusaurus-theme-openapi-docs 1.0.2 → 1.0.5

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.
Files changed (59) hide show
  1. package/lib/theme/ApiDemoPanel/Body/index.js +11 -9
  2. package/lib/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  3. package/lib/theme/ApiDemoPanel/CodeTabs/index.js +188 -0
  4. package/lib/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  5. package/lib/theme/ApiDemoPanel/Curl/index.js +41 -110
  6. package/lib/theme/ApiDemoPanel/LiveEditor/index.js +61 -0
  7. package/lib/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  8. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +9 -6
  9. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +7 -2
  10. package/lib/theme/ApiDemoPanel/index.js +3 -7
  11. package/lib/theme/ApiItem/icons/bash-original.svg +1 -0
  12. package/lib/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  13. package/lib/theme/ApiItem/icons/javascript-original.svg +1 -0
  14. package/lib/theme/ApiItem/icons/linux-original.svg +1 -0
  15. package/lib/theme/ApiItem/icons/python-original.svg +1 -0
  16. package/lib/theme/ApiItem/index.js +2 -1
  17. package/lib/theme/ApiItem/styles.module.css +89 -0
  18. package/lib-next/theme/ApiDemoPanel/Body/index.js +11 -15
  19. package/lib-next/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  20. package/lib-next/theme/ApiDemoPanel/CodeTabs/index.js +214 -0
  21. package/lib-next/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  22. package/lib-next/theme/ApiDemoPanel/Curl/index.js +46 -135
  23. package/lib-next/theme/ApiDemoPanel/LiveEditor/index.js +49 -0
  24. package/lib-next/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  25. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +9 -6
  26. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +6 -2
  27. package/lib-next/theme/ApiDemoPanel/index.js +2 -7
  28. package/lib-next/theme/ApiItem/icons/bash-original.svg +1 -0
  29. package/lib-next/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  30. package/lib-next/theme/ApiItem/icons/javascript-original.svg +1 -0
  31. package/lib-next/theme/ApiItem/icons/linux-original.svg +1 -0
  32. package/lib-next/theme/ApiItem/icons/python-original.svg +1 -0
  33. package/lib-next/theme/ApiItem/index.js +2 -1
  34. package/lib-next/theme/ApiItem/styles.module.css +89 -0
  35. package/package.json +7 -9
  36. package/src/theme/ApiDemoPanel/Body/index.tsx +9 -13
  37. package/src/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  38. package/src/theme/ApiDemoPanel/CodeTabs/index.tsx +237 -0
  39. package/src/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  40. package/src/theme/ApiDemoPanel/Curl/index.tsx +45 -124
  41. package/src/theme/ApiDemoPanel/LiveEditor/index.tsx +59 -0
  42. package/src/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  43. package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +6 -4
  44. package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +7 -2
  45. package/src/theme/ApiDemoPanel/index.tsx +8 -7
  46. package/src/theme/ApiItem/icons/bash-original.svg +1 -0
  47. package/src/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  48. package/src/theme/ApiItem/icons/javascript-original.svg +1 -0
  49. package/src/theme/ApiItem/icons/linux-original.svg +1 -0
  50. package/src/theme/ApiItem/icons/python-original.svg +1 -0
  51. package/src/theme/ApiItem/index.tsx +9 -5
  52. package/src/theme/ApiItem/styles.module.css +89 -0
  53. package/src/types.ts +112 -0
  54. package/lib/theme/ApiDemoPanel/VSCode/index.js +0 -252
  55. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  56. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +0 -265
  57. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  58. package/src/theme/ApiDemoPanel/VSCode/index.tsx +0 -205
  59. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
@@ -85,6 +85,7 @@ function DocItemContent(props) {
85
85
  frontMatter
86
86
  } = DocContent;
87
87
  const {
88
+ info_path: infoPath,
88
89
  hide_title: hideTitle,
89
90
  hide_table_of_contents: hideTableOfContents,
90
91
  toc_min_heading_level: tocMinHeadingLevel,
@@ -131,7 +132,7 @@ function DocItemContent(props) {
131
132
  <DocContent />
132
133
  </div>
133
134
  {api && <div className="col col--5">
134
- <ApiDemoPanel item={api} />
135
+ <ApiDemoPanel item={api} infoPath={infoPath} />
135
136
  </div>}
136
137
  </div>
137
138
  </_MDXContent.default>
@@ -11,6 +11,23 @@
11
11
  margin-top: 0;
12
12
  }
13
13
 
14
+ :global(.version-button div) {
15
+ display: block;
16
+ }
17
+
18
+ :global(.version-button div > button > span::after) {
19
+ border-color: currentcolor transparent;
20
+ border-style: solid;
21
+ border-width: 0.4em 0.4em 0;
22
+ content: "";
23
+ margin-left: 0.3em;
24
+ position: relative;
25
+ transform: translateY(-50%);
26
+ display: inline-block;
27
+ font-size: 0.8rem;
28
+ top: 1px;
29
+ }
30
+
14
31
  /* default markdown margins look really silly in a table */
15
32
  :global(.theme-api-markdown table *:last-child) {
16
33
  margin-bottom: 0;
@@ -111,3 +128,75 @@
111
128
  margin-top: 0 !important;
112
129
  padding-left: 2px;
113
130
  }
131
+
132
+ :global(.code__tab--python::after) {
133
+ content: "";
134
+ width: 32px;
135
+ height: 32px;
136
+ background: url(./icons/python-original.svg);
137
+ margin-block: auto;
138
+ }
139
+
140
+ :global(.code__tab--python) {
141
+ color: var(--ifm-color-success);
142
+ padding-left: 2rem;
143
+ padding-right: 2rem;
144
+ }
145
+
146
+ :global(.code__tab--python.tabs__item--active) {
147
+ border-bottom-color: var(--ifm-color-success);
148
+ }
149
+
150
+ :global(.code__tab--go::after) {
151
+ content: "";
152
+ width: 32px;
153
+ height: 32px;
154
+ background: url(./icons/go-original-wordmark.svg);
155
+ margin-block: auto;
156
+ }
157
+
158
+ :global(.code__tab--go) {
159
+ color: var(--ifm-color-info);
160
+ padding-left: 2rem;
161
+ padding-right: 2rem;
162
+ }
163
+
164
+ :global(.code__tab--go.tabs__item--active) {
165
+ border-bottom-color: var(--ifm-color-info);
166
+ }
167
+
168
+ :global(.code__tab--javascript::after) {
169
+ content: "";
170
+ width: 32px;
171
+ height: 32px;
172
+ background: url(./icons/javascript-original.svg);
173
+ margin-block: auto;
174
+ }
175
+
176
+ :global(.code__tab--javascript) {
177
+ color: var(--ifm-color-warning);
178
+ padding-left: 2rem;
179
+ padding-right: 2rem;
180
+ }
181
+
182
+ :global(.code__tab--javascript.tabs__item--active) {
183
+ border-bottom-color: var(--ifm-color-warning);
184
+ }
185
+
186
+ :global(.code__tab--bash::after) {
187
+ content: "";
188
+ width: 32px;
189
+ height: 32px;
190
+ background: url(./icons/linux-original.svg);
191
+ margin-block: auto;
192
+ }
193
+
194
+ :global(.code__tab--bash) {
195
+ color: var(--ifm-color-danger);
196
+ padding-left: 2rem;
197
+ padding-right: 2rem;
198
+ }
199
+
200
+ :global(.code__tab--bash.tabs__item--active) {
201
+ border-bottom-color: var(--ifm-color-danger);
202
+ }
@@ -8,17 +8,18 @@ import React from "react";
8
8
  import ContentType from "../ContentType";
9
9
  import FormSelect from "../FormSelect";
10
10
  import { useTypedDispatch, useTypedSelector } from "../hooks";
11
+ import LiveApp from "../LiveEditor";
11
12
  import FormFileUpload from "./../FormFileUpload";
12
13
  import FormItem from "./../FormItem";
13
- import FormTextInput from "./../FormTextInput";
14
- import VSCode from "./../VSCode";
14
+ import FormTextInput from "./../FormTextInput"; // @ts-ignore
15
+
16
+ import json2xml from "./json2xml";
15
17
  import {
16
18
  clearFormBodyKey,
17
19
  clearRawBody,
18
20
  setFileFormBody,
19
21
  setFileRawBody,
20
22
  setStringFormBody,
21
- setStringRawBody,
22
23
  } from "./slice";
23
24
 
24
25
  function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }) {
@@ -186,23 +187,18 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
186
187
  }
187
188
 
188
189
  if (contentType === "application/xml") {
190
+ if (jsonRequestBodyExample) {
191
+ exampleBodyString = json2xml(jsonRequestBodyExample);
192
+ }
193
+
189
194
  language = "xml";
190
195
  }
191
196
 
192
197
  return (
193
198
  <FormItem label="Body">
194
- <VSCode
195
- value={exampleBodyString}
196
- language={language}
197
- onChange={(value) => {
198
- if (value.trim() === "") {
199
- dispatch(clearRawBody());
200
- return;
201
- }
202
-
203
- dispatch(setStringRawBody(value));
204
- }}
205
- />
199
+ <LiveApp action={dispatch} language={language}>
200
+ {exampleBodyString}
201
+ </LiveApp>
206
202
  </FormItem>
207
203
  );
208
204
  }
@@ -0,0 +1,43 @@
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
+ export default function json2xml(o, tab) {
9
+ var toXml = function (v, name, ind) {
10
+ var xml = "";
11
+ if (v instanceof Array) {
12
+ for (var i = 0, n = v.length; i < n; i++)
13
+ xml += ind + toXml(v[i], name, ind + "\t") + "\n";
14
+ } else if (typeof v == "object") {
15
+ var hasChild = false;
16
+ xml += ind + "<" + name;
17
+ for (var m in v) {
18
+ if (m.charAt(0) === "@")
19
+ xml += " " + m.substr(1) + '="' + v[m].toString() + '"';
20
+ else hasChild = true;
21
+ }
22
+ xml += hasChild ? ">" : "/>";
23
+ if (hasChild) {
24
+ for (var m2 in v) {
25
+ if (m2 === "#text") xml += v[m2];
26
+ else if (m2 === "#cdata") xml += "<![CDATA[" + v[m2] + "]]>";
27
+ else if (m2.charAt(0) !== "@") xml += toXml(v[m2], m2, ind + "\t");
28
+ }
29
+ xml +=
30
+ (xml.charAt(xml.length - 1) === "\n" ? ind : "") +
31
+ "</" +
32
+ name +
33
+ ">";
34
+ }
35
+ } else {
36
+ xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
37
+ }
38
+ return xml;
39
+ },
40
+ xml = "";
41
+ for (var m3 in o) xml += toXml(o[m3], m3, "");
42
+ return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
43
+ }
@@ -0,0 +1,214 @@
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
+ import React, { useState, cloneElement, isValidElement } from "react";
8
+ import {
9
+ useScrollPositionBlocker,
10
+ duplicates,
11
+ useTabGroupChoice,
12
+ } from "@docusaurus/theme-common";
13
+ import useIsBrowser from "@docusaurus/useIsBrowser";
14
+ import clsx from "clsx";
15
+ import { languageSet } from "../Curl";
16
+ import styles from "./styles.module.css"; // A very rough duck type, but good enough to guard against mistakes while
17
+ // allowing customization
18
+
19
+ function isTabItem(comp) {
20
+ return "value" in comp.props;
21
+ }
22
+
23
+ function TabsComponent(props) {
24
+ const {
25
+ lazy,
26
+ block,
27
+ defaultValue: defaultValueProp,
28
+ values: valuesProp,
29
+ groupId,
30
+ className,
31
+ action,
32
+ } = props;
33
+ const children = React.Children.map(props.children, (child) => {
34
+ if (isValidElement(child) && isTabItem(child)) {
35
+ return child;
36
+ } // child.type.name will give non-sensical values in prod because of
37
+ // minification, but we assume it won't throw in prod.
38
+
39
+ throw new Error(
40
+ `Docusaurus error: Bad <Tabs> child <${
41
+ // @ts-expect-error: guarding against unexpected cases
42
+ typeof child.type === "string" ? child.type : child.type.name
43
+ }>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`
44
+ );
45
+ });
46
+ const values =
47
+ valuesProp ?? // Only pick keys that we recognize. MDX would inject some keys by default
48
+ children.map(({ props: { value, label, attributes } }) => ({
49
+ value,
50
+ label,
51
+ attributes,
52
+ }));
53
+ const dup = duplicates(values, (a, b) => a.value === b.value);
54
+
55
+ if (dup.length > 0) {
56
+ throw new Error(
57
+ `Docusaurus error: Duplicate values "${dup
58
+ .map((a) => a.value)
59
+ .join(", ")}" found in <Tabs>. Every value needs to be unique.`
60
+ );
61
+ } // When defaultValueProp is null, don't show a default tab
62
+
63
+ const defaultValue =
64
+ defaultValueProp === null
65
+ ? defaultValueProp
66
+ : defaultValueProp ??
67
+ children.find((child) => child.props.default)?.props.value ??
68
+ children[0].props.value;
69
+
70
+ if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
71
+ throw new Error(
72
+ `Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
73
+ .map((a) => a.value)
74
+ .join(
75
+ ", "
76
+ )}. If you intend to show no default tab, use defaultValue={null} instead.`
77
+ );
78
+ }
79
+
80
+ const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();
81
+ const [selectedValue, setSelectedValue] = useState(defaultValue);
82
+ const tabRefs = [];
83
+ const { blockElementScrollPositionUntilNextRender } =
84
+ useScrollPositionBlocker();
85
+
86
+ if (groupId != null) {
87
+ const relevantTabGroupChoice = tabGroupChoices[groupId];
88
+
89
+ if (
90
+ relevantTabGroupChoice != null &&
91
+ relevantTabGroupChoice !== selectedValue &&
92
+ values.some((value) => value.value === relevantTabGroupChoice)
93
+ ) {
94
+ setSelectedValue(relevantTabGroupChoice);
95
+ }
96
+ }
97
+
98
+ const handleTabChange = (event) => {
99
+ const newTab = event.currentTarget;
100
+ const newTabIndex = tabRefs.indexOf(newTab);
101
+ const newTabValue = values[newTabIndex].value;
102
+
103
+ if (newTabValue !== selectedValue) {
104
+ blockElementScrollPositionUntilNextRender(newTab);
105
+ setSelectedValue(newTabValue);
106
+
107
+ if (action) {
108
+ const newLanguage = languageSet.filter(
109
+ (lang) => lang.language === newTabValue
110
+ );
111
+ action(newLanguage[0]);
112
+ }
113
+
114
+ if (groupId != null) {
115
+ setTabGroupChoices(groupId, String(newTabValue));
116
+ }
117
+ }
118
+ };
119
+
120
+ const handleKeydown = (event) => {
121
+ let focusElement = null;
122
+
123
+ switch (event.key) {
124
+ case "ArrowRight": {
125
+ const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
126
+ focusElement = tabRefs[nextTab] ?? tabRefs[0];
127
+ break;
128
+ }
129
+
130
+ case "ArrowLeft": {
131
+ const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
132
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
133
+ break;
134
+ }
135
+
136
+ default:
137
+ break;
138
+ }
139
+
140
+ focusElement?.focus();
141
+ };
142
+
143
+ return (
144
+ <div className={clsx("tabs-container", styles.tabList)}>
145
+ <ul
146
+ role="tablist"
147
+ aria-orientation="horizontal"
148
+ className={clsx(
149
+ "tabs",
150
+ {
151
+ "tabs--block": block,
152
+ },
153
+ styles.code__tabs,
154
+ className
155
+ )}
156
+ >
157
+ {values.map(({ value, label, attributes }) => (
158
+ <li
159
+ role="tab"
160
+ tabIndex={selectedValue === value ? 0 : -1}
161
+ aria-selected={selectedValue === value}
162
+ key={value}
163
+ ref={(tabControl) => tabRefs.push(tabControl)}
164
+ onKeyDown={handleKeydown}
165
+ onFocus={handleTabChange}
166
+ onClick={handleTabChange}
167
+ {...attributes}
168
+ className={clsx(
169
+ "tabs__item",
170
+ styles.tabItem,
171
+ attributes?.className,
172
+ {
173
+ "tabs__item--active": selectedValue === value,
174
+ }
175
+ )}
176
+ >
177
+ {label ?? value}
178
+ </li>
179
+ ))}
180
+ </ul>
181
+
182
+ {lazy ? (
183
+ cloneElement(
184
+ children.filter(
185
+ (tabItem) => tabItem.props.value === selectedValue
186
+ )[0],
187
+ {
188
+ className: "margin-top--md",
189
+ }
190
+ )
191
+ ) : (
192
+ <div className="margin-top--md">
193
+ {children.map((tabItem, i) =>
194
+ cloneElement(tabItem, {
195
+ key: i,
196
+ hidden: tabItem.props.value !== selectedValue,
197
+ })
198
+ )}
199
+ </div>
200
+ )}
201
+ </div>
202
+ );
203
+ }
204
+
205
+ export default function CodeTabs(props) {
206
+ const isBrowser = useIsBrowser();
207
+ return (
208
+ <TabsComponent // Remount tabs after hydration
209
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
210
+ key={String(isBrowser)}
211
+ {...props}
212
+ />
213
+ );
214
+ }
@@ -0,0 +1,11 @@
1
+ .tabList {
2
+ margin-bottom: var(--ifm-leading);
3
+ }
4
+
5
+ .tabItem {
6
+ margin-top: 0 !important;
7
+ }
8
+
9
+ .code__tabs {
10
+ justify-content: space-around;
11
+ }
@@ -4,20 +4,21 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
- import React, { useRef, useState, useEffect } from "react";
7
+ import React, { useState, useEffect } from "react";
8
8
  import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
9
9
  import codegen from "@paloaltonetworks/postman-code-generators";
10
+ import CodeBlock from "@theme/CodeBlock";
10
11
  import clsx from "clsx";
11
- import Highlight, { defaultProps } from "prism-react-renderer";
12
+ import CodeTabs from "../CodeTabs";
12
13
  import { useTypedSelector } from "../hooks";
13
14
  import buildPostmanRequest from "./../buildPostmanRequest";
14
- import FloatingButton from "./../FloatingButton";
15
15
  import styles from "./styles.module.css";
16
- const languageSet = [
16
+ export const languageSet = [
17
17
  {
18
18
  tabName: "cURL",
19
19
  highlight: "bash",
20
20
  language: "curl",
21
+ codeLanguage: "bash",
21
22
  variant: "curl",
22
23
  options: {
23
24
  longFormat: false,
@@ -26,12 +27,12 @@ const languageSet = [
26
27
  },
27
28
  },
28
29
  {
29
- tabName: "Node",
30
- highlight: "javascript",
31
- language: "nodejs",
32
- variant: "axios",
30
+ tabName: "Python",
31
+ highlight: "python",
32
+ language: "python",
33
+ codeLanguage: "python",
34
+ variant: "requests",
33
35
  options: {
34
- ES6_enabled: true,
35
36
  followRedirect: true,
36
37
  trimRequestBody: true,
37
38
  },
@@ -40,6 +41,7 @@ const languageSet = [
40
41
  tabName: "Go",
41
42
  highlight: "go",
42
43
  language: "go",
44
+ codeLanguage: "go",
43
45
  variant: "native",
44
46
  options: {
45
47
  followRedirect: true,
@@ -47,70 +49,36 @@ const languageSet = [
47
49
  },
48
50
  },
49
51
  {
50
- tabName: "Python",
51
- highlight: "python",
52
- language: "python",
53
- variant: "requests",
52
+ tabName: "Node",
53
+ highlight: "javascript",
54
+ language: "nodejs",
55
+ codeLanguage: "javascript",
56
+ variant: "axios",
54
57
  options: {
58
+ ES6_enabled: true,
55
59
  followRedirect: true,
56
60
  trimRequestBody: true,
57
61
  },
58
62
  },
59
63
  ];
60
- const languageTheme = {
61
- plain: {
62
- color: "var(--ifm-code-color)",
63
- },
64
- styles: [
65
- {
66
- types: ["inserted", "attr-name"],
67
- style: {
68
- color: "var(--openapi-code-green)",
69
- },
70
- },
71
- {
72
- types: ["string", "url"],
73
- style: {
74
- color: "var(--openapi-code-green)",
75
- },
76
- },
77
- {
78
- types: ["builtin", "char", "constant", "function"],
79
- style: {
80
- color: "var(--openapi-code-blue)",
81
- },
82
- },
83
- {
84
- types: ["punctuation", "operator"],
85
- style: {
86
- color: "var(--openapi-code-dim)",
87
- },
88
- },
89
- {
90
- types: ["class-name"],
91
- style: {
92
- color: "var(--openapi-code-orange)",
93
- },
94
- },
95
- {
96
- types: ["tag", "arrow", "keyword"],
97
- style: {
98
- color: "var(--openapi-code-purple)",
99
- },
100
- },
101
- {
102
- types: ["boolean"],
103
- style: {
104
- color: "var(--openapi-code-red)",
105
- },
106
- },
107
- ],
108
- };
64
+
65
+ function CodeTab({ children, hidden, className, onClick }) {
66
+ return (
67
+ <div
68
+ role="tabpanel"
69
+ className={clsx(styles.tabItem, className)}
70
+ {...{
71
+ hidden,
72
+ }}
73
+ >
74
+ {children}
75
+ </div>
76
+ );
77
+ }
109
78
 
110
79
  function Curl({ postman, codeSamples }) {
111
80
  // TODO: match theme for vscode.
112
81
  const { siteConfig } = useDocusaurusContext();
113
- const [copyText, setCopyText] = useState("Copy");
114
82
  const contentType = useTypedSelector((state) => state.contentType.value);
115
83
  const accept = useTypedSelector((state) => state.accept.value);
116
84
  const server = useTypedSelector((state) => state.server.value);
@@ -125,7 +93,11 @@ function Curl({ postman, codeSamples }) {
125
93
  ...(siteConfig?.themeConfig?.languageTabs ?? languageSet),
126
94
  ...codeSamples,
127
95
  ];
128
- const [language, setLanguage] = useState(langs[0]);
96
+ const defaultLang = languageSet.filter(
97
+ (lang) =>
98
+ lang.codeLanguage === localStorage.getItem("docusaurus.tab.code-samples")
99
+ );
100
+ const [language, setLanguage] = useState(defaultLang[0] ?? langs[0]);
129
101
  const [codeText, setCodeText] = useState("");
130
102
  useEffect(() => {
131
103
  if (language && !!language.options) {
@@ -171,18 +143,6 @@ function Curl({ postman, codeSamples }) {
171
143
  server,
172
144
  auth,
173
145
  ]);
174
- const ref = useRef(null);
175
-
176
- const handleCurlCopy = () => {
177
- setCopyText("Copied");
178
- setTimeout(() => {
179
- setCopyText("Copy");
180
- }, 2000);
181
-
182
- if (ref.current?.innerText) {
183
- navigator.clipboard.writeText(ref.current.innerText);
184
- }
185
- };
186
146
 
187
147
  if (language === undefined) {
188
148
  return null;
@@ -190,71 +150,22 @@ function Curl({ postman, codeSamples }) {
190
150
 
191
151
  return (
192
152
  <>
193
- <div className={clsx(styles.buttonGroup, "api-code-tab-group")}>
153
+ <CodeTabs groupId="code-samples" action={setLanguage}>
194
154
  {langs.map((lang) => {
195
155
  return (
196
- <button
156
+ <CodeTab
157
+ value={lang.language}
158
+ label={""}
197
159
  key={lang.tabName || lang.label}
198
- className={clsx(
199
- language === lang ? styles.selected : undefined,
200
- language === lang ? "api-code-tab--active" : undefined,
201
- "api-code-tab"
202
- )}
203
- onClick={() => setLanguage(lang)}
160
+ attributes={{
161
+ className: `code__tab--${lang.codeLanguage}`,
162
+ }}
204
163
  >
205
- {lang.tabName || lang.label}
206
- </button>
164
+ <CodeBlock language={lang.codeLanguage}>{codeText}</CodeBlock>
165
+ </CodeTab>
207
166
  );
208
167
  })}
209
- </div>
210
-
211
- <Highlight
212
- {...defaultProps}
213
- theme={languageTheme}
214
- code={codeText}
215
- language={language.highlight || language.lang}
216
- >
217
- {({ className, tokens, getLineProps, getTokenProps }) => (
218
- <FloatingButton onClick={handleCurlCopy} label={copyText}>
219
- <pre
220
- className={className}
221
- style={{
222
- background: "var(--openapi-card-background-color)",
223
- paddingRight: "60px",
224
- borderRadius:
225
- "2px 2px var(--openapi-card-border-radius) var(--openapi-card-border-radius)",
226
- }}
227
- >
228
- <code ref={ref}>
229
- {tokens.map((line, i) => (
230
- <span
231
- {...getLineProps({
232
- line,
233
- key: i,
234
- })}
235
- >
236
- {line.map((token, key) => {
237
- if (token.types.includes("arrow")) {
238
- token.types = ["arrow"];
239
- }
240
-
241
- return (
242
- <span
243
- {...getTokenProps({
244
- token,
245
- key,
246
- })}
247
- />
248
- );
249
- })}
250
- {"\n"}
251
- </span>
252
- ))}
253
- </code>
254
- </pre>
255
- </FloatingButton>
256
- )}
257
- </Highlight>
168
+ </CodeTabs>
258
169
  </>
259
170
  );
260
171
  }