Skip to content

Commit 19c5963

Browse files
author
Kubit
committed
New icon props to Tabs component
1 parent 3589ed4 commit 19c5963

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

src/components/tabs/stories/tabs.stories.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type Story = StoryObj<typeof meta> & { args: { themeArgs?: object } };
3030
export const Tabs: Story = {
3131
args: {
3232
variant: Object.values(variantsObject[themeSelected].TabsVariantType || {})[0] as string,
33-
leftIcon: { icon: ICONS.ICON_CHEVRON_UP },
34-
rightIcon: { icon: ICONS.ICON_CHEVRON_DOWN },
33+
leftIcon: { icon: ICONS.ICON_CHEVRON_LEFT },
34+
rightIcon: { icon: ICONS.ICON_CHEVRON_RIGHT },
3535
unMountContent: true,
3636
content: [
3737
<ReplaceContent key="content-0" width="100%">
@@ -43,6 +43,12 @@ export const Tabs: Story = {
4343
<ReplaceContent key="content-2" width="100%">
4444
Content third tab
4545
</ReplaceContent>,
46+
<ReplaceContent key="content-3" width="100%">
47+
Content fourth tab
48+
</ReplaceContent>,
49+
<ReplaceContent key="content-4" width="100%">
50+
Content fifth tab
51+
</ReplaceContent>,
4652
],
4753
tabs: [
4854
{
@@ -56,6 +62,12 @@ export const Tabs: Story = {
5662
{
5763
content: 'Third tab',
5864
},
65+
{
66+
content: 'Fourth tab',
67+
},
68+
{
69+
content: 'Fifth tab',
70+
},
5971
],
6072
themeArgs: themesObject[themeSelected][STYLES_NAME.PRIMARY_TABS],
6173
},

src/components/tabs/tabsStandAlone.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,54 @@ const TabsStandAloneComponent = (
5656
tabsLength: tabsLength,
5757
selectedTab: props.selectedTab,
5858
});
59+
const disabledIconLeft = position === 0;
60+
const disabledIconRight = position >= tabsLength - numTabsInView;
5961

6062
const buildIconLeft = () =>
61-
position !== 0 && (
63+
tabsLength > numTabsInView && (
6264
<TabsLeftArrowContainerStyled
6365
aria-label={props.leftControlAriaLabel}
6466
data-testid={`${dataTestId}-icon-left`}
67+
disabled={disabledIconLeft}
6568
styles={props.styles}
6669
tabIndex={0}
6770
type={ButtonType.BUTTON}
68-
onClick={() => handleClickIcon(false)}
71+
onClick={() => {
72+
if (!disabledIconLeft) {
73+
handleClickIcon(false);
74+
}
75+
}}
6976
>
70-
<ElementOrIcon customIconStyles={props.styles.leftIcon} {...props.leftIcon} />
77+
<ElementOrIcon
78+
customIconStyles={
79+
!disabledIconLeft ? props.styles.leftIcon : props.styles.leftIcon?.disabled
80+
}
81+
{...props.leftIcon}
82+
/>
7183
</TabsLeftArrowContainerStyled>
7284
);
7385

7486
const buildIconRight = () =>
75-
position < tabsLength - numTabsInView && (
87+
tabsLength > numTabsInView && (
7688
<TabsRightArrowContainerStyled
7789
aria-label={props.rightControlAriaLabel}
7890
data-testid={`${dataTestId}-icon-right`}
91+
disabled={disabledIconRight}
7992
styles={props.styles}
8093
tabIndex={0}
8194
type={ButtonType.BUTTON}
82-
onClick={() => handleClickIcon(true)}
95+
onClick={() => {
96+
if (!disabledIconRight) {
97+
handleClickIcon(true);
98+
}
99+
}}
83100
>
84-
<ElementOrIcon customIconStyles={props.styles.rightIcon} {...props.rightIcon} />
101+
<ElementOrIcon
102+
customIconStyles={
103+
!disabledIconRight ? props.styles.rightIcon : props.styles.rightIcon?.disabled
104+
}
105+
{...props.rightIcon}
106+
/>
85107
</TabsRightArrowContainerStyled>
86108
);
87109

src/components/tabs/types/tabsTheme.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ export type TabsVariantStylesType = {
1616
arrowLeftIconContainer?: Omit<CommonStyleType, 'MOBILE'> & {
1717
[DeviceBreakpointsType.MOBILE]?: CommonStyleType & { focusVisible?: CommonStyleType };
1818
};
19-
leftIcon?: IconTypes;
19+
leftIcon?: IconTypes & {
20+
disabled?: IconTypes;
21+
};
2022
arrowRightIconContainer?: Omit<CommonStyleType, 'MOBILE'> & {
2123
[DeviceBreakpointsType.MOBILE]?: CommonStyleType & { focusVisible?: CommonStyleType };
2224
};
23-
rightIcon?: IconTypes;
25+
rightIcon?: IconTypes & {
26+
disabled?: IconTypes;
27+
};
2428
firstTabButton?: CommonStyleType;
2529
lastTabButton?: CommonStyleType;
2630
oneTabContainer?: CommonStyleType;

0 commit comments

Comments
 (0)