Files
Web-Frontend/client/src/components/layout/Sidebar/Sidebar.jsx
T
vkuchenik 4495cb9f78 new icons
got rid of custom imported icons, too much work to make them dark mode useable.
2025-07-28 15:10:57 -07:00

90 lines
2.9 KiB
React

import { useSlotRecipe, Box, Button, IconButton } from "@chakra-ui/react";
import { ColorModeButton } from "@/components/ui/color-mode";
import { Tooltip } from "@/components/ui/tooltip";
import { FaVolcano } from "react-icons/fa6";
import { FaHome } from "react-icons/fa";
import { FaGlobeAmericas } from "react-icons/fa";
import { FaMapMarkerAlt } from "react-icons/fa";
import { HiUsers } from "react-icons/hi2";
import { VscThreeBars } from "react-icons/vsc";
import { useState } from "react";
export default function Sidebar({ onChangeView }) {
const [isOpen, setIsOpen] = useState(true);
const [activeButton, setActiveButton] = useState(0)
// this list of btns will come from the db (not every usr will have access to admin)
const buttons = [
{icon: FaHome, name: "Home", view: "widget"},
{icon: FaGlobeAmericas, name: "Global Map", view: "global"},
{icon: FaMapMarkerAlt, name: "Regional Map", view: "regional"},
{icon: FaVolcano, name: "Volcano", view: "volcano"},
{icon: HiUsers, name: "Admin", view: "admin"}
];
const recipe = useSlotRecipe({ key: "sidebar" });
const styles = recipe();
const toggleSidebar = () => {
if (isOpen) setIsOpen(false);
else setIsOpen(true);
};
return (
<Box
css={styles.root}
width={isOpen ? "210px" : "71px"}
transition="width 0.4s ease"
>
<IconButton
aria-label="Toggle Sidebar"
variant="plain"
size="md"
onClick={toggleSidebar}
width="54px"
>
<VscThreeBars />
</IconButton>
{buttons.map((button, idx) => {
const Icon = button.icon;
const buttonElement = (
<Button
// key={idx}
css={styles.buttons}
onClick={() => {
setActiveButton(idx);
onChangeView(button.view); // Trigger state change in Dashboard
}}
bg={activeButton === idx ? "primary":undefined}
color={activeButton === idx ? "#FFFFFF":undefined}
justifyContent="flex-start"
>
<Icon />
<span style={{
opacity: isOpen ? 1 : 0,
transition: "opacity 0.4s ease",
overflow: "hidden",
whiteSpace: "nowrap",
display: "inline-block",
lineHeight: 1.2
}}
>
{button.name}
</span>
</Button>
);
// console.log("buttonElement is:", buttonElement)
console.log("Returning:", !isOpen ? "Tooltip" : "Button", buttonElement);
return !isOpen ? (
<Tooltip key={ idx } content={ button.name } placement="right" hasArrow>
{ buttonElement }
</Tooltip>
) : (
buttonElement
);
})}
<ColorModeButton position="absolute" bottom="2"/>
</Box>
);
}