Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Children, isValidElement } from 'react';
import type { ComponentWithRef } from '@vibrant-ui/core';
import { TabView } from '@vibrant-ui/core';
import { HStack } from '../HStack';
Expand All @@ -11,29 +12,33 @@ import type { ViewPagerTabGroupProps } from './ViewPagerTabGroupProps';
import { withViewPagerTabGroupVariation } from './ViewPagerTabGroupProps';

export const ViewPagerTabGroup = withViewPagerTabGroupVariation(
({ children, tabId, testId, onTabChange, tabSpacing, native_swipeEnabled = true }) => (
<TabView
tabId={tabId}
testId={testId}
renderTobBarContainer={props => (
<HStack px={[20, 20, 0]} spacing={tabSpacing} data-testid="top-bar-container">
{props}
</HStack>
)}
renderTobBarItem={({ isSelected, onClick, title, tabId }) => (
<VStack key={title} spacing={8}>
<Pressable onClick={onClick} data-testid={`top-bar-${tabId}`}>
<Title level={5}>{title}</Title>
</Pressable>
{isSelected && <Paper borderColor="onView1" borderStyle="solid" borderWidth={1} />}
</VStack>
)}
onTabChange={onTabChange}
native_swipeEnabled={native_swipeEnabled}
>
{children}
</TabView>
)
({ children, tabId, testId, onTabChange, tabSpacing, native_swipeEnabled = true }) => {
const validChildren = Children.toArray(children).filter(isValidElement<ViewPagerTabGroupItemProps>);

return (
<TabView
tabId={tabId}
testId={testId}
renderTobBarContainer={props => (
<HStack px={[20, 20, 0]} spacing={tabSpacing} data-testid="top-bar-container">
{props}
</HStack>
)}
renderTobBarItem={({ isSelected, onClick, title, tabId }) => (
<VStack key={title} spacing={8}>
<Pressable onClick={onClick} data-testid={`top-bar-${tabId}`}>
<Title level={5}>{title}</Title>
</Pressable>
{isSelected && <Paper borderColor="onView1" borderStyle="solid" borderWidth={1} />}
</VStack>
)}
onTabChange={onTabChange}
native_swipeEnabled={native_swipeEnabled}
>
{validChildren}
</TabView>
);
}
) as ComponentWithRef<ViewPagerTabGroupProps> & {
Item: ComponentWithRef<ViewPagerTabGroupItemProps>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { withVariation } from '@vibrant-ui/core';
import type { ViewPagerTabGroupItemProps } from './ViewPagerTabGroupItem';

export type ViewPagerTabGroupProps = {
children: ReactElement<ViewPagerTabGroupItemProps> | ReactElement<ViewPagerTabGroupItemProps>[];
children: (ReactElement<ViewPagerTabGroupItemProps> | undefined)[] | ReactElement<ViewPagerTabGroupItemProps>;
tabSpacing?: number;
tabId?: string;
onTabChange?: () => void;
onTabChange?: (tabId?: string) => void;
testId?: string;
native_swipeEnabled?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/vibrant-core/src/lib/TabView/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const TabView = withTabViewVariation(

setCurrentIndex(index);

onTabChange?.();
onTabChange?.(currentTab?.props.tabId);
};

const changeTabById = useCallbackRef((tabId?: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vibrant-core/src/lib/TabView/TabViewProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type TabViewProps = {
children: ReactElement<TabViewItemProps> | ReactElement<TabViewItemProps>[];
renderTobBarItem: (_: { title: string; isSelected: boolean; onClick: () => void; tabId: string }) => ReactElement;
renderTobBarContainer: (props: ReactElementChildren) => ReactElement;
onTabChange?: () => void;
onTabChange?: (tabId?: string) => void;
testId?: string;
native_swipeEnabled?: boolean;
};
Expand Down
Loading