@redocly/theme 0.59.0-next.2 → 0.59.0-rc.1

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 (53) hide show
  1. package/lib/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityApiDescriptionRelations.js +1 -1
  2. package/lib/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityTeamRelations.js +1 -1
  3. package/lib/components/Catalog/CatalogTagsWithTooltip.js +1 -1
  4. package/lib/components/Dropdown/Dropdown.d.ts +2 -16
  5. package/lib/components/Dropdown/Dropdown.js +5 -5
  6. package/lib/components/Menu/MenuItem.js +1 -1
  7. package/lib/components/OpenApiDocs/hooks/AdditionalOverviewInfo.d.ts +1 -0
  8. package/lib/components/OpenApiDocs/hooks/AdditionalOverviewInfo.js +11 -0
  9. package/lib/components/OpenApiDocs/hooks/AfterOpenApiDescription.d.ts +1 -0
  10. package/lib/components/OpenApiDocs/hooks/AfterOpenApiDescription.js +5 -0
  11. package/lib/components/Search/SearchAiConversationInput.d.ts +1 -2
  12. package/lib/components/Search/SearchAiConversationInput.js +3 -11
  13. package/lib/components/Search/SearchDialog.js +3 -6
  14. package/lib/components/Search/variables.js +1 -5
  15. package/lib/components/Select/variables.js +2 -2
  16. package/lib/components/Tag/Tag.js +4 -4
  17. package/lib/core/constants/search.d.ts +4 -5
  18. package/lib/core/constants/search.js +5 -4
  19. package/lib/core/hooks/use-tabs.d.ts +2 -3
  20. package/lib/core/hooks/use-tabs.js +57 -115
  21. package/lib/core/types/hooks.d.ts +2 -2
  22. package/lib/ext/process-scorecard.d.ts +5 -0
  23. package/lib/ext/process-scorecard.js +11 -0
  24. package/lib/icons/AiStarsIcon/AiStarsIcon.js +2 -11
  25. package/lib/icons/RedoclyIcon/RedoclyIcon.js +7 -4
  26. package/lib/index.d.ts +2 -0
  27. package/lib/index.js +2 -0
  28. package/lib/markdoc/components/Tabs/TabList.d.ts +1 -3
  29. package/lib/markdoc/components/Tabs/TabList.js +47 -197
  30. package/lib/markdoc/components/Tabs/Tabs.d.ts +1 -2
  31. package/lib/markdoc/components/Tabs/Tabs.js +12 -57
  32. package/package.json +3 -3
  33. package/src/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityApiDescriptionRelations.tsx +1 -1
  34. package/src/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityTeamRelations.tsx +1 -1
  35. package/src/components/Catalog/CatalogTagsWithTooltip.tsx +5 -1
  36. package/src/components/Dropdown/Dropdown.tsx +79 -84
  37. package/src/components/Menu/MenuItem.tsx +0 -1
  38. package/src/components/OpenApiDocs/hooks/AdditionalOverviewInfo.tsx +9 -0
  39. package/src/components/OpenApiDocs/hooks/AfterOpenApiDescription.tsx +1 -0
  40. package/src/components/Search/SearchAiConversationInput.tsx +2 -12
  41. package/src/components/Search/SearchDialog.tsx +3 -6
  42. package/src/components/Search/variables.ts +1 -5
  43. package/src/components/Select/variables.ts +2 -2
  44. package/src/components/Tag/Tag.tsx +6 -6
  45. package/src/core/constants/search.ts +4 -8
  46. package/src/core/hooks/use-tabs.ts +86 -168
  47. package/src/core/types/hooks.ts +1 -5
  48. package/src/ext/process-scorecard.ts +13 -0
  49. package/src/icons/AiStarsIcon/AiStarsIcon.tsx +2 -11
  50. package/src/icons/RedoclyIcon/RedoclyIcon.tsx +22 -4
  51. package/src/index.ts +2 -0
  52. package/src/markdoc/components/Tabs/TabList.tsx +105 -312
  53. package/src/markdoc/components/Tabs/Tabs.tsx +11 -136
@@ -1,6 +1,5 @@
1
- import React, { useState, useEffect, useLayoutEffect, useRef, useCallback } from 'react';
2
- import { useInRouterContext } from 'react-router-dom';
3
- import styled, { css } from 'styled-components';
1
+ import React, { useState, useEffect } from 'react';
2
+ import styled from 'styled-components';
4
3
 
5
4
  import type { JSX } from 'react';
6
5
 
@@ -27,26 +26,6 @@ type TabsProps = {
27
26
  className?: string;
28
27
  size: TabsSize;
29
28
  initialTab?: string;
30
- forceReady?: boolean;
31
- };
32
-
33
- type UseActiveTabFn = (
34
- initialTab: string,
35
- tabsId: string | undefined,
36
- childrenArray: React.ReactElement<TabItemProps>[],
37
- ) => {
38
- activeTab: string;
39
- setActiveTab: (tab: string) => void;
40
- };
41
-
42
- type TabsViewProps = Omit<TabsProps, 'children'> & {
43
- childrenArray: React.ReactElement<TabItemProps>[];
44
- initialTab: string;
45
- isReady: boolean;
46
- labelsHash: string;
47
- useActiveTab: UseActiveTabFn;
48
- containerRef: React.RefObject<HTMLUListElement | null>;
49
- onReadyChange: (ready: boolean) => void;
50
29
  };
51
30
 
52
31
  export function Tabs({
@@ -55,72 +34,25 @@ export function Tabs({
55
34
  className,
56
35
  size,
57
36
  initialTab: propInitialTab,
58
- forceReady = false,
59
37
  }: TabsProps): JSX.Element {
60
- const childrenArray = React.Children.toArray(children) as React.ReactElement<TabItemProps>[];
61
- const [isReady, setIsReady] = useState(false);
62
- const containerRef = useRef<HTMLUListElement | null>(null);
38
+ const [childrenArray, setChildrenArray] = useState<React.ReactElement<TabItemProps>[]>(
39
+ React.Children.toArray(children) as React.ReactElement<TabItemProps>[],
40
+ );
63
41
 
64
42
  const initialTab = propInitialTab ?? childrenArray[0]?.props.label ?? '';
65
- const labelsHash = childrenArray.map((c) => c.props.label).join('|');
66
-
67
- const handleReadyChange = useCallback((ready: boolean) => {
68
- setIsReady(ready);
69
- }, []);
70
-
71
- // Reset isReady when children change (new page/tabs)
72
- // Use useLayoutEffect to run synchronously before paint
73
- useLayoutEffect(() => {
74
- setIsReady(false);
75
- }, [labelsHash]);
76
-
77
- const inRouter = useInRouterContext();
43
+ const { activeTab, setActiveTab } = useActiveTab({ tabsId: id, initialTab });
78
44
 
79
- return (
80
- <TabsView
81
- id={id}
82
- className={className}
83
- size={size}
84
- childrenArray={childrenArray}
85
- initialTab={initialTab}
86
- useActiveTab={inRouter ? useActiveTabWithRouter : useActiveTabWithoutRouter}
87
- isReady={isReady || forceReady}
88
- labelsHash={labelsHash}
89
- containerRef={containerRef}
90
- onReadyChange={handleReadyChange}
91
- />
92
- );
93
- }
94
-
95
- function TabsView({
96
- id,
97
- className,
98
- size,
99
- childrenArray,
100
- useActiveTab,
101
- initialTab,
102
- isReady,
103
- labelsHash,
104
- containerRef,
105
- onReadyChange,
106
- }: TabsViewProps): JSX.Element {
107
- const { activeTab, setActiveTab } = useActiveTab(initialTab, id, childrenArray);
45
+ useEffect(() => {
46
+ setChildrenArray(React.Children.toArray(children) as React.ReactElement<TabItemProps>[]);
47
+ }, [children]);
108
48
 
109
49
  return (
110
- <TabsContainer
111
- data-component-name="Markdoc/Tabs/Tabs"
112
- className={className}
113
- key={id}
114
- $isReady={isReady}
115
- >
50
+ <TabsContainer data-component-name="Markdoc/Tabs/Tabs" className={className} key={id}>
116
51
  <TabList
117
- key={labelsHash}
118
52
  size={size}
119
53
  childrenArray={childrenArray}
120
54
  activeTab={activeTab}
121
55
  onTabChange={setActiveTab}
122
- containerRef={containerRef}
123
- onReadyChange={onReadyChange}
124
56
  />
125
57
  {childrenArray.map((child, index) => {
126
58
  const { label } = child.props;
@@ -140,56 +72,7 @@ function TabsView({
140
72
  </TabsContainer>
141
73
  );
142
74
  }
143
-
144
- /**
145
- * Validates that the active tab exists in children and resets to initial tab if not found.
146
- * Ensures tab state remains consistent when tab structure changes.
147
- */
148
- function useValidateActiveTab(
149
- activeTab: string,
150
- setActiveTab: (tab: string) => void,
151
- childrenArray: React.ReactElement<TabItemProps>[],
152
- initialTab: string,
153
- ) {
154
- useEffect(() => {
155
- const availableLabels = childrenArray.map((child) => child.props.label);
156
- if (activeTab && !availableLabels.includes(activeTab) && availableLabels.length > 0) {
157
- setActiveTab(initialTab);
158
- }
159
- }, [childrenArray, activeTab, initialTab, setActiveTab]);
160
- }
161
-
162
- const useActiveTabWithRouter = (
163
- initialTab: string,
164
- tabsId: string | undefined,
165
- childrenArray: React.ReactElement<TabItemProps>[],
166
- ) => {
167
- const { activeTab, setActiveTab } = useActiveTab({ initialTab, tabsId });
168
-
169
- useValidateActiveTab(activeTab, setActiveTab, childrenArray, initialTab);
170
-
171
- return {
172
- activeTab,
173
- setActiveTab,
174
- };
175
- };
176
-
177
- const useActiveTabWithoutRouter = (
178
- initialTab: string,
179
- _tabsId: string | undefined,
180
- childrenArray: React.ReactElement<TabItemProps>[],
181
- ) => {
182
- const [activeTab, setActiveTab] = useState(initialTab);
183
-
184
- useValidateActiveTab(activeTab, setActiveTab, childrenArray, initialTab);
185
-
186
- return {
187
- activeTab,
188
- setActiveTab,
189
- };
190
- };
191
-
192
- const TabsContainer = styled.div<{ $isReady: boolean }>`
75
+ const TabsContainer = styled.div`
193
76
  position: relative;
194
77
  color: var(--md-tabs-container-text-color);
195
78
  font-size: var(--md-tabs-container-font-size);
@@ -205,14 +88,6 @@ const TabsContainer = styled.div<{ $isReady: boolean }>`
205
88
  margin: 0;
206
89
  padding: 0;
207
90
  }
208
-
209
- ${({ $isReady }) =>
210
- !$isReady &&
211
- css`
212
- opacity: 0;
213
- pointer-events: none;
214
- overflow: hidden;
215
- `}
216
91
  `;
217
92
 
218
93
  export const TabContent = styled.div`