Skip to content

Commit 0eaff3b

Browse files
committed
✨ feat : Create a Dashboard component
- Selecting a tab on the dashboard allows you to load the components you've linked - The tabsMapping is responsible for rendering the components to be linked Related issue: #49
1 parent f9340ac commit 0eaff3b

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use client';
2+
3+
import {DashboardProps} from '@/src/interfaces/group';
4+
5+
const Dashboard = ({tabs, activeTab, setActiveTab}: DashboardProps) => {
6+
const handleClick = (tab: React.SetStateAction<string>) => {
7+
setActiveTab(tab);
8+
};
9+
return (
10+
<nav className="mt-4 flex">
11+
{tabs.map(tab => (
12+
<div
13+
key={tab}
14+
className={`grid place-items-center w-24 h-10 border-r border-gray-400 px-4 hover:cursor-pointer ${
15+
activeTab === tab
16+
? 'text-black bg-sky-50'
17+
: 'text-gray-400 hover:bg-slate-100 '
18+
}`}
19+
onClick={() => handleClick(tab)}
20+
>
21+
{tab}
22+
</div>
23+
))}
24+
</nav>
25+
);
26+
};
27+
28+
export default Dashboard;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {TabsMappingProps} from '@/src/interfaces/group';
2+
import React from 'react';
3+
4+
const TabsMapping = ({activeTab, tabMapping}: TabsMappingProps) => {
5+
return <>{tabMapping[activeTab]}</>;
6+
};
7+
8+
export default TabsMapping;

src/components/dashboard/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Dashboard from './Dashboard';
2+
import TabsMapping from './TabsMapping';
3+
4+
export {Dashboard, TabsMapping};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface DashboardProps {
2+
activeTab: string;
3+
setActiveTab: React.Dispatch<React.SetStateAction<string>>;
4+
tabs: string[];
5+
}
6+
7+
export type {DashboardProps};

src/interfaces/group/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type {DashboardProps} from './dashboardProps';
2+
export type {TabsMappingProps} from './tabsMappingProps';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface TabsMappingProps {
2+
activeTab: string;
3+
tabMapping: {
4+
[key: string]: JSX.Element;
5+
};
6+
}
7+
8+
export type {TabsMappingProps};

0 commit comments

Comments
 (0)