Skip to content

Commit

Permalink
refactor: made tab panel optional
Browse files Browse the repository at this point in the history
  • Loading branch information
shayan-deriv committed Jan 23, 2024
1 parent 1c5f650 commit a806974
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/components/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ReactNode } from 'react';

type TabProps = {
children: ReactNode;
children?: ReactNode;
icon?: ReactNode;
title: string;
};
Expand Down
4 changes: 3 additions & 1 deletion lib/components/Tabs/TabTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export type TabTitleProps = {
title: string;
className?: string;
variant: 'primary' | 'secondary';
onClickHandler?: () => void;
};

const TabTitle = ({ icon, activeTab, isActive, setSelectedTab, title,className,variant }: TabTitleProps) => {
const TabTitle = ({ icon, activeTab, isActive, setSelectedTab, title,className,variant, onClickHandler }: TabTitleProps) => {
const handleOnClick = useCallback((title: string) => {
setSelectedTab(title);
onClickHandler?.();
}, [setSelectedTab, activeTab]);

const classNameVariants: Record<TabTitleProps['variant'], string> = {
Expand Down
4 changes: 3 additions & 1 deletion lib/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ type TabsProps = {
wrapperClassName?: string;
className?: string;
variant?: 'primary' | 'secondary';
onClickHandler?: () => void;
};

const Tabs = ({ children, activeTab, wrapperClassName, className, variant = 'primary' }: TabsProps): JSX.Element => {
const Tabs = ({ children, activeTab, wrapperClassName, className, variant = 'primary', onClickHandler }: TabsProps): JSX.Element => {
const [selectedTab, setSelectedTab] = useState(activeTab || children[0].props.title);

return (
Expand All @@ -27,6 +28,7 @@ const Tabs = ({ children, activeTab, wrapperClassName, className, variant = 'pri
setSelectedTab={setSelectedTab}
title={item.props.title}
variant={variant}
onClickHandler={onClickHandler}
/>
)
})}
Expand Down

0 comments on commit a806974

Please sign in to comment.