tooltip works!!

(sorry i'm in the wrong branch)
This commit is contained in:
2025-07-29 11:08:36 -07:00
parent 4495cb9f78
commit 7307736662
4 changed files with 77 additions and 37 deletions
@@ -0,0 +1,45 @@
import { useState, useRef } from "react";
import { chakra, useSlotRecipe } from "@chakra-ui/react";
export default function Tooltip ({tooltipkey, content, sidebarIsOpen, children}) {
const [isVisible, setIsVisible] = useState(!sidebarIsOpen);
const recipe = useSlotRecipe({ key: "sidebar" });
const styles = recipe();
const timeoutId = useRef(null);
return (
<chakra.div
width={sidebarIsOpen ? "194px" : "55px"}
transition="width 0.4s ease"
onMouseEnter={() => { timeoutId.current = setTimeout(() => setIsVisible(true), 1000); }}
onMouseLeave={() => {
if (timeoutId.current) {
clearTimeout(timeoutId.current);
timeoutId.current = null;
}
setIsVisible(false);
}}
>
{children}
{isVisible && !sidebarIsOpen && (
<>
<chakra.div
fontSize="xs"
position="absolute"
bg="gray.700"
color="white"
left="65px"
px={2}
py={1}
borderRadius="md"
whiteSpace="nowrap"
zIndex={10}
>
{content}
</chakra.div>
</>
)}
</chakra.div>
)
}
@@ -12,13 +12,13 @@ export default function Widget({ id, title, isEditable, isDelete, DeleteWidget }
{isDelete ? ( {isDelete ? (
<> <>
<Flex flexDirection="row" justifyContent="space-between" alignItems="center"> <Flex flexDirection="row" justifyContent="space-between" alignItems="center">
<Text className="widget-handle" w="100%">{title}</Text> <Text className="widget-handle" w="100%" fontWeight="bold">{title}</Text>
<CloseButton onClick={() => DeleteWidget(id)} size="xs" _hover={{bg: "tomato", color: "white"}}/> <CloseButton onClick={() => DeleteWidget(id)} size="xs" _hover={{bg: "tomato", color: "white"}}/>
</Flex> </Flex>
</> </>
):( ):(
<> <>
<Text className="widget-handle" >{title}</Text> <Text className="widget-handle" fontWeight="bold">{title}</Text>
</> </>
)} )}
</chakra.div> </chakra.div>
@@ -81,7 +81,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
return ( return (
/* HEADER */ /* HEADER */
<Tabs.Root lazyMount defaultValue="my dashboard"> <Tabs.Root lazyMount defaultValue="my dashboard" size="lg">
<Flex <Flex
as="header" as="header"
position="sticky" position="sticky"
@@ -89,7 +89,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
zIndex="dropdown" // zIndex: 1100 zIndex="dropdown" // zIndex: 1100
bg="base200" bg="base200"
px={6} px={6}
py={3} pt={3}
align="center" align="center"
justify="space-between" justify="space-between"
> >
@@ -1,6 +1,7 @@
import { useSlotRecipe, Box, Button, IconButton } from "@chakra-ui/react"; import { useSlotRecipe, Box, Button, IconButton } from "@chakra-ui/react";
import { ColorModeButton } from "@/components/ui/color-mode"; import { ColorModeButton } from "@/components/ui/color-mode";
import { Tooltip } from "@/components/ui/tooltip"; // import { Tooltip } from "@/components/ui/tooltip";
import Tooltip from "../Canvas/components/Tooltip.jsx";
import { FaVolcano } from "react-icons/fa6"; import { FaVolcano } from "react-icons/fa6";
import { FaHome } from "react-icons/fa"; import { FaHome } from "react-icons/fa";
import { FaGlobeAmericas } from "react-icons/fa"; import { FaGlobeAmericas } from "react-icons/fa";
@@ -12,6 +13,8 @@ import { useState } from "react";
export default function Sidebar({ onChangeView }) { export default function Sidebar({ onChangeView }) {
const [isOpen, setIsOpen] = useState(true); const [isOpen, setIsOpen] = useState(true);
const [activeButton, setActiveButton] = useState(0) const [activeButton, setActiveButton] = useState(0)
const recipe = useSlotRecipe({ key: "sidebar" });
const styles = recipe();
// this list of btns will come from the db (not every usr will have access to admin) // this list of btns will come from the db (not every usr will have access to admin)
const buttons = [ const buttons = [
@@ -22,9 +25,6 @@ export default function Sidebar({ onChangeView }) {
{icon: HiUsers, name: "Admin", view: "admin"} {icon: HiUsers, name: "Admin", view: "admin"}
]; ];
const recipe = useSlotRecipe({ key: "sidebar" });
const styles = recipe();
const toggleSidebar = () => { const toggleSidebar = () => {
if (isOpen) setIsOpen(false); if (isOpen) setIsOpen(false);
else setIsOpen(true); else setIsOpen(true);
@@ -35,6 +35,7 @@ export default function Sidebar({ onChangeView }) {
css={styles.root} css={styles.root}
width={isOpen ? "210px" : "71px"} width={isOpen ? "210px" : "71px"}
transition="width 0.4s ease" transition="width 0.4s ease"
position="relative"
> >
<IconButton <IconButton
aria-label="Toggle Sidebar" aria-label="Toggle Sidebar"
@@ -48,9 +49,10 @@ export default function Sidebar({ onChangeView }) {
{buttons.map((button, idx) => { {buttons.map((button, idx) => {
const Icon = button.icon; const Icon = button.icon;
const buttonElement = ( return (
<Tooltip tooltipkeykey={idx} content={button.name} sidebarIsOpen={isOpen}>
<Button <Button
// key={idx} key={idx}
css={styles.buttons} css={styles.buttons}
onClick={() => { onClick={() => {
setActiveButton(idx); setActiveButton(idx);
@@ -61,7 +63,8 @@ export default function Sidebar({ onChangeView }) {
justifyContent="flex-start" justifyContent="flex-start"
> >
<Icon /> <Icon />
<span style={{ <span
style={{
opacity: isOpen ? 1 : 0, opacity: isOpen ? 1 : 0,
transition: "opacity 0.4s ease", transition: "opacity 0.4s ease",
overflow: "hidden", overflow: "hidden",
@@ -73,16 +76,8 @@ export default function Sidebar({ onChangeView }) {
{button.name} {button.name}
</span> </span>
</Button> </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> </Tooltip>
) : ( )
buttonElement
);
})} })}
<ColorModeButton position="absolute" bottom="2"/> <ColorModeButton position="absolute" bottom="2"/>
</Box> </Box>