docusaurus-theme-openapi-docs 0.0.0-388 → 0.0.0-392

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