From 287c85a88bf695e166378492d8b7966dadbb32e9 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Tue, 2 Jan 2024 12:06:03 +0530 Subject: [PATCH] add more tabs option --- src/Components/Common/Sidebar/Sidebar.tsx | 36 +++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Components/Common/Sidebar/Sidebar.tsx b/src/Components/Common/Sidebar/Sidebar.tsx index fa809571772..20ffb438f65 100644 --- a/src/Components/Common/Sidebar/Sidebar.tsx +++ b/src/Components/Common/Sidebar/Sidebar.tsx @@ -31,15 +31,16 @@ const NavItems = [ { text: "Facilities", to: "/facility", icon: "care-l-hospital" }, { text: "Patients", to: "/patients", icon: "care-l-user-injured" }, { text: "Assets", to: "/assets", icon: "care-l-shopping-cart-alt" }, - { text: "Sample Test", to: "/sample", icon: "care-l-medkit" }, { text: "Shifting", to: "/shifting", icon: "care-l-ambulance" }, + { text: "Users", to: "/users", icon: "care-l-users-alt" }, + // More items + { text: "Sample Test", to: "/sample", icon: "care-l-medkit" }, { text: "Resource", to: "/resource", icon: "care-l-heart-medical" }, { text: "External Results", to: "/external_results", icon: "care-l-clipboard-notes", }, - { text: "Users", to: "/users", icon: "care-l-users-alt" }, { text: "Notice Board", to: "/notice_board", icon: "care-l-meeting-board" }, ]; @@ -58,11 +59,15 @@ const StatelessSidebar = ({ const activeLinkRef = useRef(null); const [lastIndicatorPosition, setLastIndicatorPosition] = useState(0); const [isOverflowVisible, setOverflowVisisble] = useState(false); + const [moreItems, setMoreItems] = useState(false); useEffect(() => { if (!indicatorRef.current) return; - const index = NavItems.findIndex((item) => item.to === activeLink); - const navItemCount = NavItems.length + 2; // +2 for notification and dashboard + const index = NavItems.slice(0, moreItems ? NavItems.length : 5).findIndex( + (item) => item.to === activeLink + ); + const navItemCount = (moreItems ? NavItems.length : 5) + 3; // +3 for notification, Dashboard and More + if (index !== -1) { // Haha math go brrrrrrrrr @@ -83,7 +88,7 @@ const StatelessSidebar = ({ } else { indicatorRef.current.style.display = "none"; } - }, [activeLink, lastIndicatorPosition]); + }, [activeLink, lastIndicatorPosition, moreItems]); const handleOverflow = (value: boolean) => { setOverflowVisisble(value); @@ -99,7 +104,8 @@ const StatelessSidebar = ({ : " overflow-y-auto overflow-x-hidden " }`} > -
{/* flexible spacing */} +
+ {/* flexible spacing */} -
{/* flexible spacing */} +
+ {/* flexible spacing */}
- {NavItems.map((i) => { + {NavItems.slice(0, moreItems ? NavItems.length : 5).map((i) => { return ( ); })} - + setMoreItems(!moreItems)} + icon={ + moreItems ? ( + + ) : ( + + ) + } + handleOverflow={handleOverflow} + />