@redocly/theme 0.54.1 → 0.54.2

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.
@@ -18,6 +18,7 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
18
18
  title?: string;
19
19
  tabIndex?: number;
20
20
  onClick?: (e?: any) => void;
21
+ ref?: React.Ref<HTMLButtonElement>;
21
22
  type?: 'button' | 'submit' | 'reset';
22
23
  }
23
24
  export declare function generateClassName({ variant, tone, size, extraClass, }: ButtonProps): string;
@@ -26,8 +26,5 @@ export declare const TabItem: import("styled-components").StyledComponent<"li",
26
26
  size: TabsSize;
27
27
  tabIndex?: number;
28
28
  }, never>;
29
- export declare const TabButtonLink: import("styled-components").StyledComponent<"button", any, {
30
- size: TabsSize;
31
- disabled?: boolean;
32
- }, never>;
29
+ export declare const TabButtonLink: import("styled-components").StyledComponent<React.FC<import("../../../components/Button/Button").ButtonProps>, any, import("../../../components/Button/Button").ButtonProps, never>;
33
30
  export {};
@@ -22,25 +22,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.TabButtonLink = exports.TabItem = exports.TabListContainer = void 0;
27
30
  exports.TabList = TabList;
28
- const react_1 = __importStar(require("react"));
31
+ const react_1 = __importDefault(require("react"));
29
32
  const styled_components_1 = __importStar(require("styled-components"));
30
33
  const Tab_1 = require("../../../markdoc/components/Tabs/Tab");
31
34
  const Dropdown_1 = require("../../../components/Dropdown/Dropdown");
32
35
  const DropdownMenu_1 = require("../../../components/Dropdown/DropdownMenu");
33
36
  const DropdownMenuItem_1 = require("../../../components/Dropdown/DropdownMenuItem");
34
- const ChevronDownIcon_1 = require("../../../icons/ChevronDownIcon/ChevronDownIcon");
35
- const ChevronUpIcon_1 = require("../../../icons/ChevronUpIcon/ChevronUpIcon");
37
+ const Button_1 = require("../../../components/Button/Button");
36
38
  function TabList({ childrenArray, size, overflowTabs, visibleTabs, setTabRef, onTabClick, handleKeyboard, getTabId, activeTab, isAnimating, highlightStyle, allTabsHidden, tabsContainerRef, }) {
37
- const [isDropdownOpen, setIsDropdownOpen] = (0, react_1.useState)(false);
38
- const handleDropdownOpen = (0, react_1.useCallback)(() => {
39
- setIsDropdownOpen(true);
40
- }, []);
41
- const handleDropdownClose = (0, react_1.useCallback)(() => {
42
- setIsDropdownOpen(false);
43
- }, []);
44
39
  return (react_1.default.createElement(exports.TabListContainer, { role: "tablist", ref: tabsContainerRef, "data-animating": isAnimating },
45
40
  react_1.default.createElement(HighlightBar, { size: size, style: { left: highlightStyle.left, width: highlightStyle.width } },
46
41
  react_1.default.createElement("div", null)),
@@ -59,20 +54,16 @@ function TabList({ childrenArray, size, overflowTabs, visibleTabs, setTabRef, on
59
54
  onTabClick(label);
60
55
  } }));
61
56
  }),
62
- react_1.default.createElement(exports.TabItem, { size: size, active: overflowTabs.some((index) => activeTab === childrenArray[index].props.label), tabIndex: 0 }, overflowTabs.length > 0 && (react_1.default.createElement("div", { onPointerEnter: handleDropdownOpen, onPointerLeave: handleDropdownClose },
63
- react_1.default.createElement(Dropdown_1.Dropdown, { trigger: react_1.default.createElement(exports.TabButtonLink, { size: size, className: overflowTabs.some((index) => activeTab === childrenArray[index].props.label)
64
- ? 'active'
65
- : undefined },
66
- allTabsHidden ? activeTab : 'More',
67
- isDropdownOpen ? react_1.default.createElement(ChevronUpIcon_1.ChevronUpIcon, null) : react_1.default.createElement(ChevronDownIcon_1.ChevronDownIcon, null)), alignment: "start", withArrow: false, active: isDropdownOpen, triggerEvent: "click" },
68
- react_1.default.createElement(DropdownMenu_1.DropdownMenu, null, overflowTabs.map((index) => {
69
- const { label } = childrenArray[index].props;
70
- const tabId = getTabId(label, index);
71
- return (react_1.default.createElement(DropdownMenuItem_1.DropdownMenuItem, { key: `more-${tabId}`, active: activeTab === label, onAction: () => {
72
- onTabClick(index);
73
- handleDropdownClose();
74
- }, disabled: childrenArray[index].props.disable }, label));
75
- }))))))));
57
+ react_1.default.createElement(exports.TabItem, { size: size, active: overflowTabs.some((index) => activeTab === childrenArray[index].props.label), tabIndex: 0 }, overflowTabs.length > 0 && (react_1.default.createElement(Dropdown_1.Dropdown, { trigger: react_1.default.createElement(exports.TabButtonLink, { size: size, className: overflowTabs.some((index) => activeTab === childrenArray[index].props.label)
58
+ ? 'active'
59
+ : undefined }, allTabsHidden ? activeTab : 'More'), alignment: "start", withArrow: true },
60
+ react_1.default.createElement(DropdownMenu_1.DropdownMenu, null, overflowTabs.map((index) => {
61
+ const { label } = childrenArray[index].props;
62
+ const tabId = getTabId(label, index);
63
+ return (react_1.default.createElement(DropdownMenuItem_1.DropdownMenuItem, { key: `more-${tabId}`, active: activeTab === label, onAction: () => {
64
+ onTabClick(index);
65
+ }, disabled: childrenArray[index].props.disable }, label));
66
+ })))))));
76
67
  }
77
68
  exports.TabListContainer = styled_components_1.default.ul `
78
69
  position: relative;
@@ -166,22 +157,11 @@ const HighlightBar = styled_components_1.default.div `
166
157
  border-radius: var(--md-tabs-${({ size }) => size}-active-tab-border-radius);
167
158
  }
168
159
  `;
169
- exports.TabButtonLink = styled_components_1.default.button `
170
- all: unset;
171
- flex-grow: 1;
172
- cursor: pointer;
173
- width: 100%;
174
- text-align: center;
160
+ exports.TabButtonLink = (0, styled_components_1.default)(Button_1.Button) `
175
161
  color: var(--md-tabs-tab-text-color);
176
162
  font-family: var(--md-tabs-tab-font-family);
177
163
  font-style: var(--md-tabs-tab-font-style);
178
164
  background-color: var(--md-tabs-tab-bg-color);
179
- white-space: nowrap;
180
- display: inline-flex;
181
- align-items: center;
182
- justify-content: center;
183
- gap: var(--spacing-xxs);
184
- z-index: 2;
185
165
 
186
166
  transition:
187
167
  background-color 300ms ease-in-out,
@@ -92,14 +92,7 @@ function Tabs({ children, className, size }) {
92
92
  else {
93
93
  setHighlightStyle({ left: offsetLeft, width: offsetWidth });
94
94
  }
95
- const timeoutId = setTimeout(() => {
96
- if (visibleTabs.includes(activeIndex)) {
97
- activeTabElement === null || activeTabElement === void 0 ? void 0 : activeTabElement.classList.add('active');
98
- }
99
- setIsAnimating(false);
100
- }, 300);
101
95
  return () => {
102
- clearTimeout(timeoutId);
103
96
  container.querySelectorAll('[data-label]').forEach((el) => {
104
97
  el.classList.remove('active');
105
98
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.54.1",
3
+ "version": "0.54.2",
4
4
  "description": "Shared UI components lib",
5
5
  "keywords": [
6
6
  "theme",
@@ -32,7 +32,7 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
32
32
  title?: string;
33
33
  tabIndex?: number;
34
34
  onClick?: (e?: any) => void;
35
-
35
+ ref?: React.Ref<HTMLButtonElement>;
36
36
  type?: 'button' | 'submit' | 'reset';
37
37
  }
38
38
 
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useState } from 'react';
1
+ import React from 'react';
2
2
  import styled, { css } from 'styled-components';
3
3
 
4
4
  import type { JSX } from 'react';
@@ -8,8 +8,7 @@ import { TabItemProps, TabsSize } from '@redocly/theme/markdoc/components/Tabs/T
8
8
  import { Dropdown } from '@redocly/theme/components/Dropdown/Dropdown';
9
9
  import { DropdownMenu } from '@redocly/theme/components/Dropdown/DropdownMenu';
10
10
  import { DropdownMenuItem } from '@redocly/theme/components/Dropdown/DropdownMenuItem';
11
- import { ChevronDownIcon } from '@redocly/theme/icons/ChevronDownIcon/ChevronDownIcon';
12
- import { ChevronUpIcon } from '@redocly/theme/icons/ChevronUpIcon/ChevronUpIcon';
11
+ import { Button } from '@redocly/theme/components/Button/Button';
13
12
 
14
13
  type TabListProps = {
15
14
  childrenArray: React.ReactElement<TabItemProps>[];
@@ -42,16 +41,6 @@ export function TabList({
42
41
  allTabsHidden,
43
42
  tabsContainerRef,
44
43
  }: TabListProps): JSX.Element {
45
- const [isDropdownOpen, setIsDropdownOpen] = useState<boolean>(false);
46
-
47
- const handleDropdownOpen = useCallback(() => {
48
- setIsDropdownOpen(true);
49
- }, []);
50
-
51
- const handleDropdownClose = useCallback(() => {
52
- setIsDropdownOpen(false);
53
- }, []);
54
-
55
44
  return (
56
45
  <TabListContainer role="tablist" ref={tabsContainerRef} data-animating={isAnimating}>
57
46
  <HighlightBar size={size} style={{ left: highlightStyle.left, width: highlightStyle.width }}>
@@ -88,47 +77,41 @@ export function TabList({
88
77
  tabIndex={0}
89
78
  >
90
79
  {overflowTabs.length > 0 && (
91
- <div onPointerEnter={handleDropdownOpen} onPointerLeave={handleDropdownClose}>
92
- <Dropdown
93
- trigger={
94
- <TabButtonLink
95
- size={size}
96
- className={
97
- overflowTabs.some((index) => activeTab === childrenArray[index].props.label)
98
- ? 'active'
99
- : undefined
100
- }
101
- >
102
- {allTabsHidden ? activeTab : 'More'}
103
- {isDropdownOpen ? <ChevronUpIcon /> : <ChevronDownIcon />}
104
- </TabButtonLink>
105
- }
106
- alignment="start"
107
- withArrow={false}
108
- active={isDropdownOpen}
109
- triggerEvent="click"
110
- >
111
- <DropdownMenu>
112
- {overflowTabs.map((index) => {
113
- const { label } = childrenArray[index].props;
114
- const tabId = getTabId(label, index);
115
- return (
116
- <DropdownMenuItem
117
- key={`more-${tabId}`}
118
- active={activeTab === label}
119
- onAction={() => {
120
- onTabClick(index);
121
- handleDropdownClose();
122
- }}
123
- disabled={childrenArray[index].props.disable}
124
- >
125
- {label}
126
- </DropdownMenuItem>
127
- );
128
- })}
129
- </DropdownMenu>
130
- </Dropdown>
131
- </div>
80
+ <Dropdown
81
+ trigger={
82
+ <TabButtonLink
83
+ size={size}
84
+ className={
85
+ overflowTabs.some((index) => activeTab === childrenArray[index].props.label)
86
+ ? 'active'
87
+ : undefined
88
+ }
89
+ >
90
+ {allTabsHidden ? activeTab : 'More'}
91
+ </TabButtonLink>
92
+ }
93
+ alignment="start"
94
+ withArrow={true}
95
+ >
96
+ <DropdownMenu>
97
+ {overflowTabs.map((index) => {
98
+ const { label } = childrenArray[index].props;
99
+ const tabId = getTabId(label, index);
100
+ return (
101
+ <DropdownMenuItem
102
+ key={`more-${tabId}`}
103
+ active={activeTab === label}
104
+ onAction={() => {
105
+ onTabClick(index);
106
+ }}
107
+ disabled={childrenArray[index].props.disable}
108
+ >
109
+ {label}
110
+ </DropdownMenuItem>
111
+ );
112
+ })}
113
+ </DropdownMenu>
114
+ </Dropdown>
132
115
  )}
133
116
  </TabItem>
134
117
  </TabListContainer>
@@ -231,25 +214,11 @@ const HighlightBar = styled.div<{ size: TabsSize }>`
231
214
  }
232
215
  `;
233
216
 
234
- export const TabButtonLink = styled.button<{
235
- size: TabsSize;
236
- disabled?: boolean;
237
- }>`
238
- all: unset;
239
- flex-grow: 1;
240
- cursor: pointer;
241
- width: 100%;
242
- text-align: center;
217
+ export const TabButtonLink = styled(Button)`
243
218
  color: var(--md-tabs-tab-text-color);
244
219
  font-family: var(--md-tabs-tab-font-family);
245
220
  font-style: var(--md-tabs-tab-font-style);
246
221
  background-color: var(--md-tabs-tab-bg-color);
247
- white-space: nowrap;
248
- display: inline-flex;
249
- align-items: center;
250
- justify-content: center;
251
- gap: var(--spacing-xxs);
252
- z-index: 2;
253
222
 
254
223
  transition:
255
224
  background-color 300ms ease-in-out,
@@ -105,15 +105,7 @@ export function Tabs({ children, className, size }: TabsProps): JSX.Element {
105
105
  setHighlightStyle({ left: offsetLeft, width: offsetWidth });
106
106
  }
107
107
 
108
- const timeoutId = setTimeout(() => {
109
- if (visibleTabs.includes(activeIndex)) {
110
- activeTabElement?.classList.add('active');
111
- }
112
- setIsAnimating(false);
113
- }, 300);
114
-
115
108
  return () => {
116
- clearTimeout(timeoutId);
117
109
  container.querySelectorAll('[data-label]').forEach((el) => {
118
110
  el.classList.remove('active');
119
111
  });