Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Results: the AI-generated tag is a small info tip

Adarsh379a8cd6ce26
diff --git a/src/components/studio/ai-tag.tsx b/src/components/studio/ai-tag.tsx
index 50a82fc8..6311a0a2 100644
--- a/src/components/studio/ai-tag.tsx
+++ b/src/components/studio/ai-tag.tsx
@@ -1,10 +1,12 @@
"use client";
+import { Info } from "lucide-react";
+import { useEffect, useRef, useState } from "react";
import { useHydrated, useStatus } from "@/lib/api";
import { cn } from "@/lib/utils";
/**
- * Results carry an "AI-generated" tag where this studio runs visitors' work on its own GPUs (hosted runs on). With
+ * Results carry an "AI-generated" tip where this studio runs visitors' work on its own GPUs (hosted runs on). With
* hosted runs off, nothing new shows.
*/
export function useAiTag(): boolean {
@@ -14,11 +16,53 @@ export function useAiTag(): boolean {
return hydrated && hosted;
}
-/** The tag itself: a small label over a picture or a clip. */
-export function AiTag({ className }: { className?: string }) {
+export const AI_TAG_WORDS = "AI-generated";
+
+/**
+ * The tip itself: a small info icon that says "AI-generated" on hover, on keyboard focus and on tap. The outermost
+ * element carries `data-ai-tag` and holds the tooltip too (no portal), so one `[data-ai-tag]` rule covers all of it.
+ * The wrapper lets clicks through; the icon's own click stays on it. `tone`: over a picture ("media") or on the page.
+ */
+export function AiTag({ className, tone = "media" }: { className?: string; tone?: "media" | "surface" }) {
+ const [open, setOpen] = useState(false);
+ const ref = useRef<HTMLSpanElement>(null);
+ // A tap elsewhere, or Escape, closes a tip opened by a tap.
+ useEffect(() => {
+ if (!open) return;
+ const away = (e: PointerEvent) => !ref.current?.contains(e.target as Node) && setOpen(false);
+ const esc = (e: KeyboardEvent) => e.key === "Escape" && setOpen(false);
+ document.addEventListener("pointerdown", away);
+ document.addEventListener("keydown", esc);
+ return () => {
+ document.removeEventListener("pointerdown", away);
+ document.removeEventListener("keydown", esc);
+ };
+ }, [open]);
return (
- <span data-ai-tag className={cn("pointer-events-none rounded-full bg-black/55 px-2 py-0.5 text-[10.5px] font-medium text-white backdrop-blur", className)}>
- AI-generated
+ <span ref={ref} data-ai-tag className={cn("pointer-events-none relative inline-flex items-center", className)}>
+ <button
+ type="button"
+ aria-label={AI_TAG_WORDS}
+ onClick={(e) => {
+ e.stopPropagation();
+ setOpen((o) => !o);
+ }}
+ className={cn(
+ "peer pointer-events-auto grid size-5 shrink-0 cursor-help place-items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring",
+ tone === "media" ? "bg-black/45 text-white/90 backdrop-blur hover:bg-black/65" : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ <Info aria-hidden className="size-3.5" />
+ </button>
+ <span
+ aria-hidden
+ className={cn(
+ "pointer-events-none absolute top-1/2 left-full ml-1.5 -translate-y-1/2 rounded-md bg-foreground px-2 py-0.5 text-[11px] font-medium whitespace-nowrap text-background opacity-0 transition-opacity peer-hover:opacity-100 peer-focus-visible:opacity-100",
+ open && "opacity-100",
+ )}
+ >
+ {AI_TAG_WORDS}
+ </span>
</span>
);
}
diff --git a/src/components/studio/feed.tsx b/src/components/studio/feed.tsx
index e33ddb57..9b69967c 100644
--- a/src/components/studio/feed.tsx
+++ b/src/components/studio/feed.tsx
@@ -426,7 +426,7 @@ interface FeedApi {
retry: (g: Generation) => void;
runner: RunnerOptions;
reuse?: (g: Generation) => void;
- /** Pictures and clips carry an "AI-generated" tag (hosted runs on). */
+ /** Pictures and clips carry an "AI-generated" tip (hosted runs on). */
aiTag?: boolean;
}
@@ -494,7 +494,10 @@ const OutputTile = memo(function OutputTile({ g, index, ratio, layered, count }:
className={cn("absolute", o.kind === "text" ? "bottom-2" : o.draftId ? "top-11" : "top-2", audio && canHover && "group-focus-within/tile:opacity-0 group-hover/tile:opacity-0 focus-within:opacity-100! has-data-[state=open]:opacity-100!")}
/>
{g.favorite && <Heart className={cn("absolute top-2 right-2 size-4 fill-highlight text-highlight drop-shadow", audio && canHover && "group-focus-within/tile:opacity-0 group-hover/tile:opacity-0")} />}
- {feed.aiTag && (o.kind === "image" || o.kind === "video") && <AiTag className={cn("absolute bottom-2 left-2", canHover && "transition-opacity group-focus-within/tile:opacity-0 group-hover/tile:opacity-0")} />}
+ {feed.aiTag && (o.kind === "image" || o.kind === "video") && (
+ // Above the action bar while it shows, so the tip stays in reach.
+ <AiTag className={cn("absolute bottom-2 left-2 z-10", canHover && "transition-transform group-focus-within/tile:-translate-y-10 group-hover/tile:-translate-y-10")} />
+ )}
{canHover && hot === "bar" && (
<TileActions
g={g}
diff --git a/src/components/studio/viewer.tsx b/src/components/studio/viewer.tsx
index 9a15dc6f..f992a0a5 100644
--- a/src/components/studio/viewer.tsx
+++ b/src/components/studio/viewer.tsx
@@ -84,7 +84,7 @@ function Details({ g, index }: { g: Generation; index: number }) {
<div className="space-y-4">
<div>
<p className="font-heading text-[20px] leading-snug">{title}</p>
- {aiTag && <AiTag className="mt-1.5 inline-block bg-muted text-muted-foreground backdrop-blur-none" />}
+ {aiTag && <AiTag tone="surface" className="mt-1" />}
{g.prompt && g.prompt !== title && <p className="mt-1 line-clamp-6 text-[12px] leading-relaxed break-words text-muted-foreground">{g.modelId === "local-motion" ? "Words" : "Sent to the model"}: {g.prompt}</p>}
{g.prompt && (
<button
diff --git a/tests/hosted-run-tiles.test.ts b/tests/hosted-run-tiles.test.ts
index ee7d9098..6d629e65 100644
--- a/tests/hosted-run-tiles.test.ts
+++ b/tests/hosted-run-tiles.test.ts
@@ -6,7 +6,7 @@ import type { Generation } from "@/lib/catalog/types";
/*
* A run's tile on this studio's GPUs (hosted runs): "In line" with its place and wait (again after any recovery, its
- * place kept), "Working" with its progress, then the result with an "AI-generated" tag, or one plain sentence when it
+ * place kept), "Working" with its progress, then the result with an "AI-generated" info tip, or one plain sentence when it
* can't finish. Every other run's tiles render as before.
*/
@@ -111,8 +111,17 @@ describe("a run's tile on this studio's GPUs", () => {
expect(failed).toContain("Couldn&#x27;t generate this one");
expect(failed).toContain("Your ComfyUI answered HTTP 500.");
});
- it("the AI-generated tag", () => {
- expect(render(createElement(AiTag))).toContain("AI-generated");
+ it("the AI-generated tag: a small info icon whose tooltip says so, all inside [data-ai-tag]", () => {
+ const html = render(createElement(AiTag));
+ // The outermost element carries data-ai-tag, so hiding [data-ai-tag] hides the icon and its tooltip.
+ expect(html).toMatch(/^<span data-ai-tag="true" class="[^"]*pointer-events-none/);
+ expect(html.match(/data-ai-tag/g)).toHaveLength(1);
+ expect(html).toMatch(/<button type="button" aria-label="AI-generated" class="[^"]*pointer-events-auto/);
+ expect(html).toContain("lucide-info");
+ // The tooltip's words sit inside the same element, shown on hover and keyboard focus.
+ expect(html).toMatch(/<span aria-hidden="true" class="[^"]*peer-hover:opacity-100[^"]*peer-focus-visible:opacity-100[^"]*">AI-generated<\/span><\/span>$/);
+ expect(html).not.toContain("rounded-full bg-black/55 px-2");
+ expect(render(createElement(AiTag, { tone: "surface" }))).toContain("text-muted-foreground");
});
});