35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { useCanvasGraphContext } from "../../contexts/CanvasGraphContext";
|
|
import { useCanvasQuickActions } from "../../hooks/useCanvasQuickActions";
|
|
import type { QuickAction } from "../../types/quick-action";
|
|
import { getCurrentArtifactContent, isCodeArtifact } from "../../utils/artifact";
|
|
import { QUICK_ACTIONS_CODE, QUICK_ACTIONS_TEXT } from "../../constants";
|
|
|
|
export function CanvasQuickActionBar() {
|
|
const { artifact, isStreaming } = useCanvasGraphContext();
|
|
const { triggerQuickAction } = useCanvasQuickActions();
|
|
|
|
const content = getCurrentArtifactContent(artifact);
|
|
if (!content) return null;
|
|
|
|
const actions: QuickAction[] = isCodeArtifact(content)
|
|
? QUICK_ACTIONS_CODE
|
|
: QUICK_ACTIONS_TEXT;
|
|
|
|
return (
|
|
<div className="border-b px-4 py-1.5 flex items-center gap-1.5 flex-wrap shrink-0 bg-background">
|
|
{actions.map((action) => (
|
|
<button
|
|
key={action.id}
|
|
disabled={isStreaming}
|
|
onClick={() => void triggerQuickAction(action.id)}
|
|
className="inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-medium transition-colors
|
|
bg-background text-foreground hover:bg-accent hover:text-accent-foreground
|
|
disabled:opacity-40 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
>
|
|
{action.label}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|