-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCortexChatPanel.tsx
More file actions
242 lines (225 loc) · 7.22 KB
/
CortexChatPanel.tsx
File metadata and controls
242 lines (225 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**
* CortexChatPanel - Pixel-perfect chat panel matching Figma design
*
* 3 States:
* 1. Home (Full Screen) - Centered title + prompt input (Figma 1239:21705)
* 2. Minimized (Overlay) - 369×297px positioned bottom-left
* 3. Expanded (Agent Working) - Full conversation with progress indicators
*
* Figma refs: 1239:21705 (Main Screen / Home), 166:2184 (AI terminal flow / Expanded)
*/
import { Component, JSX, splitProps, Show, For } from "solid-js";
import { CortexPromptInput } from "./primitives";
import { ChatMessageBubble } from "./CortexChatMessageBubble";
export type {
ChatPanelState,
ChatMessage,
ChatAction,
ChatProgress,
ChatToolCall,
} from "./cortexChatTypes";
import type {
ChatPanelState,
ChatMessage,
} from "./cortexChatTypes";
export interface CortexChatPanelProps {
state?: ChatPanelState;
messages?: ChatMessage[];
inputValue?: string;
onInputChange?: (value: string) => void;
onSubmit?: (value: string) => void;
onStop?: () => void;
isProcessing?: boolean;
modelName?: string;
modelIcon?: string;
onModelClick?: () => void;
onUploadClick?: () => void;
class?: string;
style?: JSX.CSSProperties;
}
type InputProps = Omit<
CortexChatPanelProps,
"state" | "messages" | "class" | "style"
>;
const PromptInputBlock: Component<InputProps & { style?: JSX.CSSProperties }> = (props) => (
<CortexPromptInput
value={props.inputValue}
placeholder="Send a prompt or run a command..."
onChange={props.onInputChange}
onSubmit={props.onSubmit}
onStop={props.onStop}
isProcessing={props.isProcessing}
modelName={props.modelName}
modelIcon={props.modelIcon}
onModelClick={props.onModelClick}
onUploadClick={props.onUploadClick}
style={props.style}
/>
);
const FONT = "var(--cortex-font-sans, 'Figtree', sans-serif)";
export const CortexChatPanel: Component<CortexChatPanelProps> = (props) => {
const [local] = splitProps(props, [
"state", "messages", "inputValue", "onInputChange", "onSubmit", "onStop",
"isProcessing", "modelName", "modelIcon", "onModelClick",
"onUploadClick",
"class", "style",
]);
const state = () => local.state || "home";
return (
<Show
when={state() === "home"}
fallback={
<Show when={state() === "minimized"} fallback={<ExpandedChat {...local} />}>
<MinimizedChat {...local} />
</Show>
}
>
<HomeChat {...local} />
</Show>
);
};
/* ============================================================================
HOME STATE - Full screen, centered content
Figma: 1239:21705 → Main Screen
Layout: column, center-aligned, 922px content width, 28px gap
============================================================================ */
const HomeChat: Component<Omit<CortexChatPanelProps, "state" | "messages">> = (props) => (
<div class={props.class} style={{
display: "flex",
"flex-direction": "column",
"align-items": "center",
"justify-content": "center",
width: "100%",
height: "100%",
background: "var(--cortex-bg-primary)",
position: "relative",
overflow: "hidden",
...props.style,
}}>
{/* Container: Figma 1239:21710 - column, center, gap 28px, width 922px */}
<div style={{
display: "flex",
"flex-direction": "column",
"align-items": "center",
"justify-content": "center",
width: "922px",
"max-width": "100%",
gap: "28px",
}}>
{/* Title: Figma 1239:21711 - Figtree 32px Medium, lineHeight 40px (125%), centered */}
<h1 style={{
"font-family": FONT,
"font-size": "32px",
"font-weight": "500",
color: "var(--cortex-text-primary)",
"text-align": "center",
"line-height": "40px",
"letter-spacing": "0px",
margin: "0",
width: "100%",
}}>Hey, start building or open your project.</h1>
<PromptInputBlock {...props} />
</div>
</div>
);
/* ============================================================================
MINIMIZED STATE - 369×297px overlay, bottom-left
Figma: AI terminal / no requests → sidebar panel
============================================================================ */
const MinimizedChat: Component<Omit<CortexChatPanelProps, "state">> = (props) => (
<div class={props.class} style={{
position: "absolute",
left: "8px",
bottom: "36px",
width: "369px",
height: "297px",
background: "var(--cortex-small-btn-bg)",
"border-radius": "12px",
border: "1px solid var(--cortex-border-subtle)",
display: "flex",
"flex-direction": "column",
padding: "12px",
gap: "16px",
"box-shadow": "var(--cortex-panel-shadow)",
transition: "box-shadow 200ms ease-out, opacity 200ms ease-out",
...props.style,
}}>
{/* Title area */}
<div style={{
display: "flex",
"flex-direction": "column",
gap: "8px",
padding: "8px",
}}>
<h2 style={{
"font-family": FONT,
"font-size": "20px",
"font-weight": "500",
color: "var(--cortex-text-primary)",
"line-height": "1em",
margin: "0",
}}>What would you like to build?</h2>
<p style={{
"font-family": FONT,
"font-size": "16px",
"font-weight": "500",
color: "var(--cortex-text-secondary)",
"line-height": "1em",
margin: "0",
}}>Start a conversation or open a project</p>
</div>
<div style={{ flex: "1" }} />
<PromptInputBlock {...props} style={{ width: "100%" }} />
</div>
);
/* ============================================================================
EXPANDED STATE - Full conversation with messages + prompt
Figma: 166:2184 → AI terminal history → AI Terminal component
Chat messages in scrollable area, prompt at bottom
============================================================================ */
const ExpandedChat: Component<Omit<CortexChatPanelProps, "state">> = (props) => (
<div class={props.class} style={{
position: "absolute",
left: "8px",
bottom: "36px",
width: "369px",
"max-height": "calc(100vh - 120px)",
background: "var(--cortex-small-btn-bg)",
"border-radius": "12px",
border: "1px solid var(--cortex-border-subtle)",
display: "flex",
"flex-direction": "column",
padding: "0 8px 8px 8px",
gap: "0",
"box-shadow": "var(--cortex-panel-shadow)",
transition: "box-shadow 200ms ease-out, opacity 200ms ease-out",
overflow: "hidden",
...props.style,
}}>
{/* Scrollable message area: Figma layout_77BZNU - column, gap 16px, padding 0 8px */}
<div
aria-live="polite"
style={{
flex: "1",
"overflow-y": "auto",
display: "flex",
"flex-direction": "column",
gap: "16px",
padding: "8px 0",
}}>
<For each={props.messages || []}>
{(message) => <ChatMessageBubble message={message} />}
</For>
</div>
{/* Prompt input area: Figma layout_IFH6L8 - column, gap 10px, padding 8px */}
<div style={{
padding: "8px",
background: "var(--cortex-border-default)",
border: "1px solid var(--cortex-border-accent)",
"border-radius": "12px",
}}>
<PromptInputBlock {...props} style={{ width: "100%" }} />
</div>
</div>
);
export default CortexChatPanel;