@copilotkit/react-ui 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/.turbo/turbo-build.log +193 -16
  2. package/CHANGELOG.md +24 -0
  3. package/LICENSE +21 -0
  4. package/dist/chunk-46XC7ODX.mjs +72 -0
  5. package/dist/chunk-46XC7ODX.mjs.map +1 -0
  6. package/dist/chunk-4HK6C362.mjs +106 -0
  7. package/dist/chunk-4HK6C362.mjs.map +1 -0
  8. package/dist/chunk-6LAC5RA2.mjs +28 -0
  9. package/dist/chunk-6LAC5RA2.mjs.map +1 -0
  10. package/dist/chunk-6LRNF2VU.mjs +12 -0
  11. package/dist/chunk-6LRNF2VU.mjs.map +1 -0
  12. package/dist/chunk-7NSRDJ5C.mjs +3 -0
  13. package/dist/chunk-7NSRDJ5C.mjs.map +1 -0
  14. package/dist/chunk-BB6IP63P.mjs +29 -0
  15. package/dist/chunk-BB6IP63P.mjs.map +1 -0
  16. package/dist/chunk-BIPCPNHG.mjs +18 -0
  17. package/dist/chunk-BIPCPNHG.mjs.map +1 -0
  18. package/dist/chunk-BS6RR2DJ.mjs +25 -0
  19. package/dist/chunk-BS6RR2DJ.mjs.map +1 -0
  20. package/dist/chunk-DOMJCSI6.mjs +26 -0
  21. package/dist/chunk-DOMJCSI6.mjs.map +1 -0
  22. package/dist/chunk-E2YBQYWM.mjs +69 -0
  23. package/dist/chunk-E2YBQYWM.mjs.map +1 -0
  24. package/dist/chunk-E5BOIXYO.mjs +45 -0
  25. package/dist/chunk-E5BOIXYO.mjs.map +1 -0
  26. package/dist/chunk-H4VKQGVU.mjs +3 -0
  27. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  28. package/dist/chunk-I2AB5FK4.mjs +123 -0
  29. package/dist/chunk-I2AB5FK4.mjs.map +1 -0
  30. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  31. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  32. package/dist/chunk-KR7MH7XO.mjs +481 -0
  33. package/dist/chunk-KR7MH7XO.mjs.map +1 -0
  34. package/dist/chunk-KXJV37FS.mjs +33 -0
  35. package/dist/chunk-KXJV37FS.mjs.map +1 -0
  36. package/dist/chunk-MC6KTH4X.mjs +12 -0
  37. package/dist/chunk-MC6KTH4X.mjs.map +1 -0
  38. package/dist/chunk-MRXNTQOX.mjs +55 -0
  39. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  40. package/dist/chunk-N7KB3Z57.mjs +23 -0
  41. package/dist/chunk-N7KB3Z57.mjs.map +1 -0
  42. package/dist/chunk-QEXWZWJL.mjs +75 -0
  43. package/dist/chunk-QEXWZWJL.mjs.map +1 -0
  44. package/dist/chunk-RSONJDLO.mjs +28 -0
  45. package/dist/chunk-RSONJDLO.mjs.map +1 -0
  46. package/dist/chunk-SF56HSZW.mjs +48 -0
  47. package/dist/chunk-SF56HSZW.mjs.map +1 -0
  48. package/dist/chunk-TVTG3V4F.mjs +40 -0
  49. package/dist/chunk-TVTG3V4F.mjs.map +1 -0
  50. package/dist/chunk-U6NJWGTV.mjs +3 -0
  51. package/dist/chunk-U6NJWGTV.mjs.map +1 -0
  52. package/dist/chunk-V6QYUEJR.mjs +47 -0
  53. package/dist/chunk-V6QYUEJR.mjs.map +1 -0
  54. package/dist/chunk-VQNV2DHJ.mjs +142 -0
  55. package/dist/chunk-VQNV2DHJ.mjs.map +1 -0
  56. package/dist/chunk-VSNDSL6W.mjs +74 -0
  57. package/dist/chunk-VSNDSL6W.mjs.map +1 -0
  58. package/dist/chunk-XZFO2YEG.mjs +53 -0
  59. package/dist/chunk-XZFO2YEG.mjs.map +1 -0
  60. package/dist/components/chat-components/chat-list.d.ts +8 -0
  61. package/dist/components/chat-components/chat-list.mjs +13 -0
  62. package/dist/components/chat-components/chat-list.mjs.map +1 -0
  63. package/dist/components/chat-components/chat-message-actions.d.ts +8 -0
  64. package/dist/components/chat-components/chat-message-actions.mjs +8 -0
  65. package/dist/components/chat-components/chat-message-actions.mjs.map +1 -0
  66. package/dist/components/chat-components/chat-message.d.ts +8 -0
  67. package/dist/components/chat-components/chat-message.mjs +11 -0
  68. package/dist/components/chat-components/chat-message.mjs.map +1 -0
  69. package/dist/components/chat-components/chat-panel.d.ts +8 -0
  70. package/dist/components/chat-components/chat-panel.mjs +10 -0
  71. package/dist/components/chat-components/chat-panel.mjs.map +1 -0
  72. package/dist/components/chat-components/chat-scroll-anchor.d.ts +6 -0
  73. package/dist/components/chat-components/chat-scroll-anchor.mjs +5 -0
  74. package/dist/components/chat-components/chat-scroll-anchor.mjs.map +1 -0
  75. package/dist/components/chat-components/clear-history.d.ts +9 -0
  76. package/dist/components/chat-components/clear-history.mjs +81 -0
  77. package/dist/components/chat-components/clear-history.mjs.map +1 -0
  78. package/dist/components/chat-components/copilot-chat.d.ts +12 -0
  79. package/dist/components/chat-components/copilot-chat.mjs +22 -0
  80. package/dist/components/chat-components/copilot-chat.mjs.map +1 -0
  81. package/dist/components/chat-components/default-empty-screen.d.ts +8 -0
  82. package/dist/components/chat-components/default-empty-screen.mjs +8 -0
  83. package/dist/components/chat-components/default-empty-screen.mjs.map +1 -0
  84. package/dist/components/chat-components/external-link.d.ts +6 -0
  85. package/dist/components/chat-components/external-link.mjs +4 -0
  86. package/dist/components/chat-components/external-link.mjs.map +1 -0
  87. package/dist/components/chat-components/markdown.d.ts +6 -0
  88. package/dist/components/chat-components/markdown.mjs +4 -0
  89. package/dist/components/chat-components/markdown.mjs.map +1 -0
  90. package/dist/components/chat-components/prompt-form.d.ts +9 -0
  91. package/dist/components/chat-components/prompt-form.mjs +9 -0
  92. package/dist/components/chat-components/prompt-form.mjs.map +1 -0
  93. package/dist/components/chat-components/theme-toggle.d.ts +3 -0
  94. package/dist/components/chat-components/theme-toggle.mjs +36 -0
  95. package/dist/components/chat-components/theme-toggle.mjs.map +1 -0
  96. package/dist/components/chat-components/toaster.d.ts +1 -0
  97. package/dist/components/chat-components/toaster.mjs +4 -0
  98. package/dist/components/chat-components/toaster.mjs.map +1 -0
  99. package/dist/components/chat-components/ui/alert-dialog.d.ts +20 -0
  100. package/dist/components/chat-components/ui/alert-dialog.mjs +6 -0
  101. package/dist/components/chat-components/ui/alert-dialog.mjs.map +1 -0
  102. package/dist/components/chat-components/ui/badge.d.ts +12 -0
  103. package/dist/components/chat-components/ui/badge.mjs +31 -0
  104. package/dist/components/chat-components/ui/badge.mjs.map +1 -0
  105. package/dist/components/chat-components/ui/button.d.ts +14 -0
  106. package/dist/components/chat-components/ui/button.mjs +5 -0
  107. package/dist/components/chat-components/ui/button.mjs.map +1 -0
  108. package/dist/components/chat-components/ui/codeblock.d.ts +14 -0
  109. package/dist/components/chat-components/ui/codeblock.mjs +8 -0
  110. package/dist/components/chat-components/ui/codeblock.mjs.map +1 -0
  111. package/dist/components/chat-components/ui/dialog.d.ts +18 -0
  112. package/dist/components/chat-components/ui/dialog.mjs +119 -0
  113. package/dist/components/chat-components/ui/dialog.mjs.map +1 -0
  114. package/dist/components/chat-components/ui/dropdown-menu.d.ts +24 -0
  115. package/dist/components/chat-components/ui/dropdown-menu.mjs +84 -0
  116. package/dist/components/chat-components/ui/dropdown-menu.mjs.map +1 -0
  117. package/dist/components/chat-components/ui/icons.d.ts +33 -0
  118. package/dist/components/chat-components/ui/icons.mjs +5 -0
  119. package/dist/components/chat-components/ui/icons.mjs.map +1 -0
  120. package/dist/components/chat-components/ui/input.d.ts +7 -0
  121. package/dist/components/chat-components/ui/input.mjs +23 -0
  122. package/dist/components/chat-components/ui/input.mjs.map +1 -0
  123. package/dist/components/chat-components/ui/label.d.ts +8 -0
  124. package/dist/components/chat-components/ui/label.mjs +22 -0
  125. package/dist/components/chat-components/ui/label.mjs.map +1 -0
  126. package/dist/components/chat-components/ui/select.d.ts +13 -0
  127. package/dist/components/chat-components/ui/select.mjs +99 -0
  128. package/dist/components/chat-components/ui/select.mjs.map +1 -0
  129. package/dist/components/chat-components/ui/separator.d.ts +6 -0
  130. package/dist/components/chat-components/ui/separator.mjs +5 -0
  131. package/dist/components/chat-components/ui/separator.mjs.map +1 -0
  132. package/dist/components/chat-components/ui/sheet.d.ts +19 -0
  133. package/dist/components/chat-components/ui/sheet.mjs +109 -0
  134. package/dist/components/chat-components/ui/sheet.mjs.map +1 -0
  135. package/dist/components/chat-components/ui/switch.d.ts +6 -0
  136. package/dist/components/chat-components/ui/switch.mjs +27 -0
  137. package/dist/components/chat-components/ui/switch.mjs.map +1 -0
  138. package/dist/components/chat-components/ui/textarea.d.ts +7 -0
  139. package/dist/components/chat-components/ui/textarea.mjs +22 -0
  140. package/dist/components/chat-components/ui/textarea.mjs.map +1 -0
  141. package/dist/components/chat-components/ui/tooltip.d.ts +9 -0
  142. package/dist/components/chat-components/ui/tooltip.mjs +5 -0
  143. package/dist/components/chat-components/ui/tooltip.mjs.map +1 -0
  144. package/dist/components/index.d.ts +9 -0
  145. package/dist/components/index.mjs +26 -0
  146. package/dist/components/index.mjs.map +1 -0
  147. package/dist/components/sidebar/copilot-sidebar-ui-provider.d.ts +8 -0
  148. package/dist/components/sidebar/copilot-sidebar-ui-provider.mjs +25 -0
  149. package/dist/components/sidebar/copilot-sidebar-ui-provider.mjs.map +1 -0
  150. package/dist/components/sidebar/copilot-sidebar.d.ts +6 -0
  151. package/dist/components/sidebar/copilot-sidebar.mjs +23 -0
  152. package/dist/components/sidebar/copilot-sidebar.mjs.map +1 -0
  153. package/dist/components/sidebar/sidebar-context.d.ts +9 -0
  154. package/dist/components/sidebar/sidebar-context.mjs +4 -0
  155. package/dist/components/sidebar/sidebar-context.mjs.map +1 -0
  156. package/dist/context/index.d.ts +1 -0
  157. package/dist/context/index.mjs +3 -0
  158. package/dist/context/index.mjs.map +1 -0
  159. package/dist/hooks/index.d.ts +1 -0
  160. package/dist/hooks/index.mjs +3 -0
  161. package/dist/hooks/index.mjs.map +1 -0
  162. package/dist/hooks/use-at-bottom.d.ts +3 -0
  163. package/dist/hooks/use-at-bottom.mjs +4 -0
  164. package/dist/hooks/use-at-bottom.mjs.map +1 -0
  165. package/dist/hooks/use-copy-to-clipboard.d.ts +9 -0
  166. package/dist/hooks/use-copy-to-clipboard.mjs +4 -0
  167. package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -0
  168. package/dist/hooks/use-enter-submit.d.ts +8 -0
  169. package/dist/hooks/use-enter-submit.mjs +4 -0
  170. package/dist/hooks/use-enter-submit.mjs.map +1 -0
  171. package/dist/index.css +1249 -1
  172. package/dist/index.css.map +1 -0
  173. package/dist/index.d.ts +9 -2
  174. package/dist/index.mjs +29 -0
  175. package/dist/index.mjs.map +1 -0
  176. package/dist/lib/utils.d.ts +8 -0
  177. package/dist/lib/utils.mjs +4 -0
  178. package/dist/lib/utils.mjs.map +1 -0
  179. package/dist/types/index.d.ts +1 -0
  180. package/dist/types/index.mjs +3 -0
  181. package/dist/types/index.mjs.map +1 -0
  182. package/dist/types/types.d.ts +16 -0
  183. package/dist/types/types.mjs +3 -0
  184. package/dist/types/types.mjs.map +1 -0
  185. package/package.json +39 -8
  186. package/src/components/chat-components/chat-list.tsx +32 -0
  187. package/src/components/chat-components/chat-message-actions.tsx +40 -0
  188. package/src/components/chat-components/chat-message.tsx +74 -0
  189. package/src/components/chat-components/chat-panel.tsx +77 -0
  190. package/src/components/chat-components/chat-scroll-anchor.tsx +29 -0
  191. package/src/components/chat-components/clear-history.tsx +73 -0
  192. package/src/components/chat-components/copilot-chat.tsx +56 -0
  193. package/src/components/chat-components/default-empty-screen.tsx +64 -0
  194. package/src/components/chat-components/external-link.tsx +29 -0
  195. package/src/components/chat-components/markdown.tsx +9 -0
  196. package/src/components/chat-components/prompt-form.tsx +91 -0
  197. package/src/components/chat-components/theme-toggle.tsx +31 -0
  198. package/src/components/chat-components/toaster.tsx +3 -0
  199. package/src/components/chat-components/ui/alert-dialog.tsx +150 -0
  200. package/src/components/chat-components/ui/badge.tsx +36 -0
  201. package/src/components/chat-components/ui/button.tsx +57 -0
  202. package/src/components/chat-components/ui/codeblock.tsx +142 -0
  203. package/src/components/chat-components/ui/dialog.tsx +128 -0
  204. package/src/components/chat-components/ui/dropdown-menu.tsx +128 -0
  205. package/src/components/chat-components/ui/icons.tsx +507 -0
  206. package/src/components/chat-components/ui/input.tsx +25 -0
  207. package/src/components/chat-components/ui/label.tsx +26 -0
  208. package/src/components/chat-components/ui/select.tsx +119 -0
  209. package/src/components/chat-components/ui/separator.tsx +31 -0
  210. package/src/components/chat-components/ui/sheet.tsx +122 -0
  211. package/src/components/chat-components/ui/switch.tsx +29 -0
  212. package/src/components/chat-components/ui/textarea.tsx +24 -0
  213. package/src/components/chat-components/ui/tooltip.tsx +30 -0
  214. package/src/components/index.ts +7 -0
  215. package/src/components/sidebar/copilot-sidebar-ui-provider.tsx +77 -0
  216. package/src/components/sidebar/copilot-sidebar.tsx +40 -0
  217. package/src/components/sidebar/sidebar-context.tsx +11 -0
  218. package/src/context/index.ts +1 -0
  219. package/src/hooks/index.ts +1 -0
  220. package/src/hooks/use-at-bottom.tsx +23 -0
  221. package/src/hooks/use-copy-to-clipboard.tsx +33 -0
  222. package/src/hooks/use-enter-submit.tsx +23 -0
  223. package/src/index.tsx +4 -3
  224. package/src/lib/utils.ts +43 -0
  225. package/src/types/index.ts +1 -0
  226. package/src/types/types.ts +18 -0
  227. package/tailwind.config.js +1 -1
  228. package/tsconfig.json +1 -1
  229. package/tsup.config.ts +3 -4
  230. package/dist/Button.d.ts +0 -3
  231. package/dist/Button.js +0 -10
  232. package/dist/Card.d.ts +0 -7
  233. package/dist/Card.js +0 -10
  234. package/dist/chunk-6OZR7L23.js +0 -7
  235. package/dist/chunk-FGO3LSHH.js +0 -7
  236. package/dist/index.js +0 -15
  237. package/src/Button.tsx +0 -16
  238. package/src/Card.tsx +0 -27
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ import React from "react";
3
+ import { UseChatHelpers } from "ai/react";
4
+
5
+ import { Button } from "./ui/button";
6
+ import { ExternalLink } from "./external-link";
7
+ import { IconArrowRight } from "./ui/icons";
8
+
9
+ const exampleMessages = [
10
+ {
11
+ heading: "Explain technical concepts",
12
+ message: `What is a "serverless function"?`,
13
+ },
14
+ {
15
+ heading: "Summarize an article",
16
+ message: "Summarize the following article for a 2nd grader: \n",
17
+ },
18
+ {
19
+ heading: "Draft an email",
20
+ message: `Draft an email to my boss about the following: \n`,
21
+ },
22
+ ];
23
+
24
+ export interface EmptyScreenProps {
25
+ setInput: React.Dispatch<React.SetStateAction<string>>;
26
+ }
27
+
28
+ export const DefaultEmptyScreen: React.FC<EmptyScreenProps> = (props) => {
29
+ return (
30
+ <div className="mx-auto max-w-2xl px-4">
31
+ <div className="rounded-lg border bg-background p-8">
32
+ <h1 className="mb-2 text-lg font-semibold">
33
+ Welcome to CopilotKit! 👋
34
+ </h1>
35
+ <p className="mb-2 leading-normal text-muted-foreground">
36
+ This is a Copilot built with{" "}
37
+ <ExternalLink href="https://recursively.ai">
38
+ recursively.ai's
39
+ </ExternalLink>{" "}
40
+ <ExternalLink href="https://github.com/RecursivelyAI/CopilotKit">
41
+ CopilotKit
42
+ </ExternalLink>{" "}
43
+ .
44
+ </p>
45
+ <p className="leading-normal text-muted-foreground">
46
+ You can start a conversation here or try the following examples:
47
+ </p>
48
+ <div className="mt-4 flex flex-col items-start space-y-2">
49
+ {exampleMessages.map((message, index) => (
50
+ <Button
51
+ key={index}
52
+ variant="link"
53
+ className="h-auto p-0 text-base"
54
+ onClick={() => props.setInput(message.message)}
55
+ >
56
+ <IconArrowRight className="mr-2 text-muted-foreground" />
57
+ {message.heading}
58
+ </Button>
59
+ ))}
60
+ </div>
61
+ </div>
62
+ </div>
63
+ );
64
+ };
@@ -0,0 +1,29 @@
1
+ export function ExternalLink({
2
+ href,
3
+ children,
4
+ }: {
5
+ href: string;
6
+ children: React.ReactNode;
7
+ }) {
8
+ return (
9
+ <a
10
+ href={href}
11
+ target="_blank"
12
+ className="inline-flex flex-1 justify-center gap-1 leading-4 hover:underline"
13
+ >
14
+ <span>{children}</span>
15
+ <svg
16
+ aria-hidden="true"
17
+ height="7"
18
+ viewBox="0 0 6 6"
19
+ width="7"
20
+ className="opacity-70"
21
+ >
22
+ <path
23
+ d="M1.25215 5.54731L0.622742 4.9179L3.78169 1.75597H1.3834L1.38936 0.890915H5.27615V4.78069H4.40513L4.41109 2.38538L1.25215 5.54731Z"
24
+ fill="currentColor"
25
+ ></path>
26
+ </svg>
27
+ </a>
28
+ );
29
+ }
@@ -0,0 +1,9 @@
1
+ import { FC, memo } from "react";
2
+ import ReactMarkdown, { Options } from "react-markdown";
3
+
4
+ export const MemoizedReactMarkdown: FC<Options> = memo(
5
+ ReactMarkdown,
6
+ (prevProps, nextProps) =>
7
+ prevProps.children === nextProps.children &&
8
+ prevProps.className === nextProps.className
9
+ );
@@ -0,0 +1,91 @@
1
+ import * as React from "react";
2
+ import TextareaAutosize from "react-textarea-autosize";
3
+ import { UseChatHelpers } from "ai/react";
4
+
5
+ import { useEnterSubmit } from "../../hooks/use-enter-submit";
6
+ import { cn } from "../../lib/utils";
7
+ import { Button, buttonVariants } from "./ui/button";
8
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
9
+ import { IconArrowElbow, IconPlus } from "./ui/icons";
10
+ import Link from "next/link";
11
+
12
+ export interface PromptProps
13
+ extends Pick<UseChatHelpers, "input" | "setInput"> {
14
+ onSubmit: (value: string) => Promise<void>;
15
+ isLoading: boolean;
16
+ }
17
+
18
+ export function PromptForm({
19
+ onSubmit,
20
+ input,
21
+ setInput,
22
+ isLoading,
23
+ }: PromptProps) {
24
+ const { formRef, onKeyDown } = useEnterSubmit();
25
+ const inputRef = React.useRef<HTMLTextAreaElement>(null);
26
+
27
+ React.useEffect(() => {
28
+ if (inputRef.current) {
29
+ inputRef.current.focus();
30
+ }
31
+ }, []);
32
+
33
+ return (
34
+ <form
35
+ onSubmit={async (e) => {
36
+ e.preventDefault();
37
+ if (!input?.trim()) {
38
+ return;
39
+ }
40
+ setInput("");
41
+ await onSubmit(input);
42
+ }}
43
+ ref={formRef}
44
+ >
45
+ <div className="relative flex max-h-60 w-full grow flex-col overflow-hidden bg-background px-8 sm:rounded-md border sm:px-12">
46
+ <Tooltip>
47
+ <TooltipTrigger asChild>
48
+ <Link
49
+ href="/"
50
+ className={cn(
51
+ buttonVariants({ size: "sm", variant: "outline" }),
52
+ "absolute left-0 top-4 h-8 w-8 rounded-full bg-background p-0 sm:left-4"
53
+ )}
54
+ >
55
+ <IconPlus />
56
+ <span className="sr-only">New Chat</span>
57
+ </Link>
58
+ </TooltipTrigger>
59
+ <TooltipContent>New Chat</TooltipContent>
60
+ </Tooltip>
61
+ <TextareaAutosize
62
+ ref={inputRef}
63
+ tabIndex={0}
64
+ onKeyDown={onKeyDown}
65
+ rows={1}
66
+ value={input}
67
+ onChange={(e) => setInput(e.target.value)}
68
+ placeholder="Send a message."
69
+ spellCheck={false}
70
+ className="min-h-[60px] w-full resize-none bg-transparent px-4 py-[1.3rem] focus-within:outline-none sm:text-sm"
71
+ />
72
+ <div className="absolute right-0 top-4 sm:right-4">
73
+ <Tooltip>
74
+ <TooltipTrigger asChild>
75
+ <Button
76
+ type="submit"
77
+ size="icon"
78
+ disabled={isLoading || input === ""}
79
+ className=" bg-slate-300"
80
+ >
81
+ <IconArrowElbow />
82
+ <span className="sr-only">Send message</span>
83
+ </Button>
84
+ </TooltipTrigger>
85
+ <TooltipContent>Send message</TooltipContent>
86
+ </Tooltip>
87
+ </div>
88
+ </div>
89
+ </form>
90
+ );
91
+ }
@@ -0,0 +1,31 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { useTheme } from "next-themes";
5
+
6
+ import { Button } from "./ui/button";
7
+ import { IconMoon, IconSun } from "./ui/icons";
8
+
9
+ export function ThemeToggle() {
10
+ const { setTheme, theme } = useTheme();
11
+ const [_, startTransition] = React.useTransition();
12
+
13
+ return (
14
+ <Button
15
+ variant="ghost"
16
+ size="icon"
17
+ onClick={() => {
18
+ startTransition(() => {
19
+ setTheme(theme === "light" ? "dark" : "light");
20
+ });
21
+ }}
22
+ >
23
+ {!theme ? null : theme === "dark" ? (
24
+ <IconMoon className="transition-all" />
25
+ ) : (
26
+ <IconSun className="transition-all" />
27
+ )}
28
+ <span className="sr-only">Toggle theme</span>
29
+ </Button>
30
+ );
31
+ }
@@ -0,0 +1,3 @@
1
+ "use client";
2
+
3
+ export { Toaster } from "react-hot-toast";
@@ -0,0 +1,150 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
5
+
6
+ import { cn } from "../../../lib/utils";
7
+ import { buttonVariants } from "./button";
8
+
9
+ const AlertDialog = AlertDialogPrimitive.Root;
10
+
11
+ const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
12
+
13
+ const AlertDialogPortal = ({
14
+ className,
15
+ children,
16
+ ...props
17
+ }: AlertDialogPrimitive.AlertDialogPortalProps) => (
18
+ <AlertDialogPrimitive.Portal className={cn(className)} {...props}>
19
+ <div className="fixed inset-0 z-50 flex items-end justify-center sm:items-center">
20
+ {children}
21
+ </div>
22
+ </AlertDialogPrimitive.Portal>
23
+ );
24
+ AlertDialogPortal.displayName = AlertDialogPrimitive.Portal.displayName;
25
+
26
+ const AlertDialogOverlay = React.forwardRef<
27
+ React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
28
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
29
+ >(({ className, children, ...props }, ref) => (
30
+ <AlertDialogPrimitive.Overlay
31
+ className={cn(
32
+ "fixed inset-0 z-50 bg-background/80 backdrop-blur-sm transition-opacity animate-in fade-in",
33
+ className
34
+ )}
35
+ {...props}
36
+ ref={ref}
37
+ />
38
+ ));
39
+ AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
40
+
41
+ const AlertDialogContent = React.forwardRef<
42
+ React.ElementRef<typeof AlertDialogPrimitive.Content>,
43
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
44
+ >(({ className, ...props }, ref) => (
45
+ <AlertDialogPortal>
46
+ <AlertDialogOverlay />
47
+ <AlertDialogPrimitive.Content
48
+ ref={ref}
49
+ className={cn(
50
+ "fixed z-50 grid w-full max-w-lg scale-100 gap-4 border bg-background p-6 opacity-100 shadow-lg animate-in fade-in-90 slide-in-from-bottom-10 sm:rounded-lg sm:zoom-in-90 sm:slide-in-from-bottom-0 md:w-full",
51
+ className
52
+ )}
53
+ {...props}
54
+ />
55
+ </AlertDialogPortal>
56
+ ));
57
+ AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
58
+
59
+ const AlertDialogHeader = ({
60
+ className,
61
+ ...props
62
+ }: React.HTMLAttributes<HTMLDivElement>) => (
63
+ <div
64
+ className={cn(
65
+ "flex flex-col space-y-2 text-center sm:text-left",
66
+ className
67
+ )}
68
+ {...props}
69
+ />
70
+ );
71
+ AlertDialogHeader.displayName = "AlertDialogHeader";
72
+
73
+ const AlertDialogFooter = ({
74
+ className,
75
+ ...props
76
+ }: React.HTMLAttributes<HTMLDivElement>) => (
77
+ <div
78
+ className={cn(
79
+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
80
+ className
81
+ )}
82
+ {...props}
83
+ />
84
+ );
85
+ AlertDialogFooter.displayName = "AlertDialogFooter";
86
+
87
+ const AlertDialogTitle = React.forwardRef<
88
+ React.ElementRef<typeof AlertDialogPrimitive.Title>,
89
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
90
+ >(({ className, ...props }, ref) => (
91
+ <AlertDialogPrimitive.Title
92
+ ref={ref}
93
+ className={cn("text-lg font-semibold", className)}
94
+ {...props}
95
+ />
96
+ ));
97
+ AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
98
+
99
+ const AlertDialogDescription = React.forwardRef<
100
+ React.ElementRef<typeof AlertDialogPrimitive.Description>,
101
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
102
+ >(({ className, ...props }, ref) => (
103
+ <AlertDialogPrimitive.Description
104
+ ref={ref}
105
+ className={cn("text-sm text-muted-foreground", className)}
106
+ {...props}
107
+ />
108
+ ));
109
+ AlertDialogDescription.displayName =
110
+ AlertDialogPrimitive.Description.displayName;
111
+
112
+ const AlertDialogAction = React.forwardRef<
113
+ React.ElementRef<typeof AlertDialogPrimitive.Action>,
114
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
115
+ >(({ className, ...props }, ref) => (
116
+ <AlertDialogPrimitive.Action
117
+ ref={ref}
118
+ className={cn(buttonVariants(), className)}
119
+ {...props}
120
+ />
121
+ ));
122
+ AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
123
+
124
+ const AlertDialogCancel = React.forwardRef<
125
+ React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
126
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
127
+ >(({ className, ...props }, ref) => (
128
+ <AlertDialogPrimitive.Cancel
129
+ ref={ref}
130
+ className={cn(
131
+ buttonVariants({ variant: "outline" }),
132
+ "mt-2 sm:mt-0",
133
+ className
134
+ )}
135
+ {...props}
136
+ />
137
+ ));
138
+ AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
139
+
140
+ export {
141
+ AlertDialog,
142
+ AlertDialogTrigger,
143
+ AlertDialogContent,
144
+ AlertDialogHeader,
145
+ AlertDialogFooter,
146
+ AlertDialogTitle,
147
+ AlertDialogDescription,
148
+ AlertDialogAction,
149
+ AlertDialogCancel,
150
+ };
@@ -0,0 +1,36 @@
1
+ import * as React from "react";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+
4
+ import { cn } from "../../../lib/utils";
5
+
6
+ const badgeVariants = cva(
7
+ "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default:
12
+ "border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
13
+ secondary:
14
+ "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
15
+ destructive:
16
+ "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
17
+ outline: "text-foreground",
18
+ },
19
+ },
20
+ defaultVariants: {
21
+ variant: "default",
22
+ },
23
+ }
24
+ );
25
+
26
+ export interface BadgeProps
27
+ extends React.HTMLAttributes<HTMLDivElement>,
28
+ VariantProps<typeof badgeVariants> {}
29
+
30
+ function Badge({ className, variant, ...props }: BadgeProps) {
31
+ return (
32
+ <div className={cn(badgeVariants({ variant }), className)} {...props} />
33
+ );
34
+ }
35
+
36
+ export { Badge, badgeVariants };
@@ -0,0 +1,57 @@
1
+ import * as React from "react";
2
+ import { Slot } from "@radix-ui/react-slot";
3
+ import { cva, type VariantProps } from "class-variance-authority";
4
+
5
+ import { cn } from "../../../lib/utils";
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center rounded-md text-sm font-medium shadow ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default:
13
+ "bg-primary text-primary-foreground shadow-md hover:bg-primary/90",
14
+ destructive:
15
+ "bg-destructive text-destructive-foreground hover:bg-destructive/90",
16
+ outline:
17
+ "border border-input hover:bg-accent hover:text-accent-foreground",
18
+ secondary:
19
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
20
+ ghost: "shadow-none hover:bg-accent hover:text-accent-foreground",
21
+ link: "text-primary underline-offset-4 shadow-none hover:underline",
22
+ },
23
+ size: {
24
+ default: "h-8 px-4 py-2",
25
+ sm: "h-8 rounded-md px-3",
26
+ lg: "h-11 rounded-md px-8",
27
+ icon: "h-8 w-8 p-0",
28
+ },
29
+ },
30
+ defaultVariants: {
31
+ variant: "default",
32
+ size: "default",
33
+ },
34
+ }
35
+ );
36
+
37
+ export interface ButtonProps
38
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
39
+ VariantProps<typeof buttonVariants> {
40
+ asChild?: boolean;
41
+ }
42
+
43
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
44
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
45
+ const Comp = asChild ? Slot : "button";
46
+ return (
47
+ <Comp
48
+ className={cn(buttonVariants({ variant, size, className }))}
49
+ ref={ref}
50
+ {...props}
51
+ />
52
+ );
53
+ }
54
+ );
55
+ Button.displayName = "Button";
56
+
57
+ export { Button, buttonVariants };
@@ -0,0 +1,142 @@
1
+ "use client";
2
+
3
+ import { FC, memo } from "react";
4
+ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
5
+ import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
6
+
7
+ import { useCopyToClipboard } from "../../../hooks/use-copy-to-clipboard";
8
+ import { IconCheck, IconCopy, IconDownload } from "./icons";
9
+ import { Button } from "./button";
10
+
11
+ interface Props {
12
+ language: string;
13
+ value: string;
14
+ }
15
+
16
+ interface languageMap {
17
+ [key: string]: string | undefined;
18
+ }
19
+
20
+ export const programmingLanguages: languageMap = {
21
+ javascript: ".js",
22
+ python: ".py",
23
+ java: ".java",
24
+ c: ".c",
25
+ cpp: ".cpp",
26
+ "c++": ".cpp",
27
+ "c#": ".cs",
28
+ ruby: ".rb",
29
+ php: ".php",
30
+ swift: ".swift",
31
+ "objective-c": ".m",
32
+ kotlin: ".kt",
33
+ typescript: ".ts",
34
+ go: ".go",
35
+ perl: ".pl",
36
+ rust: ".rs",
37
+ scala: ".scala",
38
+ haskell: ".hs",
39
+ lua: ".lua",
40
+ shell: ".sh",
41
+ sql: ".sql",
42
+ html: ".html",
43
+ css: ".css",
44
+ // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
45
+ };
46
+
47
+ export const generateRandomString = (length: number, lowercase = false) => {
48
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789"; // excluding similar looking characters like Z, 2, I, 1, O, 0
49
+ let result = "";
50
+ for (let i = 0; i < length; i++) {
51
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
52
+ }
53
+ return lowercase ? result.toLowerCase() : result;
54
+ };
55
+
56
+ const CodeBlock: FC<Props> = memo(({ language, value }) => {
57
+ const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });
58
+
59
+ const downloadAsFile = () => {
60
+ if (typeof window === "undefined") {
61
+ return;
62
+ }
63
+ const fileExtension = programmingLanguages[language] || ".file";
64
+ const suggestedFileName = `file-${generateRandomString(
65
+ 3,
66
+ true
67
+ )}${fileExtension}`;
68
+ const fileName = window.prompt("Enter file name" || "", suggestedFileName);
69
+
70
+ if (!fileName) {
71
+ // User pressed cancel on prompt.
72
+ return;
73
+ }
74
+
75
+ const blob = new Blob([value], { type: "text/plain" });
76
+ const url = URL.createObjectURL(blob);
77
+ const link = document.createElement("a");
78
+ link.download = fileName;
79
+ link.href = url;
80
+ link.style.display = "none";
81
+ document.body.appendChild(link);
82
+ link.click();
83
+ document.body.removeChild(link);
84
+ URL.revokeObjectURL(url);
85
+ };
86
+
87
+ const onCopy = () => {
88
+ if (isCopied) return;
89
+ copyToClipboard(value);
90
+ };
91
+
92
+ return (
93
+ <div className="codeblock relative w-full bg-zinc-950 font-sans">
94
+ <div className="flex w-full items-center justify-between bg-zinc-800 px-6 py-2 pr-4 text-zinc-100">
95
+ <span className="text-xs lowercase">{language}</span>
96
+ <div className="flex items-center space-x-1">
97
+ <Button
98
+ variant="ghost"
99
+ className="hover:bg-zinc-800 focus-visible:ring-1 focus-visible:ring-slate-700 focus-visible:ring-offset-0"
100
+ onClick={downloadAsFile}
101
+ size="icon"
102
+ >
103
+ <IconDownload />
104
+ <span className="sr-only">Download</span>
105
+ </Button>
106
+ <Button
107
+ variant="ghost"
108
+ size="icon"
109
+ className="text-xs hover:bg-zinc-800 focus-visible:ring-1 focus-visible:ring-slate-700 focus-visible:ring-offset-0"
110
+ onClick={onCopy}
111
+ >
112
+ {isCopied ? <IconCheck /> : <IconCopy />}
113
+ <span className="sr-only">Copy code</span>
114
+ </Button>
115
+ </div>
116
+ </div>
117
+ <SyntaxHighlighter
118
+ language={language}
119
+ style={coldarkDark}
120
+ PreTag="div"
121
+ showLineNumbers
122
+ customStyle={{
123
+ margin: 0,
124
+ width: "100%",
125
+ background: "transparent",
126
+ padding: "1.5rem 1rem",
127
+ }}
128
+ codeTagProps={{
129
+ style: {
130
+ fontSize: "0.9rem",
131
+ fontFamily: "var(--font-mono)",
132
+ },
133
+ }}
134
+ >
135
+ {value}
136
+ </SyntaxHighlighter>
137
+ </div>
138
+ );
139
+ });
140
+ CodeBlock.displayName = "CodeBlock";
141
+
142
+ export { CodeBlock };