docusaurus-theme-openapi-docs 0.0.0-405 → 0.0.0-408

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.
@@ -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
  }
@@ -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
+ }
@@ -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
  }
@@ -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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-theme-openapi-docs",
3
3
  "description": "OpenAPI theme for Docusaurus.",
4
- "version": "0.0.0-405",
4
+ "version": "0.0.0-408",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -50,7 +50,7 @@
50
50
  "buffer": "^6.0.3",
51
51
  "clsx": "^1.1.1",
52
52
  "crypto-js": "^4.1.1",
53
- "docusaurus-plugin-openapi-docs": "0.0.0-405",
53
+ "docusaurus-plugin-openapi-docs": "0.0.0-408",
54
54
  "immer": "^9.0.7",
55
55
  "lodash": "^4.17.20",
56
56
  "process": "^0.11.10",
@@ -68,5 +68,5 @@
68
68
  "engines": {
69
69
  "node": ">=14"
70
70
  },
71
- "gitHead": "f87ea96605b968d06659143fc7bcf8628e9508b1"
71
+ "gitHead": "a13982ebd24d40f4a81ba75a7f1046682b2ba49b"
72
72
  }
@@ -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
  }
@@ -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
+ }