@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.
- package/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +300 -0
- package/dist/cjs/components/ScrollButton/ScrollButton.d.ts +8 -0
- package/dist/cjs/components/ScrollButton/ScrollButton.js +19 -0
- package/dist/cjs/components/ScrollButton/index.d.ts +1 -0
- package/dist/cjs/components/ScrollButton/index.js +17 -0
- package/dist/cjs/components/ScrollButton/styles.module.css +50 -0
- package/dist/cjs/components/Tab/Tab.d.ts +25 -0
- package/dist/cjs/components/Tab/Tab.js +78 -0
- package/dist/cjs/components/Tab/index.d.ts +1 -0
- package/dist/cjs/components/Tab/index.js +17 -0
- package/dist/cjs/components/Tab/styles.module.css +105 -0
- package/dist/cjs/components/TabBar/TabBar.d.ts +30 -0
- package/dist/cjs/components/TabBar/TabBar.js +119 -0
- package/dist/cjs/components/TabBar/hooks.d.ts +18 -0
- package/dist/cjs/components/TabBar/hooks.js +103 -0
- package/dist/cjs/components/TabBar/index.d.ts +1 -0
- package/dist/cjs/components/TabBar/index.js +17 -0
- package/dist/cjs/components/TabBar/styles.module.css +187 -0
- package/dist/cjs/components/TabContent/TabContent.d.ts +8 -0
- package/dist/cjs/components/TabContent/TabContent.js +14 -0
- package/dist/cjs/components/TabContent/index.d.ts +1 -0
- package/dist/cjs/components/TabContent/index.js +17 -0
- package/dist/cjs/components/Tabs/Tabs.d.ts +21 -0
- package/dist/cjs/components/Tabs/Tabs.js +39 -0
- package/dist/cjs/components/Tabs/index.d.ts +1 -0
- package/dist/cjs/components/Tabs/index.js +17 -0
- package/dist/cjs/components/Tabs/styles.module.css +21 -0
- package/dist/cjs/components/index.d.ts +5 -0
- package/dist/cjs/components/index.js +21 -0
- package/dist/cjs/constants.d.ts +32 -0
- package/dist/cjs/constants.js +35 -0
- package/dist/cjs/context.d.ts +17 -0
- package/dist/cjs/context.js +12 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +363 -0
- package/dist/cjs/types.d.ts +17 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +1 -0
- package/dist/cjs/utils.js +6 -0
- package/dist/esm/components/ScrollButton/ScrollButton.d.ts +8 -0
- package/dist/esm/components/ScrollButton/ScrollButton.js +13 -0
- package/dist/esm/components/ScrollButton/index.d.ts +1 -0
- package/dist/esm/components/ScrollButton/index.js +1 -0
- package/dist/esm/components/ScrollButton/styles.module.css +50 -0
- package/dist/esm/components/Tab/Tab.d.ts +25 -0
- package/dist/esm/components/Tab/Tab.js +72 -0
- package/dist/esm/components/Tab/index.d.ts +1 -0
- package/dist/esm/components/Tab/index.js +1 -0
- package/dist/esm/components/Tab/styles.module.css +105 -0
- package/dist/esm/components/TabBar/TabBar.d.ts +30 -0
- package/dist/esm/components/TabBar/TabBar.js +113 -0
- package/dist/esm/components/TabBar/hooks.d.ts +18 -0
- package/dist/esm/components/TabBar/hooks.js +99 -0
- package/dist/esm/components/TabBar/index.d.ts +1 -0
- package/dist/esm/components/TabBar/index.js +1 -0
- package/dist/esm/components/TabBar/styles.module.css +187 -0
- package/dist/esm/components/TabContent/TabContent.d.ts +8 -0
- package/dist/esm/components/TabContent/TabContent.js +11 -0
- package/dist/esm/components/TabContent/index.d.ts +1 -0
- package/dist/esm/components/TabContent/index.js +1 -0
- package/dist/esm/components/Tabs/Tabs.d.ts +21 -0
- package/dist/esm/components/Tabs/Tabs.js +33 -0
- package/dist/esm/components/Tabs/index.d.ts +1 -0
- package/dist/esm/components/Tabs/index.js +1 -0
- package/dist/esm/components/Tabs/styles.module.css +21 -0
- package/dist/esm/components/index.d.ts +5 -0
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/constants.d.ts +32 -0
- package/dist/esm/constants.js +32 -0
- package/dist/esm/context.d.ts +17 -0
- package/dist/esm/context.js +7 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/style.css +363 -0
- package/dist/esm/types.d.ts +17 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +3 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +48 -0
- package/src/components/ScrollButton/ScrollButton.tsx +42 -0
- package/src/components/ScrollButton/index.ts +1 -0
- package/src/components/ScrollButton/styles.module.scss +46 -0
- package/src/components/Tab/Tab.tsx +151 -0
- package/src/components/Tab/index.ts +1 -0
- package/src/components/Tab/styles.module.scss +135 -0
- package/src/components/TabBar/TabBar.tsx +269 -0
- package/src/components/TabBar/hooks.ts +139 -0
- package/src/components/TabBar/index.ts +1 -0
- package/src/components/TabBar/styles.module.scss +241 -0
- package/src/components/TabContent/TabContent.tsx +34 -0
- package/src/components/TabContent/index.ts +1 -0
- package/src/components/Tabs/Tabs.tsx +61 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/Tabs/styles.module.scss +25 -0
- package/src/components/index.ts +5 -0
- package/src/constants.ts +35 -0
- package/src/context.tsx +13 -0
- package/src/index.ts +5 -0
- package/src/types.ts +21 -0
- package/src/utils.ts +3 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
.tab{
|
|
2
|
+
cursor:pointer;
|
|
3
|
+
position:relative;
|
|
4
|
+
display:inline-flex;
|
|
5
|
+
flex-direction:row;
|
|
6
|
+
align-items:center;
|
|
7
|
+
box-sizing:border-box;
|
|
8
|
+
padding:0;
|
|
9
|
+
border-width:0;
|
|
10
|
+
color:var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8)));
|
|
11
|
+
background-color:transparent;
|
|
12
|
+
outline:none;
|
|
13
|
+
}
|
|
14
|
+
.tab[data-orientation=horizontal][data-size=m]{
|
|
15
|
+
min-height:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-minHeight, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
|
|
16
|
+
padding-left:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-horizontalPadding, var(--sn-primitive-dimension-0, 0));
|
|
17
|
+
padding-right:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-horizontalPadding, var(--sn-primitive-dimension-0, 0));
|
|
18
|
+
}
|
|
19
|
+
.tab[data-orientation=horizontal][data-size=m] .container{
|
|
20
|
+
padding-left:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-m, var(--sn-primitive-dimension-8, 8px)));
|
|
21
|
+
padding-right:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-m, var(--sn-primitive-dimension-8, 8px)));
|
|
22
|
+
border-radius:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-textWrapper-borderRadius, var(--sn-brand-anatomy-radius-button-m, var(--sn-primitive-dimension-2, 2px)));
|
|
23
|
+
min-width:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-textWrapper-minWidth, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
|
|
24
|
+
gap:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-textWrapper-gap, var(--sn-density-spacing-control-wrapper-horizontal-m, var(--sn-primitive-dimension-8, 8px)));
|
|
25
|
+
min-height:var(--sn-tabs-anatomy-size-m-tabsHorizontal-tabContainer-textWrapper-minHeight, var(--sn-density-size-s, var(--sn-primitive-dimension-48, 48px)));
|
|
26
|
+
}
|
|
27
|
+
.tab[data-orientation=vertical][data-size=m]{
|
|
28
|
+
padding-left:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-horizontalPadding, var(--sn-density-spacing-interval-m, var(--sn-primitive-dimension-16, 16px)));
|
|
29
|
+
padding-right:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-horizontalPadding, var(--sn-density-spacing-interval-m, var(--sn-primitive-dimension-16, 16px)));
|
|
30
|
+
min-height:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-minHeight, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
|
|
31
|
+
}
|
|
32
|
+
.tab[data-orientation=vertical][data-size=m] .container{
|
|
33
|
+
min-width:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-textWrapper-minWidth, var(--sn-primitive-dimension-0, 0));
|
|
34
|
+
gap:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-textWrapper-gap, var(--sn-density-spacing-control-wrapper-horizontal-m, var(--sn-primitive-dimension-8, 8px)));
|
|
35
|
+
min-height:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-textWrapper-minHeight, var(--sn-density-size-s, var(--sn-primitive-dimension-48, 48px)));
|
|
36
|
+
border-radius:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-textWrapper-borderRadius, var(--sn-brand-anatomy-radius-button-m, var(--sn-primitive-dimension-2, 2px)));
|
|
37
|
+
padding-left:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-m, var(--sn-primitive-dimension-8, 8px)));
|
|
38
|
+
padding-right:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-m, var(--sn-primitive-dimension-8, 8px)));
|
|
39
|
+
}
|
|
40
|
+
.tab[data-orientation=horizontal][data-size=l]{
|
|
41
|
+
min-height:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-minHeight, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
|
|
42
|
+
padding-left:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-horizontalPadding, var(--sn-density-spacing-control-container-horizontal-l, var(--sn-primitive-dimension-20, 20px)));
|
|
43
|
+
padding-right:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-horizontalPadding, var(--sn-density-spacing-control-container-horizontal-l, var(--sn-primitive-dimension-20, 20px)));
|
|
44
|
+
}
|
|
45
|
+
.tab[data-orientation=horizontal][data-size=l] .container{
|
|
46
|
+
min-width:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-textWrapper-minWidth, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
|
|
47
|
+
min-height:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-textWrapper-minHeight, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
|
|
48
|
+
gap:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-textWrapper-gap, var(--sn-density-spacing-control-wrapper-horizontal-l, var(--sn-primitive-dimension-12, 12px)));
|
|
49
|
+
border-radius:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-textWrapper-borderRadius, var(--sn-brand-anatomy-radius-button-l, var(--sn-primitive-dimension-2, 2px)));
|
|
50
|
+
padding-left:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-l, var(--sn-primitive-dimension-12, 12px)));
|
|
51
|
+
padding-right:var(--sn-tabs-anatomy-size-l-tabsHorizontal-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-l, var(--sn-primitive-dimension-12, 12px)));
|
|
52
|
+
}
|
|
53
|
+
.tab[data-orientation=vertical][data-size=l]{
|
|
54
|
+
padding-left:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-horizontalPadding, var(--sn-density-spacing-control-container-horizontal-l, var(--sn-primitive-dimension-20, 20px)));
|
|
55
|
+
padding-right:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-horizontalPadding, var(--sn-density-spacing-control-container-horizontal-l, var(--sn-primitive-dimension-20, 20px)));
|
|
56
|
+
min-height:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-minHeight, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
|
|
57
|
+
}
|
|
58
|
+
.tab[data-orientation=vertical][data-size=l] .container{
|
|
59
|
+
min-width:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-textWrapper-minWidth, var(--sn-density-size-l, var(--sn-primitive-dimension-64, 64px)));
|
|
60
|
+
padding-left:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-l, var(--sn-primitive-dimension-12, 12px)));
|
|
61
|
+
padding-right:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-textWrapper-horizontalPadding, var(--sn-density-spacing-control-wrapper-horizontal-l, var(--sn-primitive-dimension-12, 12px)));
|
|
62
|
+
border-radius:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-textWrapper-borderRadius, var(--sn-brand-anatomy-radius-button-l, var(--sn-primitive-dimension-2, 2px)));
|
|
63
|
+
gap:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-textWrapper-gap, var(--sn-density-spacing-control-wrapper-horizontal-l, var(--sn-primitive-dimension-12, 12px)));
|
|
64
|
+
min-height:var(--sn-tabs-anatomy-size-l-tabsVertical-tabContainer-textWrapper-minHeight, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px)));
|
|
65
|
+
}
|
|
66
|
+
.tab[data-orientation=vertical][data-size=l]{
|
|
67
|
+
padding-right:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-horizontalPadding, var(--sn-density-spacing-interval-m, var(--sn-primitive-dimension-16, 16px)));
|
|
68
|
+
padding-left:var(--sn-tabs-anatomy-size-m-tabsVertical-tabContainer-horizontalPadding, var(--sn-density-spacing-interval-m, var(--sn-primitive-dimension-16, 16px)));
|
|
69
|
+
}
|
|
70
|
+
.tab[data-selected=true], .tab:focus-visible, .tab:hover{
|
|
71
|
+
color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
|
|
72
|
+
}
|
|
73
|
+
.tab[data-disabled]{
|
|
74
|
+
cursor:not-allowed;
|
|
75
|
+
opacity:var(--sn-theme-effect-opacity-disabled, 0.4);
|
|
76
|
+
}
|
|
77
|
+
.tab .container > [data-state-layer]{
|
|
78
|
+
position:absolute;
|
|
79
|
+
inset:0;
|
|
80
|
+
border-radius:inherit;
|
|
81
|
+
}
|
|
82
|
+
.tab .container > [data-state-layer][data-state=emptyNeutralOnBackground]{
|
|
83
|
+
background:var(--sn-theme-color-material-stateLayer-neutral-onBackground-defaultEmpty-filled, var(--sn-brand-color-state-neutral-forLightMode-default-background, rgba(120, 123, 138, 0)));
|
|
84
|
+
}
|
|
85
|
+
@media (hover: hover){
|
|
86
|
+
.tab:hover:not([data-disabled], [data-loading]) .container > [data-state-layer][data-state=emptyNeutralOnBackground]{
|
|
87
|
+
background:var(--sn-theme-color-material-stateLayer-neutral-onBackground-hovered-filled, var(--sn-brand-color-state-neutral-forLightMode-hovered-background, rgba(188, 195, 220, 0.1490196078)));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
.tab{
|
|
91
|
+
}
|
|
92
|
+
.tab[data-loading] .container > [data-state-layer][data-state=emptyNeutralOnBackground], .tab:active:not([data-disabled], [data-loading]) .container > [data-state-layer][data-state=emptyNeutralOnBackground]{
|
|
93
|
+
background:var(--sn-theme-color-material-stateLayer-neutral-onBackground-pressed-filled, var(--sn-brand-color-state-neutral-forLightMode-pressed-background, rgba(188, 195, 220, 0.3019607843)));
|
|
94
|
+
}
|
|
95
|
+
.tab .container{
|
|
96
|
+
position:relative;
|
|
97
|
+
display:flex;
|
|
98
|
+
align-items:center;
|
|
99
|
+
justify-content:center;
|
|
100
|
+
box-sizing:border-box;
|
|
101
|
+
}
|
|
102
|
+
.tab:focus-visible .container{
|
|
103
|
+
outline:var(--sn-primitive-strokeWeight-strokeSemiBold, 2px) solid var(--sn-theme-color-available-complementary, #000000);
|
|
104
|
+
outline-offset:calc(0px - var(--sn-primitive-strokeWeight-strokeSemiBold, 2px));
|
|
105
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
2
|
+
import { ReactElement, ReactNode } from 'react';
|
|
3
|
+
import { MarkerPosition, Orientation, Size } from '../../types.js';
|
|
4
|
+
import { TabProps } from '../Tab/index.js';
|
|
5
|
+
export type TabBarProps = WithSupportProps<{
|
|
6
|
+
/** Контент (элементы Tabs.Tab) */
|
|
7
|
+
children: ReactElement<TabProps>[];
|
|
8
|
+
/**
|
|
9
|
+
* Слот действия: контент после списка табов — справа при горизонтальной
|
|
10
|
+
* ориентации, снизу при вертикальной. Разделитель под ним не продолжается.
|
|
11
|
+
*/
|
|
12
|
+
slotActionButton?: ReactNode;
|
|
13
|
+
/** Ориентация */
|
|
14
|
+
orientation?: Orientation;
|
|
15
|
+
/**
|
|
16
|
+
* Позиция маркера относительно таб-бара.
|
|
17
|
+
*
|
|
18
|
+
* Значения ориентационно-нейтральны, в Figma та же ось названа сторонами:
|
|
19
|
+
* `before` = Figma `top` (horizontal) / `left` (vertical),
|
|
20
|
+
* `after` = Figma `bottom` (horizontal) / `right` (vertical).
|
|
21
|
+
*/
|
|
22
|
+
markerPosition?: MarkerPosition;
|
|
23
|
+
/** Размер панели табов: L — верхнеуровневый, M — на уровне контента */
|
|
24
|
+
size?: Size;
|
|
25
|
+
/** Скрыть разделитель под/рядом с панелью табов */
|
|
26
|
+
disableDivider?: boolean;
|
|
27
|
+
/** CSS-класс */
|
|
28
|
+
className?: string;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function TabBar({ children, className, size, orientation, markerPosition, slotActionButton, disableDivider, ...otherProps }: TabBarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Divider } from '@cloud-ru/ds-divider';
|
|
3
|
+
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { Children, useCallback, useEffect, useRef, useState, } from 'react';
|
|
6
|
+
import ScrollContainer from 'react-indiana-drag-scroll';
|
|
7
|
+
import { MARKER_POSITION, ORIENTATION, SIZE } from '../../constants.js';
|
|
8
|
+
import { TabBarContext, useTabsContext } from '../../context.js';
|
|
9
|
+
import { ScrollButton } from '../ScrollButton/index.js';
|
|
10
|
+
import { useFocusControl, useScrollContainer } from './hooks.js';
|
|
11
|
+
import styles from './styles.module.css';
|
|
12
|
+
const SCROLL_CONTAINER_ORIENTATION_MAP = {
|
|
13
|
+
[ORIENTATION.Horizontal]: styles.horizontalScrollContainer,
|
|
14
|
+
[ORIENTATION.Vertical]: styles.verticalScrollContainer,
|
|
15
|
+
};
|
|
16
|
+
export function TabBar({ children, className, size = SIZE.L, orientation = ORIENTATION.Horizontal, markerPosition = MARKER_POSITION.After, slotActionButton, disableDivider = false, ...otherProps }) {
|
|
17
|
+
const scrollContainerRef = useRef(null);
|
|
18
|
+
const { selectedTab, setSelectedTab } = useTabsContext();
|
|
19
|
+
const { hasOverflow, scrollLeft, scrollRight, scrollTop, scrollBottom } = useScrollContainer(scrollContainerRef);
|
|
20
|
+
const selectedRef = useRef(null);
|
|
21
|
+
const [markerScrollPosition, setMarkerScrollPosition] = useState({});
|
|
22
|
+
const [focusedTab, setFocusedTab] = useState();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!selectedTab) {
|
|
25
|
+
const firstEnabled = Children.map(children, child => child.props).find((props) => !props.disabled);
|
|
26
|
+
if (firstEnabled) {
|
|
27
|
+
setSelectedTab(firstEnabled.value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, [children, selectedTab, setSelectedTab]);
|
|
31
|
+
const updateMarkPosition = useCallback((element) => {
|
|
32
|
+
if (orientation === 'horizontal') {
|
|
33
|
+
setMarkerScrollPosition({
|
|
34
|
+
left: element.offsetLeft,
|
|
35
|
+
width: element.offsetWidth,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
setMarkerScrollPosition({
|
|
40
|
+
top: element.offsetTop,
|
|
41
|
+
height: element.offsetHeight,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
selectedRef.current = element;
|
|
45
|
+
}, [orientation]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!selectedRef.current) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const updatePosition = () => {
|
|
51
|
+
if (selectedRef.current) {
|
|
52
|
+
updateMarkPosition(selectedRef.current);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
updatePosition();
|
|
56
|
+
const resizeObserver = new ResizeObserver(updatePosition);
|
|
57
|
+
resizeObserver.observe(selectedRef.current);
|
|
58
|
+
return () => {
|
|
59
|
+
resizeObserver.disconnect();
|
|
60
|
+
};
|
|
61
|
+
}, [children, size, updateMarkPosition]);
|
|
62
|
+
const scrollContainerToElement = useCallback((element) => {
|
|
63
|
+
const container = scrollContainerRef.current;
|
|
64
|
+
if (element && container) {
|
|
65
|
+
if (orientation === 'vertical') {
|
|
66
|
+
const overflowTop = element.offsetTop < container.scrollTop;
|
|
67
|
+
const overflowBottom = element.offsetTop + element.offsetHeight > container.scrollTop + container.offsetHeight;
|
|
68
|
+
if (overflowTop || overflowBottom) {
|
|
69
|
+
const count = element.offsetTop - container.offsetHeight / 2 + element.offsetHeight / 2;
|
|
70
|
+
container.scroll({ top: count, behavior: 'smooth' });
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const overflowLeft = element.offsetLeft < container.scrollLeft;
|
|
75
|
+
const overflowRight = element.offsetLeft + element.offsetWidth > container.scrollLeft + container.offsetWidth;
|
|
76
|
+
if (overflowLeft || overflowRight) {
|
|
77
|
+
const count = element.offsetLeft - container.offsetWidth / 2 + element.offsetWidth / 2;
|
|
78
|
+
container.scroll({ left: count, behavior: 'smooth' });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, [orientation]);
|
|
82
|
+
const onSelectHandler = useCallback((element) => {
|
|
83
|
+
updateMarkPosition(element);
|
|
84
|
+
scrollContainerToElement(element);
|
|
85
|
+
}, [scrollContainerToElement, updateMarkPosition]);
|
|
86
|
+
const onFocusHandler = useCallback((element, value) => {
|
|
87
|
+
setFocusedTab(value);
|
|
88
|
+
scrollContainerToElement(element);
|
|
89
|
+
}, [scrollContainerToElement]);
|
|
90
|
+
const [getPrev, getNext] = useFocusControl(children);
|
|
91
|
+
const handleKeyDown = useCallback((e) => {
|
|
92
|
+
let newFocusTab;
|
|
93
|
+
if (e.key === 'ArrowRight')
|
|
94
|
+
newFocusTab = getNext(focusedTab || selectedTab);
|
|
95
|
+
if (e.key === 'ArrowLeft')
|
|
96
|
+
newFocusTab = getPrev(focusedTab || selectedTab);
|
|
97
|
+
if (e.key === 'ArrowUp')
|
|
98
|
+
newFocusTab = getPrev(focusedTab || selectedTab);
|
|
99
|
+
if (e.key === 'ArrowDown')
|
|
100
|
+
newFocusTab = getNext(focusedTab || selectedTab);
|
|
101
|
+
if (newFocusTab) {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
setFocusedTab(newFocusTab);
|
|
104
|
+
}
|
|
105
|
+
}, [getPrev, getNext, focusedTab, selectedTab]);
|
|
106
|
+
return (_jsxs("div", { className: cn(styles.tabBar, className), role: 'tablist', "data-orientation": orientation, "data-size": size, ...extractSupportProps(otherProps), children: [_jsxs("div", { className: styles.tabListWrapper, "data-orientation": orientation, children: [!disableDivider && (_jsx("div", { className: styles.divider, "data-position": markerPosition, children: _jsx(Divider, { variant: 'regular', orientation: orientation }) })), _jsxs("div", { className: styles.tabBarScrollZone, "data-orientation": orientation, children: [_jsx("div", { className: styles.tabBarMain, "data-testid": 'tabs__bar-wrap', "data-orientation": orientation, children: _jsx(ScrollContainer, { className: cn(SCROLL_CONTAINER_ORIENTATION_MAP[orientation], styles.scrollArea), innerRef: scrollContainerRef, children: _jsxs("div", { className: styles.tabsRow, "data-size": size, "data-orientation": orientation, onKeyDown: handleKeyDown, role: 'presentation', children: [_jsx(TabBarContext.Provider, { value: {
|
|
107
|
+
onSelect: onSelectHandler,
|
|
108
|
+
size,
|
|
109
|
+
orientation,
|
|
110
|
+
focusedTab,
|
|
111
|
+
onFocus: onFocusHandler,
|
|
112
|
+
}, children: children }), _jsx("div", { className: styles.marker, style: markerScrollPosition, "data-position": markerPosition, "data-orientation": orientation })] }) }) }), orientation === ORIENTATION.Horizontal && hasOverflow.left && (_jsx(ScrollButton, { direction: 'left', onClick: scrollLeft, orientation: orientation, size: size })), orientation === ORIENTATION.Horizontal && hasOverflow.right && (_jsx(ScrollButton, { direction: 'right', onClick: scrollRight, orientation: orientation, size: size })), orientation === ORIENTATION.Vertical && hasOverflow.top && (_jsx(ScrollButton, { direction: 'top', onClick: scrollTop, orientation: orientation, size: size })), orientation === ORIENTATION.Vertical && hasOverflow.bottom && (_jsx(ScrollButton, { direction: 'bottom', onClick: scrollBottom, orientation: orientation, size: size }))] })] }), slotActionButton && (_jsx("div", { "data-testid": 'tabs__bar__after', "data-orientation": orientation, "data-size": size, className: styles.tabBarAfter, children: slotActionButton }))] }));
|
|
113
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactElement, RefObject } from 'react';
|
|
2
|
+
import { Direction } from '../../types.js';
|
|
3
|
+
type OverflowState = {
|
|
4
|
+
[key in Direction]: boolean;
|
|
5
|
+
};
|
|
6
|
+
type ScrollContainerControl = {
|
|
7
|
+
hasOverflow: OverflowState;
|
|
8
|
+
scrollLeft: () => void;
|
|
9
|
+
scrollRight: () => void;
|
|
10
|
+
scrollTop: () => void;
|
|
11
|
+
scrollBottom: () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function useScrollContainer(container: RefObject<HTMLElement | null>): ScrollContainerControl;
|
|
14
|
+
export declare function useFocusControl(children: ReactElement<{
|
|
15
|
+
value: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}>[]): readonly [(id?: string) => string | undefined, (id?: string) => string | undefined];
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useLayoutEffect } from '@cloud-ru/ds-utils';
|
|
2
|
+
import { Children, useMemo, useState } from 'react';
|
|
3
|
+
const defaultOverflowState = {
|
|
4
|
+
top: false,
|
|
5
|
+
bottom: false,
|
|
6
|
+
left: false,
|
|
7
|
+
right: false,
|
|
8
|
+
};
|
|
9
|
+
export function useScrollContainer(container) {
|
|
10
|
+
const [hasOverflow, setHasOverflow] = useState(defaultOverflowState);
|
|
11
|
+
useLayoutEffect(() => {
|
|
12
|
+
const recheck = () => {
|
|
13
|
+
const element = container.current;
|
|
14
|
+
if (!element) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const left = element.scrollLeft > 0;
|
|
18
|
+
const right = element.scrollLeft + element.offsetWidth <= element.scrollWidth - 2;
|
|
19
|
+
const top = element.scrollTop > 0;
|
|
20
|
+
const bottom = element.scrollTop + element.offsetHeight <= element.scrollHeight - 2;
|
|
21
|
+
setHasOverflow(prevState => {
|
|
22
|
+
if (prevState.left !== left ||
|
|
23
|
+
prevState.right !== right ||
|
|
24
|
+
prevState.top !== top ||
|
|
25
|
+
prevState.bottom !== bottom) {
|
|
26
|
+
return { left, right, top, bottom };
|
|
27
|
+
}
|
|
28
|
+
return prevState;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const onWheel = (e) => {
|
|
32
|
+
if (container?.current) {
|
|
33
|
+
container.current.scrollLeft = container.current.scrollLeft + e.deltaY;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const element = container.current;
|
|
37
|
+
if (!element) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const resizeObserver = new ResizeObserver(recheck);
|
|
41
|
+
resizeObserver.observe(element);
|
|
42
|
+
element.addEventListener('scroll', recheck);
|
|
43
|
+
element.addEventListener('wheel', onWheel);
|
|
44
|
+
// Первичная проверка и после layout (важно для вертикального скролла)
|
|
45
|
+
recheck();
|
|
46
|
+
const rafId = requestAnimationFrame(() => {
|
|
47
|
+
recheck();
|
|
48
|
+
});
|
|
49
|
+
return () => {
|
|
50
|
+
cancelAnimationFrame(rafId);
|
|
51
|
+
resizeObserver.disconnect();
|
|
52
|
+
element.removeEventListener('scroll', recheck);
|
|
53
|
+
element.removeEventListener('wheel', onWheel);
|
|
54
|
+
};
|
|
55
|
+
}, [container]);
|
|
56
|
+
const [scrollLeft, scrollRight, scrollTop, scrollBottom] = useMemo(() => {
|
|
57
|
+
function scroll(direction) {
|
|
58
|
+
const containerElement = container.current;
|
|
59
|
+
if (!containerElement) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const scrollHorizontalSize = containerElement.offsetWidth / 2;
|
|
63
|
+
const scrollVerticalSize = containerElement.offsetHeight / 2;
|
|
64
|
+
if (['top', 'bottom'].includes(direction)) {
|
|
65
|
+
containerElement.scroll({
|
|
66
|
+
top: direction === 'top'
|
|
67
|
+
? containerElement.scrollTop - scrollVerticalSize
|
|
68
|
+
: containerElement.scrollTop + scrollVerticalSize,
|
|
69
|
+
behavior: 'smooth',
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
containerElement.scroll({
|
|
74
|
+
left: direction === 'left'
|
|
75
|
+
? containerElement.scrollLeft - scrollHorizontalSize
|
|
76
|
+
: containerElement.scrollLeft + scrollHorizontalSize,
|
|
77
|
+
behavior: 'smooth',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return [() => scroll('left'), () => scroll('right'), () => scroll('top'), () => scroll('bottom')];
|
|
81
|
+
}, [container]);
|
|
82
|
+
return { hasOverflow, scrollLeft, scrollRight, scrollTop, scrollBottom };
|
|
83
|
+
}
|
|
84
|
+
export function useFocusControl(children) {
|
|
85
|
+
return useMemo(() => {
|
|
86
|
+
const arrayOfIds = Children.map(children, (child) => {
|
|
87
|
+
const { value, disabled } = child.props;
|
|
88
|
+
return !disabled ? value : null;
|
|
89
|
+
}).filter(Boolean);
|
|
90
|
+
const getterElementWithShift = (shift) => (id) => {
|
|
91
|
+
if (id) {
|
|
92
|
+
const position = arrayOfIds.indexOf(id);
|
|
93
|
+
return position > -1 ? arrayOfIds[position + shift] : undefined;
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
};
|
|
97
|
+
return [getterElementWithShift(-1), getterElementWithShift(+1)];
|
|
98
|
+
}, [children]);
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TabBar.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TabBar.js';
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
.tabBar{
|
|
2
|
+
position:relative;
|
|
3
|
+
display:flex;
|
|
4
|
+
box-sizing:border-box;
|
|
5
|
+
}
|
|
6
|
+
.tabBar[data-orientation=vertical]{
|
|
7
|
+
flex-direction:column;
|
|
8
|
+
align-items:stretch;
|
|
9
|
+
height:100%;
|
|
10
|
+
min-height:0;
|
|
11
|
+
}
|
|
12
|
+
.tabBar[data-orientation=horizontal]{
|
|
13
|
+
flex-direction:row;
|
|
14
|
+
align-items:center;
|
|
15
|
+
}
|
|
16
|
+
.tabBar[data-size=l][data-orientation=horizontal]{
|
|
17
|
+
gap:var(--sn-tabs-anatomy-size-l-tabsHorizontal-actionSlot-gap, var(--sn-primitive-dimension-16, 16px));
|
|
18
|
+
}
|
|
19
|
+
.tabBar[data-size=l][data-orientation=vertical]{
|
|
20
|
+
gap:var(--sn-tabs-anatomy-size-l-tabsVertical-actionSlot-gap, var(--sn-primitive-dimension-16, 16px));
|
|
21
|
+
}
|
|
22
|
+
.tabBar[data-size=m][data-orientation=horizontal]{
|
|
23
|
+
gap:var(--sn-tabs-anatomy-size-m-tabsHorizontal-actionSlot-gap, var(--sn-primitive-dimension-16, 16px));
|
|
24
|
+
}
|
|
25
|
+
.tabBar[data-size=m][data-orientation=vertical]{
|
|
26
|
+
gap:var(--sn-tabs-anatomy-size-m-tabsVertical-actionSlot-gap, var(--sn-primitive-dimension-16, 16px));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.tabListWrapper{
|
|
30
|
+
position:relative;
|
|
31
|
+
display:flex;
|
|
32
|
+
box-sizing:border-box;
|
|
33
|
+
min-width:0;
|
|
34
|
+
min-height:0;
|
|
35
|
+
}
|
|
36
|
+
.tabListWrapper[data-orientation=horizontal]{
|
|
37
|
+
flex:1;
|
|
38
|
+
flex-direction:row;
|
|
39
|
+
align-items:center;
|
|
40
|
+
}
|
|
41
|
+
.tabListWrapper[data-orientation=vertical]{
|
|
42
|
+
flex:1;
|
|
43
|
+
flex-direction:column;
|
|
44
|
+
align-items:stretch;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.tabBarScrollZone{
|
|
48
|
+
position:relative;
|
|
49
|
+
overflow:visible;
|
|
50
|
+
display:flex;
|
|
51
|
+
box-sizing:border-box;
|
|
52
|
+
min-width:0;
|
|
53
|
+
min-height:0;
|
|
54
|
+
}
|
|
55
|
+
.tabBarScrollZone[data-orientation=horizontal]{
|
|
56
|
+
flex:1;
|
|
57
|
+
flex-direction:row;
|
|
58
|
+
align-items:center;
|
|
59
|
+
}
|
|
60
|
+
.tabBarScrollZone[data-orientation=vertical]{
|
|
61
|
+
flex:1;
|
|
62
|
+
flex-direction:column;
|
|
63
|
+
align-items:stretch;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.tabBarMain{
|
|
67
|
+
position:relative;
|
|
68
|
+
display:flex;
|
|
69
|
+
box-sizing:border-box;
|
|
70
|
+
min-width:0;
|
|
71
|
+
min-height:0;
|
|
72
|
+
}
|
|
73
|
+
.tabBarMain[data-orientation=horizontal]{
|
|
74
|
+
flex-direction:row;
|
|
75
|
+
align-items:center;
|
|
76
|
+
}
|
|
77
|
+
.tabBarMain[data-orientation=horizontal] .scrollArea{
|
|
78
|
+
flex:1;
|
|
79
|
+
min-width:0;
|
|
80
|
+
}
|
|
81
|
+
.tabBarMain[data-orientation=vertical]{
|
|
82
|
+
flex:1;
|
|
83
|
+
flex-direction:column;
|
|
84
|
+
align-items:stretch;
|
|
85
|
+
min-height:0;
|
|
86
|
+
}
|
|
87
|
+
.tabBarMain[data-orientation=vertical] .scrollArea{
|
|
88
|
+
flex:1;
|
|
89
|
+
min-height:0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.horizontalScrollContainer{
|
|
93
|
+
overflow:scroll visible;
|
|
94
|
+
max-width:100%;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.verticalScrollContainer{
|
|
98
|
+
overflow:visible scroll;
|
|
99
|
+
max-height:100%;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.tabsRow{
|
|
103
|
+
position:relative;
|
|
104
|
+
overflow:hidden;
|
|
105
|
+
display:flex;
|
|
106
|
+
width:-moz-fit-content;
|
|
107
|
+
width:fit-content;
|
|
108
|
+
white-space:nowrap;
|
|
109
|
+
}
|
|
110
|
+
.tabsRow[data-size=l][data-orientation=horizontal]{
|
|
111
|
+
gap:var(--sn-tabs-anatomy-size-l-tabsHorizontal-gap, var(--sn-primitive-dimension-0, 0));
|
|
112
|
+
}
|
|
113
|
+
.tabsRow[data-size=l][data-orientation=vertical]{
|
|
114
|
+
gap:var(--sn-tabs-anatomy-size-l-tabsVertical-gap, var(--sn-primitive-dimension-0, 0));
|
|
115
|
+
}
|
|
116
|
+
.tabsRow[data-size=m][data-orientation=horizontal]{
|
|
117
|
+
gap:var(--sn-tabs-anatomy-size-m-tabsHorizontal-gap, var(--sn-density-spacing-interval-l, var(--sn-primitive-dimension-24, 24px)));
|
|
118
|
+
}
|
|
119
|
+
.tabsRow[data-size=m][data-orientation=vertical]{
|
|
120
|
+
gap:var(--sn-tabs-anatomy-size-m-tabsVertical-gap, var(--sn-primitive-dimension-0, 0));
|
|
121
|
+
}
|
|
122
|
+
.tabsRow[data-orientation=vertical]{
|
|
123
|
+
flex-direction:column;
|
|
124
|
+
width:auto;
|
|
125
|
+
min-height:-moz-min-content;
|
|
126
|
+
min-height:min-content;
|
|
127
|
+
}
|
|
128
|
+
.tabsRow[data-orientation=horizontal]{
|
|
129
|
+
flex-direction:row;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.marker{
|
|
133
|
+
position:absolute;
|
|
134
|
+
background-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-55, var(--sn-brandRole-color-brandA-55, var(--sn-primitive-color-brandA-55, #389f74))));
|
|
135
|
+
transition:left 0.1s ease, width 0.1s ease, top 0.1s ease, height 0.1s ease;
|
|
136
|
+
}
|
|
137
|
+
.marker[data-orientation=horizontal]{
|
|
138
|
+
bottom:0;
|
|
139
|
+
height:var(--sn-tabs-anatomy-size-l-tabsHorizontal-selected-height, var(--sn-primitive-dimension-2, 2px));
|
|
140
|
+
border-radius:var(--sn-tabs-anatomy-size-l-tabsHorizontal-selected-borderRadius, var(--sn-brand-anatomy-radius-button-l, var(--sn-primitive-dimension-2, 2px)));
|
|
141
|
+
}
|
|
142
|
+
.marker[data-orientation=vertical]{
|
|
143
|
+
right:0;
|
|
144
|
+
width:var(--sn-tabs-anatomy-size-l-tabsVertical-selected-height, var(--sn-primitive-dimension-2, 2px));
|
|
145
|
+
border-radius:var(--sn-tabs-anatomy-size-l-tabsVertical-selected-borderRadius, var(--sn-brand-anatomy-radius-button-l, var(--sn-primitive-dimension-2, 2px)));
|
|
146
|
+
}
|
|
147
|
+
.marker[data-position=before]{
|
|
148
|
+
top:0;
|
|
149
|
+
left:0;
|
|
150
|
+
}
|
|
151
|
+
.marker[data-position=after]{
|
|
152
|
+
right:0;
|
|
153
|
+
bottom:0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.tabsRow[data-size=m] .marker[data-orientation=horizontal]{
|
|
157
|
+
height:var(--sn-tabs-anatomy-size-m-tabsHorizontal-selected-height, var(--sn-primitive-dimension-2, 2px));
|
|
158
|
+
border-radius:var(--sn-tabs-anatomy-size-m-tabsHorizontal-selected-borderRadius, var(--sn-brand-anatomy-radius-button-m, var(--sn-primitive-dimension-2, 2px)));
|
|
159
|
+
}
|
|
160
|
+
.tabsRow[data-size=m] .marker[data-orientation=vertical]{
|
|
161
|
+
width:var(--sn-tabs-anatomy-size-m-tabsVertical-selected-height, var(--sn-primitive-dimension-2, 2px));
|
|
162
|
+
border-radius:var(--sn-tabs-anatomy-size-m-tabsVertical-selected-borderRadius, var(--sn-brand-anatomy-radius-button-m, var(--sn-primitive-dimension-2, 2px)));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.divider{
|
|
166
|
+
position:absolute;
|
|
167
|
+
}
|
|
168
|
+
.divider[data-position=before]{
|
|
169
|
+
top:0;
|
|
170
|
+
left:0;
|
|
171
|
+
}
|
|
172
|
+
.divider[data-position=after]{
|
|
173
|
+
right:0;
|
|
174
|
+
bottom:0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.tabBar[data-orientation=horizontal] .divider{
|
|
178
|
+
width:100%;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.tabBar[data-orientation=vertical] .divider{
|
|
182
|
+
height:100%;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.tabBarAfter[data-orientation=vertical][data-size=l], .tabBarAfter[data-orientation=vertical][data-size=m]{
|
|
186
|
+
min-height:auto;
|
|
187
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
export type TabContentProps = WithSupportProps<PropsWithChildren<{
|
|
4
|
+
/** Значение таба */
|
|
5
|
+
value: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
}>>;
|
|
8
|
+
export declare function TabContent({ children, value, className, ...rest }: TabContentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
import { useTabsContext } from '../../context.js';
|
|
4
|
+
import { getTabContentId } from '../../utils.js';
|
|
5
|
+
export function TabContent({ children, value, className, ...rest }) {
|
|
6
|
+
const { selectedTab } = useTabsContext();
|
|
7
|
+
if (value !== selectedTab) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return (_jsx("div", { className: className, role: 'tabpanel', id: getTabContentId(value), ...extractSupportProps(rest), "aria-labelledby": value, "data-testid": `tabs__tab-content-${value}`, children: children }));
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TabContent.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TabContent.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Tab as TabComponent } from '../Tab/index.js';
|
|
3
|
+
import { TabBar as TabBarComponent } from '../TabBar/index.js';
|
|
4
|
+
import { TabContent as TabContentComponent } from '../TabContent/index.js';
|
|
5
|
+
export type TabsProps<T extends string = string> = {
|
|
6
|
+
/** Текущая вкладка */
|
|
7
|
+
value?: T;
|
|
8
|
+
/** Выбранная вкладка по умолчанию */
|
|
9
|
+
defaultValue?: T;
|
|
10
|
+
/** Колбек выбора вкладки */
|
|
11
|
+
onChange?(id: T): void;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
/** Дополнительный класс на корневой контейнер */
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function Tabs<T extends string = string>({ children, onChange, value, defaultValue, className }: TabsProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare namespace Tabs {
|
|
18
|
+
const Tab: typeof TabComponent;
|
|
19
|
+
const TabBar: typeof TabBarComponent;
|
|
20
|
+
const TabContent: typeof TabContentComponent;
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useValueControl } from '@cloud-ru/ds-utils';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { Children, isValidElement } from 'react';
|
|
5
|
+
import { ORIENTATION } from '../../constants.js';
|
|
6
|
+
import { TabsContext } from '../../context.js';
|
|
7
|
+
import { Tab as TabComponent } from '../Tab/index.js';
|
|
8
|
+
import { TabBar as TabBarComponent } from '../TabBar/index.js';
|
|
9
|
+
import { TabContent as TabContentComponent } from '../TabContent/index.js';
|
|
10
|
+
import styles from './styles.module.css';
|
|
11
|
+
function getOrientationFromChildren(children) {
|
|
12
|
+
const array = Children.toArray(children);
|
|
13
|
+
const tabBar = array.find((child) => isValidElement(child) && child.type === TabBarComponent);
|
|
14
|
+
return tabBar?.props?.orientation === ORIENTATION.Vertical ? ORIENTATION.Vertical : ORIENTATION.Horizontal;
|
|
15
|
+
}
|
|
16
|
+
export function Tabs({ children, onChange, value, defaultValue, className }) {
|
|
17
|
+
const [selectedTab, setSelectedTab] = useValueControl({
|
|
18
|
+
value,
|
|
19
|
+
defaultValue,
|
|
20
|
+
onChange: onChange,
|
|
21
|
+
});
|
|
22
|
+
const orientation = getOrientationFromChildren(children);
|
|
23
|
+
const isVertical = orientation === ORIENTATION.Vertical;
|
|
24
|
+
return (_jsx(TabsContext.Provider, { value: {
|
|
25
|
+
selectedTab,
|
|
26
|
+
setSelectedTab,
|
|
27
|
+
}, children: _jsx("div", { className: cn(styles.root, isVertical && styles.rootVertical, className), children: children }) }));
|
|
28
|
+
}
|
|
29
|
+
(function (Tabs) {
|
|
30
|
+
Tabs.Tab = TabComponent;
|
|
31
|
+
Tabs.TabBar = TabBarComponent;
|
|
32
|
+
Tabs.TabContent = TabContentComponent;
|
|
33
|
+
})(Tabs || (Tabs = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Tabs.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Tabs.js';
|