@dt-dds/react-tabs 1.0.0-beta.100

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Tabs Package
2
+
3
+ The Tabs component allows different views/information to be switched easily.
4
+ If the Tabs run out of space, it will appear horizontal scroll.
5
+
6
+ ## Usage
7
+
8
+ ```jsx
9
+ import { Tabs, TabPanel, useTabs } from '@dt-dds/react';
10
+ import { Icon } from '@dt-dds/react-icon';
11
+
12
+ const { activeTab, handleChange } = useTabs(0);
13
+
14
+ return (
15
+ <>
16
+ <Tabs activeTab={activeTab} handleChange={handleChange}>
17
+ <Tabs.Item icon={<Icon code='menu' />} label='Tab 1' />
18
+ <Tabs.Item label='Tab 2' />
19
+ <Tabs.Item label='Tab 3' isDisabled />
20
+ </Tabs>
21
+ </>
22
+ );
23
+ ```
24
+
25
+ ## API
26
+
27
+ ### Tabs
28
+
29
+ | Property | Type | Default | Description |
30
+ | -------------- | ----------------------- | --------- | ----------------------------------------- |
31
+ | `children` | `ReactNode` | - | Child components to be rendered |
32
+ | `dataTestId` | `string` | `tabs` | Customizable test identifier |
33
+ | `style` | `React.CSSProperties` | - | Styles to be used in the Tabs |
34
+ | `activeTab` | `number` | - | Represents the active tab |
35
+ | `variant` | `default` / `contained` | `default` | Defines type of tab |
36
+ | `handleChange` | `function` | - | When triggered, it changes the active tab |
37
+
38
+ ### Tabs.Item
39
+
40
+ | Property | Type | Default | Description |
41
+ | ------------ | ----------- | ------- | ---------------------------------------- |
42
+ | `label` | `string` | - | Defines the tab label |
43
+ | `icon` | `ReactNode` | - | Defines the tab icon |
44
+ | `dataTestId` | `string` | - | Customizable test identifier |
45
+ | `isDisabled` | `string` | - | Determines the disabled state of the tab |
46
+
47
+ ## Stack
48
+
49
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
50
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
51
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
52
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
53
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
54
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
55
+ - [ESLint](https://eslint.org/) for code linting
56
+ - [Prettier](https://prettier.io) for code formatting
57
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
58
+ - [Yarn](https://yarnpkg.com/) from managing packages
59
+
60
+ ## Commands
61
+
62
+ - `yarn build` - Build the package
63
+ - `yarn dev` - Run the package locally
64
+ - `yarn lint` - Lint all files within this package
65
+ - `yarn test` - Run all unit tests
66
+ - `yarn test:report` - Open the test coverage report
67
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
68
+
69
+ ## Compilation
70
+
71
+ Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
72
+
73
+ The `/dist` folder contains the compiled output.
74
+
75
+ ```bash
76
+ tabs
77
+ └── dist
78
+ ├── index.d.ts <-- Types
79
+ ├── index.js <-- CommonJS version
80
+ └── index.mjs <-- ES Modules version
81
+ ...
82
+ ```
83
+
84
+ ## Versioning
85
+
86
+ Follows [semantic versioning](https://semver.org/)
87
+
88
+ ## &copy; License
89
+
90
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,38 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { BaseProps } from '@dt-dds/react-core';
4
+ import { ReactNode } from 'react';
5
+
6
+ type Variant = 'default' | 'contained';
7
+
8
+ interface TabItemProps extends BaseProps {
9
+ activeTab?: number;
10
+ variant?: Variant;
11
+ index?: number;
12
+ isDisabled?: boolean;
13
+ label: string;
14
+ icon?: ReactNode;
15
+ handleChange?: (value: number) => void;
16
+ }
17
+
18
+ interface TabsProps extends BaseProps {
19
+ activeTab: number;
20
+ variant?: Variant;
21
+ handleChange: (value: number) => void;
22
+ }
23
+ declare const Tabs: {
24
+ ({ children, style, activeTab, dataTestId, variant, handleChange, }: TabsProps): react_jsx_runtime.JSX.Element;
25
+ Item: ({ activeTab, dataTestId, isDisabled, index, variant, label, icon, handleChange, }: TabItemProps) => react_jsx_runtime.JSX.Element;
26
+ };
27
+
28
+ declare const useTabs: (initialTab?: number) => {
29
+ activeTab: number;
30
+ handleChange: (value: number) => void;
31
+ };
32
+
33
+ declare module '@emotion/react' {
34
+ interface Theme extends CustomTheme {
35
+ }
36
+ }
37
+
38
+ export { Tabs, type TabsProps, useTabs };
@@ -0,0 +1,38 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { BaseProps } from '@dt-dds/react-core';
4
+ import { ReactNode } from 'react';
5
+
6
+ type Variant = 'default' | 'contained';
7
+
8
+ interface TabItemProps extends BaseProps {
9
+ activeTab?: number;
10
+ variant?: Variant;
11
+ index?: number;
12
+ isDisabled?: boolean;
13
+ label: string;
14
+ icon?: ReactNode;
15
+ handleChange?: (value: number) => void;
16
+ }
17
+
18
+ interface TabsProps extends BaseProps {
19
+ activeTab: number;
20
+ variant?: Variant;
21
+ handleChange: (value: number) => void;
22
+ }
23
+ declare const Tabs: {
24
+ ({ children, style, activeTab, dataTestId, variant, handleChange, }: TabsProps): react_jsx_runtime.JSX.Element;
25
+ Item: ({ activeTab, dataTestId, isDisabled, index, variant, label, icon, handleChange, }: TabItemProps) => react_jsx_runtime.JSX.Element;
26
+ };
27
+
28
+ declare const useTabs: (initialTab?: number) => {
29
+ activeTab: number;
30
+ handleChange: (value: number) => void;
31
+ };
32
+
33
+ declare module '@emotion/react' {
34
+ interface Theme extends CustomTheme {
35
+ }
36
+ }
37
+
38
+ export { Tabs, type TabsProps, useTabs };
package/dist/index.js ADDED
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // index.ts
48
+ var index_exports = {};
49
+ __export(index_exports, {
50
+ Tabs: () => Tabs,
51
+ useTabs: () => useTabs
52
+ });
53
+ module.exports = __toCommonJS(index_exports);
54
+
55
+ // src/Tabs.tsx
56
+ var import_react2 = require("react");
57
+ var import_react3 = require("@emotion/react");
58
+ var import_react_box = require("@dt-dds/react-box");
59
+ var import_react_core = require("@dt-dds/react-core");
60
+ var import_react_icon = require("@dt-dds/react-icon");
61
+ var import_react_icon_button = require("@dt-dds/react-icon-button");
62
+
63
+ // src/components/TabItem/TabItem.tsx
64
+ var import_react = require("react");
65
+
66
+ // src/components/TabItem/TabItem.styled.ts
67
+ var import_styled = __toESM(require("@emotion/styled"));
68
+ var TabItemStyled = import_styled.default.button`
69
+ border: none;
70
+ display: flex;
71
+ align-items: center;
72
+
73
+ ${({ theme, active, disabled, variant }) => `
74
+ ${active ? theme.fontStyles.bodyMdBold : theme.fontStyles.bodyMdRegular}
75
+ ${variant === "default" ? `
76
+ background-color: transparent;
77
+ ${active ? `border-bottom: 2px solid ${theme.palette.accent.default};` : ""}
78
+ ` : `
79
+ background-color: ${active ? theme.palette.surface.contrast : "transparent"};`}
80
+
81
+ color: ${disabled ? theme.palette.content.light : theme.palette.accent.default};
82
+ padding: ${theme.spacing.spacing_40} ${theme.spacing.s};
83
+ cursor: ${active ? "default" : disabled ? "not-allowed" : "pointer"};
84
+ white-space: nowrap;
85
+ gap: ${theme.spacing.spacing_30};
86
+
87
+ ${!active && !disabled && `
88
+ &:hover {
89
+ background-color: ${theme.palette.accent.light};
90
+ }
91
+ `}
92
+ `}
93
+ `;
94
+
95
+ // src/components/TabItem/TabItem.tsx
96
+ var import_jsx_runtime = require("react/jsx-runtime");
97
+ var TabItem = ({
98
+ activeTab,
99
+ dataTestId,
100
+ isDisabled,
101
+ index,
102
+ variant,
103
+ label,
104
+ icon,
105
+ handleChange
106
+ }) => {
107
+ const ref = (0, import_react.useRef)(null);
108
+ const handleOnClick = () => {
109
+ if (!ref || !ref.current || !ref.current.parentElement) return;
110
+ const elementClientRect = ref.current.getBoundingClientRect();
111
+ const parentClientRect = ref.current.parentElement.getBoundingClientRect();
112
+ if (elementClientRect.left < parentClientRect.left) {
113
+ ref.current.parentElement.scroll({
114
+ left: ref.current.parentElement.scrollLeft - (parentClientRect.left - elementClientRect.left),
115
+ behavior: "smooth"
116
+ });
117
+ }
118
+ if (parentClientRect.right < elementClientRect.right) {
119
+ ref.current.parentElement.scroll({
120
+ left: ref.current.parentElement.scrollLeft + (elementClientRect.right - parentClientRect.right),
121
+ behavior: "smooth"
122
+ });
123
+ }
124
+ handleChange(index);
125
+ };
126
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
127
+ TabItemStyled,
128
+ {
129
+ active: activeTab === index,
130
+ "data-testid": dataTestId ? dataTestId : `tab-item-${index}`,
131
+ disabled: isDisabled,
132
+ onClick: handleOnClick,
133
+ ref,
134
+ role: "tab",
135
+ tabIndex: activeTab === index ? 0 : -1,
136
+ variant,
137
+ children: [
138
+ icon,
139
+ label
140
+ ]
141
+ }
142
+ );
143
+ };
144
+
145
+ // src/Tabs.styled.ts
146
+ var import_styled2 = __toESM(require("@emotion/styled"));
147
+ var TabsStyled = import_styled2.default.div`
148
+ ${({ variant }) => `
149
+ display: flex;
150
+ flex-direction: row;
151
+ overflow: hidden;
152
+ width: 100%;
153
+ ${variant === "default" && "margin-bottom: -1px;"}
154
+ `};
155
+ `;
156
+
157
+ // src/Tabs.tsx
158
+ var import_jsx_runtime2 = require("react/jsx-runtime");
159
+ var SCROLL_MOVEMENT = 120;
160
+ var SCROLL_OFFSET = 0.5;
161
+ var Tabs = ({
162
+ children,
163
+ style,
164
+ activeTab,
165
+ dataTestId = "tabs",
166
+ variant = "default",
167
+ handleChange
168
+ }) => {
169
+ const ref = (0, import_react2.useRef)(null);
170
+ const [isLeftSideOverflowing, setIsLeftSideOverflowing] = (0, import_react2.useState)(false);
171
+ const [isRightSideOverflowing, setIsRightSideOverflowing] = (0, import_react2.useState)(false);
172
+ const theme = (0, import_react3.useTheme)();
173
+ const clonedChildren = (0, import_react2.useMemo)(
174
+ () => import_react2.Children.map(children, (child, index) => {
175
+ return child && (0, import_react2.cloneElement)(child, __spreadProps(__spreadValues({}, child.props), {
176
+ activeTab,
177
+ variant,
178
+ index,
179
+ handleChange
180
+ }));
181
+ }),
182
+ [children, activeTab, variant, handleChange]
183
+ );
184
+ const handleScroll = (scrollOffset) => {
185
+ if (!ref || !ref.current) return;
186
+ const left = ref.current.scrollLeft + scrollOffset;
187
+ ref.current.scroll({
188
+ left,
189
+ behavior: "smooth"
190
+ });
191
+ calculateIfIsOverflowing(left);
192
+ };
193
+ const calculateIfIsOverflowing = (currentScrollLeft) => {
194
+ if (!ref || !ref.current) return;
195
+ const scrollLeft = currentScrollLeft != null ? currentScrollLeft : ref.current.scrollLeft;
196
+ setIsLeftSideOverflowing(scrollLeft > 0);
197
+ setIsRightSideOverflowing(
198
+ ref.current.clientWidth + scrollLeft + SCROLL_OFFSET < ref.current.scrollWidth
199
+ );
200
+ };
201
+ (0, import_react2.useEffect)(() => calculateIfIsOverflowing(), []);
202
+ (0, import_react_core.useDebounceResize)(() => calculateIfIsOverflowing());
203
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
204
+ import_react_box.Box,
205
+ {
206
+ style: __spreadValues({
207
+ flexDirection: "row"
208
+ }, variant === "default" && {
209
+ borderBottom: `1px solid ${theme.palette.border.default}`
210
+ }),
211
+ children: [
212
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_icon_button.IconButton, { onClick: () => handleScroll(-SCROLL_MOVEMENT), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
213
+ import_react_icon.Icon,
214
+ {
215
+ code: "keyboard_arrow_left",
216
+ dataTestId: "left-arrow",
217
+ style: __spreadValues({}, !isLeftSideOverflowing && { display: "none" })
218
+ }
219
+ ) }),
220
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
221
+ TabsStyled,
222
+ {
223
+ "data-testid": dataTestId,
224
+ ref,
225
+ role: "tablist",
226
+ style,
227
+ variant,
228
+ children: clonedChildren
229
+ }
230
+ ),
231
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_icon_button.IconButton, { onClick: () => handleScroll(SCROLL_MOVEMENT), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
232
+ import_react_icon.Icon,
233
+ {
234
+ code: "keyboard_arrow_right",
235
+ dataTestId: "right-arrow",
236
+ style: __spreadValues({}, !isRightSideOverflowing && { display: "none" })
237
+ }
238
+ ) })
239
+ ]
240
+ }
241
+ );
242
+ };
243
+ Tabs.Item = TabItem;
244
+
245
+ // src/hooks/useTabs.ts
246
+ var import_react4 = require("react");
247
+ var useTabs = (initialTab = 0) => {
248
+ const [activeTab, setActiveTab] = (0, import_react4.useState)(initialTab);
249
+ (0, import_react4.useEffect)(() => {
250
+ setActiveTab(initialTab);
251
+ }, [initialTab]);
252
+ const handleChange = (value) => {
253
+ setActiveTab(value);
254
+ };
255
+ return {
256
+ activeTab,
257
+ handleChange
258
+ };
259
+ };
260
+ // Annotate the CommonJS export names for ESM import in node:
261
+ 0 && (module.exports = {
262
+ Tabs,
263
+ useTabs
264
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,236 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/Tabs.tsx
22
+ import {
23
+ Children,
24
+ cloneElement,
25
+ useEffect,
26
+ useMemo,
27
+ useRef as useRef2,
28
+ useState
29
+ } from "react";
30
+ import { useTheme } from "@emotion/react";
31
+ import { Box } from "@dt-dds/react-box";
32
+ import { useDebounceResize } from "@dt-dds/react-core";
33
+ import { Icon } from "@dt-dds/react-icon";
34
+ import { IconButton } from "@dt-dds/react-icon-button";
35
+
36
+ // src/components/TabItem/TabItem.tsx
37
+ import { useRef } from "react";
38
+
39
+ // src/components/TabItem/TabItem.styled.ts
40
+ import styled from "@emotion/styled";
41
+ var TabItemStyled = styled.button`
42
+ border: none;
43
+ display: flex;
44
+ align-items: center;
45
+
46
+ ${({ theme, active, disabled, variant }) => `
47
+ ${active ? theme.fontStyles.bodyMdBold : theme.fontStyles.bodyMdRegular}
48
+ ${variant === "default" ? `
49
+ background-color: transparent;
50
+ ${active ? `border-bottom: 2px solid ${theme.palette.accent.default};` : ""}
51
+ ` : `
52
+ background-color: ${active ? theme.palette.surface.contrast : "transparent"};`}
53
+
54
+ color: ${disabled ? theme.palette.content.light : theme.palette.accent.default};
55
+ padding: ${theme.spacing.spacing_40} ${theme.spacing.s};
56
+ cursor: ${active ? "default" : disabled ? "not-allowed" : "pointer"};
57
+ white-space: nowrap;
58
+ gap: ${theme.spacing.spacing_30};
59
+
60
+ ${!active && !disabled && `
61
+ &:hover {
62
+ background-color: ${theme.palette.accent.light};
63
+ }
64
+ `}
65
+ `}
66
+ `;
67
+
68
+ // src/components/TabItem/TabItem.tsx
69
+ import { jsxs } from "react/jsx-runtime";
70
+ var TabItem = ({
71
+ activeTab,
72
+ dataTestId,
73
+ isDisabled,
74
+ index,
75
+ variant,
76
+ label,
77
+ icon,
78
+ handleChange
79
+ }) => {
80
+ const ref = useRef(null);
81
+ const handleOnClick = () => {
82
+ if (!ref || !ref.current || !ref.current.parentElement) return;
83
+ const elementClientRect = ref.current.getBoundingClientRect();
84
+ const parentClientRect = ref.current.parentElement.getBoundingClientRect();
85
+ if (elementClientRect.left < parentClientRect.left) {
86
+ ref.current.parentElement.scroll({
87
+ left: ref.current.parentElement.scrollLeft - (parentClientRect.left - elementClientRect.left),
88
+ behavior: "smooth"
89
+ });
90
+ }
91
+ if (parentClientRect.right < elementClientRect.right) {
92
+ ref.current.parentElement.scroll({
93
+ left: ref.current.parentElement.scrollLeft + (elementClientRect.right - parentClientRect.right),
94
+ behavior: "smooth"
95
+ });
96
+ }
97
+ handleChange(index);
98
+ };
99
+ return /* @__PURE__ */ jsxs(
100
+ TabItemStyled,
101
+ {
102
+ active: activeTab === index,
103
+ "data-testid": dataTestId ? dataTestId : `tab-item-${index}`,
104
+ disabled: isDisabled,
105
+ onClick: handleOnClick,
106
+ ref,
107
+ role: "tab",
108
+ tabIndex: activeTab === index ? 0 : -1,
109
+ variant,
110
+ children: [
111
+ icon,
112
+ label
113
+ ]
114
+ }
115
+ );
116
+ };
117
+
118
+ // src/Tabs.styled.ts
119
+ import styled2 from "@emotion/styled";
120
+ var TabsStyled = styled2.div`
121
+ ${({ variant }) => `
122
+ display: flex;
123
+ flex-direction: row;
124
+ overflow: hidden;
125
+ width: 100%;
126
+ ${variant === "default" && "margin-bottom: -1px;"}
127
+ `};
128
+ `;
129
+
130
+ // src/Tabs.tsx
131
+ import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
132
+ var SCROLL_MOVEMENT = 120;
133
+ var SCROLL_OFFSET = 0.5;
134
+ var Tabs = ({
135
+ children,
136
+ style,
137
+ activeTab,
138
+ dataTestId = "tabs",
139
+ variant = "default",
140
+ handleChange
141
+ }) => {
142
+ const ref = useRef2(null);
143
+ const [isLeftSideOverflowing, setIsLeftSideOverflowing] = useState(false);
144
+ const [isRightSideOverflowing, setIsRightSideOverflowing] = useState(false);
145
+ const theme = useTheme();
146
+ const clonedChildren = useMemo(
147
+ () => Children.map(children, (child, index) => {
148
+ return child && cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
149
+ activeTab,
150
+ variant,
151
+ index,
152
+ handleChange
153
+ }));
154
+ }),
155
+ [children, activeTab, variant, handleChange]
156
+ );
157
+ const handleScroll = (scrollOffset) => {
158
+ if (!ref || !ref.current) return;
159
+ const left = ref.current.scrollLeft + scrollOffset;
160
+ ref.current.scroll({
161
+ left,
162
+ behavior: "smooth"
163
+ });
164
+ calculateIfIsOverflowing(left);
165
+ };
166
+ const calculateIfIsOverflowing = (currentScrollLeft) => {
167
+ if (!ref || !ref.current) return;
168
+ const scrollLeft = currentScrollLeft != null ? currentScrollLeft : ref.current.scrollLeft;
169
+ setIsLeftSideOverflowing(scrollLeft > 0);
170
+ setIsRightSideOverflowing(
171
+ ref.current.clientWidth + scrollLeft + SCROLL_OFFSET < ref.current.scrollWidth
172
+ );
173
+ };
174
+ useEffect(() => calculateIfIsOverflowing(), []);
175
+ useDebounceResize(() => calculateIfIsOverflowing());
176
+ return /* @__PURE__ */ jsxs2(
177
+ Box,
178
+ {
179
+ style: __spreadValues({
180
+ flexDirection: "row"
181
+ }, variant === "default" && {
182
+ borderBottom: `1px solid ${theme.palette.border.default}`
183
+ }),
184
+ children: [
185
+ /* @__PURE__ */ jsx(IconButton, { onClick: () => handleScroll(-SCROLL_MOVEMENT), children: /* @__PURE__ */ jsx(
186
+ Icon,
187
+ {
188
+ code: "keyboard_arrow_left",
189
+ dataTestId: "left-arrow",
190
+ style: __spreadValues({}, !isLeftSideOverflowing && { display: "none" })
191
+ }
192
+ ) }),
193
+ /* @__PURE__ */ jsx(
194
+ TabsStyled,
195
+ {
196
+ "data-testid": dataTestId,
197
+ ref,
198
+ role: "tablist",
199
+ style,
200
+ variant,
201
+ children: clonedChildren
202
+ }
203
+ ),
204
+ /* @__PURE__ */ jsx(IconButton, { onClick: () => handleScroll(SCROLL_MOVEMENT), children: /* @__PURE__ */ jsx(
205
+ Icon,
206
+ {
207
+ code: "keyboard_arrow_right",
208
+ dataTestId: "right-arrow",
209
+ style: __spreadValues({}, !isRightSideOverflowing && { display: "none" })
210
+ }
211
+ ) })
212
+ ]
213
+ }
214
+ );
215
+ };
216
+ Tabs.Item = TabItem;
217
+
218
+ // src/hooks/useTabs.ts
219
+ import { useState as useState2, useEffect as useEffect2 } from "react";
220
+ var useTabs = (initialTab = 0) => {
221
+ const [activeTab, setActiveTab] = useState2(initialTab);
222
+ useEffect2(() => {
223
+ setActiveTab(initialTab);
224
+ }, [initialTab]);
225
+ const handleChange = (value) => {
226
+ setActiveTab(value);
227
+ };
228
+ return {
229
+ activeTab,
230
+ handleChange
231
+ };
232
+ };
233
+ export {
234
+ Tabs,
235
+ useTabs
236
+ };