Skip to content

The Open Standard for Generative UI

feat: Enhance CopilotShell and Shell components with artifact panel support (#223)

Shivam Budhiad180ee6dea25
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.json
index 70b55af3b..671a2898e 100644
--- a/js/packages/react-ui/package.json
+++ b/js/packages/react-ui/package.json
@@ -2,7 +2,7 @@
"type": "module",
"name": "@crayonai/react-ui",
"license": "MIT",
- "version": "0.8.43",
+ "version": "0.9.0",
"description": "Component library for Generative UI SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/js/packages/react-ui/src/components/CopilotShell/Thread.tsx b/js/packages/react-ui/src/components/CopilotShell/Thread.tsx
index f3cf94ef5..f53a403bb 100644
--- a/js/packages/react-ui/src/components/CopilotShell/Thread.tsx
+++ b/js/packages/react-ui/src/components/CopilotShell/Thread.tsx
@@ -7,19 +7,34 @@ import {
} from "@crayonai/react-core";
import clsx from "clsx";
import { ArrowRight, Square } from "lucide-react";
-import React, { memo, useLayoutEffect, useRef } from "react";
+import React, { memo, useEffect, useLayoutEffect, useRef } from "react";
import { useComposerState } from "../../hooks/useComposerState";
import { ScrollVariant, useScrollToBottom } from "../../hooks/useScrollToBottom";
import { IconButton } from "../IconButton";
import { MessageLoading as MessageLoadingComponent } from "../MessageLoading";
+import { useShellStore } from "../Shell/store";
export const ThreadContainer = ({
children,
className,
+ isArtifactActive = false,
+ renderArtifact = () => null,
}: {
children?: React.ReactNode;
className?: string;
+ isArtifactActive?: boolean;
+ renderArtifact?: () => React.ReactNode;
}) => {
+ const { setIsArtifactActive, setArtifactRenderer } = useShellStore((state) => ({
+ setIsArtifactActive: state.setIsArtifactActive,
+ setArtifactRenderer: state.setArtifactRenderer,
+ }));
+
+ useEffect(() => {
+ setIsArtifactActive(isArtifactActive);
+ setArtifactRenderer(renderArtifact);
+ }, [isArtifactActive, setIsArtifactActive]);
+
return <div className={clsx("crayon-copilot-shell-thread-container", className)}>{children}</div>;
};
@@ -41,7 +56,12 @@ export const ScrollArea = ({
userMessageSelector?: string;
}) => {
const ref = useRef<HTMLDivElement>(null);
+
const { messages, isRunning, isLoadingMessages } = useThreadState();
+ const { isArtifactActive, artifactRenderer } = useShellStore((store) => ({
+ isArtifactActive: store.isArtifactActive,
+ artifactRenderer: store.artifactRenderer,
+ }));
useScrollToBottom({
ref,
@@ -53,18 +73,25 @@ export const ScrollArea = ({
});
return (
- <div
- ref={ref}
- className={clsx(
- "crayon-copilot-shell-thread-scroll-area",
- {
- "crayon-copilot-shell-thread-scroll-area--user-message-anchor":
- scrollVariant === "user-message-anchor",
- },
- className,
+ <div className="crayon-copilot-shell-thread-scroll-container">
+ <div
+ ref={ref}
+ className={clsx(
+ "crayon-copilot-shell-thread-scroll-area",
+ {
+ "crayon-copilot-shell-thread-scroll-area--user-message-anchor":
+ scrollVariant === "user-message-anchor",
+ },
+ className,
+ )}
+ >
+ {children}
+ </div>
+ {isArtifactActive && (
+ <div className="crayon-copilot-shell-thread-artifact-panel--mobile">
+ {artifactRenderer()}
+ </div>
)}
- >
- {children}
</div>
);
};
diff --git a/js/packages/react-ui/src/components/CopilotShell/thread.scss b/js/packages/react-ui/src/components/CopilotShell/thread.scss
index 2e5d423c0..de452a517 100644
--- a/js/packages/react-ui/src/components/CopilotShell/thread.scss
+++ b/js/packages/react-ui/src/components/CopilotShell/thread.scss
@@ -1,15 +1,22 @@
@use "../../cssUtils" as cssUtils;
.crayon-copilot-shell-thread-container {
+ display: flex;
flex: 1;
overflow: hidden;
- display: flex;
flex-direction: column;
}
-.crayon-copilot-shell-thread-scroll-area {
+.crayon-copilot-shell-thread-scroll-container {
width: 100%;
flex: 1;
+ position: relative;
+ overflow: hidden;
+}
+
+.crayon-copilot-shell-thread-scroll-area {
+ width: 100%;
+ height: 100%;
overflow: auto;
padding: cssUtils.$spacing-l;
&--user-message-anchor {
@@ -19,6 +26,29 @@
}
}
+// Artifact panel (overlay style)
+.crayon-copilot-shell-thread-artifact-panel--mobile {
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ z-index: 10;
+ background-color: cssUtils.$bg-container;
+ animation: slideInFromBottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
+}
+
+@keyframes slideInFromBottom {
+ from {
+ opacity: 0;
+ transform: translateY(20px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
+
.crayon-copilot-shell-thread-messages {
margin: 0 auto;
display: flex;
diff --git a/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx b/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx
index 8d702d127..2957757e8 100644
--- a/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx
+++ b/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx
@@ -13,6 +13,8 @@ interface ComposedCopilotProps {
agentName?: string;
messageLoadingComponent?: () => React.ReactNode;
scrollVariant: ScrollVariant;
+ isArtifactActive?: boolean;
+ renderArtifact?: () => React.ReactNode;
}
export const ComposedCopilot = ({
@@ -20,10 +22,12 @@ export const ComposedCopilot = ({
agentName = "My Agent",
messageLoadingComponent: MessageLoadingComponent = MessageLoading,
scrollVariant,
+ isArtifactActive,
+ renderArtifact,
}: ComposedCopilotProps) => {
return (
<Container logoUrl={logoUrl} agentName={agentName}>
- <ThreadContainer>
+ <ThreadContainer isArtifactActive={isArtifactActive} renderArtifact={renderArtifact}>
<Header />
<ScrollArea scrollVariant={scrollVariant}>
<Messages loader={<MessageLoadingComponent />} />
diff --git a/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx b/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx
index 4d8b697dd..83293a30c 100644
--- a/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx
+++ b/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx
@@ -19,6 +19,8 @@ interface ComposedStandaloneProps {
agentName?: string;
messageLoadingComponent?: () => React.ReactNode;
scrollVariant: ScrollVariant;
+ isArtifactActive?: boolean;
+ renderArtifact?: () => React.ReactNode;
}
export const ComposedStandalone = ({
@@ -26,6 +28,8 @@ export const ComposedStandalone = ({
agentName = "My Agent",
messageLoadingComponent: MessageLoadingComponent = MessageLoading,
scrollVariant,
+ isArtifactActive,
+ renderArtifact,
}: ComposedStandaloneProps) => {
return (
<Container logoUrl={logoUrl} agentName={agentName}>
@@ -37,7 +41,7 @@ export const ComposedStandalone = ({
<ThreadList />
</SidebarContent>
</SidebarContainer>
- <ThreadContainer>
+ <ThreadContainer isArtifactActive={isArtifactActive} renderArtifact={renderArtifact}>
<MobileHeader />
<ScrollArea scrollVariant={scrollVariant}>
<Messages loader={<MessageLoadingComponent />} />
diff --git a/js/packages/react-ui/src/components/CrayonChat/CrayonChat.tsx b/js/packages/react-ui/src/components/CrayonChat/CrayonChat.tsx
index 8f6333f74..bfbbe2d16 100644
--- a/js/packages/react-ui/src/components/CrayonChat/CrayonChat.tsx
+++ b/js/packages/react-ui/src/components/CrayonChat/CrayonChat.tsx
@@ -44,6 +44,9 @@ type CrayonChatProps = {
messageLoadingComponent?: () => React.ReactNode;
disableThemeProvider?: boolean;
+
+ isArtifactActive?: boolean;
+ renderArtifact?: () => React.ReactNode;
};
const DummyThemeProvider = ({ children }: { children: React.ReactNode }) => {
@@ -65,6 +68,8 @@ export const CrayonChat = ({
theme,
scrollVariant = "user-message-anchor",
disableThemeProvider,
+ isArtifactActive,
+ renderArtifact,
}: CrayonChatProps) => {
invariant(processMessage || userThreadManager, "processMessage or threadManager is required");
const ThemeProviderComponent = disableThemeProvider ? DummyThemeProvider : ThemeProvider;
@@ -148,6 +153,8 @@ export const CrayonChat = ({
agentName={agentName}
messageLoadingComponent={messageLoadingComponent}
scrollVariant={scrollVariant}
+ isArtifactActive={isArtifactActive}
+ renderArtifact={renderArtifact}
/>
) : (
<ComposedStandalone
@@ -155,6 +162,8 @@ export const CrayonChat = ({
agentName={agentName}
messageLoadingComponent={messageLoadingComponent}
scrollVariant={scrollVariant}
+ isArtifactActive={isArtifactActive}
+ renderArtifact={renderArtifact}
/>
)}
</ChatProvider>
diff --git a/js/packages/react-ui/src/components/Shell/ResizableSeparator.tsx b/js/packages/react-ui/src/components/Shell/ResizableSeparator.tsx
new file mode 100644
index 000000000..cc5a1bada
--- /dev/null
+++ b/js/packages/react-ui/src/components/Shell/ResizableSeparator.tsx
@@ -0,0 +1,77 @@
+import clsx from "clsx";
+import { useEffect, useRef } from "react";
+
+interface ResizableSeparatorProps {
+ onResize: (clientX: number) => void;
+ onDragStart: () => void;
+ onDragEnd: () => void;
+ className?: string;
+}
+
+/**
+ * A draggable vertical separator for resizing panels.
+ * Used between chat and artifact panels in desktop mode.
+ */
+export const ResizableSeparator = ({
+ onResize,
+ onDragStart,
+ onDragEnd,
+ className,
+}: ResizableSeparatorProps) => {
+ const isDraggingRef = useRef(false);
+ const onResizeRef = useRef(onResize);
+ const onDragStartRef = useRef(onDragStart);
+ const onDragEndRef = useRef(onDragEnd);
+
+ // Keep callback refs up to date without triggering effect re-runs
+ useEffect(() => {
+ onResizeRef.current = onResize;
+ onDragStartRef.current = onDragStart;
+ onDragEndRef.current = onDragEnd;
+ }, [onResize, onDragStart, onDragEnd]);
+
+ // Global mouse event handlers for drag behavior
+ // Uses refs instead of dependencies to avoid re-creating listeners
+ useEffect(() => {
+ const handleMouseMove = (e: MouseEvent) => {
+ if (isDraggingRef.current) {
+ e.preventDefault();
+ onResizeRef.current(e.clientX);
+ }
+ };
+
+ const handleMouseUp = () => {
+ if (isDraggingRef.current) {
+ isDraggingRef.current = false;
+ onDragEndRef.current();
+ // Reset cursor styles
+ document.body.style.cursor = "";
+ document.body.style.userSelect = "";
+ }
+ };
+
+ document.addEventListener("mousemove", handleMouseMove);
+ document.addEventListener("mouseup", handleMouseUp);
+
+ return () => {
+ document.removeEventListener("mousemove", handleMouseMove);
+ document.removeEventListener("mouseup", handleMouseUp);
+ };
+ }, []); // Empty deps - handlers use refs to access latest callbacks
+
+ const handleMouseDown = () => {
+ isDraggingRef.current = true;
+ onDragStartRef.current();
+ document.body.style.cursor = "col-resize";
+ document.body.style.userSelect = "none";
+ };
+
+ return (
+ <div
+ className={clsx("crayon-shell-resizable-separator", className)}
+ onMouseDown={handleMouseDown}
+ >
+ <div className="crayon-shell-resizable-separator__handle" />
+ </div>
+ );
+};
diff --git a/js/packages/react-ui/src/components/Shell/Sidebar.tsx b/js/packages/react-ui/src/components/Shell/Sidebar.tsx
index eb9bb0a4b..f617e0563 100644
--- a/js/packages/react-ui/src/components/Shell/Sidebar.tsx
+++ b/js/packages/react-ui/src/components/Shell/Sidebar.tsx
@@ -12,12 +12,12 @@ export const SidebarContainer = ({
children?: React.ReactNode;
className?: string;
}) => {
- const { isSidebarOpen, setIsSidebarOpen } = useShellStore((state) => ({
+ const { isSidebarOpen, setIsSidebarOpen, isArtifactActive } = useShellStore((state) => ({
isSidebarOpen: state.isSidebarOpen,
setIsSidebarOpen: state.setIsSidebarOpen,
+ isArtifactActive: state.isArtifactActive,
}));
const { layout } = useLayoutContext() || {};
-
const isMobile = layout === "mobile";
useEffect(() => {
@@ -45,6 +45,7 @@ export const SidebarContainer = ({
"crayon-shell-sidebar-container",
{
"crayon-shell-sidebar-container--collapsed": !isSidebarOpen,
+ "crayon-shell-sidebar-container--hidden": isArtifactActive && !isMobile,
},
className,
)}
@@ -91,11 +92,15 @@ export const SidebarContent = ({
isSidebarOpen: state.isSidebarOpen,
}));
- if (!isSidebarOpen) {
- return null;
- }
-
- return <div className={clsx("crayon-shell-sidebar-content", className)}>{children}</div>;
+ return (
+ <div
+ className={clsx("crayon-shell-sidebar-content", className, {
+ "crayon-shell-sidebar-content--collapsed": !isSidebarOpen,
+ })}
+ >
+ {children}
+ </div>
+ );
};
export const SidebarSeparator = () => {
diff --git a/js/packages/react-ui/src/components/Shell/Thread.tsx b/js/packages/react-ui/src/components/Shell/Thread.tsx
index 1a7c9a034..486d73f09 100644
--- a/js/packages/react-ui/src/components/Shell/Thread.tsx
+++ b/js/packages/react-ui/src/components/Shell/Thread.tsx
@@ -7,21 +7,95 @@ import {
} from "@crayonai/react-core";
import clsx from "clsx";
import { ArrowRight, Square } from "lucide-react";
-import React, { memo, useLayoutEffect, useRef } from "react";
+import React, { memo, useEffect, useLayoutEffect, useRef } from "react";
+import { useLayoutContext } from "../../context/LayoutContext";
import { useComposerState } from "../../hooks/useComposerState";
import { ScrollVariant, useScrollToBottom } from "../../hooks/useScrollToBottom";
import { IconButton } from "../IconButton";
import { MessageLoading as MessageLoadingComponent } from "../MessageLoading";
+import { ResizableSeparator } from "./ResizableSeparator";
import { useShellStore } from "./store";
+import { useArtifactResize } from "./useArtifactResize";
export const ThreadContainer = ({
children,
className,
+ isArtifactActive = false,
+ renderArtifact = () => null,
}: {
children?: React.ReactNode;
className?: string;
+ isArtifactActive?: boolean;
+ renderArtifact?: () => React.ReactNode;
}) => {
- return <div className={clsx("crayon-shell-thread-container", className)}>{children}</div>;
+ const { layout } = useLayoutContext();
+ const isMobile = layout === "mobile";
+
+ const { setIsSidebarOpen, setIsArtifactActive, setArtifactRenderer } = useShellStore((state) => ({
+ setIsSidebarOpen: state.setIsSidebarOpen,
+ setIsArtifactActive: state.setIsArtifactActive,
+ setArtifactRenderer: state.setArtifactRenderer,
+ }));
+
+ // Sync artifact state and renderer with store
+ useEffect(() => {
+ setIsArtifactActive(isArtifactActive);
+ setArtifactRenderer(renderArtifact);
+ }, [isArtifactActive, renderArtifact, setIsArtifactActive, setArtifactRenderer]);
+
+ // Desktop-only: Handle resize logic for artifact panel
+ const {
+ containerRef,
+ chatPanelRef,
+ artifactPanelRef,
+ isDragging,
+ handleResize,
+ handleDragStart,
+ handleDragEnd,
+ } = useArtifactResize({
+ isArtifactActive,
+ isMobile,
+ setIsSidebarOpen,
+ });
+
+ return (
+ <div
+ className={clsx("crayon-shell-thread-container", className, {
+ "crayon-shell-thread-container--artifact-active": isArtifactActive,
+ })}
+ >
+ <div className="crayon-shell-thread-wrapper" ref={containerRef}>
+ {/* Chat panel - always visible */}
+ <div
+ ref={chatPanelRef}
+ className={clsx("crayon-shell-thread-chat-panel", {
+ "crayon-shell-thread-chat-panel--animating": !isDragging,
+ })}
+ >
+ {children}
+ </div>
+
+ {/* Desktop only: Resizable separator and artifact panel */}
+ {!isMobile && isArtifactActive && (
+ <>
+ <ResizableSeparator
+ onResize={handleResize}
+ onDragStart={handleDragStart}
+ onDragEnd={handleDragEnd}
+ />
+ <div
+ ref={artifactPanelRef}
+ className={clsx("crayon-shell-thread-artifact-panel", {
+ "crayon-shell-thread-artifact-panel--animating": !isDragging,
+ })}
+ >
+ {renderArtifact?.()}
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+ );
};
export const ScrollArea = ({
@@ -42,7 +116,14 @@ export const ScrollArea = ({
userMessageSelector?: string;
}) => {
const ref = useRef<HTMLDivElement>(null);
+ const { layout } = useLayoutContext();
+ const isMobile = layout === "mobile";
+
const { messages, isRunning, isLoadingMessages } = useThreadState();
+ const { isArtifactActive, artifactRenderer } = useShellStore((store) => ({
+ isArtifactActive: store.isArtifactActive,
+ artifactRenderer: store.artifactRenderer,
+ }));
useScrollToBottom({
ref,
@@ -54,18 +135,23 @@ export const ScrollArea = ({
});
return (
- <div
- ref={ref}
- className={clsx(
- "crayon-shell-thread-scroll-area",
- {
- "crayon-shell-thread-scroll-area--user-message-anchor":
- scrollVariant === "user-message-anchor",
- },
- className,
+ <div className="crayon-shell-thread-scroll-container">
+ <div
+ ref={ref}
+ className={clsx(
+ "crayon-shell-thread-scroll-area",
+ {
+ "crayon-shell-thread-scroll-area--user-message-anchor":
+ scrollVariant === "user-message-anchor",
+ },
+ className,
+ )}
+ >
+ {children}
+ </div>
+ {isMobile && isArtifactActive && (
+ <div className="crayon-shell-thread-artifact-panel--mobile">{artifactRenderer()}</div>
)}
- >
- {children}
</div>
);
};
diff --git a/js/packages/react-ui/src/components/Shell/resizableSeparator.scss b/js/packages/react-ui/src/components/Shell/resizableSeparator.scss
new file mode 100644
index 000000000..830386607
--- /dev/null
+++ b/js/packages/react-ui/src/components/Shell/resizableSeparator.scss
@@ -0,0 +1,53 @@
+@use "../../cssUtils" as cssUtils;
+
+.crayon-shell-resizable-separator {
+ width: 1px;
+ background-color: cssUtils.$stroke-default;
+ cursor: col-resize;
+ position: relative;
+ flex-shrink: 0;
+ user-select: none;
+ animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
+
+ // Wider invisible hit area for easier grabbing
+ &::before {
+ content: "";
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: -8px;
+ right: -8px;
+ cursor: col-resize;
+ }
+
+ &:hover {
+ background-color: cssUtils.$stroke-emphasis;
+ }
+
+ &:hover &__handle {
+ opacity: 1;
+ }
+
+ &__handle {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ width: 4px;
+ height: 40px;
+ background-color: cssUtils.$stroke-emphasis;
+ border-radius: cssUtils.$rounded-full;
+ opacity: 0;
+ transition: opacity 0.2s ease-in-out;
+ pointer-events: none;
+ }
+}
+
+@keyframes fadeIn {
+ from {
+ opacity: 0;
+ }
+ to {
+ opacity: 1;
+ }
+}
diff --git a/js/packages/react-ui/src/components/Shell/shell.scss b/js/packages/react-ui/src/components/Shell/shell.scss
index 78bce57f6..6fa3ced8c 100644
--- a/js/packages/react-ui/src/components/Shell/shell.scss
+++ b/js/packages/react-ui/src/components/Shell/shell.scss
@@ -3,6 +3,7 @@
@use "./threadlist.scss";
@use "./thread.scss";
@use "./mobileHeader.scss";
+@use "./resizableSeparator.scss";
.crayon-shell-container {
display: flex;
diff --git a/js/packages/react-ui/src/components/Shell/sidebar.scss b/js/packages/react-ui/src/components/Shell/sidebar.scss
index 6b171827a..e68e3f52e 100644
--- a/js/packages/react-ui/src/components/Shell/sidebar.scss
+++ b/js/packages/react-ui/src/components/Shell/sidebar.scss
@@ -15,6 +15,11 @@ $sidebar-mobile-padding: cssUtils.$spacing-l;
display: flex;
flex-direction: column;
gap: cssUtils.$spacing-m;
+ z-index: 999;
+ transition:
+ width 0.4s ease-in-out,
+ height 0.4s ease-in-out,
+ transform 0.4s ease-in-out;
.crayon-shell-container--mobile & {
width: $sidebar-mobile-width;
@@ -29,16 +34,22 @@ $sidebar-mobile-padding: cssUtils.$spacing-l;
}
&--collapsed {
- width: auto;
+ width: 104px; // Fixed width for collapsed state (logo:36px + button:40px + gaps:12px + padding:16px)
height: min-content;
- position: absolute;
+ transform: translateX(0);
+ gap: 0;
.crayon-shell-container--mobile & {
width: $sidebar-mobile-width;
height: 100%;
left: -$sidebar-mobile-width;
+ transform: none; // Reset transform for mobile
}
}
+
+ &--hidden {
+ display: none;
+ }
}
.crayon-shell-sidebar-header {
@@ -74,6 +85,18 @@ $sidebar-mobile-padding: cssUtils.$spacing-l;
flex-direction: column;
gap: cssUtils.$spacing-m;
overflow: hidden;
+ opacity: 1;
+ transition:
+ opacity 0.2s ease-in-out 0.3s,
+ display 0.4s 0.5s;
+
+ &--collapsed {
+ opacity: 0;
+ display: none;
+ transition:
+ opacity 0.2s ease-in-out,
+ display 0s 0.5s; // Delay display:none until after transitions complete
+ }
}
.crayon-shell-sidebar-separator {
@@ -96,6 +119,7 @@ $sidebar-mobile-padding: cssUtils.$spacing-l;
height: 100%;
background-color: cssUtils.$bg-overlay;
transition: opacity 0.3s ease-in-out;
+ z-index: 99;
&--collapsed {
opacity: 0;
diff --git a/js/packages/react-ui/src/components/Shell/store.tsx b/js/packages/react-ui/src/components/Shell/store.tsx
index 07c35042f..4d5e0a6e7 100644
--- a/js/packages/react-ui/src/components/Shell/store.tsx
+++ b/js/packages/react-ui/src/components/Shell/store.tsx
@@ -6,9 +6,13 @@ interface ShellState {
isSidebarOpen: boolean;
agentName: string;
logoUrl: string;
+ isArtifactActive: boolean;
+ artifactRenderer: () => React.ReactNode;
setIsSidebarOpen: (isOpen: boolean) => void;
setAgentName: (name: string) => void;
setLogoUrl: (url: string) => void;
+ setIsArtifactActive: (isActive: boolean) => void;
+ setArtifactRenderer: (renderer: () => React.ReactNode) => void;
}
export const createShellStore = ({ logoUrl, agentName }: { logoUrl: string; agentName: string }) =>
@@ -16,10 +20,13 @@ export const createShellStore = ({ logoUrl, agentName }: { logoUrl: string; agen
isSidebarOpen: true,
agentName: agentName,
logoUrl: logoUrl,
-
+ isArtifactActive: false,
+ artifactRenderer: () => null,
setIsSidebarOpen: (isOpen: boolean) => set({ isSidebarOpen: isOpen }),
setAgentName: (name: string) => set({ agentName: name }),
setLogoUrl: (url: string) => set({ logoUrl: url }),
+ setIsArtifactActive: (isActive: boolean) => set({ isArtifactActive: isActive }),
+ setArtifactRenderer: (renderer: () => React.ReactNode) => set({ artifactRenderer: renderer }),
}));
export const ShellStoreContext = createContext<ReturnType<typeof createShellStore> | null>(null);
diff --git a/js/packages/react-ui/src/components/Shell/thread.scss b/js/packages/react-ui/src/components/Shell/thread.scss
index 8d0a23ef4..9a991d3b4 100644
--- a/js/packages/react-ui/src/components/Shell/thread.scss
+++ b/js/packages/react-ui/src/components/Shell/thread.scss
@@ -1,5 +1,12 @@
@use "../../cssUtils" as cssUtils;
+// =============================================================================
+// Thread Layout Structure
+// =============================================================================
+// The thread container uses a flexbox layout that supports both:
+// 1. Desktop: Resizable side-by-side chat and artifact panels
+// 2. Mobile: Full-width chat with absolute-positioned artifact overlay
+
.crayon-shell-thread-container {
flex: 1;
overflow: hidden;
@@ -7,11 +14,99 @@
flex-direction: column;
}
+// Wrapper for horizontal layout (chat + separator + artifact)
+.crayon-shell-thread-wrapper {
+ flex: 1;
+ display: flex;
+ overflow: hidden;
+ height: 100%;
+}
+
+// Chat panel (left side on desktop, full-width when no artifact)
+.crayon-shell-thread-chat-panel {
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+ height: 100%;
+ min-width: 360px;
+ flex-shrink: 0;
+ position: relative;
+
+ &--animating {
+ transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+}
+
+// Artifact panel (right side on desktop, fills remaining space)
+.crayon-shell-thread-artifact-panel {
+ display: flex;
+ flex-direction: column;
+ overflow: auto;
+ height: 100%;
+ flex: 1; // Fills remaining space after chat panel
+ min-width: 0;
+ background-color: cssUtils.$bg-container;
+ animation: slideInFromRight 0.5s cubic-bezier(0.4, 0, 0.2, 1);
+
+ &--animating {
+ transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
+ }
+}
+
+// Mobile artifact panel (absolute overlay)
+.crayon-shell-thread-artifact-panel--mobile {
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ z-index: 10;
+ animation: slideInFromBottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
+}
+
+// =============================================================================
+// Animations
+// =============================================================================
+
+@keyframes slideInFromRight {
+ from {
+ opacity: 0;
+ transform: translateX(20px);
+ }
+ to {
+ opacity: 1;
+ transform: translateX(0);
+ }
+}
+
+@keyframes slideInFromBottom {
+ from {
+ opacity: 0;
+ transform: translateY(20px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
+
+// =============================================================================
+// Scroll Area
+// =============================================================================
+
$center-align-spacing: calc(32px + cssUtils.$spacing-s);
-.crayon-shell-thread-scroll-area {
+.crayon-shell-thread-scroll-container {
+ display: flex;
width: 100%;
flex: 1;
+ position: relative;
+ overflow: hidden;
+}
+
+.crayon-shell-thread-scroll-area {
+ width: 100%;
+ height: 100%;
overflow: auto;
padding: cssUtils.$spacing-m $center-align-spacing cssUtils.$spacing-xl;
@@ -19,6 +114,12 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
padding: cssUtils.$spacing-l;
}
+ // When artifact is active, reduce padding to maximize space
+ .crayon-shell-thread-container--artifact-active & {
+ padding-left: 0;
+ padding-right: cssUtils.$spacing-m;
+ }
+
&--user-message-anchor {
& .crayon-shell-thread-messages > *:last-child {
min-height: calc(-200px + 100dvh);
@@ -26,6 +127,10 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
}
}
+// =============================================================================
+// Messages
+// =============================================================================
+
.crayon-shell-thread-messages {
max-width: 880px;
margin: 0 auto;
@@ -50,6 +155,12 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
padding: 0;
}
+ // When artifact is active, minimize spacing and hide logo
+ .crayon-shell-thread-container--artifact-active & {
+ gap: 0;
+ padding-right: 0;
+ }
+
&__content {
display: flex;
flex-direction: column;
@@ -71,6 +182,14 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
width: 32px;
height: 32px;
border-radius: cssUtils.$rounded-m;
+
+ .crayon-shell-container--mobile & {
+ display: none;
+ }
+
+ .crayon-shell-thread-container--artifact-active & {
+ display: none;
+ }
}
}
@@ -83,6 +202,11 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
padding: 0;
}
+ .crayon-shell-thread-container--artifact-active & {
+ padding-left: 0;
+ padding-right: 0;
+ }
+
&__content {
@include cssUtils.typography(primary, default);
padding: cssUtils.$spacing-m cssUtils.$spacing-l;
@@ -95,6 +219,10 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
}
}
+// =============================================================================
+// Composer
+// =============================================================================
+
.crayon-shell-thread-composer {
max-width: 880px;
width: 100%;
@@ -107,6 +235,11 @@ $center-align-spacing: calc(32px + cssUtils.$spacing-s);
background-color: cssUtils.$bg-container;
}
+ .crayon-shell-thread-container--artifact-active & {
+ padding-left: 0;
+ padding-right: cssUtils.$spacing-m;
+ }
+
&__input-wrapper {
border: 1.256px solid cssUtils.$stroke-default;
border-radius: cssUtils.$rounded-xl;
diff --git a/js/packages/react-ui/src/components/Shell/threadlist.scss b/js/packages/react-ui/src/components/Shell/threadlist.scss
index be52cf0d3..e84778baa 100644
--- a/js/packages/react-ui/src/components/Shell/threadlist.scss
+++ b/js/packages/react-ui/src/components/Shell/threadlist.scss
@@ -74,6 +74,7 @@
border: 1px solid cssUtils.$stroke-default;
border-radius: cssUtils.$rounded-m;
background-color: cssUtils.$bg-container;
+ z-index: 9999;
}
.crayon-shell-thread-button-dropdown-menu-item {
diff --git a/js/packages/react-ui/src/components/Shell/useArtifactResize.ts b/js/packages/react-ui/src/components/Shell/useArtifactResize.ts
new file mode 100644
index 000000000..b2f095134
--- /dev/null
+++ b/js/packages/react-ui/src/components/Shell/useArtifactResize.ts
@@ -0,0 +1,89 @@
+import { useCallback, useEffect, useRef, useState } from "react";
+
+interface UseArtifactResizeProps {
+ isArtifactActive: boolean;
+ isMobile: boolean;
+ setIsSidebarOpen: (isOpen: boolean) => void;
+}
+
+interface UseArtifactResizeReturn {
+ containerRef: React.RefObject<HTMLDivElement | null>;
+ chatPanelRef: React.RefObject<HTMLDivElement | null>;
+ artifactPanelRef: React.RefObject<HTMLDivElement | null>;
+ isDragging: boolean;
+ handleResize: (clientX: number) => void;
+ handleDragStart: () => void;
+ handleDragEnd: () => void;
+}
+
+const INITIAL_CHAT_WIDTH = 420;
+const MIN_CHAT_WIDTH = 420;
+const MAX_CHAT_WIDTH_RATIO = 0.8;
+
+/**
+ * Custom hook to manage artifact panel resizing logic (desktop only).
+ * Handles:
+ * - Chat panel width constraints
+ * - Resize drag events
+ * - Sidebar state when artifact is active/inactive
+ */
+export const useArtifactResize = ({
+ isArtifactActive,
+ isMobile,
+ setIsSidebarOpen,
+}: UseArtifactResizeProps): UseArtifactResizeReturn => {
+ const [isDragging, setIsDragging] = useState(false);
+ const containerRef = useRef<HTMLDivElement>(null);
+ const chatPanelRef = useRef<HTMLDivElement>(null);
+ const artifactPanelRef = useRef<HTMLDivElement>(null);
+
+ // Handle sidebar visibility and panel widths when artifact state changes
+ useEffect(() => {
+ if (isMobile) return;
+
+ if (isArtifactActive) {
+ // Desktop artifact active: close sidebar and set chat width to 420px
+ setIsSidebarOpen(false);
+ if (chatPanelRef.current) {
+ chatPanelRef.current.style.width = `${INITIAL_CHAT_WIDTH}px`;
+ }
+ } else {
+ // Desktop artifact inactive: open sidebar and reset chat width
+ setIsSidebarOpen(true);
+ if (chatPanelRef.current) {
+ chatPanelRef.current.style.width = "100%";
+ }
+ }
+ }, [isArtifactActive, isMobile, setIsSidebarOpen]);
+
+ const handleResize = useCallback((clientX: number) => {
+ if (!containerRef.current || !chatPanelRef.current) return;
+
+ const containerRect = containerRef.current.getBoundingClientRect();
+ const newWidthPx = clientX - containerRect.left;
+
+ // Constrain width between min and max
+ const maxWidthPx = containerRect.width * MAX_CHAT_WIDTH_RATIO;
+ const constrainedWidth = Math.min(Math.max(newWidthPx, MIN_CHAT_WIDTH), maxWidthPx);
+
+ chatPanelRef.current.style.width = `${constrainedWidth}px`;
+ }, []);
+
+ const handleDragStart = useCallback(() => {
+ setIsDragging(true);
+ }, []);
+
+ const handleDragEnd = useCallback(() => {
+ setIsDragging(false);
+ }, []);
+
+ return {
+ containerRef,
+ chatPanelRef,
+ artifactPanelRef,
+ isDragging,
+ handleResize,
+ handleDragStart,
+ handleDragEnd,
+ };
+};