diff --git a/src/components/TabBar/TabBar.stories.tsx b/src/components/TabBar/TabBar.stories.tsx index 104855a..6071b0d 100644 --- a/src/components/TabBar/TabBar.stories.tsx +++ b/src/components/TabBar/TabBar.stories.tsx @@ -62,7 +62,7 @@ export const PanelTabDisabled: Story = { }, } -export const PanelTabWitIcons: Story = { +export const PanelTabWithIcons: Story = { args: { variant: 'panel', tabs: [ diff --git a/src/components/TabBar/index.tsx b/src/components/TabBar/index.tsx index 14d3ddd..a3054c0 100644 --- a/src/components/TabBar/index.tsx +++ b/src/components/TabBar/index.tsx @@ -1,9 +1,29 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars -import React from 'react' +import React, { useState } from 'react' import { Box, Tabs } from '@chakra-ui/react' -import { TabBarContainer, TabBarItemPanel, TabBarItemView } from './styled' -import { TabBarProps } from './types' +import { + TabBarContainer, + TabBarItemPanel, + TabBarItemView, + TabBarItemViewDivider, +} from './styled' +import { TabBarItemProps, TabBarProps } from './types' + +const getTabIndex = (tabs: TabBarItemProps[], selectedTab?: string) => + tabs.findIndex((t) => t.value === selectedTab) + +const getBorderSide = (selectedTabIndex: number) => { + if (selectedTabIndex === 1) { + return 'none' + } + + if (selectedTabIndex === 2) { + return 'left' + } + + return 'right' +} const TabBar = ({ variant = 'panel', @@ -11,13 +31,21 @@ const TabBar = ({ tabs, onTabClick, }: TabBarProps) => { + const [selectedTabIndex, setSelectedTabIndex] = useState( + getTabIndex(tabs, defaultValue) || 0, + ) + + const isView = variant === 'view' + const handleOnTabClick = (tabValue: string) => { + setSelectedTabIndex(getTabIndex(tabs, tabValue)) + if (onTabClick) { onTabClick(tabValue) } } - const TabBarItem = variant === 'view' ? TabBarItemView : TabBarItemPanel + const TabBarItem = isView ? TabBarItemView : TabBarItemPanel return ( @@ -27,17 +55,29 @@ const TabBar = ({ onFocusChange={({ focusedValue }) => handleOnTabClick(focusedValue)} > - {tabs.map((tab) => ( - - - {tab.icon} - {tab.label} - - + {tabs.map((tab, idx) => ( + <> + {isView && + idx === 1 && + getBorderSide(selectedTabIndex) === 'left' ? ( + + ) : null} + + + {tab.icon} + {tab.label} + + + {isView && + idx === 1 && + getBorderSide(selectedTabIndex) === 'right' ? ( + + ) : null} + ))} diff --git a/src/components/TabBar/styled.ts b/src/components/TabBar/styled.ts index 7ff99c9..aefdf96 100644 --- a/src/components/TabBar/styled.ts +++ b/src/components/TabBar/styled.ts @@ -15,13 +15,13 @@ export const TabBarContainer = styled.div<{ ` border: 1px solid ${getThemedColor('neutral', 400)}; background-color: ${getThemedColor('neutral', 200)}; - border-radius: 2px; + border-radius: 4px; padding: 4px; `} ` export const DefaultTab = styled(Tabs.Trigger)` - width: 100%; + width: 99%; height: 40px; padding: 8px 16px; border-radius: 0px; @@ -91,6 +91,12 @@ export const TabBarItemPanel = styled(DefaultTab)` } ` +export const TabBarItemViewDivider = styled.div` + width: 4px; + height: 24px; + background-color: ${getThemedColor('neutral', 400)}; +` + export const TabBarItemView = styled(DefaultTab)` height: 32px; border-radius: 2px;