docusaurus-theme-openapi-docs 1.1.2 → 1.1.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.
- package/lib/markdown/schema.js +85 -20
- package/lib/theme/ApiDemoPanel/Body/index.js +1 -1
- package/lib/theme/ApiItem/Layout/styles.module.css +16 -0
- package/lib/theme/ApiLogo/index.js +29 -0
- package/lib/theme/DiscriminatorTabs/index.js +263 -0
- package/lib/theme/DiscriminatorTabs/styles.module.css +111 -0
- package/lib/theme/MimeTabs/index.js +260 -0
- package/lib/theme/MimeTabs/styles.module.css +125 -0
- package/lib/theme/ParamsItem/index.js +10 -0
- package/lib/theme/ResponseSamples/index.js +27 -0
- package/lib/theme/ResponseSamples/styles.module.css +7 -0
- package/lib/theme/SchemaItem/index.js +15 -3
- package/lib/theme/SchemaTabs/styles.module.css +0 -8
- package/lib-next/markdown/schema.js +88 -22
- package/lib-next/theme/ApiDemoPanel/Body/index.js +1 -1
- package/lib-next/theme/ApiItem/Layout/styles.module.css +16 -0
- package/lib-next/theme/ApiLogo/index.js +21 -0
- package/lib-next/theme/DiscriminatorTabs/index.js +263 -0
- package/lib-next/theme/DiscriminatorTabs/styles.module.css +111 -0
- package/lib-next/theme/MimeTabs/index.js +260 -0
- package/lib-next/theme/MimeTabs/styles.module.css +125 -0
- package/lib-next/theme/ParamsItem/index.js +10 -0
- package/lib-next/theme/ResponseSamples/index.js +27 -0
- package/lib-next/theme/ResponseSamples/styles.module.css +7 -0
- package/lib-next/theme/SchemaItem/index.js +15 -3
- package/lib-next/theme/SchemaTabs/styles.module.css +0 -8
- package/package.json +6 -6
- package/src/markdown/schema.ts +86 -20
- package/src/markdown/utils.ts +2 -2
- package/src/theme/ApiDemoPanel/Body/index.tsx +1 -1
- package/src/theme/ApiItem/Layout/styles.module.css +16 -0
- package/src/theme/ApiLogo/index.tsx +25 -0
- package/src/theme/DiscriminatorTabs/index.js +263 -0
- package/src/theme/DiscriminatorTabs/styles.module.css +111 -0
- package/src/theme/MimeTabs/index.js +260 -0
- package/src/theme/MimeTabs/styles.module.css +125 -0
- package/src/theme/ParamsItem/index.js +10 -0
- package/src/theme/ResponseSamples/index.js +27 -0
- package/src/theme/ResponseSamples/styles.module.css +7 -0
- package/src/theme/SchemaItem/index.js +15 -3
- package/src/theme/SchemaTabs/styles.module.css +0 -8
|
@@ -126,6 +126,18 @@
|
|
|
126
126
|
border-left: thin solid var(--ifm-color-gray-500) !important;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
:global(.discriminatorItem) {
|
|
130
|
+
list-style: none;
|
|
131
|
+
position: relative;
|
|
132
|
+
margin: 0 !important;
|
|
133
|
+
padding: 5px 0 5px 0 !important;
|
|
134
|
+
border-left: thin solid var(--ifm-color-gray-500) !important;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
:global(.discriminatorTabsContainer) {
|
|
138
|
+
padding-left: 0 !important;
|
|
139
|
+
}
|
|
140
|
+
|
|
129
141
|
:global(.schemaItem:hover) {
|
|
130
142
|
background-color: var(--ifm-menu-color-background-active);
|
|
131
143
|
}
|
|
@@ -163,6 +175,7 @@
|
|
|
163
175
|
|
|
164
176
|
:global(.code__tab--python.tabs__item--active) {
|
|
165
177
|
border-bottom-color: var(--ifm-color-success);
|
|
178
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
166
179
|
}
|
|
167
180
|
|
|
168
181
|
:global(.language-python) {
|
|
@@ -186,6 +199,7 @@
|
|
|
186
199
|
|
|
187
200
|
:global(.code__tab--go.tabs__item--active) {
|
|
188
201
|
border-bottom-color: var(--ifm-color-info);
|
|
202
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
189
203
|
}
|
|
190
204
|
|
|
191
205
|
:global(.language-go) {
|
|
@@ -209,6 +223,7 @@
|
|
|
209
223
|
|
|
210
224
|
:global(.code__tab--javascript.tabs__item--active) {
|
|
211
225
|
border-bottom-color: var(--ifm-color-warning);
|
|
226
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
212
227
|
}
|
|
213
228
|
|
|
214
229
|
:global(.language-javascript) {
|
|
@@ -232,6 +247,7 @@
|
|
|
232
247
|
|
|
233
248
|
:global(.code__tab--bash.tabs__item--active) {
|
|
234
249
|
border-bottom-color: var(--ifm-color-danger);
|
|
250
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
235
251
|
}
|
|
236
252
|
|
|
237
253
|
:global(.language-bash) {
|
|
@@ -0,0 +1,21 @@
|
|
|
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 from "react";
|
|
8
|
+
import { useColorMode } from "@docusaurus/theme-common";
|
|
9
|
+
export default function ApiLogo(props) {
|
|
10
|
+
const { colorMode } = useColorMode();
|
|
11
|
+
const { logo, darkLogo } = props;
|
|
12
|
+
return logo ? (
|
|
13
|
+
<img
|
|
14
|
+
alt={colorMode === "dark" && darkLogo ? darkLogo.altText : logo.altText}
|
|
15
|
+
src={colorMode === "dark" && darkLogo ? darkLogo.url : logo.url}
|
|
16
|
+
width="250px"
|
|
17
|
+
/>
|
|
18
|
+
) : (
|
|
19
|
+
<div />
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
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, {
|
|
9
|
+
Children,
|
|
10
|
+
cloneElement,
|
|
11
|
+
isValidElement,
|
|
12
|
+
useEffect,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from "react";
|
|
16
|
+
|
|
17
|
+
import { duplicates } from "@docusaurus/theme-common";
|
|
18
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
19
|
+
import clsx from "clsx";
|
|
20
|
+
|
|
21
|
+
import styles from "./styles.module.css"; // A very rough duck type, but good enough to guard against mistakes while
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
useScrollPositionBlocker,
|
|
25
|
+
useTabGroupChoice,
|
|
26
|
+
} = require("@docusaurus/theme-common/internal");
|
|
27
|
+
|
|
28
|
+
// allowing customization
|
|
29
|
+
|
|
30
|
+
function isTabItem(comp) {
|
|
31
|
+
return typeof comp.props.value !== "undefined";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function DiscriminatorTabsComponent(props) {
|
|
35
|
+
const {
|
|
36
|
+
lazy,
|
|
37
|
+
block,
|
|
38
|
+
defaultValue: defaultValueProp,
|
|
39
|
+
values: valuesProp,
|
|
40
|
+
groupId,
|
|
41
|
+
className,
|
|
42
|
+
} = props;
|
|
43
|
+
const children = Children.map(props.children, (child) => {
|
|
44
|
+
if (isValidElement(child) && isTabItem(child)) {
|
|
45
|
+
return child;
|
|
46
|
+
} // child.type.name will give non-sensical values in prod because of
|
|
47
|
+
// minification, but we assume it won't throw in prod.
|
|
48
|
+
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Docusaurus error: Bad <Tabs> child <${
|
|
51
|
+
// @ts-expect-error: guarding against unexpected cases
|
|
52
|
+
typeof child.type === "string" ? child.type : child.type.name
|
|
53
|
+
}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
const values =
|
|
57
|
+
valuesProp ?? // We only pick keys that we recognize. MDX would inject some keys by default
|
|
58
|
+
children.map(({ props: { value, label, attributes } }) => ({
|
|
59
|
+
value,
|
|
60
|
+
label,
|
|
61
|
+
attributes,
|
|
62
|
+
}));
|
|
63
|
+
const dup = duplicates(values, (a, b) => a.value === b.value);
|
|
64
|
+
|
|
65
|
+
if (dup.length > 0) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Docusaurus error: Duplicate values "${dup
|
|
68
|
+
.map((a) => a.value)
|
|
69
|
+
.join(", ")}" found in <Tabs>. Every value needs to be unique.`
|
|
70
|
+
);
|
|
71
|
+
} // When defaultValueProp is null, don't show a default tab
|
|
72
|
+
|
|
73
|
+
const defaultValue =
|
|
74
|
+
defaultValueProp === null
|
|
75
|
+
? defaultValueProp
|
|
76
|
+
: defaultValueProp ??
|
|
77
|
+
children.find((child) => child.props.default)?.props.value ??
|
|
78
|
+
children[0]?.props.value;
|
|
79
|
+
|
|
80
|
+
if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
|
|
83
|
+
.map((a) => a.value)
|
|
84
|
+
.join(
|
|
85
|
+
", "
|
|
86
|
+
)}. If you intend to show no default tab, use defaultValue={null} instead.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();
|
|
91
|
+
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
|
92
|
+
const tabRefs = [];
|
|
93
|
+
const { blockElementScrollPositionUntilNextRender } =
|
|
94
|
+
useScrollPositionBlocker();
|
|
95
|
+
|
|
96
|
+
if (groupId != null) {
|
|
97
|
+
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
relevantTabGroupChoice != null &&
|
|
101
|
+
relevantTabGroupChoice !== selectedValue &&
|
|
102
|
+
values.some((value) => value.value === relevantTabGroupChoice)
|
|
103
|
+
) {
|
|
104
|
+
setSelectedValue(relevantTabGroupChoice);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const handleTabChange = (event) => {
|
|
109
|
+
const newTab = event.currentTarget;
|
|
110
|
+
const newTabIndex = tabRefs.indexOf(newTab);
|
|
111
|
+
const newTabValue = values[newTabIndex].value;
|
|
112
|
+
|
|
113
|
+
if (newTabValue !== selectedValue) {
|
|
114
|
+
blockElementScrollPositionUntilNextRender(newTab);
|
|
115
|
+
setSelectedValue(newTabValue);
|
|
116
|
+
|
|
117
|
+
if (groupId != null) {
|
|
118
|
+
setTabGroupChoices(groupId, newTabValue);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const handleKeydown = (event) => {
|
|
124
|
+
let focusElement = null;
|
|
125
|
+
|
|
126
|
+
switch (event.key) {
|
|
127
|
+
case "ArrowRight": {
|
|
128
|
+
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
129
|
+
focusElement = tabRefs[nextTab] || tabRefs[0];
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case "ArrowLeft": {
|
|
134
|
+
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
135
|
+
focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
default:
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
focusElement?.focus();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const tabItemListContainerRef = useRef(null);
|
|
147
|
+
const [showTabArrows, setShowTabArrows] = useState(false);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const tabOffsetWidth = tabItemListContainerRef.current.offsetWidth;
|
|
151
|
+
const tabScrollWidth = tabItemListContainerRef.current.scrollWidth;
|
|
152
|
+
|
|
153
|
+
if (tabOffsetWidth < tabScrollWidth) {
|
|
154
|
+
setShowTabArrows(true);
|
|
155
|
+
}
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
const handleRightClick = () => {
|
|
159
|
+
tabItemListContainerRef.current.scrollLeft += 90;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const handleLeftClick = () => {
|
|
163
|
+
tabItemListContainerRef.current.scrollLeft -= 90;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div className="tabs__container">
|
|
168
|
+
<div className={styles.discriminatorTabsTopSection}>
|
|
169
|
+
<div className={clsx(styles.discriminatorTabsContainer)}>
|
|
170
|
+
{showTabArrows && (
|
|
171
|
+
<button
|
|
172
|
+
className={clsx(styles.tabArrow, styles.tabArrowLeft)}
|
|
173
|
+
onClick={handleLeftClick}
|
|
174
|
+
/>
|
|
175
|
+
)}
|
|
176
|
+
<ul
|
|
177
|
+
ref={tabItemListContainerRef}
|
|
178
|
+
role="tablist"
|
|
179
|
+
aria-orientation="horizontal"
|
|
180
|
+
className={clsx(
|
|
181
|
+
styles.discriminatorTabsListContainer,
|
|
182
|
+
"tabs",
|
|
183
|
+
{
|
|
184
|
+
"tabs--block": block,
|
|
185
|
+
},
|
|
186
|
+
className
|
|
187
|
+
)}
|
|
188
|
+
>
|
|
189
|
+
{values.map(({ value, label, attributes }) => {
|
|
190
|
+
return (
|
|
191
|
+
<li
|
|
192
|
+
role="tab"
|
|
193
|
+
tabIndex={selectedValue === value ? 0 : -1}
|
|
194
|
+
aria-selected={selectedValue === value}
|
|
195
|
+
key={value}
|
|
196
|
+
ref={(tabControl) => tabRefs.push(tabControl)}
|
|
197
|
+
onKeyDown={handleKeydown}
|
|
198
|
+
onFocus={handleTabChange}
|
|
199
|
+
onClick={handleTabChange}
|
|
200
|
+
{...attributes}
|
|
201
|
+
className={clsx(
|
|
202
|
+
"tabs__item",
|
|
203
|
+
styles.tabItem,
|
|
204
|
+
attributes?.className,
|
|
205
|
+
{
|
|
206
|
+
[styles.discriminatorTabActive]: selectedValue === value,
|
|
207
|
+
}
|
|
208
|
+
)}
|
|
209
|
+
>
|
|
210
|
+
<span className={styles.discriminatorTabLabel}>
|
|
211
|
+
{label ?? value}
|
|
212
|
+
</span>
|
|
213
|
+
</li>
|
|
214
|
+
);
|
|
215
|
+
})}
|
|
216
|
+
</ul>
|
|
217
|
+
{showTabArrows && (
|
|
218
|
+
<button
|
|
219
|
+
className={clsx(styles.tabArrow, styles.tabArrowRight)}
|
|
220
|
+
onClick={handleRightClick}
|
|
221
|
+
/>
|
|
222
|
+
)}
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
<hr />
|
|
226
|
+
{lazy ? (
|
|
227
|
+
cloneElement(
|
|
228
|
+
children.filter(
|
|
229
|
+
(tabItem) => tabItem.props.value === selectedValue
|
|
230
|
+
)[0],
|
|
231
|
+
{
|
|
232
|
+
className: clsx(
|
|
233
|
+
"margin-vert--md",
|
|
234
|
+
styles.discriminatorTabsContainer
|
|
235
|
+
),
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
) : (
|
|
239
|
+
<div
|
|
240
|
+
className={clsx("margin-vert--md", styles.discriminatorTabsContainer)}
|
|
241
|
+
>
|
|
242
|
+
{children.map((tabItem, i) =>
|
|
243
|
+
cloneElement(tabItem, {
|
|
244
|
+
key: i,
|
|
245
|
+
hidden: tabItem.props.value !== selectedValue,
|
|
246
|
+
})
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
)}
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export default function DiscriminatorTabs(props) {
|
|
255
|
+
const isBrowser = useIsBrowser();
|
|
256
|
+
return (
|
|
257
|
+
<DiscriminatorTabsComponent // Remount tabs after hydration
|
|
258
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
259
|
+
key={String(isBrowser)}
|
|
260
|
+
{...props}
|
|
261
|
+
/>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
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
|
+
.tabItem {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
height: 1.8rem;
|
|
13
|
+
margin-top: 0 !important;
|
|
14
|
+
margin-right: 0.5rem;
|
|
15
|
+
border: 1px solid var(--openapi-code-dim-dark);
|
|
16
|
+
border-radius: var(--ifm-global-radius);
|
|
17
|
+
color: var(--openapi-code-dim-dark);
|
|
18
|
+
font-size: 12px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.tabItem:hover {
|
|
22
|
+
color: var(--ifm-color-emphasis-500) !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.tabItem:last-child {
|
|
26
|
+
margin-right: 0 !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Open API Schema Tabs */
|
|
30
|
+
.discriminatorTabsTopSection {
|
|
31
|
+
margin-top: 1rem;
|
|
32
|
+
margin-left: 0.9rem;
|
|
33
|
+
display: flex;
|
|
34
|
+
justify-content: space-between;
|
|
35
|
+
align-items: center;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.discriminatorTabsTopSection + hr {
|
|
39
|
+
display: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.discriminatorTabsContainer {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
max-width: 390px;
|
|
46
|
+
padding-left: 3px;
|
|
47
|
+
overflow: hidden;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.discriminatorTabsListContainer {
|
|
51
|
+
padding: 0 0.25rem;
|
|
52
|
+
overflow-y: hidden;
|
|
53
|
+
overflow-x: scroll;
|
|
54
|
+
scroll-behavior: smooth;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.discriminatorTabsListContainer::-webkit-scrollbar {
|
|
58
|
+
display: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.tabItem.discriminatorTabActive {
|
|
62
|
+
border: 1px solid var(--ifm-color-primary);
|
|
63
|
+
color: var(--ifm-color-primary);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.discriminatorTabLabel {
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.discriminatorTabsContainer {
|
|
71
|
+
max-width: 600px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Tab Arrows */
|
|
75
|
+
.tabArrow {
|
|
76
|
+
content: "";
|
|
77
|
+
height: 1.25rem;
|
|
78
|
+
width: 1.25rem;
|
|
79
|
+
padding: 0 0.75rem;
|
|
80
|
+
border: none;
|
|
81
|
+
min-width: 1.25rem;
|
|
82
|
+
background: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem;
|
|
83
|
+
filter: var(--ifm-menu-link-sublist-icon-filter);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.tabArrow:hover {
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.tabArrowLeft {
|
|
91
|
+
transform: rotate(270deg);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.tabArrowRight {
|
|
95
|
+
transform: rotate(90deg);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@media screen and (max-width: 500px) {
|
|
99
|
+
.discriminatorTabsTopSection {
|
|
100
|
+
flex-direction: column;
|
|
101
|
+
align-items: flex-start;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.discriminatorTabsContainer {
|
|
105
|
+
width: 100%;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.tabItem {
|
|
109
|
+
height: 100%;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
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, {
|
|
9
|
+
Children,
|
|
10
|
+
cloneElement,
|
|
11
|
+
isValidElement,
|
|
12
|
+
useEffect,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from "react";
|
|
16
|
+
|
|
17
|
+
import { duplicates } from "@docusaurus/theme-common";
|
|
18
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
19
|
+
import clsx from "clsx";
|
|
20
|
+
|
|
21
|
+
import styles from "./styles.module.css"; // A very rough duck type, but good enough to guard against mistakes while
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
useScrollPositionBlocker,
|
|
25
|
+
useTabGroupChoice,
|
|
26
|
+
} = require("@docusaurus/theme-common/internal");
|
|
27
|
+
|
|
28
|
+
// allowing customization
|
|
29
|
+
|
|
30
|
+
function isTabItem(comp) {
|
|
31
|
+
return typeof comp.props.value !== "undefined";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function MimeTabsComponent(props) {
|
|
35
|
+
const {
|
|
36
|
+
lazy,
|
|
37
|
+
block,
|
|
38
|
+
defaultValue: defaultValueProp,
|
|
39
|
+
values: valuesProp,
|
|
40
|
+
groupId,
|
|
41
|
+
className,
|
|
42
|
+
} = props;
|
|
43
|
+
const children = Children.map(props.children, (child) => {
|
|
44
|
+
if (isValidElement(child) && isTabItem(child)) {
|
|
45
|
+
return child;
|
|
46
|
+
} // child.type.name will give non-sensical values in prod because of
|
|
47
|
+
// minification, but we assume it won't throw in prod.
|
|
48
|
+
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Docusaurus error: Bad <Tabs> child <${
|
|
51
|
+
// @ts-expect-error: guarding against unexpected cases
|
|
52
|
+
typeof child.type === "string" ? child.type : child.type.name
|
|
53
|
+
}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
const values =
|
|
57
|
+
valuesProp ?? // We only pick keys that we recognize. MDX would inject some keys by default
|
|
58
|
+
children.map(({ props: { value, label, attributes } }) => ({
|
|
59
|
+
value,
|
|
60
|
+
label,
|
|
61
|
+
attributes,
|
|
62
|
+
}));
|
|
63
|
+
const dup = duplicates(values, (a, b) => a.value === b.value);
|
|
64
|
+
|
|
65
|
+
if (dup.length > 0) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Docusaurus error: Duplicate values "${dup
|
|
68
|
+
.map((a) => a.value)
|
|
69
|
+
.join(", ")}" found in <Tabs>. Every value needs to be unique.`
|
|
70
|
+
);
|
|
71
|
+
} // When defaultValueProp is null, don't show a default tab
|
|
72
|
+
|
|
73
|
+
const defaultValue =
|
|
74
|
+
defaultValueProp === null
|
|
75
|
+
? defaultValueProp
|
|
76
|
+
: defaultValueProp ??
|
|
77
|
+
children.find((child) => child.props.default)?.props.value ??
|
|
78
|
+
children[0]?.props.value;
|
|
79
|
+
|
|
80
|
+
if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
|
|
83
|
+
.map((a) => a.value)
|
|
84
|
+
.join(
|
|
85
|
+
", "
|
|
86
|
+
)}. If you intend to show no default tab, use defaultValue={null} instead.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();
|
|
91
|
+
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
|
92
|
+
const tabRefs = [];
|
|
93
|
+
const { blockElementScrollPositionUntilNextRender } =
|
|
94
|
+
useScrollPositionBlocker();
|
|
95
|
+
|
|
96
|
+
if (groupId != null) {
|
|
97
|
+
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
relevantTabGroupChoice != null &&
|
|
101
|
+
relevantTabGroupChoice !== selectedValue &&
|
|
102
|
+
values.some((value) => value.value === relevantTabGroupChoice)
|
|
103
|
+
) {
|
|
104
|
+
setSelectedValue(relevantTabGroupChoice);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const handleTabChange = (event) => {
|
|
109
|
+
const newTab = event.currentTarget;
|
|
110
|
+
const newTabIndex = tabRefs.indexOf(newTab);
|
|
111
|
+
const newTabValue = values[newTabIndex].value;
|
|
112
|
+
|
|
113
|
+
if (newTabValue !== selectedValue) {
|
|
114
|
+
blockElementScrollPositionUntilNextRender(newTab);
|
|
115
|
+
setSelectedValue(newTabValue);
|
|
116
|
+
|
|
117
|
+
if (groupId != null) {
|
|
118
|
+
setTabGroupChoices(groupId, newTabValue);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const handleKeydown = (event) => {
|
|
124
|
+
let focusElement = null;
|
|
125
|
+
|
|
126
|
+
switch (event.key) {
|
|
127
|
+
case "ArrowRight": {
|
|
128
|
+
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
129
|
+
focusElement = tabRefs[nextTab] || tabRefs[0];
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case "ArrowLeft": {
|
|
134
|
+
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
135
|
+
focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
default:
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
focusElement?.focus();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const tabItemListContainerRef = useRef(null);
|
|
147
|
+
const [showTabArrows, setShowTabArrows] = useState(false);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const tabOffsetWidth = tabItemListContainerRef.current.offsetWidth;
|
|
151
|
+
const tabScrollWidth = tabItemListContainerRef.current.scrollWidth;
|
|
152
|
+
|
|
153
|
+
if (tabOffsetWidth < tabScrollWidth) {
|
|
154
|
+
setShowTabArrows(true);
|
|
155
|
+
}
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
const handleRightClick = () => {
|
|
159
|
+
tabItemListContainerRef.current.scrollLeft += 90;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const handleLeftClick = () => {
|
|
163
|
+
tabItemListContainerRef.current.scrollLeft -= 90;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div className="tabs__container">
|
|
168
|
+
<div className={styles.mimeTabsTopSection}>
|
|
169
|
+
{/* <strong>MIME Type</strong> */}
|
|
170
|
+
<div className={styles.mimeTabsContainer}>
|
|
171
|
+
{showTabArrows && (
|
|
172
|
+
<button
|
|
173
|
+
className={clsx(styles.tabArrow, styles.tabArrowLeft)}
|
|
174
|
+
onClick={handleLeftClick}
|
|
175
|
+
/>
|
|
176
|
+
)}
|
|
177
|
+
<ul
|
|
178
|
+
ref={tabItemListContainerRef}
|
|
179
|
+
role="tablist"
|
|
180
|
+
aria-orientation="horizontal"
|
|
181
|
+
className={clsx(
|
|
182
|
+
styles.mimeTabsListContainer,
|
|
183
|
+
"tabs",
|
|
184
|
+
{
|
|
185
|
+
"tabs--block": block,
|
|
186
|
+
},
|
|
187
|
+
className
|
|
188
|
+
)}
|
|
189
|
+
>
|
|
190
|
+
{values.map(({ value, label, attributes }) => {
|
|
191
|
+
return (
|
|
192
|
+
<li
|
|
193
|
+
role="tab"
|
|
194
|
+
tabIndex={selectedValue === value ? 0 : -1}
|
|
195
|
+
aria-selected={selectedValue === value}
|
|
196
|
+
key={value}
|
|
197
|
+
ref={(tabControl) => tabRefs.push(tabControl)}
|
|
198
|
+
onKeyDown={handleKeydown}
|
|
199
|
+
onFocus={handleTabChange}
|
|
200
|
+
onClick={handleTabChange}
|
|
201
|
+
{...attributes}
|
|
202
|
+
className={clsx(
|
|
203
|
+
"tabs__item",
|
|
204
|
+
styles.tabItem,
|
|
205
|
+
attributes?.className,
|
|
206
|
+
{
|
|
207
|
+
[styles.mimeTabActive]: selectedValue === value,
|
|
208
|
+
}
|
|
209
|
+
)}
|
|
210
|
+
>
|
|
211
|
+
{/* <div
|
|
212
|
+
className={clsx(styles.mimeTabDot, mimeTabDotStyle)}
|
|
213
|
+
/> */}
|
|
214
|
+
{label ?? value}
|
|
215
|
+
</li>
|
|
216
|
+
);
|
|
217
|
+
})}
|
|
218
|
+
</ul>
|
|
219
|
+
{showTabArrows && (
|
|
220
|
+
<button
|
|
221
|
+
className={clsx(styles.tabArrow, styles.tabArrowRight)}
|
|
222
|
+
onClick={handleRightClick}
|
|
223
|
+
/>
|
|
224
|
+
)}
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
{/* <hr /> */}
|
|
228
|
+
{lazy ? (
|
|
229
|
+
cloneElement(
|
|
230
|
+
children.filter(
|
|
231
|
+
(tabItem) => tabItem.props.value === selectedValue
|
|
232
|
+
)[0],
|
|
233
|
+
{
|
|
234
|
+
className: clsx("margin-vert--md", styles.mimeSchemaContainer),
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
) : (
|
|
238
|
+
<div className={clsx("margin-vert--md", styles.mimeSchemaContainer)}>
|
|
239
|
+
{children.map((tabItem, i) =>
|
|
240
|
+
cloneElement(tabItem, {
|
|
241
|
+
key: i,
|
|
242
|
+
hidden: tabItem.props.value !== selectedValue,
|
|
243
|
+
})
|
|
244
|
+
)}
|
|
245
|
+
</div>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export default function MimeTabs(props) {
|
|
252
|
+
const isBrowser = useIsBrowser();
|
|
253
|
+
return (
|
|
254
|
+
<MimeTabsComponent // Remount tabs after hydration
|
|
255
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
256
|
+
key={String(isBrowser)}
|
|
257
|
+
{...props}
|
|
258
|
+
/>
|
|
259
|
+
);
|
|
260
|
+
}
|