2025-07-28 15:10:57 -07:00
|
|
|
import { useSlotRecipe, Box, Button, IconButton } from "@chakra-ui/react";
|
2026-06-05 13:38:35 -07:00
|
|
|
import { ColorModeButton } from "@/components/ui/color-mode";
|
2026-06-04 15:30:01 -07:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import { NavLink } from "react-router-dom";
|
2025-08-05 12:57:18 -07:00
|
|
|
import Tooltip from "../Canvas/CanvasComponents/Tooltip.jsx";
|
2026-06-05 13:38:35 -07:00
|
|
|
import { Mountain, House, Earth, MapPin, ShieldUser, Menu } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
const SIDEBAR_DEFAULT_BUTTONS = [
|
|
|
|
|
{ icon: House, name: "Home", url: "/home" },
|
|
|
|
|
{ icon: Earth, name: "Global Map", url: "/global-map" },
|
|
|
|
|
{ icon: MapPin, name: "Regional Map", url: "/regional-map" },
|
|
|
|
|
{ icon: Mountain, name: "Volcano", url: "/volcano" },
|
|
|
|
|
{ icon: ShieldUser, name: "Admin", url: "/admin" } // TODO remove in the future as default should not have admin
|
|
|
|
|
];
|
2025-07-16 15:02:57 -07:00
|
|
|
|
2026-06-04 15:30:01 -07:00
|
|
|
export default function Sidebar() {
|
2025-07-16 15:02:57 -07:00
|
|
|
const [isOpen, setIsOpen] = useState(true);
|
2025-07-29 11:08:36 -07:00
|
|
|
const recipe = useSlotRecipe({ key: "sidebar" });
|
|
|
|
|
const styles = recipe();
|
2025-07-17 09:45:36 -07:00
|
|
|
|
2026-06-05 13:38:35 -07:00
|
|
|
// TODO we will need to call buttons here by authorized user, for now we update the visible buttons as simply the default buttons
|
|
|
|
|
const visibleButtons = SIDEBAR_DEFAULT_BUTTONS;
|
2026-06-04 15:30:01 -07:00
|
|
|
|
2026-06-05 13:38:35 -07:00
|
|
|
const toggleSidebar = () => setIsOpen((prev) => !prev);
|
2025-07-16 15:02:57 -07:00
|
|
|
|
|
|
|
|
return (
|
2026-06-05 13:38:35 -07:00
|
|
|
<Box css={styles.root} width={isOpen ? "210px" : "71px"} transition="width 0.4s ease" position="relative" display="flex" flexDirection="column" gap={2}
|
|
|
|
|
>
|
|
|
|
|
{/* Menu Trigger */}
|
|
|
|
|
<IconButton aria-label="Toggle Sidebar" variant="plain" size="md" onClick={toggleSidebar} width="54px" alignSelf="flex-start"
|
|
|
|
|
>
|
|
|
|
|
<Menu />
|
|
|
|
|
</IconButton>
|
2025-07-17 09:45:36 -07:00
|
|
|
|
2026-06-05 13:38:35 -07:00
|
|
|
{/* Navigation Buttons */}
|
|
|
|
|
{visibleButtons.map((button) => {
|
|
|
|
|
const Icon = button.icon;
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip key={button.name} content={button.name} sidebarIsOpen={isOpen}>
|
|
|
|
|
<Button
|
|
|
|
|
as={NavLink}
|
|
|
|
|
to={button.url}
|
|
|
|
|
css={styles.buttons}
|
|
|
|
|
justifyContent="flex-start"
|
|
|
|
|
width="100%"
|
|
|
|
|
overflow="hidden" // Prevents text popout on collapse
|
|
|
|
|
>
|
|
|
|
|
<Icon style={{ flexShrink: 0 }} /> {/* Prevents icon from squishing */}
|
|
|
|
|
|
|
|
|
|
{/* Cleaned conditional transition styling */}
|
|
|
|
|
<Box
|
|
|
|
|
as="span"
|
|
|
|
|
ml={isOpen ? 3 : 0}
|
|
|
|
|
opacity={isOpen ? 1 : 0}
|
|
|
|
|
visibility={isOpen ? "visible" : "hidden"} // Prevents phantom width calculations and overflow into canvas
|
|
|
|
|
transition="opacity 0.3s ease, visibility 0.3s ease, margin 0.3s ease"
|
|
|
|
|
whiteSpace="nowrap"
|
|
|
|
|
>
|
|
|
|
|
{button.name}
|
|
|
|
|
</Box>
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
{/* Theme Toggler */}
|
|
|
|
|
<ColorModeButton
|
|
|
|
|
position="absolute"
|
|
|
|
|
bottom="4"
|
|
|
|
|
left="4"
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
2025-07-16 15:02:57 -07:00
|
|
|
);
|
2025-07-17 09:45:36 -07:00
|
|
|
}
|