-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathllms-full.txt
More file actions
1817 lines (1287 loc) · 63.4 KB
/
llms-full.txt
File metadata and controls
1817 lines (1287 loc) · 63.4 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# prompt-kit
> prompt-kit is a library of customizable, high-quality UI components for AI applications. It provides ready-to-use components for building chat experiences, AI agents, autonomous assistants, and more, with a focus on rapid development and beautiful design.
## Table of Contents
- [Installation](#installation)
- [Introduction](#introduction)
- [Components](#components)
- [Blocks](#blocks)
- [Prompt input](#prompt-input)
- [Code block](#code-block)
- [Markdown](#markdown)
- [Message](#message)
- [Chat container](#chat-container)
- [Scroll button](#scroll-button)
- [Loader](#loader)
- [Prompt suggestion](#prompt-suggestion)
- [Response stream](#response-stream)
- [Reasoning](#reasoning)
- [File upload](#file-upload)
- [Jsx preview](#jsx-preview)
- [Showcase](#showcase)
## Components
import { generateMetadata } from "../utils/metadata"
export const metadata = generateMetadata(
"Introduction",
"Introduction to prompt-kit."
)
**prompt-kit** is a set of customizable, high-quality components built for AI applications, making it easy to design chat experiences, AI agents, autonomous assistants, and more, quickly and beautifully.
**prompt-kit** is built on top of shadcn/ui with the same design principles. But instead of helping you build a component library, it helps you build AI interfaces.
This project is a work in progress, and we're continuously improving and expanding the collection. We'd love to hear your feedback or see your contributions as it evolves!
prompt-kit is open source. Check out the code and contribute on [GitHub](https://github.com/ibelick/prompt-kit).
import { generateMetadata } from "../utils/metadata"
export const metadata = generateMetadata(
"Installation",
"Installation guide for prompt-kit."
)
# Installation
## Prerequisites
Before installing, ensure you have the following:
- [Node.js](https://nodejs.org/en/download/) version **18** or later
- [React](https://react.dev/) version **19** or later
## Install shadcn/ui
First, you'll need to install and configure shadcn/ui in your project. Follow the installation guide at [shadcn/ui documentation](https://ui.shadcn.com/docs/installation).
Once shadcn/ui is set up, you can install **prompt-kit** components using the **shadcn CLI**.
## Using the shadcn CLI
<CodeBlock
language="bash"
code={`npx shadcn@latest add "https://prompt-kit.com/c/[COMPONENT].json"`}
/>
## Usage
After installation, import and start using the components in your project:
<CodeBlock
language="tsx"
code={`import { PromptInput } from "@/components/ui/prompt-input";`}
/>
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { PromptInputBasic } from "./prompt-input-basic"
import { PromptInputWithActions } from "./prompt-input-with-actions"
export const metadata = generateMetadata(
"Prompt Input",
"An input field that allows users to enter and submit text to an AI model."
)
# Prompt Input
An input field that allows users to enter and submit text to an AI model.
## Examples
### Prompt Input basic
<ComponentCodePreview
component={<PromptInputBasic />}
filePath="app/docs/prompt-input/prompt-input-basic.tsx"
classNameComponentContainer="p-8"
/>
### Prompt Input with actions
You can use `PromptInputActions` to add actions with tooltips to the `PromptInput`.
<ComponentCodePreview
component={<PromptInputWithActions />}
filePath="app/docs/prompt-input/prompt-input-with-actions.tsx"
classNameComponentContainer="p-8"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/prompt-input.json"`}
language="bash"
/>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/prompt-input.tsx" language="tsx" />
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</Tabs>
## Component API
### PromptInput
| Prop | Type | Default | Description |
| :------------ | :---------------------- | :------ | :---------------------------------------------- |
| isLoading | boolean | false | Loading state of the input |
| value | string | | Controlled value of the input |
| onValueChange | (value: string) => void | | Callback when input value changes |
| maxHeight | number \| string | 240 | Maximum height of the textarea in pixels |
| onSubmit | () => void | | Callback when form is submitted (Enter pressed) |
| children | React.ReactNode | | Child components to render |
| className | string | | Additional CSS classes |
### PromptInputTextarea
| Prop | Type | Default | Description |
| :-------------- | :--------------------------------- | :------ | :------------------------------------- |
| disableAutosize | boolean | false | Disable automatic height adjustment |
| className | string | | Additional CSS classes |
| onKeyDown | (e: KeyboardEvent) => void | | Keyboard event handler |
| disabled | boolean | false | Disable the textarea input |
| ...props | `React.ComponentProps<"textarea">` | | All other textarea props are supported |
### PromptInputActions
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :-------------------------------- |
| children | React.ReactNode | | Child components to render |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLAttributes<HTMLDivElement>` | | All other div props are supported |
### PromptInputAction
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :---------------------------------------------- |
| tooltip | React.ReactNode | | Content to show in the tooltip |
| children | React.ReactNode | | Child component to trigger the tooltip |
| className | string | | Additional CSS classes for the tooltip |
| side | "top" \| "bottom" \| "left" \| "right" | "top" | Position of the tooltip relative to the trigger |
| disabled | boolean | false | Disable the tooltip trigger |
| ...props | `React.ComponentProps<typeof Tooltip>` | | All other Tooltip component props are supported |
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { CodeBlockBasic } from "./code-block-basic"
import { CodeBlockCSS } from "./code-block-css"
import { CodeBlockNord } from "./code-block-nord"
import { CodeBlockPython } from "./code-block-python"
import { CodeBlockThemed } from "./code-block-themed"
import { CodeBlockWithHeader } from "./code-block-with-header"
export const metadata = generateMetadata(
"Code Block",
"A component for displaying code snippets with syntax highlighting and customizable styling."
)
# Code Block
A component for displaying code snippets with syntax highlighting and customizable styling.
## Examples
### Basic Code Block
<ComponentCodePreview
component={<CodeBlockBasic />}
filePath="app/docs/code-block/code-block-basic.tsx"
classNameComponentContainer="p-8"
/>
### Code Block with Header
You can use `CodeBlockGroup` to add a header with metadata and actions to your code blocks.
<ComponentCodePreview
component={<CodeBlockWithHeader />}
filePath="app/docs/code-block/code-block-with-header.tsx"
classNameComponentContainer="p-8"
/>
### Different Languages
You can highlight code in various languages by changing the `language` prop.
#### Python Example
<ComponentCodePreview
component={<CodeBlockPython />}
filePath="app/docs/code-block/code-block-python.tsx"
classNameComponentContainer="p-8"
/>
#### CSS Example
<ComponentCodePreview
component={<CodeBlockCSS />}
filePath="app/docs/code-block/code-block-css.tsx"
classNameComponentContainer="p-8"
/>
### Different Themes
Shiki supports many popular themes. Here are some examples:
#### GitHub Dark Theme
<ComponentCodePreview
component={<CodeBlockThemed />}
filePath="app/docs/code-block/code-block-themed.tsx"
classNameComponentContainer="p-8"
/>
#### Nord Theme
<ComponentCodePreview
component={<CodeBlockNord />}
filePath="app/docs/code-block/code-block-nord.tsx"
classNameComponentContainer="p-8"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/code-block.json"`}
language="bash"
/>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/code-block.tsx" language="tsx" />
<Step>Install the required dependencies.</Step>
<CodeBlock code={`npm install shiki`} language="bash" />
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</Tabs>
## Component API
### CodeBlock
| Prop | Type | Default | Description |
| :-------- | :-------------------------------- | :------ | :------------------------- |
| children | React.ReactNode | | Child components to render |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLProps<HTMLDivElement>` | | All other div props |
### CodeBlockCode
| Prop | Type | Default | Description |
| :-------- | :-------------------------------- | :------------- | :----------------------------------- |
| code | string | | The code to display and highlight |
| language | string | "tsx" | The language for syntax highlighting |
| theme | string | "github-light" | The theme for syntax highlighting |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLProps<HTMLDivElement>` | | All other div props |
### CodeBlockGroup
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :------------------------- |
| children | React.ReactNode | | Child components to render |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLAttributes<HTMLDivElement>` | | All other div props |
## Usage with Markdown
The `CodeBlock` component is used internally by the `Markdown` component to render code blocks in markdown content. When used within the `Markdown` component, code blocks are automatically wrapped with the `not-prose` class to prevent conflicts with prose styling.
<CodeBlock
code={`import { Markdown } from "@/components/prompt-kit/markdown"
function MyComponent() {
const markdownContent = \` # Example
\\\`\\\`\\\`javascript
function greet(name) {
return \`Hello, \\\${name}!\\\`;
}
\\\`\\\`\\\`
return <Markdown className="prose">{markdownContent}</Markdown>
}`}
language="tsx"
/>
## Tailwind Typography and not-prose
The `CodeBlock` component includes the `not-prose` class by default to prevent Tailwind Typography's prose styling from affecting code blocks. This is important when using the [@tailwindcss/typography](https://github.com/tailwindlabs/tailwindcss-typography) plugin, which provides beautiful typography defaults but can interfere with code block styling.
Since code blocks are styled with Shiki for syntax highlighting, they should not inherit Tailwind Typography styles. The `not-prose` class ensures that code blocks maintain their intended appearance regardless of the surrounding typography context.
<CodeBlock
code={`<article className="prose">
<h1>My Content</h1>
<p>This content has prose styling applied.</p>
{/* The CodeBlock has not-prose to prevent prose styling */}
<CodeBlock>
<CodeBlockCode code={code} language="javascript" />
</CodeBlock>
</article>`}
language="tsx"
/>
## Customizing Syntax Highlighting
The `CodeBlockCode` component uses [Shiki](https://shiki.matsu.io/) for syntax highlighting. You can customize the theme by passing a different theme name to the `theme` prop.
Shiki supports many popular themes including:
- github-light (default)
- github-dark
- dracula
- nord
- and more.
For a complete list of supported themes, refer to the [Shiki documentation](https://github.com/shikijs/shiki/blob/main/docs/themes.md).
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { MarkdownBasic } from "./markdown-basic"
import { MarkdownCustomComponents } from "./markdown-custom-components"
export const metadata = generateMetadata(
"Markdown",
"A component for rendering Markdown content with support for GitHub Flavored Markdown (GFM) and custom component styling."
)
# Markdown
A component for rendering Markdown content with support for GitHub Flavored Markdown (GFM) and custom component styling.
## Examples
### Basic Markdown
Render basic Markdown with support for bold, italics, lists, code blocks and more.
<ComponentCodePreview
component={<MarkdownBasic />}
filePath="app/docs/markdown/markdown-basic.tsx"
classNameComponentContainer="p-8"
disableNotProse
/>
### Markdown with Custom Components
You can customize how different Markdown elements are rendered by providing custom components.
<ComponentCodePreview
component={<MarkdownCustomComponents />}
filePath="app/docs/markdown/markdown-custom-components.tsx"
classNameComponentContainer="p-8"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/markdown.json"`}
language="bash"
/>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/markdown.tsx" language="tsx" />
<Step>Install the required dependencies.</Step>
<CodeBlock
code={`npm install react-markdown remark-gfm remark-breaks`}
language="bash"
/>
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</Tabs>
## Component API
### Markdown
| Prop | Type | Default | Description |
| :--------- | :------------------------------------------- | :----------------- | :---------------------------------------------- |
| children | string | | Markdown content to render |
| className | string | | Additional CSS classes |
| components | `Partial<Components>` | INITIAL_COMPONENTS | Custom components to override default rendering |
| ...props | `React.ComponentProps<typeof ReactMarkdown>` | | All other ReactMarkdown props |
## Performance Optimization
The Markdown component employs advanced memoization techniques to optimize rendering performance, especially in streaming AI response scenarios. This approach is crucial when rendering chat interfaces where new tokens are continuously streamed.
### How Memoization Works
Our implementation:
1. Splits Markdown content into discrete semantic blocks using the `marked` library
2. Memoizes each block individually with React's `memo`
3. Only re-renders blocks that have actually changed when new content arrives
4. Preserves already rendered blocks to prevent unnecessary re-parsing and re-rendering
This pattern significantly improves performance in chat applications by preventing the entire message history from re-rendering with each new token, which becomes increasingly important as conversations grow longer.
For AI chat interfaces using streaming responses, always provide a unique `id` prop (typically the message ID) to ensure proper block caching:
<CodeBlock
code={`<Markdown id={message.id}>{message.content}</Markdown>`}
language="tsx"
/>
This memoization implementation is based on the [Vercel AI SDK Cookbook](https://sdk.vercel.ai/cookbook/next/markdown-chatbot-with-memoization) with enhancements for better React integration.
## Customizing Components
You can customize how different Markdown elements are rendered by providing a `components` prop. This is an object where keys are HTML element names and values are React components.
<CodeBlock code={`const customComponents = {
h1: ({ children }) => <h1 className="text-2xl font-bold text-blue-500">{children}</h1>,
a: ({ href, children }) => <a href={href} className="text-purple-500 underline">{children}</a>,
// ... other components
}
<Markdown components={customComponents}>{markdownContent}</Markdown>
`} language="tsx" />
## Supported Markdown Features
The Markdown component uses [react-markdown](https://github.com/remarkjs/react-markdown) with [remark-gfm](https://github.com/remarkjs/remark-gfm) to support GitHub Flavored Markdown, which includes:
- Tables
- Strikethrough
- Tasklists
- Literal URLs
- Footnotes
Additionally, the component includes built-in code block highlighting through the `CodeBlock` component.
## Styling with Tailwind Typography
For the best typography styling experience, we recommend using the [@tailwindcss/typography](https://github.com/tailwindlabs/tailwindcss-typography) plugin. This plugin provides a set of `prose` classes that add beautiful typographic defaults to your markdown content.
<CodeBlock code={`npm install -D @tailwindcss/typography`} language="bash" />
When using the Markdown component with Tailwind Typography, you can apply the `prose` class:
<CodeBlock
code={`<Markdown className="prose dark:prose-invert">{markdownContent}</Markdown>`}
language="tsx"
/>
### Handling Code Blocks
As you've seen in our examples, code blocks within prose content can sometimes cause styling conflicts. The Tailwind Typography plugin provides a `not-prose` class to exclude elements from prose styling:
<CodeBlock code={`<article className="prose">
<h1>My Content</h1>
<p>Regular content with prose styling...</p>
<div className="not-prose">
<!-- Code blocks or other elements that shouldn't inherit prose styles -->
</div>
</article>
`} language="tsx" />
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { MessageBasic } from "./message-basic"
import { MessageWithActions } from "./message-with-actions"
import { MessageWithMarkdown } from "./message-with-markdown"
export const metadata = generateMetadata(
"Message",
"A component for displaying messages in a conversation interface, with support for avatars, markdown content, and interactive actions."
)
# Message
A component for displaying messages in a conversation interface, with support for avatars, markdown content, and interactive actions.
## Examples
### Basic Message
<ComponentCodePreview
component={<MessageBasic />}
filePath="app/docs/message/message-basic.tsx"
classNameComponentContainer="p-8"
/>
### Message with Markdown
The `markdown` prop enables rendering content as [Markdown](/docs/markdown), perfect for rich text formatting in messages.
<ComponentCodePreview
component={<MessageWithMarkdown />}
filePath="app/docs/message/message-with-markdown.tsx"
classNameComponentContainer="p-8"
disableNotProse
/>
### Message with Actions
You can use `MessageActions` and `MessageAction` to add interactive elements to your messages.
<ComponentCodePreview
component={<MessageWithActions />}
filePath="app/docs/message/message-with-actions.tsx"
classNameComponentContainer="p-8"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/message.json"`}
language="bash"
/>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/message.tsx" language="tsx" />
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</Tabs>
## Component API
### Message
| Prop | Type | Default | Description |
| :-------- | :-------------------------------- | :------ | :------------------------- |
| children | React.ReactNode | | Child components to render |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLProps<HTMLDivElement>` | | All other div props |
### MessageAvatar
| Prop | Type | Default | Description |
| :-------- | :----- | :------ | :------------------------------------- |
| src | string | | URL of the avatar image |
| alt | string | | Alt text for the avatar image |
| fallback | string | | Text to display if image fails to load |
| delayMs | number | | Delay before showing fallback (in ms) |
| className | string | | Additional CSS classes |
### MessageContent
| Prop | Type | Default | Description |
| :-------- | :-------------------------------- | :------ | :------------------------------------ |
| children | React.ReactNode | | Content to display in the message |
| markdown | boolean | false | Whether to render content as markdown |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLProps<HTMLDivElement>` | | All other div props |
### MessageActions
| Prop | Type | Default | Description |
| :-------- | :-------------------------------- | :------ | :------------------------- |
| children | React.ReactNode | | Child components to render |
| className | string | | Additional CSS classes |
| ...props | `React.HTMLProps<HTMLDivElement>` | | All other div props |
### MessageAction
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :---------------------------------------------- |
| tooltip | React.ReactNode | | Content to show in the tooltip |
| children | React.ReactNode | | Child component to trigger the tooltip |
| className | string | | Additional CSS classes for the tooltip |
| side | "top" \| "bottom" \| "left" \| "right" | "top" | Position of the tooltip relative to the trigger |
| ...props | `React.ComponentProps<typeof Tooltip>` | | All other Tooltip component props |
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { ChatBasic } from "./chat-basic"
import { ChatWithCustomScroll } from "./chat-with-custom-scroll"
export const metadata = generateMetadata(
"Chat Container",
"A component for creating chat interfaces with intelligent auto-scrolling behavior, designed to provide a smooth experience in conversation interfaces."
)
# Chat Container
A component for creating chat interfaces with intelligent auto-scrolling behavior, designed to provide a smooth experience in conversation interfaces.
## Examples
### Chat container basic
<ComponentCodePreview
component={<ChatWithCustomScroll />}
filePath="app/docs/chat-container/chat-with-custom-scroll.tsx"
classNameComponentContainer="p-0"
/>
### Streaming Text Example
A chat container that demonstrates text streaming with automatic scrolling. Click the "Show Streaming" button to see a simulated streaming response with the smart auto-scroll behavior in action.
<ComponentCodePreview
component={<ChatBasic />}
filePath="app/docs/chat-container/chat-basic.tsx"
classNameComponentContainer="p-0"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/chat-container.json"`}
language="bash"
/>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/chat-container.tsx" language="tsx" />
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</Tabs>
## Component API
The ChatContainer is built using three separate components that work together:
### ChatContainerRoot
The main container that provides auto-scrolling functionality using the `use-stick-to-bottom` library.
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :---------------------------------------------- |
| children | React.ReactNode | | Child components to render inside the container |
| className | string | | Additional CSS classes |
| ...props | React.HTMLAttributes\<HTMLDivElement\> | | All other div props |
### ChatContainerContent
The content wrapper that should contain your messages.
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :------------------------------------------------------ |
| children | React.ReactNode | | Child components to render inside the content container |
| className | string | | Additional CSS classes |
| ...props | React.HTMLAttributes\<HTMLDivElement\> | | All other div props |
### ChatContainerScrollAnchor
An optional scroll anchor element that can be used for scroll targeting.
| Prop | Type | Default | Description |
| :-------- | :------------------------------------- | :------ | :----------------------------------------- |
| className | string | | Additional CSS classes |
| ref | React.RefObject\<HTMLDivElement\> | | Optional ref for the scroll anchor element |
| ...props | React.HTMLAttributes\<HTMLDivElement\> | | All other div props |
## Auto-Scroll Behavior
The component uses the `use-stick-to-bottom` library to provide sophisticated auto-scrolling:
- **Smooth Animations**: Uses velocity-based spring animations for natural scrolling
- **Content Resizing**: Automatically detects content changes using ResizeObserver API
- **User Control**: Automatically disables sticky behavior when users scroll up
- **Mobile Support**: Works seamlessly on touch devices
- **Performance**: Zero dependencies and optimized for chat applications
- **Scroll Anchoring**: Prevents content jumping when new content is added above the viewport
Key behaviors:
- **Stick to Bottom**: Automatically scrolls to bottom when new content is added (if already at bottom)
- **Smart Scrolling**: Only scrolls when user is at the bottom, preserves scroll position otherwise
- **Cancel on Scroll**: User can scroll up to cancel auto-scrolling behavior
- **Resume Auto-Scroll**: Returns to auto-scrolling when user scrolls back to bottom
## Using with ScrollButton
The ChatContainer pairs perfectly with the ScrollButton component. The ScrollButton automatically appears when the user scrolls up and disappears when at the bottom:
<CodeBlock
code={`import { ChatContainerRoot, ChatContainerContent,
ChatContainerScrollAnchor } from "@/components/prompt-kit/chat-container"
import { ScrollButton } from "@/components/prompt-kit/scroll-button"
function ChatInterface() {
return (
<div className="relative h-[500px]">
<ChatContainerRoot className="h-full">
<ChatContainerContent className="space-y-4">
{/* Your chat messages here */}
<div>Message 1</div>
<div>Message 2</div>
<div>Message 3</div>
</ChatContainerContent>
<ChatContainerScrollAnchor />
<div className="absolute right-4 bottom-4">
<ScrollButton className="shadow-sm" />
</div>
</ChatContainerRoot>
</div>
) } `} language="tsx" />
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { ScrollButtonBasic } from "./scroll-button-basic"
import { ScrollButtonCustom } from "./scroll-button-custom"
import { ScrollButtonWithChat } from "./scroll-button-with-chat"
export const metadata = generateMetadata(
"Scroll Button",
"A floating button that appears when the user scrolls up and lets them return to the bottom of the chat."
)
# Scroll Button
A minimal floating button that appears when the user scrolls up, allowing them to jump back to the bottom of the chat.
## Usage
The `ScrollButton` only works inside `ChatContainerRoot`, which uses `use-stick-to-bottom` under the hood.
It **will not work** with a plain `div` or custom scroll container.
## Examples
### Basic Scroll Button
A simple implementation of the scroll button that appears when scrolling up and disappears when at the bottom of the container.
<ComponentCodePreview
component={<ScrollButtonBasic />}
filePath="app/docs/scroll-button/scroll-button-basic.tsx"
classNameComponentContainer="p-0"
/>
### Custom Scroll Button
Customize the appearance and behavior of the scroll button with different variants, sizes, and threshold values.
<ComponentCodePreview
component={<ScrollButtonCustom />}
filePath="app/docs/scroll-button/scroll-button-custom.tsx"
classNameComponentContainer="p-0"
/>
### With Chat Container
The ScrollButton works perfectly with ChatContainer for chat interfaces, providing an easy way for users to navigate long conversations.
<ComponentCodePreview
component={<ScrollButtonWithChat />}
filePath="app/docs/scroll-button/scroll-button-with-chat.tsx"
classNameComponentContainer="p-0"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/scroll-button.json"`}
language="bash"
/>
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/scroll-button.tsx" language="tsx" />
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</Tabs>
## Component API
### ScrollButton
| Prop | Type | Default | Description |
| :----------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- |
| scrollRef | React.RefObject\<HTMLElement\> | | Reference to the element to scroll to |
| containerRef | React.RefObject\<HTMLElement\> | | Reference to the scrollable container |
| className | string | | Additional CSS classes |
| threshold | number | 50 | Distance from bottom (in px) to show/hide the button |
| variant | "default" \| "outline" \| "ghost" \| etc. | "outline" | Button variant from your UI button component |
| size | "default" \| "sm" \| "lg" \| etc. | "sm" | Button size from your UI button component |
| ...props | React.ButtonHTMLAttributes\<HTMLButtonElement\> | | All other button props |
import ComponentCodePreview from "@/components/app/component-code-preview"
import { generateMetadata } from "../utils/metadata"
import { LoaderBasic } from "./loader-basic"
import { LoaderSizes } from "./loader-sizes"
import { LoaderWithText } from "./loader-with-text"
export const metadata = generateMetadata(
"Loader",
"A loading component with multiple variants to indicate processing states and provide visual feedback to users during wait times."
)
# Loader
A loading component with multiple variants to indicate processing states and provide visual feedback to users during wait times.
## Examples
### Basic Loader
Showcasing all available loader variants with default settings.
<ComponentCodePreview
component={<LoaderBasic />}
filePath="app/docs/loader/loader-basic.tsx"
classNameComponentContainer="p-0"
/>
### Loader Sizes
Customize the size of any loader variant with predefined size options.
<ComponentCodePreview
component={<LoaderSizes />}
filePath="app/docs/loader/loader-sizes.tsx"
classNameComponentContainer="p-0"
/>
### Loader With Text
Some loader variants support displaying custom text while loading.
<ComponentCodePreview
component={<LoaderWithText />}
filePath="app/docs/loader/loader-with-text.tsx"
classNameComponentContainer="p-0 min-h-auto items-start"
/>
## Installation
<Tabs defaultValue="cli">
<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
<CodeBlock
code={`npx shadcn add "https://prompt-kit.com/c/loader.json"`}
language="bash"