Skip to content

Commit 44b1450

Browse files
committed
chore: fixed chat-input component
1 parent ee74ec7 commit 44b1450

File tree

6 files changed

+335
-138
lines changed

6 files changed

+335
-138
lines changed

apps/site/src/demos/ChatInputDemo.tsx

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const ChatInputDemo = () => {
1616
const [playgroundMaxLength, setPlaygroundMaxLength] = useState<
1717
number | undefined
1818
>(undefined)
19-
const [playgroundMaxVisible, setPlaygroundMaxVisible] = useState(3)
2019
const [playgroundFiles, setPlaygroundFiles] = useState<AttachedFile[]>([])
2120
const [playgroundWidth, setPlaygroundWidth] = useState<string>('100%')
2221

2322
// Demo state
2423
const [basicMessage, setBasicMessage] = useState('')
2524
const [basicFiles, setBasicFiles] = useState<AttachedFile[]>([])
25+
const [topQueriesMessage, setTopQueriesMessage] = useState('')
2626

2727
// File type utilities
2828
const getFileType = (file: File): AttachedFile['type'] => {
@@ -118,6 +118,8 @@ const ChatInputDemo = () => {
118118
setPlaygroundFiles([])
119119
}
120120

121+
console.log('topQueriesMessage-->>', topQueriesMessage)
122+
121123
return (
122124
<div className="p-8 space-y-12">
123125
{/* Header */}
@@ -135,7 +137,7 @@ const ChatInputDemo = () => {
135137
<h2 className="text-2xl font-bold">Interactive Playground</h2>
136138
<div className="space-y-6">
137139
{/* Controls */}
138-
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
140+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
139141
<TextInput
140142
label="Width"
141143
value={playgroundWidth}
@@ -155,19 +157,6 @@ const ChatInputDemo = () => {
155157
placeholder="Enter max length"
156158
type="number"
157159
/>
158-
159-
<TextInput
160-
label="Max Visible Files"
161-
value={playgroundMaxVisible.toString()}
162-
onChange={(e) => {
163-
const val = parseInt(e.target.value)
164-
if (!isNaN(val) && val > 0) {
165-
setPlaygroundMaxVisible(val)
166-
}
167-
}}
168-
placeholder="Max visible files"
169-
type="number"
170-
/>
171160
</div>
172161

173162
<div className="flex items-center gap-6">
@@ -220,8 +209,48 @@ const ChatInputDemo = () => {
220209
disabled={playgroundDisabled}
221210
autoResize={playgroundAutoResize}
222211
maxLength={playgroundMaxLength}
223-
maxVisibleFiles={playgroundMaxVisible}
224212
placeholder="Type your message here..."
213+
onTopQuerySelect={(query) => {
214+
setPlaygroundMessage(query.text)
215+
addSnackbar({
216+
header: 'Query Selected',
217+
description: `Selected: "${query.text}"`,
218+
})
219+
}}
220+
topQueries={[
221+
{
222+
id: '1',
223+
text: 'Show me the trend of last month success rate for razorpay',
224+
},
225+
{
226+
id: '2',
227+
text: 'What are the latest sales figures?',
228+
},
229+
{
230+
id: '3',
231+
text: 'Generate a report for Q3 performance',
232+
},
233+
{
234+
id: '4',
235+
text: 'Show customer satisfaction metrics',
236+
},
237+
{
238+
id: '5',
239+
text: 'Display user engagement analytics for this quarter',
240+
},
241+
{
242+
id: '6',
243+
text: 'Show revenue breakdown by product category',
244+
},
245+
{
246+
id: '7',
247+
text: 'Generate monthly performance summary',
248+
},
249+
{
250+
id: '8',
251+
text: 'Display conversion rate trends',
252+
},
253+
]}
225254
/>
226255
</div>
227256
</div>
@@ -422,26 +451,26 @@ const ChatInputDemo = () => {
422451
{/* Overflow Demo */}
423452
<div className="space-y-4">
424453
<h3 className="text-lg font-semibold">
425-
File Overflow (Max 2 visible)
454+
File Overflow (Dynamic)
426455
</h3>
427456
<ChatInput
428457
value=""
429458
onChange={() => {}}
430459
onSend={() => {}}
431460
attachedFiles={createSampleFiles()}
432-
maxVisibleFiles={2}
433461
onFileClick={(file) => {
434462
addSnackbar({
435463
header: 'File from overflow menu',
436464
description: file.name,
437465
})
438466
}}
439-
placeholder="Shows overflow menu with '+4 more'..."
467+
placeholder="Dynamically shows overflow menu..."
440468
/>
441469
<p className="text-sm text-gray-600">
442-
When files exceed maxVisibleFiles, a "+X more"
443-
button appears that opens a menu with the remaining
444-
files.
470+
The component automatically calculates how many
471+
files can fit based on the available width. A "+X
472+
more" button appears that opens a menu with the
473+
remaining files.
445474
</p>
446475
</div>
447476
</div>
@@ -456,15 +485,18 @@ const ChatInputDemo = () => {
456485
With Top Queries
457486
</h3>
458487
<ChatInput
459-
value=""
460-
onChange={() => {}}
461-
onSend={(message) =>
488+
value={topQueriesMessage}
489+
onChange={setTopQueriesMessage}
490+
onSend={(message) => {
462491
addSnackbar({
463492
header: 'Message Sent',
464493
description: `"${message}"`,
465494
})
466-
}
495+
setTopQueriesMessage('')
496+
}}
467497
onTopQuerySelect={(query) => {
498+
console.log('query', query)
499+
setTopQueriesMessage(query.text)
468500
addSnackbar({
469501
header: 'Query Selected',
470502
description: `Selected: "${query.text}"`,
@@ -591,7 +623,6 @@ const ChatInputDemo = () => {
591623
})
592624
}
593625
placeholder="Message your team..."
594-
maxVisibleFiles={4}
595626
attachButtonIcon={<Hash size={20} />}
596627
voiceButtonIcon={<Mic size={20} />}
597628
sendButtonIcon={<Send size={20} />}
@@ -710,13 +741,8 @@ const ChatInputDemo = () => {
710741
<code className="bg-gray-200 px-2 py-1 rounded">
711742
attachedFiles
712743
</code>{' '}
713-
- Array of attached files
714-
</li>
715-
<li>
716-
<code className="bg-gray-200 px-2 py-1 rounded">
717-
maxVisibleFiles
718-
</code>{' '}
719-
- Files shown before overflow
744+
- Array of attached files (overflow
745+
calculated dynamically)
720746
</li>
721747
</ul>
722748
</div>

0 commit comments

Comments
 (0)