Skip to content

Commit

Permalink
feat(#68): add tabs component
Browse files Browse the repository at this point in the history
- add a component for it
- add it to storybook
  • Loading branch information
mari1912 committed Jul 12, 2024
1 parent 648a904 commit cafa6be
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions dashboard/src/components/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Meta, StoryObj } from '@storybook/react';

import TabsComponent, { ITabItem } from './Tabs';

const meta = {
title: 'Tabs',
component: TabsComponent,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
} satisfies Meta<typeof TabsComponent>;

export default meta;
type Story = StoryObj<typeof meta>;

const tabs: ITabItem[] = [
{ name: 'Boots', content: <span>Boots</span> },
{ name: 'Tests', content: <span>Tests</span>, disabled: true },
{ name: 'Builds', content: <span>Builds</span> },
];
export const Default: Story = {
args: {
tabs: tabs,
defaultTab: tabs[0],
},
};
45 changes: 45 additions & 0 deletions dashboard/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ReactElement, useMemo } from 'react';

import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';

export interface ITabItem {
name: string;
content: ReactElement;
disabled?: boolean;
}

export interface ITabsComponent {
tabs: ITabItem[];
defaultTab: ITabItem;
}

const TabsComponent = ({ defaultTab, tabs }: ITabsComponent): JSX.Element => {
const tabsTrigger = useMemo(
() =>
tabs.map(tab => (
<TabsTrigger disabled={tab.disabled} key={tab.name} value={tab.name}>
{tab.name}
</TabsTrigger>
)),
[tabs],
);

const tabsContent = useMemo(
() =>
tabs.map(tab => (
<TabsContent key={tab.name} value={tab.name}>
{tab.content}
</TabsContent>
)),
[tabs],
);

return (
<Tabs defaultValue={defaultTab.name} className="w-full">
<TabsList>{tabsTrigger}</TabsList>
{tabsContent}
</Tabs>
);
};

export default TabsComponent;

0 comments on commit cafa6be

Please sign in to comment.