mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-19 16:15:04 +00:00
tooltip updates + close on click / popover open
This commit is contained in:
1 parent
b2016dcfb9
commit
f81a215133
3 files changed
+112
-35
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useRef } from "react";
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
@@ -8,6 +8,7 @@ interface TooltipProps {
|
||||
position: "top" | "bottom" | "left" | "right";
|
||||
className?: string;
|
||||
delay?: number;
|
||||
closeOnClick?: boolean;
|
||||
}
|
||||
|
||||
export const Tooltip = ({
|
||||
@@ -16,11 +17,48 @@ export const Tooltip = ({
|
||||
position,
|
||||
className,
|
||||
delay = 300,
|
||||
closeOnClick = false,
|
||||
}: TooltipProps) => {
|
||||
const [isShowing, setIsShowing] = useState(false);
|
||||
const triggerRef = useRef<HTMLDivElement>(null);
|
||||
const tooltipRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const checkForOpenPopovers = () => {
|
||||
if (!triggerRef.current) return false;
|
||||
return (
|
||||
triggerRef.current.querySelectorAll('[data-headlessui-state="open"]')
|
||||
.length > 0
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (
|
||||
mutation.type === "attributes" &&
|
||||
mutation.attributeName === "data-headlessui-state"
|
||||
) {
|
||||
const target = mutation.target as HTMLElement;
|
||||
if (target.getAttribute("data-headlessui-state") === "open") {
|
||||
setIsShowing(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (triggerRef.current) {
|
||||
observer.observe(triggerRef.current, {
|
||||
attributes: true,
|
||||
subtree: true,
|
||||
attributeFilter: ["data-headlessui-state"],
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const getStyleForPosition = () => {
|
||||
if (triggerRef.current) {
|
||||
const rect = triggerRef.current.getBoundingClientRect();
|
||||
@@ -55,17 +93,34 @@ export const Tooltip = ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleClick = (e: React.MouseEvent) => {
|
||||
if (closeOnClick) {
|
||||
setIsShowing(false);
|
||||
e.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={triggerRef}
|
||||
onMouseEnter={() => setIsShowing(true)}
|
||||
onMouseLeave={() => setIsShowing(false)}
|
||||
onMouseEnter={() => {
|
||||
if (!checkForOpenPopovers()) {
|
||||
setIsShowing(true);
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
setIsShowing(false);
|
||||
}}
|
||||
onClick={handleClick}
|
||||
className="relative"
|
||||
>
|
||||
{children}
|
||||
<Transition
|
||||
show={isShowing}
|
||||
enter={`transition ease-out duration-200 delay-${delay}`}
|
||||
enter={twMerge(
|
||||
"transition ease-out duration-200",
|
||||
delay ? `delay-[${delay}ms]` : "delay-[300ms]",
|
||||
)}
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="transition ease-in duration-150"
|
||||
@@ -74,7 +129,13 @@ export const Tooltip = ({
|
||||
>
|
||||
<div
|
||||
ref={tooltipRef}
|
||||
style={getStyleForPosition()}
|
||||
style={{
|
||||
...getStyleForPosition(),
|
||||
transitionDelay: `${delay}ms`,
|
||||
transitionProperty: "opacity",
|
||||
transitionDuration: "200ms",
|
||||
transitionTimingFunction: "ease-out",
|
||||
}}
|
||||
className={twMerge(
|
||||
"pointer-events-none absolute z-10 w-max rounded-lg bg-[#5F5F68] px-2.5 py-1.5 text-sm font-medium text-white shadow-xl",
|
||||
className ? className : "",
|
||||
|
||||
@@ -11,7 +11,7 @@ export function Activity() {
|
||||
useSignals();
|
||||
|
||||
return (
|
||||
<Tooltip content="Activity" position="bottom">
|
||||
<Tooltip content="Activity" position="bottom" closeOnClick={true}>
|
||||
<PopoverMenu
|
||||
mode="default"
|
||||
buttonClassName="h-[38px] w-[38px] !p-0"
|
||||
|
||||
@@ -499,33 +499,48 @@ export const PromptBox = () => {
|
||||
</div>
|
||||
<div className="mt-2 flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<PopoverMenu
|
||||
items={aspectRatioList}
|
||||
onSelect={handleAspectRatioSelect}
|
||||
mode="toggle"
|
||||
panelTitle="Aspect Ratio"
|
||||
showIconsInList
|
||||
triggerIcon={
|
||||
<FontAwesomeIcon
|
||||
icon={getCurrentAspectRatioIcon()}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<PopoverMenu
|
||||
items={cameraList}
|
||||
onSelect={handleCameraSelect}
|
||||
onAdd={handleAddCamera}
|
||||
triggerIcon={
|
||||
<FontAwesomeIcon icon={faCamera} className="h-4 w-4" />
|
||||
}
|
||||
showAddButton
|
||||
showIconsInList
|
||||
mode="toggle"
|
||||
panelTitle="Camera"
|
||||
panelActionLabel="Settings"
|
||||
onPanelAction={() => setIsCameraSettingsOpen(true)}
|
||||
/>
|
||||
<Tooltip
|
||||
content="Aspect ratio"
|
||||
position="top"
|
||||
className="z-50"
|
||||
closeOnClick={true}
|
||||
>
|
||||
<PopoverMenu
|
||||
items={aspectRatioList}
|
||||
onSelect={handleAspectRatioSelect}
|
||||
mode="toggle"
|
||||
panelTitle="Aspect Ratio"
|
||||
showIconsInList
|
||||
triggerIcon={
|
||||
<FontAwesomeIcon
|
||||
icon={getCurrentAspectRatioIcon()}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
content="Camera"
|
||||
position="top"
|
||||
className="z-50"
|
||||
delay={500}
|
||||
closeOnClick={true}
|
||||
>
|
||||
<PopoverMenu
|
||||
items={cameraList}
|
||||
onSelect={handleCameraSelect}
|
||||
onAdd={handleAddCamera}
|
||||
triggerIcon={
|
||||
<FontAwesomeIcon icon={faCamera} className="h-4 w-4" />
|
||||
}
|
||||
showAddButton
|
||||
showIconsInList
|
||||
mode="toggle"
|
||||
panelTitle="Camera"
|
||||
panelActionLabel="Settings"
|
||||
onPanelAction={() => setIsCameraSettingsOpen(true)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
content={
|
||||
useSystemPrompt
|
||||
@@ -534,7 +549,7 @@ export const PromptBox = () => {
|
||||
}
|
||||
position="top"
|
||||
className="z-50"
|
||||
delay={100}
|
||||
delay={200}
|
||||
>
|
||||
<ToggleButton
|
||||
isActive={useSystemPrompt}
|
||||
@@ -549,7 +564,8 @@ export const PromptBox = () => {
|
||||
content="Download frame"
|
||||
position="top"
|
||||
className="z-50"
|
||||
delay={100}
|
||||
closeOnClick={true}
|
||||
delay={200}
|
||||
>
|
||||
<Button
|
||||
className="flex h-9 items-center border-none bg-[#5F5F68]/60 px-3 text-sm text-white backdrop-blur-lg hover:bg-[#5F5F68]/90"
|
||||
|
||||
Reference in new issue
Block a user