Skip to content

Commit

Permalink
✨ feat : Create a Dashboard component
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Lainari committed Feb 23, 2024
1 parent f9340ac commit 0eaff3b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/components/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client';

import {DashboardProps} from '@/src/interfaces/group';

const Dashboard = ({tabs, activeTab, setActiveTab}: DashboardProps) => {
const handleClick = (tab: React.SetStateAction<string>) => {
setActiveTab(tab);
};
return (
<nav className="mt-4 flex">
{tabs.map(tab => (
<div
key={tab}
className={`grid place-items-center w-24 h-10 border-r border-gray-400 px-4 hover:cursor-pointer ${
activeTab === tab
? 'text-black bg-sky-50'
: 'text-gray-400 hover:bg-slate-100 '
}`}
onClick={() => handleClick(tab)}
>
{tab}
</div>
))}
</nav>
);
};

export default Dashboard;
8 changes: 8 additions & 0 deletions src/components/dashboard/TabsMapping.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {TabsMappingProps} from '@/src/interfaces/group';
import React from 'react';

const TabsMapping = ({activeTab, tabMapping}: TabsMappingProps) => {
return <>{tabMapping[activeTab]}</>;
};

export default TabsMapping;
4 changes: 4 additions & 0 deletions src/components/dashboard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Dashboard from './Dashboard';
import TabsMapping from './TabsMapping';

export {Dashboard, TabsMapping};
7 changes: 7 additions & 0 deletions src/interfaces/group/dashboardProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface DashboardProps {
activeTab: string;
setActiveTab: React.Dispatch<React.SetStateAction<string>>;
tabs: string[];
}

export type {DashboardProps};
2 changes: 2 additions & 0 deletions src/interfaces/group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type {DashboardProps} from './dashboardProps';
export type {TabsMappingProps} from './tabsMappingProps';
8 changes: 8 additions & 0 deletions src/interfaces/group/tabsMappingProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface TabsMappingProps {
activeTab: string;
tabMapping: {
[key: string]: JSX.Element;
};
}

export type {TabsMappingProps};

0 comments on commit 0eaff3b

Please sign in to comment.