xonecas.io
53129
Pa

PAT / commit e5cb04d

feat: new buttons and anchors

xonecas2025-12-17 e5cb04d1465fdb1c0e4d7b11e26d3633355d7127 parent 033c109

15 files changed

AGENTS.md+5−6
@@ -72,7 +72,6 @@ Add tests when prompted only.
7272 - Prettier configuration is in `.prettierrc`
7373 - Prettier automatically sorts Tailwind CSS classes via `prettier-plugin-tailwindcss`
7474
75-
7675 8. **Error Handling**:
7776 - Use `console.error` for errors
7877 - Use `lib/debug` for debug information
@@ -80,11 +79,11 @@ Add tests when prompted only.
8079 - Handle API errors gracefully with try/catch blocks
8180
8281 9. **Imports**:
83- - Use absolute imports with `@/` prefix for local files (e.g., `import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon"`)
84- - Group imports: external packages first, then local imports
85- - Use named imports from libraries (e.g., `import { NextResponse } from "next/server"`)
86- - Use default imports for component files (e.g., `import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon"`)
87- - Path alias `@/` is configured in `tsconfig.json` to point to the project root
82+ - Use absolute imports with `@/` prefix for local files (e.g., `import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon"`)
83+ - Group imports: external packages first, then local imports
84+ - Use named imports from libraries (e.g., `import { NextResponse } from "next/server"`)
85+ - Use default imports for component files (e.g., `import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon"`)
86+ - Path alias `@/` is configured in `tsconfig.json` to point to the project root
8887
8988 ## Key Implementation Details
9089
app/globals.css+7−7
@@ -12,7 +12,7 @@
1212 .prose {
1313 font-size: inherit;
1414 }
15-
15+
1616 .prose p,
1717 .prose ul,
1818 .prose ol,
@@ -28,29 +28,29 @@
2828 .prose h6 {
2929 font-size: inherit;
3030 }
31-
31+
3232 .prose h1 {
3333 font-size: 1.5em;
3434 }
35-
35+
3636 .prose h2 {
3737 font-size: 1.3em;
3838 }
39-
39+
4040 .prose h3 {
4141 font-size: 1.15em;
4242 }
43-
43+
4444 .prose h4,
4545 .prose h5,
4646 .prose h6 {
4747 font-size: 1.05em;
4848 }
49-
49+
5050 .prose code {
5151 font-size: 0.9em;
5252 }
53-
53+
5454 .prose pre {
5555 font-size: 0.9em;
5656 }
app/page.tsx+0−1
@@ -36,7 +36,6 @@ export default function Home() {
3636 await sendMessage(message, currentThreadId, createThread, selectThread, loadThreads);
3737 };
3838
39-
4039 return (
4140 <div className="flex h-screen bg-neutral-100 text-neutral-800 dark:bg-neutral-950 dark:text-neutral-200">
4241 <div className="flex min-w-0 flex-1 flex-col">
src/components/Anchor.tsx+63−0
@@ -0,0 +1,63 @@
1+"use client";
2+
3+import type { AnchorHTMLAttributes, ReactNode } from "react";
4+
5+type AnchorProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
6+ children: ReactNode;
7+ isSelected?: boolean;
8+ color?: string;
9+};
10+
11+// Anchor: A reusable anchor component with customizable selection highlight color.
12+// When selected (isSelected=true), displays a colored border based on the color prop.
13+// When not selected, uses neutral borders with hover effects.
14+export default function Anchor({
15+ children,
16+ isSelected = false,
17+ color = "green",
18+ className = "",
19+ ...props
20+}: AnchorProps) {
21+ // Map color to Tailwind border classes (using full class names for JIT compilation)
22+ const getBorderColorClasses = (colorName: string) => {
23+ const colorMap: Record<string, string> = {
24+ green: "border-green-900 dark:border-green-500",
25+ rose: "border-rose-900 dark:border-rose-500",
26+ red: "border-red-900 dark:border-red-500",
27+ orange: "border-orange-900 dark:border-orange-500",
28+ amber: "border-amber-900 dark:border-amber-500",
29+ yellow: "border-yellow-900 dark:border-yellow-500",
30+ lime: "border-lime-900 dark:border-lime-500",
31+ emerald: "border-emerald-900 dark:border-emerald-500",
32+ teal: "border-teal-900 dark:border-teal-500",
33+ cyan: "border-cyan-900 dark:border-cyan-500",
34+ sky: "border-sky-900 dark:border-sky-500",
35+ blue: "border-blue-900 dark:border-blue-500",
36+ indigo: "border-indigo-900 dark:border-indigo-500",
37+ violet: "border-violet-900 dark:border-violet-500",
38+ purple: "border-purple-900 dark:border-purple-500",
39+ fuchsia: "border-fuchsia-900 dark:border-fuchsia-500",
40+ pink: "border-pink-900 dark:border-pink-500",
41+ slate: "border-slate-900 dark:border-slate-500",
42+ gray: "border-gray-900 dark:border-gray-500",
43+ zinc: "border-zinc-900 dark:border-zinc-500",
44+ neutral: "border-neutral-900 dark:border-neutral-500",
45+ stone: "border-stone-900 dark:border-stone-500",
46+ };
47+ return colorMap[colorName] || colorMap.green;
48+ };
49+
50+ return (
51+ <a
52+ className={`m-1 line-clamp-1 break-words border-b-2 p-1 italic ${
53+ isSelected
54+ ? getBorderColorClasses(color)
55+ : "border-neutral-300 hover:border-neutral-400 dark:border-neutral-800 dark:hover:border-neutral-700"
56+ } ${className}`}
57+ {...props}
58+ >
59+ {children}
60+ </a>
61+ );
62+}
63+
src/components/MessageInput.tsx+7−7
@@ -34,19 +34,19 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
3434
3535 // Reset height to auto to get the correct scrollHeight
3636 textarea.style.height = "auto";
37-
37+
3838 // Calculate line height from computed styles
3939 const computedStyle = getComputedStyle(textarea);
4040 const lineHeight = parseFloat(computedStyle.lineHeight) || 24;
4141 const paddingTop = parseFloat(computedStyle.paddingTop) || 8;
4242 const paddingBottom = parseFloat(computedStyle.paddingBottom) || 8;
43-
43+
4444 // Minimum height for 3 lines
4545 const minHeight = lineHeight * 3 + paddingTop + paddingBottom;
46-
46+
4747 // Maximum height for 10 lines
4848 const maxHeight = lineHeight * 10 + paddingTop + paddingBottom;
49-
49+
5050 // Set height to scrollHeight or minHeight, whichever is larger
5151 // Add one extra line height to keep an empty line at the bottom
5252 // Cap at maxHeight to enable scrolling after 10 lines
@@ -65,7 +65,7 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
6565 onSubmit(inputValue);
6666 setInput("");
6767 setHistoryIndex(null);
68-
68+
6969 // Reset textarea height after submit
7070 if (textareaRef.current) {
7171 textareaRef.current.style.height = "auto";
@@ -115,11 +115,11 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
115115 placeholder={isLoading ? "Loading answer..." : "Type a message..."}
116116 disabled={isLoading}
117117 rows={3}
118- className="w-full bg-neutral-200 px-2 py-2 pr-12 placeholder:italic placeholder:text-neutral-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-neutral-900 dark:placeholder:text-neutral-400 resize-none overflow-y-auto"
118+ className="w-full resize-none overflow-y-auto bg-neutral-200 px-2 py-2 pr-12 placeholder:italic placeholder:text-neutral-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-neutral-900 dark:placeholder:text-neutral-400"
119119 />
120120 <div className="absolute bottom-2 right-2">
121121 <PrimaryButton type="submit" disabled={isLoading}>
122- <PaperPlaneIcon className={`h-8 w-5 ${isLoading ? "animate-spin" : ""}`} />
122+ <PaperPlaneIcon className={`h-9 w-9 p-1.5 ${isLoading ? "animate-spin" : ""}`} />
123123 </PrimaryButton>
124124 </div>
125125 </form>
src/components/MessageList.tsx+1−3
@@ -115,8 +115,7 @@ function UserMessageContent({ content }: { content: string }) {
115115 useEffect(() => {
116116 const checkOverflow = () => {
117117 if (contentRef.current) {
118- const isScrollable =
119- contentRef.current.scrollHeight > contentRef.current.clientHeight;
118+ const isScrollable = contentRef.current.scrollHeight > contentRef.current.clientHeight;
120119 setShowGradient(isScrollable);
121120 }
122121 };
@@ -148,4 +147,3 @@ function UserMessageContent({ content }: { content: string }) {
148147 </div>
149148 );
150149 }
151-
src/components/NoThreadSelected.tsx+6−1
@@ -36,7 +36,12 @@ export default function NoThreadSelected({ threadCount }: NoThreadSelectedProps)
3636 </p>
3737 <hr className="border-neutral-300 dark:border-neutral-700" />
3838 <p className="text-sm text-neutral-600 dark:text-neutral-400">
39- {timeDisplay && <><em>Current time: {timeDisplay}</em><br /></>}
39+ {timeDisplay && (
40+ <>
41+ <em>Current time: {timeDisplay}</em>
42+ <br />
43+ </>
44+ )}
4045 <em>
4146 {threadCount} {threadCount === 1 ? "thread" : "threads"} created
4247 </em>
src/components/Sidebar.tsx+18−14
@@ -4,7 +4,7 @@ import type { Thread } from "@/src/lib/db/schema";
44 import PlusIcon from "@/src/components/icons/PlusIcon";
55 import ChevronDownIcon from "@/src/components/icons/ChevronDownIcon";
66 import AlternateButton from "@/src/components/buttons/AlternateButton";
7-import SecondaryButton from "@/src/components/buttons/SecondaryButton";
7+import Anchor from "@/src/components/Anchor";
88
99 type SidebarProps = {
1010 threads: Thread[];
@@ -38,21 +38,25 @@ export default function Sidebar({
3838 New Thread
3939 </AlternateButton>
4040 {threads.length === 0 ? (
41- <div className="px-3 py-2 text-neutral-600 dark:text-neutral-400">
42- No threads yet
43- </div>
41+ <div className="px-3 py-2 text-neutral-600 dark:text-neutral-400">No threads yet</div>
4442 ) : (
45- threads.map((thread) => (
46- <SecondaryButton
47- key={thread.id}
48- onClick={() => onThreadSelect(thread.id)}
49- isSelected={currentThreadId === thread.id}
50- >
51- <div className="line-clamp-2 break-words">
43+ threads.map((thread) => {
44+ const isSelected = currentThreadId === thread.id;
45+ return (
46+ <Anchor
47+ key={thread.id}
48+ href={`#thread-${thread.id}`}
49+ onClick={(e) => {
50+ e.preventDefault();
51+ onThreadSelect(thread.id);
52+ }}
53+ isSelected={isSelected}
54+ color="green"
55+ >
5256 {thread.title || `Thread ${thread.id}`}
53- </div>
54- </SecondaryButton>
55- ))
57+ </Anchor>
58+ );
59+ })
5660 )}
5761 </div>
5862 {hasMoreThreads && (
src/components/buttons/AlternateButton.tsx+3−6
@@ -1,6 +1,7 @@
11 "use client";
22
33 import type { ButtonHTMLAttributes, ReactNode } from "react";
4+import BasicButton from "./BasicButton";
45
56 type AlternateButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
67 children: ReactNode;
@@ -16,12 +17,8 @@ export default function AlternateButton({
1617 ...props
1718 }: AlternateButtonProps) {
1819 return (
19- <button
20- className={`flex items-center justify-center gap-1 bg-indigo-200 px-1 py-1 text-indigo-900 hover:bg-indigo-300 dark:bg-indigo-950 dark:text-indigo-200 dark:hover:bg-indigo-700 ${className}`}
21- {...props}
22- >
20+ <BasicButton color="indigo" className={className} {...props}>
2321 {children}
24- </button>
22+ </BasicButton>
2523 );
2624 }
27-
src/components/buttons/BasicButton.tsx+65−0
@@ -0,0 +1,65 @@
1+"use client";
2+
3+import type { ButtonHTMLAttributes, ReactNode } from "react";
4+
5+type BasicButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
6+ children: ReactNode;
7+ color?: string;
8+};
9+
10+// BasicButton: A button with animated border effects and customizable color.
11+// Features a bottom border that moves to top on active state, with rounded corners.
12+// Color prop allows customization of the button's color scheme.
13+export default function BasicButton({
14+ children,
15+ color = "rose",
16+ className = "",
17+ ...props
18+}: BasicButtonProps) {
19+ // Map color to Tailwind classes (using full class names for JIT compilation)
20+ const getColorClasses = (colorName: string) => {
21+ const colorMap: Record<string, string> = {
22+ green: "text-green-100 bg-green-800 hover:bg-green-900 border-t-green-950 border-b-green-950",
23+
24+ rose: "text-rose-100 bg-rose-800 hover:bg-rose-900 border-t-rose-950 border-b-rose-950",
25+ red: "text-red-100 bg-red-800 hover:bg-red-900 border-t-red-950 border-b-red-950",
26+ orange:
27+ "text-orange-100 bg-orange-800 hover:bg-orange-900 border-t-orange-950 border-b-orange-950",
28+ amber: "text-amber-100 bg-amber-800 hover:bg-amber-900 border-t-amber-950 border-b-amber-950",
29+ yellow:
30+ "text-yellow-100 bg-yellow-800 hover:bg-yellow-900 border-t-yellow-950 border-b-yellow-950",
31+ lime: "text-lime-100 bg-lime-800 hover:bg-lime-900 border-t-lime-950 border-b-lime-950",
32+ emerald:
33+ "text-emerald-100 bg-emerald-800 hover:bg-emerald-900 border-t-emerald-950 border-b-emerald-950",
34+ teal: "text-teal-100 bg-teal-800 hover:bg-teal-900 border-t-teal-950 border-b-teal-950",
35+ cyan: "text-cyan-100 bg-cyan-800 hover:bg-cyan-900 border-t-cyan-950 border-b-cyan-950",
36+ sky: "text-sky-100 bg-sky-800 hover:bg-sky-900 border-t-sky-950 border-b-sky-950",
37+ blue: "text-blue-100 bg-blue-800 hover:bg-blue-900 border-t-blue-950 border-b-blue-950",
38+ indigo:
39+ "text-indigo-100 bg-indigo-800 hover:bg-indigo-900 border-t-indigo-950 border-b-indigo-950",
40+ violet:
41+ "text-violet-100 bg-violet-800 hover:bg-violet-900 border-t-violet-950 border-b-violet-950",
42+ purple:
43+ "text-purple-100 bg-purple-800 hover:bg-purple-900 border-t-purple-950 border-b-purple-950",
44+ fuchsia:
45+ "text-fuchsia-100 bg-fuchsia-800 hover:bg-fuchsia-900 border-t-fuchsia-950 border-b-fuchsia-950",
46+ pink: "text-pink-100 bg-pink-800 hover:bg-pink-900 border-t-pink-950 border-b-pink-950",
47+ slate: "text-slate-100 bg-slate-800 hover:bg-slate-900 border-t-slate-950 border-b-slate-950",
48+ gray: "text-gray-100 bg-gray-800 hover:bg-gray-900 border-t-gray-950 border-b-gray-950",
49+ zinc: "text-zinc-100 bg-zinc-800 hover:bg-zinc-900 border-t-zinc-950 border-b-zinc-950",
50+ neutral:
51+ "text-neutral-100 bg-neutral-800 hover:bg-neutral-900 border-t-neutral-950 border-b-neutral-950",
52+ stone: "text-stone-100 bg-stone-800 hover:bg-stone-900 border-t-stone-950 border-b-stone-950",
53+ };
54+ return colorMap[colorName] || colorMap.rose;
55+ };
56+
57+ return (
58+ <button
59+ className={`${getColorClasses(color)} flex cursor-pointer items-center justify-center gap-1 rounded-b-xl rounded-t-lg border-b-8 p-2 font-bold shadow-sm shadow-stone-800 active:rounded-t-xl active:border-b-0 active:border-t-8 ${className}`}
60+ {...props}
61+ >
62+ {children}
63+ </button>
64+ );
65+}
src/components/buttons/PrimaryButton.tsx+4−11
@@ -1,6 +1,7 @@
11 "use client";
22
33 import type { ButtonHTMLAttributes, ReactNode } from "react";
4+import BasicButton from "./BasicButton";
45
56 type PrimaryButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
67 children: ReactNode;
@@ -10,18 +11,10 @@ type PrimaryButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
1011 // Uses green-900 (light mode) and green-500 (dark mode) as background;
1112 // white text in light mode, dark text in dark mode. Transitions to a lighter green on hover.
1213 // Disabled state lowers opacity and disables cursor interaction.
13-export default function PrimaryButton({
14- children,
15- className = "",
16- ...props
17-}: PrimaryButtonProps) {
14+export default function PrimaryButton({ children, className = "", ...props }: PrimaryButtonProps) {
1815 return (
19- <button
20- className={`bg-green-900 px-3 py-1 text-neutral-100 hover:bg-green-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-green-500 dark:text-neutral-900 dark:hover:bg-green-600 ${className}`}
21- {...props}
22- >
16+ <BasicButton color="green" className={className} {...props}>
2317 {children}
24- </button>
18+ </BasicButton>
2519 );
2620 }
27-
src/components/buttons/SecondaryButton.tsx+3−10
@@ -1,6 +1,7 @@
11 "use client";
22
33 import type { ButtonHTMLAttributes, ReactNode } from "react";
4+import BasicButton from "./BasicButton";
45
56 type SecondaryButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
67 children: ReactNode;
@@ -18,16 +19,8 @@ export default function SecondaryButton({
1819 ...props
1920 }: SecondaryButtonProps) {
2021 return (
21- <button
22- className={`border-2 px-3 py-2 text-left hover:bg-neutral-300 dark:hover:bg-neutral-800 ${
23- isSelected
24- ? "border-green-900 bg-neutral-300 dark:border-green-500 dark:bg-neutral-800"
25- : "border-transparent bg-neutral-100 dark:bg-neutral-950"
26- } ${className}`}
27- {...props}
28- >
22+ <BasicButton color="neutral" className={className} {...props}>
2923 {children}
30- </button>
24+ </BasicButton>
3125 );
3226 }
33-
src/hooks/useMessages.ts+1−2
@@ -35,7 +35,7 @@ export function useMessages(threadId: number | null) {
3535
3636 setIsLoading(true);
3737 let targetThreadId = currentThreadId;
38-
38+
3939 if (!targetThreadId) {
4040 // Create a new thread if none exists
4141 targetThreadId = await onCreateThread(message.substring(0, 100), message);
@@ -100,4 +100,3 @@ export function useMessages(threadId: number | null) {
100100 clearMessages,
101101 };
102102 }
103-
src/hooks/useThreadSelection.ts+0−2
@@ -36,5 +36,3 @@ export function useThreadSelection(
3636 messagesContainerRef,
3737 };
3838 }
39-
40-
src/hooks/useThreads.ts+2−3
@@ -49,10 +49,10 @@ export function useThreads() {
4949 });
5050 const data = await res.json();
5151 const newThread = data.thread;
52-
52+
5353 // Reload threads to get the full list
5454 await loadThreads(8);
55-
55+
5656 return newThread.id;
5757 } catch (error) {
5858 console.error("Failed to create thread", error);
@@ -73,4 +73,3 @@ export function useThreads() {
7373 createThread,
7474 };
7575 }
76-