@cloud-ru/ds-tabs 1.0.0

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 (106) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +201 -0
  3. package/README.md +300 -0
  4. package/dist/cjs/components/ScrollButton/ScrollButton.d.ts +8 -0
  5. package/dist/cjs/components/ScrollButton/ScrollButton.js +19 -0
  6. package/dist/cjs/components/ScrollButton/index.d.ts +1 -0
  7. package/dist/cjs/components/ScrollButton/index.js +17 -0
  8. package/dist/cjs/components/ScrollButton/styles.module.css +50 -0
  9. package/dist/cjs/components/Tab/Tab.d.ts +25 -0
  10. package/dist/cjs/components/Tab/Tab.js +78 -0
  11. package/dist/cjs/components/Tab/index.d.ts +1 -0
  12. package/dist/cjs/components/Tab/index.js +17 -0
  13. package/dist/cjs/components/Tab/styles.module.css +105 -0
  14. package/dist/cjs/components/TabBar/TabBar.d.ts +30 -0
  15. package/dist/cjs/components/TabBar/TabBar.js +119 -0
  16. package/dist/cjs/components/TabBar/hooks.d.ts +18 -0
  17. package/dist/cjs/components/TabBar/hooks.js +103 -0
  18. package/dist/cjs/components/TabBar/index.d.ts +1 -0
  19. package/dist/cjs/components/TabBar/index.js +17 -0
  20. package/dist/cjs/components/TabBar/styles.module.css +187 -0
  21. package/dist/cjs/components/TabContent/TabContent.d.ts +8 -0
  22. package/dist/cjs/components/TabContent/TabContent.js +14 -0
  23. package/dist/cjs/components/TabContent/index.d.ts +1 -0
  24. package/dist/cjs/components/TabContent/index.js +17 -0
  25. package/dist/cjs/components/Tabs/Tabs.d.ts +21 -0
  26. package/dist/cjs/components/Tabs/Tabs.js +39 -0
  27. package/dist/cjs/components/Tabs/index.d.ts +1 -0
  28. package/dist/cjs/components/Tabs/index.js +17 -0
  29. package/dist/cjs/components/Tabs/styles.module.css +21 -0
  30. package/dist/cjs/components/index.d.ts +5 -0
  31. package/dist/cjs/components/index.js +21 -0
  32. package/dist/cjs/constants.d.ts +32 -0
  33. package/dist/cjs/constants.js +35 -0
  34. package/dist/cjs/context.d.ts +17 -0
  35. package/dist/cjs/context.js +12 -0
  36. package/dist/cjs/index.d.ts +5 -0
  37. package/dist/cjs/index.js +21 -0
  38. package/dist/cjs/package.json +3 -0
  39. package/dist/cjs/style.css +363 -0
  40. package/dist/cjs/types.d.ts +17 -0
  41. package/dist/cjs/types.js +2 -0
  42. package/dist/cjs/utils.d.ts +1 -0
  43. package/dist/cjs/utils.js +6 -0
  44. package/dist/esm/components/ScrollButton/ScrollButton.d.ts +8 -0
  45. package/dist/esm/components/ScrollButton/ScrollButton.js +13 -0
  46. package/dist/esm/components/ScrollButton/index.d.ts +1 -0
  47. package/dist/esm/components/ScrollButton/index.js +1 -0
  48. package/dist/esm/components/ScrollButton/styles.module.css +50 -0
  49. package/dist/esm/components/Tab/Tab.d.ts +25 -0
  50. package/dist/esm/components/Tab/Tab.js +72 -0
  51. package/dist/esm/components/Tab/index.d.ts +1 -0
  52. package/dist/esm/components/Tab/index.js +1 -0
  53. package/dist/esm/components/Tab/styles.module.css +105 -0
  54. package/dist/esm/components/TabBar/TabBar.d.ts +30 -0
  55. package/dist/esm/components/TabBar/TabBar.js +113 -0
  56. package/dist/esm/components/TabBar/hooks.d.ts +18 -0
  57. package/dist/esm/components/TabBar/hooks.js +99 -0
  58. package/dist/esm/components/TabBar/index.d.ts +1 -0
  59. package/dist/esm/components/TabBar/index.js +1 -0
  60. package/dist/esm/components/TabBar/styles.module.css +187 -0
  61. package/dist/esm/components/TabContent/TabContent.d.ts +8 -0
  62. package/dist/esm/components/TabContent/TabContent.js +11 -0
  63. package/dist/esm/components/TabContent/index.d.ts +1 -0
  64. package/dist/esm/components/TabContent/index.js +1 -0
  65. package/dist/esm/components/Tabs/Tabs.d.ts +21 -0
  66. package/dist/esm/components/Tabs/Tabs.js +33 -0
  67. package/dist/esm/components/Tabs/index.d.ts +1 -0
  68. package/dist/esm/components/Tabs/index.js +1 -0
  69. package/dist/esm/components/Tabs/styles.module.css +21 -0
  70. package/dist/esm/components/index.d.ts +5 -0
  71. package/dist/esm/components/index.js +5 -0
  72. package/dist/esm/constants.d.ts +32 -0
  73. package/dist/esm/constants.js +32 -0
  74. package/dist/esm/context.d.ts +17 -0
  75. package/dist/esm/context.js +7 -0
  76. package/dist/esm/index.d.ts +5 -0
  77. package/dist/esm/index.js +5 -0
  78. package/dist/esm/style.css +363 -0
  79. package/dist/esm/types.d.ts +17 -0
  80. package/dist/esm/types.js +1 -0
  81. package/dist/esm/utils.d.ts +1 -0
  82. package/dist/esm/utils.js +3 -0
  83. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  84. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  85. package/package.json +48 -0
  86. package/src/components/ScrollButton/ScrollButton.tsx +42 -0
  87. package/src/components/ScrollButton/index.ts +1 -0
  88. package/src/components/ScrollButton/styles.module.scss +46 -0
  89. package/src/components/Tab/Tab.tsx +151 -0
  90. package/src/components/Tab/index.ts +1 -0
  91. package/src/components/Tab/styles.module.scss +135 -0
  92. package/src/components/TabBar/TabBar.tsx +269 -0
  93. package/src/components/TabBar/hooks.ts +139 -0
  94. package/src/components/TabBar/index.ts +1 -0
  95. package/src/components/TabBar/styles.module.scss +241 -0
  96. package/src/components/TabContent/TabContent.tsx +34 -0
  97. package/src/components/TabContent/index.ts +1 -0
  98. package/src/components/Tabs/Tabs.tsx +61 -0
  99. package/src/components/Tabs/index.ts +1 -0
  100. package/src/components/Tabs/styles.module.scss +25 -0
  101. package/src/components/index.ts +5 -0
  102. package/src/constants.ts +35 -0
  103. package/src/context.tsx +13 -0
  104. package/src/index.ts +5 -0
  105. package/src/types.ts +21 -0
  106. package/src/utils.ts +3 -0
@@ -0,0 +1,139 @@
1
+ import { useLayoutEffect } from '@cloud-ru/ds-utils';
2
+ import { Children, ReactElement, RefObject, useMemo, useState } from 'react';
3
+
4
+ import { Direction } from '../../types';
5
+
6
+ type OverflowState = {
7
+ [key in Direction]: boolean;
8
+ };
9
+
10
+ type ScrollContainerControl = {
11
+ hasOverflow: OverflowState;
12
+ scrollLeft: () => void;
13
+ scrollRight: () => void;
14
+ scrollTop: () => void;
15
+ scrollBottom: () => void;
16
+ };
17
+
18
+ const defaultOverflowState: OverflowState = {
19
+ top: false,
20
+ bottom: false,
21
+ left: false,
22
+ right: false,
23
+ };
24
+
25
+ export function useScrollContainer(container: RefObject<HTMLElement | null>): ScrollContainerControl {
26
+ const [hasOverflow, setHasOverflow] = useState<OverflowState>(defaultOverflowState);
27
+
28
+ useLayoutEffect(() => {
29
+ const recheck = () => {
30
+ const element = container.current;
31
+
32
+ if (!element) {
33
+ return;
34
+ }
35
+
36
+ const left = element.scrollLeft > 0;
37
+ const right = element.scrollLeft + element.offsetWidth <= element.scrollWidth - 2;
38
+ const top = element.scrollTop > 0;
39
+ const bottom = element.scrollTop + element.offsetHeight <= element.scrollHeight - 2;
40
+
41
+ setHasOverflow(prevState => {
42
+ if (
43
+ prevState.left !== left ||
44
+ prevState.right !== right ||
45
+ prevState.top !== top ||
46
+ prevState.bottom !== bottom
47
+ ) {
48
+ return { left, right, top, bottom };
49
+ }
50
+ return prevState;
51
+ });
52
+ };
53
+
54
+ const onWheel = (e: WheelEvent) => {
55
+ if (container?.current) {
56
+ container.current.scrollLeft = container.current.scrollLeft + e.deltaY;
57
+ }
58
+ };
59
+
60
+ const element = container.current;
61
+
62
+ if (!element) {
63
+ return;
64
+ }
65
+
66
+ const resizeObserver = new ResizeObserver(recheck);
67
+ resizeObserver.observe(element);
68
+ element.addEventListener('scroll', recheck);
69
+ element.addEventListener('wheel', onWheel);
70
+
71
+ // Первичная проверка и после layout (важно для вертикального скролла)
72
+ recheck();
73
+ const rafId = requestAnimationFrame(() => {
74
+ recheck();
75
+ });
76
+
77
+ return () => {
78
+ cancelAnimationFrame(rafId);
79
+ resizeObserver.disconnect();
80
+ element.removeEventListener('scroll', recheck);
81
+ element.removeEventListener('wheel', onWheel);
82
+ };
83
+ }, [container]);
84
+
85
+ const [scrollLeft, scrollRight, scrollTop, scrollBottom] = useMemo(() => {
86
+ function scroll(direction: Direction) {
87
+ const containerElement = container.current;
88
+
89
+ if (!containerElement) {
90
+ return;
91
+ }
92
+
93
+ const scrollHorizontalSize = containerElement.offsetWidth / 2;
94
+ const scrollVerticalSize = containerElement.offsetHeight / 2;
95
+
96
+ if (['top', 'bottom'].includes(direction)) {
97
+ containerElement.scroll({
98
+ top:
99
+ direction === 'top'
100
+ ? containerElement.scrollTop - scrollVerticalSize
101
+ : containerElement.scrollTop + scrollVerticalSize,
102
+ behavior: 'smooth',
103
+ });
104
+ return;
105
+ }
106
+
107
+ containerElement.scroll({
108
+ left:
109
+ direction === 'left'
110
+ ? containerElement.scrollLeft - scrollHorizontalSize
111
+ : containerElement.scrollLeft + scrollHorizontalSize,
112
+ behavior: 'smooth',
113
+ });
114
+ }
115
+
116
+ return [() => scroll('left'), () => scroll('right'), () => scroll('top'), () => scroll('bottom')];
117
+ }, [container]);
118
+
119
+ return { hasOverflow, scrollLeft, scrollRight, scrollTop, scrollBottom };
120
+ }
121
+
122
+ export function useFocusControl(children: ReactElement<{ value: string; disabled?: boolean }>[]) {
123
+ return useMemo(() => {
124
+ const arrayOfIds = Children.map(children, (child: ReactElement<{ value: string; disabled?: boolean }>) => {
125
+ const { value, disabled } = child.props;
126
+ return !disabled ? value : null;
127
+ }).filter(Boolean) as string[];
128
+
129
+ const getterElementWithShift = (shift: number) => (id?: string) => {
130
+ if (id) {
131
+ const position = arrayOfIds.indexOf(id);
132
+ return position > -1 ? arrayOfIds[position + shift] : undefined;
133
+ }
134
+ return undefined;
135
+ };
136
+
137
+ return [getterElementWithShift(-1), getterElementWithShift(+1)] as const;
138
+ }, [children]);
139
+ }
@@ -0,0 +1 @@
1
+ export * from './TabBar';
@@ -0,0 +1,241 @@
1
+ @use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
2
+ @use '@cloud-ru/ds-figma-variables/build/scss/components/tabs.module' as tabs;
3
+
4
+ $orientations: 'vertical', 'horizontal';
5
+ $sizes: 'l', 'm';
6
+
7
+ .tabBar {
8
+ position: relative;
9
+ display: flex;
10
+ box-sizing: border-box;
11
+
12
+ &[data-orientation='vertical'] {
13
+ flex-direction: column;
14
+ align-items: stretch;
15
+ height: 100%;
16
+ min-height: 0;
17
+ }
18
+
19
+ &[data-orientation='horizontal'] {
20
+ flex-direction: row;
21
+ align-items: center;
22
+ }
23
+
24
+ // Зазор между областью списка и слотом действия (`slotActionButton`)
25
+ @each $size in $sizes {
26
+ &[data-size='#{$size}'][data-orientation='horizontal'] {
27
+ gap: base.simple-var(tabs.$tabs, 'anatomy', 'size', $size, 'tabsHorizontal', 'actionSlot', 'gap');
28
+ }
29
+
30
+ &[data-size='#{$size}'][data-orientation='vertical'] {
31
+ gap: base.simple-var(tabs.$tabs, 'anatomy', 'size', $size, 'tabsVertical', 'actionSlot', 'gap');
32
+ }
33
+ }
34
+ }
35
+
36
+ // Область списка: слот табов, кнопки прокрутки и линия. Линия под слотом действия
37
+ // не продолжается, поэтому её носитель — эта обёртка, а не вся панель.
38
+ .tabListWrapper {
39
+ position: relative;
40
+
41
+ display: flex;
42
+
43
+ box-sizing: border-box;
44
+ min-width: 0;
45
+ min-height: 0;
46
+
47
+ &[data-orientation='horizontal'] {
48
+ flex: 1;
49
+ flex-direction: row;
50
+ align-items: center;
51
+ }
52
+
53
+ &[data-orientation='vertical'] {
54
+ flex: 1;
55
+ flex-direction: column;
56
+ align-items: stretch;
57
+ }
58
+ }
59
+
60
+ // Обёртка области скролла и кнопок: overflow visible, чтобы тень кнопок не обрезалась
61
+ .tabBarScrollZone {
62
+ position: relative;
63
+
64
+ overflow: visible;
65
+ display: flex;
66
+
67
+ box-sizing: border-box;
68
+ min-width: 0;
69
+ min-height: 0;
70
+
71
+ &[data-orientation='horizontal'] {
72
+ flex: 1;
73
+ flex-direction: row;
74
+ align-items: center;
75
+ }
76
+
77
+ &[data-orientation='vertical'] {
78
+ flex: 1;
79
+ flex-direction: column;
80
+ align-items: stretch;
81
+ }
82
+ }
83
+
84
+ .tabBarMain {
85
+ position: relative;
86
+
87
+ display: flex;
88
+
89
+ box-sizing: border-box;
90
+ min-width: 0;
91
+ min-height: 0;
92
+
93
+ &[data-orientation='horizontal'] {
94
+ flex-direction: row;
95
+ align-items: center;
96
+
97
+ .scrollArea {
98
+ flex: 1;
99
+ min-width: 0;
100
+ }
101
+ }
102
+
103
+ &[data-orientation='vertical'] {
104
+ flex: 1;
105
+ flex-direction: column;
106
+ align-items: stretch;
107
+ min-height: 0;
108
+
109
+ .scrollArea {
110
+ flex: 1;
111
+ min-height: 0;
112
+ }
113
+ }
114
+ }
115
+
116
+ .horizontalScrollContainer {
117
+ overflow: scroll visible;
118
+ max-width: 100%;
119
+ }
120
+
121
+ .verticalScrollContainer {
122
+ overflow: visible scroll;
123
+ max-height: 100%;
124
+ }
125
+
126
+ .tabsRow {
127
+ position: relative;
128
+
129
+ overflow: hidden;
130
+ display: flex;
131
+
132
+ width: fit-content;
133
+
134
+ white-space: nowrap;
135
+
136
+ &[data-size='l'] {
137
+ &[data-orientation='horizontal'] {
138
+ gap: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'l', 'tabsHorizontal', 'gap');
139
+ }
140
+
141
+ &[data-orientation='vertical'] {
142
+ gap: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'l', 'tabsVertical', 'gap');
143
+ }
144
+ }
145
+
146
+ &[data-size='m'] {
147
+ &[data-orientation='horizontal'] {
148
+ gap: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'm', 'tabsHorizontal', 'gap');
149
+ }
150
+
151
+ &[data-orientation='vertical'] {
152
+ gap: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'm', 'tabsVertical', 'gap');
153
+ }
154
+ }
155
+
156
+ &[data-orientation='vertical'] {
157
+ flex-direction: column;
158
+ // Ряд тянется на ширину списка: строки табов занимают её целиком, как в макете.
159
+ width: auto;
160
+ min-height: min-content;
161
+ }
162
+
163
+ &[data-orientation='horizontal'] {
164
+ flex-direction: row;
165
+ }
166
+ }
167
+
168
+ .marker {
169
+ position: absolute;
170
+ background-color: base.$sn-theme-color-primary-accent;
171
+ transition:
172
+ left 0.1s ease,
173
+ width 0.1s ease,
174
+ top 0.1s ease,
175
+ height 0.1s ease;
176
+
177
+ &[data-orientation='horizontal'] {
178
+ bottom: 0;
179
+ height: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'l', 'tabsHorizontal', 'selected', 'height');
180
+ border-radius: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'l', 'tabsHorizontal', 'selected', 'border-radius');
181
+ }
182
+
183
+ &[data-orientation='vertical'] {
184
+ right: 0;
185
+ width: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'l', 'tabsVertical', 'selected', 'height');
186
+ border-radius: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'l', 'tabsVertical', 'selected', 'border-radius');
187
+ }
188
+
189
+ &[data-position='before'] {
190
+ top: 0;
191
+ left: 0;
192
+ }
193
+
194
+ &[data-position='after'] {
195
+ right: 0;
196
+ bottom: 0;
197
+ }
198
+ }
199
+
200
+ .tabsRow[data-size='m'] .marker {
201
+ &[data-orientation='horizontal'] {
202
+ height: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'm', 'tabsHorizontal', 'selected', 'height');
203
+ border-radius: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'm', 'tabsHorizontal', 'selected', 'border-radius');
204
+ }
205
+
206
+ &[data-orientation='vertical'] {
207
+ width: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'm', 'tabsVertical', 'selected', 'height');
208
+ border-radius: base.simple-var(tabs.$tabs, 'anatomy', 'size', 'm', 'tabsVertical', 'selected', 'border-radius');
209
+ }
210
+ }
211
+
212
+ .divider {
213
+ position: absolute;
214
+
215
+ &[data-position='before'] {
216
+ top: 0;
217
+ left: 0;
218
+ }
219
+
220
+ &[data-position='after'] {
221
+ right: 0;
222
+ bottom: 0;
223
+ }
224
+ }
225
+
226
+ .tabBar[data-orientation='horizontal'] .divider {
227
+ width: 100%;
228
+ }
229
+
230
+ .tabBar[data-orientation='vertical'] .divider {
231
+ height: 100%;
232
+ }
233
+
234
+ .tabBarAfter {
235
+ &[data-orientation='vertical'] {
236
+ &[data-size='l'],
237
+ &[data-size='m'] {
238
+ min-height: auto;
239
+ }
240
+ }
241
+ }
@@ -0,0 +1,34 @@
1
+ import { extractSupportProps, WithSupportProps } from '@cloud-ru/ds-utils';
2
+ import { PropsWithChildren } from 'react';
3
+
4
+ import { useTabsContext } from '../../context';
5
+ import { getTabContentId } from '../../utils';
6
+
7
+ export type TabContentProps = WithSupportProps<
8
+ PropsWithChildren<{
9
+ /** Значение таба */
10
+ value: string;
11
+ className?: string;
12
+ }>
13
+ >;
14
+
15
+ export function TabContent({ children, value, className, ...rest }: TabContentProps) {
16
+ const { selectedTab } = useTabsContext();
17
+
18
+ if (value !== selectedTab) {
19
+ return null;
20
+ }
21
+
22
+ return (
23
+ <div
24
+ className={className}
25
+ role='tabpanel'
26
+ id={getTabContentId(value)}
27
+ {...extractSupportProps(rest)}
28
+ aria-labelledby={value}
29
+ data-testid={`tabs__tab-content-${value}`}
30
+ >
31
+ {children}
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1 @@
1
+ export * from './TabContent';
@@ -0,0 +1,61 @@
1
+ import { useValueControl } from '@cloud-ru/ds-utils';
2
+ import cn from 'classnames';
3
+ import { Children, isValidElement, ReactElement, ReactNode } from 'react';
4
+
5
+ import { ORIENTATION } from '../../constants';
6
+ import { TabsContext } from '../../context';
7
+ import { Orientation } from '../../types';
8
+ import { Tab as TabComponent } from '../Tab';
9
+ import { TabBar as TabBarComponent } from '../TabBar';
10
+ import { TabContent as TabContentComponent } from '../TabContent';
11
+ import styles from './styles.module.scss';
12
+
13
+ export type TabsProps<T extends string = string> = {
14
+ /** Текущая вкладка */
15
+ value?: T;
16
+ /** Выбранная вкладка по умолчанию */
17
+ defaultValue?: T;
18
+ /** Колбек выбора вкладки */
19
+ onChange?(id: T): void;
20
+ children?: ReactNode;
21
+ /** Дополнительный класс на корневой контейнер */
22
+ className?: string;
23
+ };
24
+
25
+ function getOrientationFromChildren(children: ReactNode): Orientation {
26
+ const array = Children.toArray(children);
27
+
28
+ const tabBar = array.find(
29
+ (child): child is ReactElement<{ orientation?: string }> => isValidElement(child) && child.type === TabBarComponent,
30
+ );
31
+
32
+ return tabBar?.props?.orientation === ORIENTATION.Vertical ? ORIENTATION.Vertical : ORIENTATION.Horizontal;
33
+ }
34
+
35
+ export function Tabs<T extends string = string>({ children, onChange, value, defaultValue, className }: TabsProps<T>) {
36
+ const [selectedTab, setSelectedTab] = useValueControl({
37
+ value,
38
+ defaultValue,
39
+ onChange: onChange as TabsProps<T>['onChange'],
40
+ });
41
+
42
+ const orientation = getOrientationFromChildren(children);
43
+ const isVertical = orientation === ORIENTATION.Vertical;
44
+
45
+ return (
46
+ <TabsContext.Provider
47
+ value={{
48
+ selectedTab,
49
+ setSelectedTab,
50
+ }}
51
+ >
52
+ <div className={cn(styles.root, isVertical && styles.rootVertical, className)}>{children}</div>
53
+ </TabsContext.Provider>
54
+ );
55
+ }
56
+
57
+ export namespace Tabs {
58
+ export const Tab = TabComponent;
59
+ export const TabBar = TabBarComponent;
60
+ export const TabContent = TabContentComponent;
61
+ }
@@ -0,0 +1 @@
1
+ export * from './Tabs';
@@ -0,0 +1,25 @@
1
+ .root {
2
+ display: flex;
3
+ flex-direction: column;
4
+ min-width: 0;
5
+ }
6
+
7
+ .rootVertical {
8
+ display: flex;
9
+ flex-direction: row;
10
+ align-items: stretch;
11
+ min-height: 0;
12
+
13
+ // TabBar (первый ребёнок) — колонка табов слева, ограничена по высоте для скролла
14
+ [role='tablist'] {
15
+ flex: 0 1 auto;
16
+ min-height: 0;
17
+ max-height: 100%;
18
+ }
19
+
20
+ // TabContent и остальное — контент справа от табов
21
+ [role='tabpanel'] {
22
+ flex: 1;
23
+ min-width: 0;
24
+ }
25
+ }
@@ -0,0 +1,5 @@
1
+ export * from './ScrollButton';
2
+ export * from './Tab';
3
+ export * from './TabBar';
4
+ export * from './TabContent';
5
+ export * from './Tabs';
@@ -0,0 +1,35 @@
1
+ export const ORIENTATION = {
2
+ Horizontal: 'horizontal',
3
+ Vertical: 'vertical',
4
+ } as const;
5
+
6
+ export const MARKER_POSITION = {
7
+ Before: 'before',
8
+ After: 'after',
9
+ } as const;
10
+
11
+ export const SIZE = {
12
+ L: 'l',
13
+ M: 'm',
14
+ } as const;
15
+
16
+ /**
17
+ * Канонические `data-test-id` для слотов Tabs-стека. Реализация
18
+ * компонентов не ставит эти id сама — они проксируются через `...rest`,
19
+ * поэтому потребитель свободен в выборе значения. Эти константы
20
+ * закрепляют единый набор для stories и e2e, чтобы не плодить дубли строк.
21
+ */
22
+ export const TEST_IDS = {
23
+ tabs: {
24
+ root: 'tabs',
25
+ },
26
+ tabBar: {
27
+ root: 'tabs-bar',
28
+ },
29
+ tab: {
30
+ root: 'tabs-tab',
31
+ },
32
+ tabContent: {
33
+ root: 'tabs-panel',
34
+ },
35
+ } as const;
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ import { TabBarContextValue, TabsContextValue } from './types';
4
+
5
+ export const TabsContext = createContext<TabsContextValue>({
6
+ setSelectedTab: function () {},
7
+ });
8
+
9
+ export const useTabsContext = () => useContext(TabsContext);
10
+
11
+ export const TabBarContext = createContext<TabBarContextValue>({});
12
+
13
+ export const useTabBarContext = () => useContext(TabBarContext);
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './components';
2
+ export * from './constants';
3
+ export * from './context';
4
+ export * from './types';
5
+ export * from './utils';
package/src/types.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { ValueOf } from '@cloud-ru/ds-utils';
2
+
3
+ import { MARKER_POSITION, ORIENTATION, SIZE } from './constants';
4
+
5
+ export type Size = ValueOf<typeof SIZE>;
6
+ export type Orientation = ValueOf<typeof ORIENTATION>;
7
+ export type MarkerPosition = ValueOf<typeof MARKER_POSITION>;
8
+ export type Direction = 'left' | 'right' | 'top' | 'bottom';
9
+
10
+ export type TabsContextValue = {
11
+ selectedTab?: string;
12
+ setSelectedTab(id: string): void;
13
+ };
14
+
15
+ export type TabBarContextValue = Partial<{
16
+ size: Size;
17
+ orientation: Orientation;
18
+ focusedTab: string;
19
+ onSelect(element: HTMLButtonElement): void;
20
+ onFocus(element: HTMLElement, id: string): void;
21
+ }>;
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function getTabContentId(id: string) {
2
+ return `design-system-tab-content-${id}`;
3
+ }