@dt-dds/react-tabs 1.0.0-beta.39
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/CHANGELOG.md +385 -0
- package/LICENSE.md +21 -0
- package/README.md +90 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +267 -0
- package/dist/index.mjs +239 -0
- package/package.json +57 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
# @dt-ui/react-tabs
|
|
2
|
+
|
|
3
|
+
## 1.0.0-beta.39
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore: fix publish after npmjs.org pkg unpublish
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- Updated dependencies [223664b]
|
|
10
|
+
- @dt-dds/react-box@1.0.0-beta.10
|
|
11
|
+
|
|
12
|
+
## 1.0.0-beta.38
|
|
13
|
+
|
|
14
|
+
### Major Changes
|
|
15
|
+
|
|
16
|
+
- refactor!: rename pkg and publish to npmjs
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @dt-dds/react-box@1.0.0-beta.9
|
|
22
|
+
- @dt-dds/react-core@1.0.0-beta.41
|
|
23
|
+
- @dt-dds/react-icon@1.0.0-beta.42
|
|
24
|
+
- @dt-dds/react-icon-button@1.0.0-beta.9
|
|
25
|
+
|
|
26
|
+
## 0.1.0-beta.37
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- chore: fix pkg deps versions
|
|
31
|
+
|
|
32
|
+
## 0.1.0-beta.36
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- refactor: drop icon funcional state
|
|
37
|
+
- Updated dependencies
|
|
38
|
+
- @dt-ui/react-icon@0.1.0-beta.41
|
|
39
|
+
|
|
40
|
+
## 0.1.0-beta.35
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- refactor: theme typography values
|
|
45
|
+
- Updated dependencies
|
|
46
|
+
- @dt-ui/react-core@0.1.0-beta.40
|
|
47
|
+
- @dt-ui/react-icon@0.1.0-beta.40
|
|
48
|
+
|
|
49
|
+
## 0.1.0-beta.34
|
|
50
|
+
|
|
51
|
+
### Minor Changes
|
|
52
|
+
|
|
53
|
+
- feat: update shadow theme values
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies
|
|
58
|
+
- @dt-ui/react-core@0.1.0-beta.39
|
|
59
|
+
- @dt-ui/react-icon@0.1.0-beta.39
|
|
60
|
+
|
|
61
|
+
## 0.1.0-beta.33
|
|
62
|
+
|
|
63
|
+
### Minor Changes
|
|
64
|
+
|
|
65
|
+
- feat: add new icon font sizes
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- Updated dependencies
|
|
70
|
+
- @dt-ui/react-icon@0.1.0-beta.38
|
|
71
|
+
|
|
72
|
+
## 0.1.0-beta.32
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- chore: update theme font-styles
|
|
77
|
+
- Updated dependencies
|
|
78
|
+
- @dt-ui/react-core@0.1.0-beta.38
|
|
79
|
+
- @dt-ui/react-icon@0.1.0-beta.37
|
|
80
|
+
|
|
81
|
+
## 0.1.0-beta.31
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- chore: review OSS files
|
|
86
|
+
- Updated dependencies
|
|
87
|
+
- @dt-ui/react-box@0.1.0-beta.8
|
|
88
|
+
- @dt-ui/react-core@0.1.0-beta.37
|
|
89
|
+
- @dt-ui/react-icon@0.1.0-beta.36
|
|
90
|
+
|
|
91
|
+
## 0.1.0-beta.30
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- chore: update contextual colors
|
|
96
|
+
- Updated dependencies
|
|
97
|
+
- @dt-ui/react-core@0.1.0-beta.36
|
|
98
|
+
- @dt-ui/react-icon@0.1.0-beta.35
|
|
99
|
+
|
|
100
|
+
## 0.1.0-beta.29
|
|
101
|
+
|
|
102
|
+
### Minor Changes
|
|
103
|
+
|
|
104
|
+
- feat: implement IconButton contrast and size
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- Updated dependencies
|
|
109
|
+
- @dt-ui/react-icon@0.1.0-beta.34
|
|
110
|
+
|
|
111
|
+
## 0.1.0-beta.28
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- fix: change tabs styled border logic
|
|
116
|
+
|
|
117
|
+
## 0.1.0-beta.27
|
|
118
|
+
|
|
119
|
+
### Minor Changes
|
|
120
|
+
|
|
121
|
+
- feat: add border bottom to tab default
|
|
122
|
+
|
|
123
|
+
## 0.1.0-beta.26
|
|
124
|
+
|
|
125
|
+
### Minor Changes
|
|
126
|
+
|
|
127
|
+
- feat: improve Tabs component and apply new colors
|
|
128
|
+
|
|
129
|
+
### Patch Changes
|
|
130
|
+
|
|
131
|
+
- fix: change content.light contextual color
|
|
132
|
+
- Updated dependencies
|
|
133
|
+
- @dt-ui/react-core@0.1.0-beta.35
|
|
134
|
+
- @dt-ui/react-icon@0.1.0-beta.33
|
|
135
|
+
|
|
136
|
+
## 0.1.0-beta.25
|
|
137
|
+
|
|
138
|
+
### Minor Changes
|
|
139
|
+
|
|
140
|
+
- feat: move icon-button to independent
|
|
141
|
+
|
|
142
|
+
### Patch Changes
|
|
143
|
+
|
|
144
|
+
- Updated dependencies
|
|
145
|
+
- @dt-ui/react-icon@0.1.0-beta.32
|
|
146
|
+
|
|
147
|
+
## 0.1.0-beta.24
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- fix: add accent to colors type
|
|
152
|
+
- Updated dependencies
|
|
153
|
+
- @dt-ui/react-core@0.1.0-beta.34
|
|
154
|
+
- @dt-ui/react-icon@0.1.0-beta.31
|
|
155
|
+
|
|
156
|
+
## 0.1.0-beta.23
|
|
157
|
+
|
|
158
|
+
### Patch Changes
|
|
159
|
+
|
|
160
|
+
- fix: change button text according to ux
|
|
161
|
+
- Updated dependencies
|
|
162
|
+
- @dt-ui/react-core@0.1.0-beta.33
|
|
163
|
+
- @dt-ui/react-icon@0.1.0-beta.30
|
|
164
|
+
|
|
165
|
+
## 0.1.0-beta.22
|
|
166
|
+
|
|
167
|
+
### Patch Changes
|
|
168
|
+
|
|
169
|
+
- chore: update contexual colors
|
|
170
|
+
- Updated dependencies
|
|
171
|
+
- @dt-ui/react-core@0.1.0-beta.32
|
|
172
|
+
- @dt-ui/react-icon@0.1.0-beta.29
|
|
173
|
+
|
|
174
|
+
## 0.1.0-beta.21
|
|
175
|
+
|
|
176
|
+
### Patch Changes
|
|
177
|
+
|
|
178
|
+
- style: update responsive font styles
|
|
179
|
+
- Updated dependencies
|
|
180
|
+
- @dt-ui/react-core@0.1.0-beta.31
|
|
181
|
+
- @dt-ui/react-icon@0.1.0-beta.28
|
|
182
|
+
|
|
183
|
+
## 0.1.0-beta.20
|
|
184
|
+
|
|
185
|
+
### Minor Changes
|
|
186
|
+
|
|
187
|
+
- feat: add spinner size 'extra-small' & update specs
|
|
188
|
+
|
|
189
|
+
### Patch Changes
|
|
190
|
+
|
|
191
|
+
- Updated dependencies
|
|
192
|
+
- @dt-ui/react-core@0.1.0-beta.30
|
|
193
|
+
- @dt-ui/react-icon@0.1.0-beta.27
|
|
194
|
+
|
|
195
|
+
## 0.1.0-beta.19
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- chore: add theme breakpoints
|
|
200
|
+
- Updated dependencies
|
|
201
|
+
- @dt-ui/react-core@0.1.0-beta.29
|
|
202
|
+
- @dt-ui/react-icon@0.1.0-beta.26
|
|
203
|
+
|
|
204
|
+
## 0.1.0-beta.18
|
|
205
|
+
|
|
206
|
+
### Minor Changes
|
|
207
|
+
|
|
208
|
+
- feat: add id to base props
|
|
209
|
+
|
|
210
|
+
### Patch Changes
|
|
211
|
+
|
|
212
|
+
- Updated dependencies
|
|
213
|
+
- @dt-ui/react-core@0.1.0-beta.28
|
|
214
|
+
- @dt-ui/react-icon@0.1.0-beta.25
|
|
215
|
+
|
|
216
|
+
## 0.1.0-beta.17
|
|
217
|
+
|
|
218
|
+
### Minor Changes
|
|
219
|
+
|
|
220
|
+
- feat: change breakpoints values
|
|
221
|
+
|
|
222
|
+
### Patch Changes
|
|
223
|
+
|
|
224
|
+
- Updated dependencies
|
|
225
|
+
- @dt-ui/react-core@0.1.0-beta.27
|
|
226
|
+
- @dt-ui/react-icon@0.1.0-beta.24
|
|
227
|
+
|
|
228
|
+
## 0.1.0-beta.16
|
|
229
|
+
|
|
230
|
+
### Patch Changes
|
|
231
|
+
|
|
232
|
+
- fix: replace body to correct one
|
|
233
|
+
- Updated dependencies
|
|
234
|
+
- @dt-ui/react-core@0.1.0-beta.26
|
|
235
|
+
- @dt-ui/react-icon@0.1.0-beta.23
|
|
236
|
+
|
|
237
|
+
## 0.1.0-beta.15
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- chore: add theme colors missing types
|
|
242
|
+
- Updated dependencies
|
|
243
|
+
- @dt-ui/react-core@0.1.0-beta.25
|
|
244
|
+
- @dt-ui/react-icon@0.1.0-beta.22
|
|
245
|
+
|
|
246
|
+
## 0.1.0-beta.14
|
|
247
|
+
|
|
248
|
+
### Patch Changes
|
|
249
|
+
|
|
250
|
+
- refactor: drop truckapi theme
|
|
251
|
+
- Updated dependencies
|
|
252
|
+
- @dt-ui/react-core@0.1.0-beta.24
|
|
253
|
+
- @dt-ui/react-icon@0.1.0-beta.21
|
|
254
|
+
|
|
255
|
+
## 0.1.0-beta.13
|
|
256
|
+
|
|
257
|
+
### Minor Changes
|
|
258
|
+
|
|
259
|
+
- feat: update core and semantic colors
|
|
260
|
+
- feat: remove greenlane theme
|
|
261
|
+
|
|
262
|
+
### Patch Changes
|
|
263
|
+
|
|
264
|
+
- Updated dependencies
|
|
265
|
+
- Updated dependencies
|
|
266
|
+
- @dt-ui/react-core@0.1.0-beta.23
|
|
267
|
+
- @dt-ui/react-icon@0.1.0-beta.20
|
|
268
|
+
|
|
269
|
+
## 0.1.0-beta.12
|
|
270
|
+
|
|
271
|
+
### Minor Changes
|
|
272
|
+
|
|
273
|
+
- feat: add icon option for truckapi theme
|
|
274
|
+
|
|
275
|
+
### Patch Changes
|
|
276
|
+
|
|
277
|
+
- Updated dependencies
|
|
278
|
+
- @dt-ui/react-core@0.1.0-beta.22
|
|
279
|
+
- @dt-ui/react-icon@0.1.0-beta.19
|
|
280
|
+
|
|
281
|
+
## 0.1.0-beta.11
|
|
282
|
+
|
|
283
|
+
### Patch Changes
|
|
284
|
+
|
|
285
|
+
- fix: tooltip z index
|
|
286
|
+
- Updated dependencies
|
|
287
|
+
- @dt-ui/react-core@0.1.0-beta.21
|
|
288
|
+
- @dt-ui/react-icon@0.1.0-beta.18
|
|
289
|
+
|
|
290
|
+
## 0.1.0-beta.10
|
|
291
|
+
|
|
292
|
+
### Minor Changes
|
|
293
|
+
|
|
294
|
+
- feat: add segmented control component
|
|
295
|
+
|
|
296
|
+
### Patch Changes
|
|
297
|
+
|
|
298
|
+
- Updated dependencies
|
|
299
|
+
- @dt-ui/react-core@0.1.0-beta.20
|
|
300
|
+
- @dt-ui/react-icon@0.1.0-beta.17
|
|
301
|
+
|
|
302
|
+
## 0.1.0-beta.9
|
|
303
|
+
|
|
304
|
+
### Patch Changes
|
|
305
|
+
|
|
306
|
+
- fix: add shape for tooltip on truckapi theme
|
|
307
|
+
- Updated dependencies
|
|
308
|
+
- @dt-ui/react-core@0.1.0-beta.19
|
|
309
|
+
- @dt-ui/react-icon@0.1.0-beta.16
|
|
310
|
+
|
|
311
|
+
## 0.1.0-beta.8
|
|
312
|
+
|
|
313
|
+
### Patch Changes
|
|
314
|
+
|
|
315
|
+
- fix: remove devDependecy export
|
|
316
|
+
- Updated dependencies
|
|
317
|
+
- @dt-ui/react-core@0.1.0-beta.18
|
|
318
|
+
- @dt-ui/react-icon@0.1.0-beta.15
|
|
319
|
+
|
|
320
|
+
## 0.1.0-beta.7
|
|
321
|
+
|
|
322
|
+
### Patch Changes
|
|
323
|
+
|
|
324
|
+
- test: add test custom render
|
|
325
|
+
- chore: move counter component to stepper pkg
|
|
326
|
+
- fix: tab variant type export
|
|
327
|
+
- Updated dependencies
|
|
328
|
+
- @dt-ui/react-core@0.1.0-beta.17
|
|
329
|
+
- @dt-ui/react-icon@0.1.0-beta.14
|
|
330
|
+
|
|
331
|
+
## 0.1.0-beta.6
|
|
332
|
+
|
|
333
|
+
### Minor Changes
|
|
334
|
+
|
|
335
|
+
- feat: create select
|
|
336
|
+
|
|
337
|
+
### Patch Changes
|
|
338
|
+
|
|
339
|
+
- Updated dependencies
|
|
340
|
+
- @dt-ui/react-core@0.1.0-beta.16
|
|
341
|
+
- @dt-ui/react-icon@0.1.0-beta.13
|
|
342
|
+
|
|
343
|
+
## 0.1.0-beta.5
|
|
344
|
+
|
|
345
|
+
### Patch Changes
|
|
346
|
+
|
|
347
|
+
- fix: show shadows only when scroll is visible
|
|
348
|
+
- Updated dependencies
|
|
349
|
+
- @dt-ui/react-core@0.1.0-beta.15
|
|
350
|
+
- @dt-ui/react-icon@0.1.0-beta.12
|
|
351
|
+
|
|
352
|
+
## 0.1.0-beta.4
|
|
353
|
+
|
|
354
|
+
### Patch Changes
|
|
355
|
+
|
|
356
|
+
- fix: update border radius theme specifications
|
|
357
|
+
- Updated dependencies
|
|
358
|
+
- @dt-ui/react-core@0.1.0-beta.14
|
|
359
|
+
- @dt-ui/react-icon@0.1.0-beta.11
|
|
360
|
+
|
|
361
|
+
## 0.1.0-beta.3
|
|
362
|
+
|
|
363
|
+
### Minor Changes
|
|
364
|
+
|
|
365
|
+
- feat: add onClick on Icon
|
|
366
|
+
- feat: scrollable tabs
|
|
367
|
+
|
|
368
|
+
### Patch Changes
|
|
369
|
+
|
|
370
|
+
- Updated dependencies
|
|
371
|
+
- @dt-ui/react-icon@0.1.0-beta.10
|
|
372
|
+
|
|
373
|
+
## 0.1.0-beta.2
|
|
374
|
+
|
|
375
|
+
### Patch Changes
|
|
376
|
+
|
|
377
|
+
- fix: match accordion design
|
|
378
|
+
- Updated dependencies
|
|
379
|
+
- @dt-ui/react-core@0.1.0-beta.13
|
|
380
|
+
|
|
381
|
+
## 0.1.0-beta.1
|
|
382
|
+
|
|
383
|
+
### Patch Changes
|
|
384
|
+
|
|
385
|
+
- chore: make tabs independent component
|
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
|
+
## © License
|
|
89
|
+
|
|
90
|
+
Licensed under [MIT License](LICENSE.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseProps, Theme } from '@dt-dds/react-core';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type Variant = 'default' | 'contained';
|
|
6
|
+
|
|
7
|
+
interface TabItemProps extends BaseProps {
|
|
8
|
+
activeTab?: number;
|
|
9
|
+
variant?: Variant;
|
|
10
|
+
index?: number;
|
|
11
|
+
isDisabled?: boolean;
|
|
12
|
+
label: string;
|
|
13
|
+
icon?: ReactNode;
|
|
14
|
+
handleChange?: (value: number) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface TabsProps extends BaseProps {
|
|
18
|
+
activeTab: number;
|
|
19
|
+
variant?: Variant;
|
|
20
|
+
handleChange: (value: number) => void;
|
|
21
|
+
}
|
|
22
|
+
declare const Tabs: {
|
|
23
|
+
({ children, style, activeTab, dataTestId, variant, handleChange, }: TabsProps): react_jsx_runtime.JSX.Element;
|
|
24
|
+
Item: ({ activeTab, dataTestId, isDisabled, index, variant, label, icon, handleChange, }: TabItemProps) => react_jsx_runtime.JSX.Element;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare const useTabs: (initialTab?: number) => {
|
|
28
|
+
activeTab: number;
|
|
29
|
+
handleChange: (value: number) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
declare module '@emotion/react' {
|
|
33
|
+
interface Theme extends Theme {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { Tabs, TabsProps, useTabs };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
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 tabs_exports = {};
|
|
49
|
+
__export(tabs_exports, {
|
|
50
|
+
Tabs: () => Tabs,
|
|
51
|
+
useTabs: () => useTabs
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(tabs_exports);
|
|
54
|
+
|
|
55
|
+
// src/Tabs.tsx
|
|
56
|
+
var import_react_box = require("@dt-dds/react-box");
|
|
57
|
+
var import_react_core = require("@dt-dds/react-core");
|
|
58
|
+
var import_react_icon = require("@dt-dds/react-icon");
|
|
59
|
+
var import_react_icon_button = require("@dt-dds/react-icon-button");
|
|
60
|
+
var import_react2 = require("@emotion/react");
|
|
61
|
+
var import_react3 = require("react");
|
|
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.body2Bold : theme.fontStyles.body2}
|
|
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["3xs"]} ${theme.spacing.s};
|
|
83
|
+
cursor: ${active ? "default" : disabled ? "not-allowed" : "pointer"};
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
gap: ${theme.spacing["4xs"]};
|
|
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)
|
|
110
|
+
return;
|
|
111
|
+
const elementClientRect = ref.current.getBoundingClientRect();
|
|
112
|
+
const parentClientRect = ref.current.parentElement.getBoundingClientRect();
|
|
113
|
+
if (elementClientRect.left < parentClientRect.left) {
|
|
114
|
+
ref.current.parentElement.scroll({
|
|
115
|
+
left: ref.current.parentElement.scrollLeft - (parentClientRect.left - elementClientRect.left),
|
|
116
|
+
behavior: "smooth"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (parentClientRect.right < elementClientRect.right) {
|
|
120
|
+
ref.current.parentElement.scroll({
|
|
121
|
+
left: ref.current.parentElement.scrollLeft + (elementClientRect.right - parentClientRect.right),
|
|
122
|
+
behavior: "smooth"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
handleChange(index);
|
|
126
|
+
};
|
|
127
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
128
|
+
TabItemStyled,
|
|
129
|
+
{
|
|
130
|
+
active: activeTab === index,
|
|
131
|
+
"data-testid": dataTestId ? dataTestId : `tab-item-${index}`,
|
|
132
|
+
disabled: isDisabled,
|
|
133
|
+
onClick: handleOnClick,
|
|
134
|
+
ref,
|
|
135
|
+
role: "tab",
|
|
136
|
+
tabIndex: activeTab === index ? 0 : -1,
|
|
137
|
+
variant,
|
|
138
|
+
children: [
|
|
139
|
+
icon,
|
|
140
|
+
label
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/Tabs.styled.ts
|
|
147
|
+
var import_styled2 = __toESM(require("@emotion/styled"));
|
|
148
|
+
var TabsStyled = import_styled2.default.div`
|
|
149
|
+
${({ variant }) => `
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: row;
|
|
152
|
+
overflow: hidden;
|
|
153
|
+
width: 100%;
|
|
154
|
+
${variant === "default" && "margin-bottom: -1px;"}
|
|
155
|
+
`};
|
|
156
|
+
`;
|
|
157
|
+
|
|
158
|
+
// src/Tabs.tsx
|
|
159
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
160
|
+
var SCROLL_MOVEMENT = 120;
|
|
161
|
+
var SCROLL_OFFSET = 0.5;
|
|
162
|
+
var Tabs = ({
|
|
163
|
+
children,
|
|
164
|
+
style,
|
|
165
|
+
activeTab,
|
|
166
|
+
dataTestId = "tabs",
|
|
167
|
+
variant = "default",
|
|
168
|
+
handleChange
|
|
169
|
+
}) => {
|
|
170
|
+
const ref = (0, import_react3.useRef)(null);
|
|
171
|
+
const [isLeftSideOverflowing, setIsLeftSideOverflowing] = (0, import_react3.useState)(false);
|
|
172
|
+
const [isRightSideOverflowing, setIsRightSideOverflowing] = (0, import_react3.useState)(false);
|
|
173
|
+
const theme = (0, import_react2.useTheme)();
|
|
174
|
+
const clonedChildren = (0, import_react3.useMemo)(
|
|
175
|
+
() => import_react3.Children.map(children, (child, index) => {
|
|
176
|
+
return child && (0, import_react3.cloneElement)(child, __spreadProps(__spreadValues({}, child.props), {
|
|
177
|
+
activeTab,
|
|
178
|
+
variant,
|
|
179
|
+
index,
|
|
180
|
+
handleChange
|
|
181
|
+
}));
|
|
182
|
+
}),
|
|
183
|
+
[children, activeTab, variant, handleChange]
|
|
184
|
+
);
|
|
185
|
+
const handleScroll = (scrollOffset) => {
|
|
186
|
+
if (!ref || !ref.current)
|
|
187
|
+
return;
|
|
188
|
+
const left = ref.current.scrollLeft + scrollOffset;
|
|
189
|
+
ref.current.scroll({
|
|
190
|
+
left,
|
|
191
|
+
behavior: "smooth"
|
|
192
|
+
});
|
|
193
|
+
calculateIfIsOverflowing(left);
|
|
194
|
+
};
|
|
195
|
+
const calculateIfIsOverflowing = (currentScrollLeft) => {
|
|
196
|
+
if (!ref || !ref.current)
|
|
197
|
+
return;
|
|
198
|
+
const scrollLeft = currentScrollLeft != null ? currentScrollLeft : ref.current.scrollLeft;
|
|
199
|
+
setIsLeftSideOverflowing(scrollLeft > 0);
|
|
200
|
+
setIsRightSideOverflowing(
|
|
201
|
+
ref.current.clientWidth + scrollLeft + SCROLL_OFFSET < ref.current.scrollWidth
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
(0, import_react3.useEffect)(() => calculateIfIsOverflowing(), []);
|
|
205
|
+
(0, import_react_core.useDebounceResize)(() => calculateIfIsOverflowing());
|
|
206
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
207
|
+
import_react_box.Box,
|
|
208
|
+
{
|
|
209
|
+
style: __spreadValues({
|
|
210
|
+
flexDirection: "row"
|
|
211
|
+
}, variant === "default" && {
|
|
212
|
+
borderBottom: `1px solid ${theme.palette.border.default}`
|
|
213
|
+
}),
|
|
214
|
+
children: [
|
|
215
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_icon_button.IconButton, { onClick: () => handleScroll(-SCROLL_MOVEMENT), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
216
|
+
import_react_icon.Icon,
|
|
217
|
+
{
|
|
218
|
+
code: "keyboard_arrow_left",
|
|
219
|
+
dataTestId: "left-arrow",
|
|
220
|
+
style: __spreadValues({}, !isLeftSideOverflowing && { display: "none" })
|
|
221
|
+
}
|
|
222
|
+
) }),
|
|
223
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
224
|
+
TabsStyled,
|
|
225
|
+
{
|
|
226
|
+
"data-testid": dataTestId,
|
|
227
|
+
ref,
|
|
228
|
+
role: "tablist",
|
|
229
|
+
style,
|
|
230
|
+
variant,
|
|
231
|
+
children: clonedChildren
|
|
232
|
+
}
|
|
233
|
+
),
|
|
234
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_icon_button.IconButton, { onClick: () => handleScroll(SCROLL_MOVEMENT), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
235
|
+
import_react_icon.Icon,
|
|
236
|
+
{
|
|
237
|
+
code: "keyboard_arrow_right",
|
|
238
|
+
dataTestId: "right-arrow",
|
|
239
|
+
style: __spreadValues({}, !isRightSideOverflowing && { display: "none" })
|
|
240
|
+
}
|
|
241
|
+
) })
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
Tabs.Item = TabItem;
|
|
247
|
+
|
|
248
|
+
// src/hooks/useTabs.ts
|
|
249
|
+
var import_react4 = require("react");
|
|
250
|
+
var useTabs = (initialTab = 0) => {
|
|
251
|
+
const [activeTab, setActiveTab] = (0, import_react4.useState)(initialTab);
|
|
252
|
+
(0, import_react4.useEffect)(() => {
|
|
253
|
+
setActiveTab(initialTab);
|
|
254
|
+
}, [initialTab]);
|
|
255
|
+
const handleChange = (value) => {
|
|
256
|
+
setActiveTab(value);
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
activeTab,
|
|
260
|
+
handleChange
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
264
|
+
0 && (module.exports = {
|
|
265
|
+
Tabs,
|
|
266
|
+
useTabs
|
|
267
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
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 { Box } from "@dt-dds/react-box";
|
|
23
|
+
import { useDebounceResize } from "@dt-dds/react-core";
|
|
24
|
+
import { Icon } from "@dt-dds/react-icon";
|
|
25
|
+
import { IconButton } from "@dt-dds/react-icon-button";
|
|
26
|
+
import { useTheme } from "@emotion/react";
|
|
27
|
+
import {
|
|
28
|
+
Children,
|
|
29
|
+
cloneElement,
|
|
30
|
+
useEffect,
|
|
31
|
+
useMemo,
|
|
32
|
+
useRef as useRef2,
|
|
33
|
+
useState
|
|
34
|
+
} from "react";
|
|
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.body2Bold : theme.fontStyles.body2}
|
|
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["3xs"]} ${theme.spacing.s};
|
|
56
|
+
cursor: ${active ? "default" : disabled ? "not-allowed" : "pointer"};
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
gap: ${theme.spacing["4xs"]};
|
|
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)
|
|
83
|
+
return;
|
|
84
|
+
const elementClientRect = ref.current.getBoundingClientRect();
|
|
85
|
+
const parentClientRect = ref.current.parentElement.getBoundingClientRect();
|
|
86
|
+
if (elementClientRect.left < parentClientRect.left) {
|
|
87
|
+
ref.current.parentElement.scroll({
|
|
88
|
+
left: ref.current.parentElement.scrollLeft - (parentClientRect.left - elementClientRect.left),
|
|
89
|
+
behavior: "smooth"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (parentClientRect.right < elementClientRect.right) {
|
|
93
|
+
ref.current.parentElement.scroll({
|
|
94
|
+
left: ref.current.parentElement.scrollLeft + (elementClientRect.right - parentClientRect.right),
|
|
95
|
+
behavior: "smooth"
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
handleChange(index);
|
|
99
|
+
};
|
|
100
|
+
return /* @__PURE__ */ jsxs(
|
|
101
|
+
TabItemStyled,
|
|
102
|
+
{
|
|
103
|
+
active: activeTab === index,
|
|
104
|
+
"data-testid": dataTestId ? dataTestId : `tab-item-${index}`,
|
|
105
|
+
disabled: isDisabled,
|
|
106
|
+
onClick: handleOnClick,
|
|
107
|
+
ref,
|
|
108
|
+
role: "tab",
|
|
109
|
+
tabIndex: activeTab === index ? 0 : -1,
|
|
110
|
+
variant,
|
|
111
|
+
children: [
|
|
112
|
+
icon,
|
|
113
|
+
label
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/Tabs.styled.ts
|
|
120
|
+
import styled2 from "@emotion/styled";
|
|
121
|
+
var TabsStyled = styled2.div`
|
|
122
|
+
${({ variant }) => `
|
|
123
|
+
display: flex;
|
|
124
|
+
flex-direction: row;
|
|
125
|
+
overflow: hidden;
|
|
126
|
+
width: 100%;
|
|
127
|
+
${variant === "default" && "margin-bottom: -1px;"}
|
|
128
|
+
`};
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
// src/Tabs.tsx
|
|
132
|
+
import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
133
|
+
var SCROLL_MOVEMENT = 120;
|
|
134
|
+
var SCROLL_OFFSET = 0.5;
|
|
135
|
+
var Tabs = ({
|
|
136
|
+
children,
|
|
137
|
+
style,
|
|
138
|
+
activeTab,
|
|
139
|
+
dataTestId = "tabs",
|
|
140
|
+
variant = "default",
|
|
141
|
+
handleChange
|
|
142
|
+
}) => {
|
|
143
|
+
const ref = useRef2(null);
|
|
144
|
+
const [isLeftSideOverflowing, setIsLeftSideOverflowing] = useState(false);
|
|
145
|
+
const [isRightSideOverflowing, setIsRightSideOverflowing] = useState(false);
|
|
146
|
+
const theme = useTheme();
|
|
147
|
+
const clonedChildren = useMemo(
|
|
148
|
+
() => Children.map(children, (child, index) => {
|
|
149
|
+
return child && cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
150
|
+
activeTab,
|
|
151
|
+
variant,
|
|
152
|
+
index,
|
|
153
|
+
handleChange
|
|
154
|
+
}));
|
|
155
|
+
}),
|
|
156
|
+
[children, activeTab, variant, handleChange]
|
|
157
|
+
);
|
|
158
|
+
const handleScroll = (scrollOffset) => {
|
|
159
|
+
if (!ref || !ref.current)
|
|
160
|
+
return;
|
|
161
|
+
const left = ref.current.scrollLeft + scrollOffset;
|
|
162
|
+
ref.current.scroll({
|
|
163
|
+
left,
|
|
164
|
+
behavior: "smooth"
|
|
165
|
+
});
|
|
166
|
+
calculateIfIsOverflowing(left);
|
|
167
|
+
};
|
|
168
|
+
const calculateIfIsOverflowing = (currentScrollLeft) => {
|
|
169
|
+
if (!ref || !ref.current)
|
|
170
|
+
return;
|
|
171
|
+
const scrollLeft = currentScrollLeft != null ? currentScrollLeft : ref.current.scrollLeft;
|
|
172
|
+
setIsLeftSideOverflowing(scrollLeft > 0);
|
|
173
|
+
setIsRightSideOverflowing(
|
|
174
|
+
ref.current.clientWidth + scrollLeft + SCROLL_OFFSET < ref.current.scrollWidth
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
useEffect(() => calculateIfIsOverflowing(), []);
|
|
178
|
+
useDebounceResize(() => calculateIfIsOverflowing());
|
|
179
|
+
return /* @__PURE__ */ jsxs2(
|
|
180
|
+
Box,
|
|
181
|
+
{
|
|
182
|
+
style: __spreadValues({
|
|
183
|
+
flexDirection: "row"
|
|
184
|
+
}, variant === "default" && {
|
|
185
|
+
borderBottom: `1px solid ${theme.palette.border.default}`
|
|
186
|
+
}),
|
|
187
|
+
children: [
|
|
188
|
+
/* @__PURE__ */ jsx(IconButton, { onClick: () => handleScroll(-SCROLL_MOVEMENT), children: /* @__PURE__ */ jsx(
|
|
189
|
+
Icon,
|
|
190
|
+
{
|
|
191
|
+
code: "keyboard_arrow_left",
|
|
192
|
+
dataTestId: "left-arrow",
|
|
193
|
+
style: __spreadValues({}, !isLeftSideOverflowing && { display: "none" })
|
|
194
|
+
}
|
|
195
|
+
) }),
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
TabsStyled,
|
|
198
|
+
{
|
|
199
|
+
"data-testid": dataTestId,
|
|
200
|
+
ref,
|
|
201
|
+
role: "tablist",
|
|
202
|
+
style,
|
|
203
|
+
variant,
|
|
204
|
+
children: clonedChildren
|
|
205
|
+
}
|
|
206
|
+
),
|
|
207
|
+
/* @__PURE__ */ jsx(IconButton, { onClick: () => handleScroll(SCROLL_MOVEMENT), children: /* @__PURE__ */ jsx(
|
|
208
|
+
Icon,
|
|
209
|
+
{
|
|
210
|
+
code: "keyboard_arrow_right",
|
|
211
|
+
dataTestId: "right-arrow",
|
|
212
|
+
style: __spreadValues({}, !isRightSideOverflowing && { display: "none" })
|
|
213
|
+
}
|
|
214
|
+
) })
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
Tabs.Item = TabItem;
|
|
220
|
+
|
|
221
|
+
// src/hooks/useTabs.ts
|
|
222
|
+
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
223
|
+
var useTabs = (initialTab = 0) => {
|
|
224
|
+
const [activeTab, setActiveTab] = useState2(initialTab);
|
|
225
|
+
useEffect2(() => {
|
|
226
|
+
setActiveTab(initialTab);
|
|
227
|
+
}, [initialTab]);
|
|
228
|
+
const handleChange = (value) => {
|
|
229
|
+
setActiveTab(value);
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
activeTab,
|
|
233
|
+
handleChange
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
export {
|
|
237
|
+
Tabs,
|
|
238
|
+
useTabs
|
|
239
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dt-dds/react-tabs",
|
|
3
|
+
"version": "1.0.0-beta.39",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"lint": "eslint --cache .",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test:report": "open ./jest-coverage/lcov-report/index.html",
|
|
20
|
+
"test:update:snapshot": "jest -u"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@dt-dds/react-core": "1.0.0-beta.41",
|
|
24
|
+
"@dt-dds/react-icon": "1.0.0-beta.42",
|
|
25
|
+
"@dt-dds/react-icon-button": "1.0.0-beta.9",
|
|
26
|
+
"@dt-dds/react-box": "1.0.0-beta.10"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/core": "^7.22.9",
|
|
30
|
+
"@babel/preset-env": "^7.22.9",
|
|
31
|
+
"@babel/preset-react": "^7.22.5",
|
|
32
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
33
|
+
"@emotion/babel-plugin": "^11.11.0",
|
|
34
|
+
"@emotion/css": "^11.7.1",
|
|
35
|
+
"@emotion/jest": "^11.10.0",
|
|
36
|
+
"@emotion/react": "^11.8.2",
|
|
37
|
+
"@emotion/styled": "^11.8.1",
|
|
38
|
+
"@types/react": "^18.0.9",
|
|
39
|
+
"@types/react-dom": "^18.0.4",
|
|
40
|
+
"babel-loader": "^8.3.0",
|
|
41
|
+
"eslint-config-custom": "*",
|
|
42
|
+
"eslint-plugin-storybook": "^9.1.0",
|
|
43
|
+
"jest-config": "*",
|
|
44
|
+
"react": "^18.1.0",
|
|
45
|
+
"react-dom": "^18.2.0",
|
|
46
|
+
"tsconfig": "*",
|
|
47
|
+
"tsup": "^6.6.3",
|
|
48
|
+
"typescript": "^4.5.3"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@emotion/css": "^11.7.1",
|
|
52
|
+
"@emotion/react": "^11.8.2",
|
|
53
|
+
"@emotion/styled": "^11.8.1",
|
|
54
|
+
"react": ">=17.0.2",
|
|
55
|
+
"react-dom": ">=17.0.2"
|
|
56
|
+
}
|
|
57
|
+
}
|