@istmx/ui 0.1.12 → 0.1.13
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.
- package/LICENSE +21 -21
- package/README.md +533 -469
- package/bin/istmx.mjs +481 -318
- package/package.json +27 -27
- package/registry/accordion.tsx +186 -0
- package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
- package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
- package/registry/ai-chat-block/attachment.tsx +466 -466
- package/registry/ai-chat-block/chat-code-block.tsx +50 -50
- package/registry/ai-chat-block/chat-composer.tsx +51 -51
- package/registry/ai-chat-block/chat-logo.tsx +18 -18
- package/registry/ai-chat-block/chat-message.tsx +161 -161
- package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
- package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
- package/registry/ai-chat-block/code-highlighter.tsx +342 -357
- package/registry/ai-chat-block/default-attachments.tsx +42 -42
- package/registry/ai-chat-block/index.ts +30 -30
- package/registry/ai-chat-block/message-content.tsx +287 -287
- package/registry/ai-chat-block/message-list.tsx +93 -93
- package/registry/ai-chat-block/send-button.tsx +102 -102
- package/registry/ai-chat-block/types.ts +70 -71
- package/registry/ai-chat-block/utils.ts +6 -6
- package/registry/ai-chat-block/voice-button.tsx +66 -66
- package/registry/alert-dialog.tsx +229 -0
- package/registry/alert.tsx +188 -0
- package/registry/animated-text.tsx +228 -225
- package/registry/aspect-ratio.tsx +32 -0
- package/registry/avatar-group.tsx +66 -0
- package/registry/avatar.tsx +121 -0
- package/registry/badge.tsx +52 -0
- package/registry/bento-grid.tsx +438 -433
- package/registry/button.tsx +156 -237
- package/registry/carousel.tsx +184 -0
- package/registry/dock-navigation.tsx +200 -198
- package/registry/drift-canvas.tsx +383 -0
- package/registry/drift-wall.tsx +361 -0
- package/registry/flex-carousel.tsx +1430 -0
- package/registry/guided-gallery.tsx +1506 -0
- package/registry/image-accordion.tsx +306 -302
- package/registry/image-trail.tsx +126 -121
- package/registry/infinite-image-canvas.tsx +268 -263
- package/registry/input-otp.tsx +332 -0
- package/registry/list-card.tsx +130 -0
- package/registry/mobile-menu-dock.tsx +216 -211
- package/registry/morph-slider.tsx +756 -0
- package/registry/pixel-cat.tsx +972 -1020
- package/registry/scroll-canvas-cards.tsx +643 -640
- package/registry/scroll-parallax-hero.tsx +566 -565
- package/registry/scroll-story-cards.tsx +443 -438
- package/registry/slider.tsx +163 -0
- package/registry/spotlight-grid.tsx +226 -0
- package/registry/streaming-text.tsx +269 -278
- package/registry/text-reveal.tsx +311 -307
- package/registry/user-avatar.tsx +99 -0
- package/registry/utils.ts +6 -6
|
@@ -1,273 +1,273 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
IconArchive,
|
|
5
|
-
IconDots,
|
|
6
|
-
IconMessageCircle,
|
|
7
|
-
IconMessageCircleFilled,
|
|
8
|
-
IconPin,
|
|
9
|
-
IconPlus,
|
|
10
|
-
IconRestore,
|
|
11
|
-
IconTrash,
|
|
12
|
-
IconX,
|
|
13
|
-
} from '@tabler/icons-react'
|
|
14
|
-
import type { ReactNode } from 'react'
|
|
15
|
-
import { useEffect, useRef, useState } from 'react'
|
|
16
|
-
import { createPortal } from 'react-dom'
|
|
17
|
-
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
18
|
-
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand } from '@tabler/icons-react'
|
|
19
|
-
import { cn } from './utils'
|
|
20
|
-
import ChatUserAvatar from './chat-user-avatar'
|
|
21
|
-
import ChatLogo from './chat-logo'
|
|
22
|
-
|
|
23
|
-
export type ChatSidebarItem = {
|
|
24
|
-
id: string
|
|
25
|
-
title: string
|
|
26
|
-
pinned?: boolean
|
|
27
|
-
archived?: boolean
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type ChatSidebarProps = {
|
|
31
|
-
items: readonly ChatSidebarItem[]
|
|
32
|
-
activeId: string
|
|
33
|
-
userName: string
|
|
34
|
-
userAvatar?: ReactNode
|
|
35
|
-
mobileOpen: boolean
|
|
36
|
-
desktopHidden: boolean
|
|
37
|
-
onToggleDesktop: () => void
|
|
38
|
-
onCloseMobile: () => void
|
|
39
|
-
onNewChat: () => void
|
|
40
|
-
onSelect: (id: string) => void
|
|
41
|
-
onPin: (id: string) => void
|
|
42
|
-
onArchive: (id: string) => void
|
|
43
|
-
onDelete: (id: string) => void
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default function ChatSidebar({
|
|
47
|
-
items,
|
|
48
|
-
activeId,
|
|
49
|
-
userName,
|
|
50
|
-
userAvatar,
|
|
51
|
-
mobileOpen,
|
|
52
|
-
desktopHidden,
|
|
53
|
-
onToggleDesktop,
|
|
54
|
-
onCloseMobile,
|
|
55
|
-
onNewChat,
|
|
56
|
-
onSelect,
|
|
57
|
-
onPin,
|
|
58
|
-
onArchive,
|
|
59
|
-
onDelete,
|
|
60
|
-
}: ChatSidebarProps) {
|
|
61
|
-
const [openMenuId, setOpenMenuId] = useState<string | null>(null)
|
|
62
|
-
const [showArchived, setShowArchived] = useState(false)
|
|
63
|
-
const [deleteTarget, setDeleteTarget] = useState<ChatSidebarItem | null>(null)
|
|
64
|
-
const confirmDeleteRef = useRef<HTMLButtonElement>(null)
|
|
65
|
-
const reduceMotion = useReducedMotion()
|
|
66
|
-
const activeItems = items.filter((item) => !item.archived)
|
|
67
|
-
const pinnedItems = activeItems.filter((item) => item.pinned)
|
|
68
|
-
const recentItems = activeItems.filter((item) => !item.pinned)
|
|
69
|
-
const archivedItems = items.filter((item) => item.archived)
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (!deleteTarget) return
|
|
73
|
-
confirmDeleteRef.current?.focus()
|
|
74
|
-
const onKeyDown = (event: KeyboardEvent) => {
|
|
75
|
-
if (event.key === 'Escape') setDeleteTarget(null)
|
|
76
|
-
}
|
|
77
|
-
document.addEventListener('keydown', onKeyDown)
|
|
78
|
-
return () => document.removeEventListener('keydown', onKeyDown)
|
|
79
|
-
}, [deleteTarget])
|
|
80
|
-
|
|
81
|
-
function renderItem(item: ChatSidebarItem) {
|
|
82
|
-
const menuOpen = openMenuId === item.id
|
|
83
|
-
const isActive = activeId === item.id
|
|
84
|
-
return (
|
|
85
|
-
<li key={item.id} className="group relative">
|
|
86
|
-
<button
|
|
87
|
-
type="button"
|
|
88
|
-
onClick={() => {
|
|
89
|
-
onSelect(item.id)
|
|
90
|
-
onCloseMobile()
|
|
91
|
-
setOpenMenuId(null)
|
|
92
|
-
}}
|
|
93
|
-
title={item.title}
|
|
94
|
-
aria-current={activeId === item.id ? 'page' : undefined}
|
|
95
|
-
className={cn(
|
|
96
|
-
'flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg border px-2.5 pr-9 text-left text-xs transition-colors',
|
|
97
|
-
isActive ? 'border-[var(--chat-accent)]/25 bg-surface/65 text-foreground shadow-sm' : 'border-transparent text-muted hover:border-border/50 hover:bg-surface/40 hover:text-foreground',
|
|
98
|
-
item.archived && 'opacity-70',
|
|
99
|
-
)}
|
|
100
|
-
>
|
|
101
|
-
{item.pinned ? <IconPin size={14} stroke={1.7} className="shrink-0" aria-hidden="true" /> : isActive ? <IconMessageCircleFilled size={15} className="text-[var(--chat-accent)] shrink-0" aria-hidden="true" /> : <IconMessageCircle size={15} stroke={1.6} className="shrink-0" aria-hidden="true" />}
|
|
102
|
-
<span className="min-w-0 flex-1 truncate">{item.title}</span>
|
|
103
|
-
</button>
|
|
104
|
-
<button
|
|
105
|
-
type="button"
|
|
106
|
-
aria-label={`Options for ${item.title}`}
|
|
107
|
-
aria-haspopup="menu"
|
|
108
|
-
aria-expanded={menuOpen}
|
|
109
|
-
title="Chat options"
|
|
110
|
-
onClick={() => setOpenMenuId(menuOpen ? null : item.id)}
|
|
111
|
-
className={cn(
|
|
112
|
-
'text-muted hover:bg-surface hover:text-foreground absolute right-1 top-1 flex size-7 cursor-pointer items-center justify-center rounded-md opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100 sm:focus-visible:opacity-100',
|
|
113
|
-
)}
|
|
114
|
-
>
|
|
115
|
-
<IconDots size={16} stroke={1.8} aria-hidden="true" />
|
|
116
|
-
</button>
|
|
117
|
-
{menuOpen ? (
|
|
118
|
-
<div role="menu" aria-label={`${item.title} actions`} className="border-border/70 bg-background absolute right-1 top-9 z-40 min-w-40 rounded-xl border p-1 shadow-xl">
|
|
119
|
-
{!item.archived ? (
|
|
120
|
-
<>
|
|
121
|
-
<button role="menuitem" type="button" onClick={() => { onPin(item.id); setOpenMenuId(null) }} className="text-muted hover:bg-surface hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
122
|
-
<IconPin size={14} aria-hidden="true" />{item.pinned ? 'Unpin chat' : 'Pin chat'}
|
|
123
|
-
</button>
|
|
124
|
-
<button role="menuitem" type="button" onClick={() => { onArchive(item.id); setOpenMenuId(null) }} className="text-muted hover:bg-surface hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
125
|
-
<IconArchive size={14} aria-hidden="true" />Archive chat
|
|
126
|
-
</button>
|
|
127
|
-
</>
|
|
128
|
-
) : (
|
|
129
|
-
<button role="menuitem" type="button" onClick={() => { onArchive(item.id); setOpenMenuId(null) }} className="text-muted hover:bg-surface hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
130
|
-
<IconRestore size={14} aria-hidden="true" />Restore chat
|
|
131
|
-
</button>
|
|
132
|
-
)}
|
|
133
|
-
<button role="menuitem" type="button" onClick={() => { setDeleteTarget(item); setOpenMenuId(null) }} className="text-rose-400 hover:bg-rose-500/10 flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
134
|
-
<IconTrash size={14} aria-hidden="true" />Delete chat
|
|
135
|
-
</button>
|
|
136
|
-
</div>
|
|
137
|
-
) : null}
|
|
138
|
-
</li>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<>
|
|
144
|
-
<button
|
|
145
|
-
type="button"
|
|
146
|
-
aria-label="Close chat history"
|
|
147
|
-
aria-hidden={!mobileOpen}
|
|
148
|
-
tabIndex={mobileOpen ? 0 : -1}
|
|
149
|
-
onClick={onCloseMobile}
|
|
150
|
-
className={cn(
|
|
151
|
-
'absolute inset-0 z-20 flex cursor-default bg-black/45 opacity-0 transition-opacity duration-300 ease-out motion-reduce:transition-none md:hidden',
|
|
152
|
-
mobileOpen ? 'visible opacity-100' : 'invisible pointer-events-none',
|
|
153
|
-
)}
|
|
154
|
-
/>
|
|
155
|
-
<aside
|
|
156
|
-
aria-label="Chat history"
|
|
157
|
-
className={cn(
|
|
158
|
-
'border-border/70 bg-background absolute inset-y-0 left-0 z-30 flex w-[min(17rem,84vw)] flex-col overflow-hidden border-r shadow-2xl transition-[transform,width,visibility,opacity] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none md:relative md:inset-auto md:z-auto md:w-60 md:shrink-0 md:translate-x-0 md:bg-surface/10 md:shadow-none',
|
|
159
|
-
mobileOpen ? 'visible translate-x-0' : 'invisible -translate-x-full md:visible',
|
|
160
|
-
desktopHidden && 'md:w-14',
|
|
161
|
-
)}
|
|
162
|
-
>
|
|
163
|
-
<div className={cn('border-border/50 flex h-14 shrink-0 items-center gap-2 border-b px-3', desktopHidden && 'md:justify-center md:px-1')}>
|
|
164
|
-
<span className={cn('bg-[var(--chat-accent)] text-white flex size-8 shrink-0 items-center justify-center rounded-xl p-1.5', desktopHidden && 'md:hidden')}>
|
|
165
|
-
<ChatLogo className="size-full" />
|
|
166
|
-
</span>
|
|
167
|
-
<span className={cn('font-display min-w-0 flex-1 truncate text-xs font-semibold', desktopHidden && 'md:hidden')}>istmX chat</span>
|
|
168
|
-
<button type="button" onClick={onToggleDesktop} aria-label={desktopHidden ? 'Expand chat sidebar' : 'Collapse chat sidebar'} title={desktopHidden ? 'Expand sidebar' : 'Collapse sidebar'} className="text-muted hover:text-foreground hidden size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg transition-colors md:flex">
|
|
169
|
-
{desktopHidden ? <IconLayoutSidebarLeftExpand size={17} stroke={1.7} /> : <IconLayoutSidebarLeftCollapse size={17} stroke={1.7} />}
|
|
170
|
-
</button>
|
|
171
|
-
<button type="button" onClick={onCloseMobile} aria-label="Close chat sidebar" className="text-muted hover:text-foreground ml-auto flex size-8 cursor-pointer items-center justify-center rounded-lg md:hidden">
|
|
172
|
-
<IconX size={16} stroke={1.8} />
|
|
173
|
-
</button>
|
|
174
|
-
</div>
|
|
175
|
-
|
|
176
|
-
<div className={cn('px-2 pb-3', desktopHidden && 'md:hidden')}>
|
|
177
|
-
<button
|
|
178
|
-
type="button"
|
|
179
|
-
onClick={onNewChat}
|
|
180
|
-
title="New chat"
|
|
181
|
-
className={cn(
|
|
182
|
-
'border-border/70 text-foreground hover:bg-surface/50 flex h-9 w-full cursor-pointer items-center gap-2 rounded-xl border px-2.5 text-left text-xs transition-colors',
|
|
183
|
-
)}
|
|
184
|
-
>
|
|
185
|
-
<IconPlus size={16} stroke={1.8} aria-hidden="true" />
|
|
186
|
-
<span>New chat</span>
|
|
187
|
-
</button>
|
|
188
|
-
</div>
|
|
189
|
-
|
|
190
|
-
<nav aria-label="Chat history" className={cn('[scrollbar-width:none] [&::-webkit-scrollbar]:hidden min-h-0 flex-1 overflow-y-auto overscroll-contain px-2 pb-3', desktopHidden && 'md:hidden')}>
|
|
191
|
-
{pinnedItems.length ? (
|
|
192
|
-
<section className="mb-3">
|
|
193
|
-
<h3 className="text-muted px-2 pb-1.5 pt-1 font-mono text-[9px] tracking-[0.14em] uppercase">Pinned</h3>
|
|
194
|
-
<ul className="space-y-0.5">{pinnedItems.map(renderItem)}</ul>
|
|
195
|
-
</section>
|
|
196
|
-
) : null}
|
|
197
|
-
<section>
|
|
198
|
-
<h3 className="text-muted px-2 pb-1.5 pt-1 font-mono text-[9px] tracking-[0.14em] uppercase">Recent chats</h3>
|
|
199
|
-
<ul className="space-y-0.5">{recentItems.map(renderItem)}</ul>
|
|
200
|
-
</section>
|
|
201
|
-
{archivedItems.length ? (
|
|
202
|
-
<section className="mt-3">
|
|
203
|
-
<button type="button" aria-expanded={showArchived} onClick={() => setShowArchived((show) => !show)} className="text-muted hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 px-2 text-left font-mono text-[9px] tracking-[0.14em] uppercase">
|
|
204
|
-
<IconArchive size={14} aria-hidden="true" />
|
|
205
|
-
<span>Archived · {archivedItems.length}</span>
|
|
206
|
-
</button>
|
|
207
|
-
{showArchived ? <ul className="space-y-0.5">{archivedItems.map(renderItem)}</ul> : null}
|
|
208
|
-
</section>
|
|
209
|
-
) : null}
|
|
210
|
-
</nav>
|
|
211
|
-
|
|
212
|
-
<div className={cn('border-border/60 mt-auto flex min-h-14 items-center gap-2.5 border-t px-3 py-2.5', desktopHidden && 'md:justify-center md:px-1')}>
|
|
213
|
-
<span className="border-border/60 bg-background relative flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full border">
|
|
214
|
-
{userAvatar ?? <ChatUserAvatar />}
|
|
215
|
-
</span>
|
|
216
|
-
<span className={cn('min-w-0 flex-1', desktopHidden && 'md:hidden')}>
|
|
217
|
-
<span className="text-foreground block truncate text-xs font-medium">{userName}</span>
|
|
218
|
-
<span className="text-muted mt-0.5 block truncate text-[10px]">Preview account</span>
|
|
219
|
-
</span>
|
|
220
|
-
</div>
|
|
221
|
-
</aside>
|
|
222
|
-
{typeof document !== 'undefined' ? createPortal(
|
|
223
|
-
<AnimatePresence>
|
|
224
|
-
{deleteTarget ? (
|
|
225
|
-
<motion.div
|
|
226
|
-
className="fixed inset-0 z-[600] flex items-center justify-center p-4"
|
|
227
|
-
initial={{ opacity: 0 }}
|
|
228
|
-
animate={{ opacity: 1 }}
|
|
229
|
-
exit={{ opacity: 0 }}
|
|
230
|
-
transition={{ duration: reduceMotion ? 0 : 0.16 }}
|
|
231
|
-
onMouseDown={(event) => {
|
|
232
|
-
if (event.target === event.currentTarget) setDeleteTarget(null)
|
|
233
|
-
}}
|
|
234
|
-
>
|
|
235
|
-
<div className="absolute inset-0 bg-black/65 backdrop-blur-sm" aria-hidden="true" />
|
|
236
|
-
<motion.section
|
|
237
|
-
role="alertdialog"
|
|
238
|
-
aria-modal="true"
|
|
239
|
-
aria-labelledby="delete-chat-title"
|
|
240
|
-
aria-describedby="delete-chat-description"
|
|
241
|
-
className="border-border/70 bg-background relative z-10 w-full max-w-sm rounded-2xl border p-5 shadow-2xl"
|
|
242
|
-
initial={reduceMotion ? { scale: 1 } : { opacity: 0, y: 10, scale: 0.97 }}
|
|
243
|
-
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
244
|
-
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 6, scale: 0.98 }}
|
|
245
|
-
transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 380, damping: 30 }}
|
|
246
|
-
>
|
|
247
|
-
<h2 id="delete-chat-title" className="font-display text-base font-semibold">Delete this chat?</h2>
|
|
248
|
-
<p id="delete-chat-description" className="text-muted mt-2 text-sm leading-5">
|
|
249
|
-
“{deleteTarget.title}” will be permanently deleted. This can’t be undone.
|
|
250
|
-
</p>
|
|
251
|
-
<div className="mt-5 flex justify-end gap-2">
|
|
252
|
-
<button type="button" onClick={() => setDeleteTarget(null)} className="border-border/70 text-muted hover:bg-surface hover:text-foreground h-9 cursor-pointer rounded-lg border px-3 text-xs font-medium transition-colors">Cancel</button>
|
|
253
|
-
<button
|
|
254
|
-
ref={confirmDeleteRef}
|
|
255
|
-
type="button"
|
|
256
|
-
onClick={() => {
|
|
257
|
-
onDelete(deleteTarget.id)
|
|
258
|
-
setDeleteTarget(null)
|
|
259
|
-
}}
|
|
260
|
-
className="bg-rose-500 text-white hover:bg-rose-400 h-9 cursor-pointer rounded-lg px-3 text-xs font-semibold transition-colors"
|
|
261
|
-
>
|
|
262
|
-
Delete chat
|
|
263
|
-
</button>
|
|
264
|
-
</div>
|
|
265
|
-
</motion.section>
|
|
266
|
-
</motion.div>
|
|
267
|
-
) : null}
|
|
268
|
-
</AnimatePresence>,
|
|
269
|
-
document.body,
|
|
270
|
-
) : null}
|
|
271
|
-
</>
|
|
272
|
-
)
|
|
273
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
IconArchive,
|
|
5
|
+
IconDots,
|
|
6
|
+
IconMessageCircle,
|
|
7
|
+
IconMessageCircleFilled,
|
|
8
|
+
IconPin,
|
|
9
|
+
IconPlus,
|
|
10
|
+
IconRestore,
|
|
11
|
+
IconTrash,
|
|
12
|
+
IconX,
|
|
13
|
+
} from '@tabler/icons-react'
|
|
14
|
+
import type { ReactNode } from 'react'
|
|
15
|
+
import { useEffect, useRef, useState } from 'react'
|
|
16
|
+
import { createPortal } from 'react-dom'
|
|
17
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
18
|
+
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand } from '@tabler/icons-react'
|
|
19
|
+
import { cn } from './utils'
|
|
20
|
+
import ChatUserAvatar from './chat-user-avatar'
|
|
21
|
+
import ChatLogo from './chat-logo'
|
|
22
|
+
|
|
23
|
+
export type ChatSidebarItem = {
|
|
24
|
+
id: string
|
|
25
|
+
title: string
|
|
26
|
+
pinned?: boolean
|
|
27
|
+
archived?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ChatSidebarProps = {
|
|
31
|
+
items: readonly ChatSidebarItem[]
|
|
32
|
+
activeId: string
|
|
33
|
+
userName: string
|
|
34
|
+
userAvatar?: ReactNode
|
|
35
|
+
mobileOpen: boolean
|
|
36
|
+
desktopHidden: boolean
|
|
37
|
+
onToggleDesktop: () => void
|
|
38
|
+
onCloseMobile: () => void
|
|
39
|
+
onNewChat: () => void
|
|
40
|
+
onSelect: (id: string) => void
|
|
41
|
+
onPin: (id: string) => void
|
|
42
|
+
onArchive: (id: string) => void
|
|
43
|
+
onDelete: (id: string) => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function ChatSidebar({
|
|
47
|
+
items,
|
|
48
|
+
activeId,
|
|
49
|
+
userName,
|
|
50
|
+
userAvatar,
|
|
51
|
+
mobileOpen,
|
|
52
|
+
desktopHidden,
|
|
53
|
+
onToggleDesktop,
|
|
54
|
+
onCloseMobile,
|
|
55
|
+
onNewChat,
|
|
56
|
+
onSelect,
|
|
57
|
+
onPin,
|
|
58
|
+
onArchive,
|
|
59
|
+
onDelete,
|
|
60
|
+
}: ChatSidebarProps) {
|
|
61
|
+
const [openMenuId, setOpenMenuId] = useState<string | null>(null)
|
|
62
|
+
const [showArchived, setShowArchived] = useState(false)
|
|
63
|
+
const [deleteTarget, setDeleteTarget] = useState<ChatSidebarItem | null>(null)
|
|
64
|
+
const confirmDeleteRef = useRef<HTMLButtonElement>(null)
|
|
65
|
+
const reduceMotion = useReducedMotion()
|
|
66
|
+
const activeItems = items.filter((item) => !item.archived)
|
|
67
|
+
const pinnedItems = activeItems.filter((item) => item.pinned)
|
|
68
|
+
const recentItems = activeItems.filter((item) => !item.pinned)
|
|
69
|
+
const archivedItems = items.filter((item) => item.archived)
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!deleteTarget) return
|
|
73
|
+
confirmDeleteRef.current?.focus()
|
|
74
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
75
|
+
if (event.key === 'Escape') setDeleteTarget(null)
|
|
76
|
+
}
|
|
77
|
+
document.addEventListener('keydown', onKeyDown)
|
|
78
|
+
return () => document.removeEventListener('keydown', onKeyDown)
|
|
79
|
+
}, [deleteTarget])
|
|
80
|
+
|
|
81
|
+
function renderItem(item: ChatSidebarItem) {
|
|
82
|
+
const menuOpen = openMenuId === item.id
|
|
83
|
+
const isActive = activeId === item.id
|
|
84
|
+
return (
|
|
85
|
+
<li key={item.id} className="group relative">
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
onClick={() => {
|
|
89
|
+
onSelect(item.id)
|
|
90
|
+
onCloseMobile()
|
|
91
|
+
setOpenMenuId(null)
|
|
92
|
+
}}
|
|
93
|
+
title={item.title}
|
|
94
|
+
aria-current={activeId === item.id ? 'page' : undefined}
|
|
95
|
+
className={cn(
|
|
96
|
+
'flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg border px-2.5 pr-9 text-left text-xs transition-colors',
|
|
97
|
+
isActive ? 'border-[var(--chat-accent)]/25 bg-surface/65 text-foreground shadow-sm' : 'border-transparent text-muted hover:border-border/50 hover:bg-surface/40 hover:text-foreground',
|
|
98
|
+
item.archived && 'opacity-70',
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
{item.pinned ? <IconPin size={14} stroke={1.7} className="shrink-0" aria-hidden="true" /> : isActive ? <IconMessageCircleFilled size={15} className="text-[var(--chat-accent)] shrink-0" aria-hidden="true" /> : <IconMessageCircle size={15} stroke={1.6} className="shrink-0" aria-hidden="true" />}
|
|
102
|
+
<span className="min-w-0 flex-1 truncate">{item.title}</span>
|
|
103
|
+
</button>
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
aria-label={`Options for ${item.title}`}
|
|
107
|
+
aria-haspopup="menu"
|
|
108
|
+
aria-expanded={menuOpen}
|
|
109
|
+
title="Chat options"
|
|
110
|
+
onClick={() => setOpenMenuId(menuOpen ? null : item.id)}
|
|
111
|
+
className={cn(
|
|
112
|
+
'text-muted hover:bg-surface hover:text-foreground absolute right-1 top-1 flex size-7 cursor-pointer items-center justify-center rounded-md opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100 sm:focus-visible:opacity-100',
|
|
113
|
+
)}
|
|
114
|
+
>
|
|
115
|
+
<IconDots size={16} stroke={1.8} aria-hidden="true" />
|
|
116
|
+
</button>
|
|
117
|
+
{menuOpen ? (
|
|
118
|
+
<div role="menu" aria-label={`${item.title} actions`} className="border-border/70 bg-background absolute right-1 top-9 z-40 min-w-40 rounded-xl border p-1 shadow-xl">
|
|
119
|
+
{!item.archived ? (
|
|
120
|
+
<>
|
|
121
|
+
<button role="menuitem" type="button" onClick={() => { onPin(item.id); setOpenMenuId(null) }} className="text-muted hover:bg-surface hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
122
|
+
<IconPin size={14} aria-hidden="true" />{item.pinned ? 'Unpin chat' : 'Pin chat'}
|
|
123
|
+
</button>
|
|
124
|
+
<button role="menuitem" type="button" onClick={() => { onArchive(item.id); setOpenMenuId(null) }} className="text-muted hover:bg-surface hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
125
|
+
<IconArchive size={14} aria-hidden="true" />Archive chat
|
|
126
|
+
</button>
|
|
127
|
+
</>
|
|
128
|
+
) : (
|
|
129
|
+
<button role="menuitem" type="button" onClick={() => { onArchive(item.id); setOpenMenuId(null) }} className="text-muted hover:bg-surface hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
130
|
+
<IconRestore size={14} aria-hidden="true" />Restore chat
|
|
131
|
+
</button>
|
|
132
|
+
)}
|
|
133
|
+
<button role="menuitem" type="button" onClick={() => { setDeleteTarget(item); setOpenMenuId(null) }} className="text-rose-400 hover:bg-rose-500/10 flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs">
|
|
134
|
+
<IconTrash size={14} aria-hidden="true" />Delete chat
|
|
135
|
+
</button>
|
|
136
|
+
</div>
|
|
137
|
+
) : null}
|
|
138
|
+
</li>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<>
|
|
144
|
+
<button
|
|
145
|
+
type="button"
|
|
146
|
+
aria-label="Close chat history"
|
|
147
|
+
aria-hidden={!mobileOpen}
|
|
148
|
+
tabIndex={mobileOpen ? 0 : -1}
|
|
149
|
+
onClick={onCloseMobile}
|
|
150
|
+
className={cn(
|
|
151
|
+
'absolute inset-0 z-20 flex cursor-default bg-black/45 opacity-0 transition-opacity duration-300 ease-out motion-reduce:transition-none md:hidden',
|
|
152
|
+
mobileOpen ? 'visible opacity-100' : 'invisible pointer-events-none',
|
|
153
|
+
)}
|
|
154
|
+
/>
|
|
155
|
+
<aside
|
|
156
|
+
aria-label="Chat history"
|
|
157
|
+
className={cn(
|
|
158
|
+
'border-border/70 bg-background absolute inset-y-0 left-0 z-30 flex w-[min(17rem,84vw)] flex-col overflow-hidden border-r shadow-2xl transition-[transform,width,visibility,opacity] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none md:relative md:inset-auto md:z-auto md:w-60 md:shrink-0 md:translate-x-0 md:bg-surface/10 md:shadow-none',
|
|
159
|
+
mobileOpen ? 'visible translate-x-0' : 'invisible -translate-x-full md:visible',
|
|
160
|
+
desktopHidden && 'md:w-14',
|
|
161
|
+
)}
|
|
162
|
+
>
|
|
163
|
+
<div className={cn('border-border/50 flex h-14 shrink-0 items-center gap-2 border-b px-3', desktopHidden && 'md:justify-center md:px-1')}>
|
|
164
|
+
<span className={cn('bg-[var(--chat-accent)] text-white flex size-8 shrink-0 items-center justify-center rounded-xl p-1.5', desktopHidden && 'md:hidden')}>
|
|
165
|
+
<ChatLogo className="size-full" />
|
|
166
|
+
</span>
|
|
167
|
+
<span className={cn('font-display min-w-0 flex-1 truncate text-xs font-semibold', desktopHidden && 'md:hidden')}>istmX chat</span>
|
|
168
|
+
<button type="button" onClick={onToggleDesktop} aria-label={desktopHidden ? 'Expand chat sidebar' : 'Collapse chat sidebar'} title={desktopHidden ? 'Expand sidebar' : 'Collapse sidebar'} className="text-muted hover:text-foreground hidden size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg transition-colors md:flex">
|
|
169
|
+
{desktopHidden ? <IconLayoutSidebarLeftExpand size={17} stroke={1.7} /> : <IconLayoutSidebarLeftCollapse size={17} stroke={1.7} />}
|
|
170
|
+
</button>
|
|
171
|
+
<button type="button" onClick={onCloseMobile} aria-label="Close chat sidebar" className="text-muted hover:text-foreground ml-auto flex size-8 cursor-pointer items-center justify-center rounded-lg md:hidden">
|
|
172
|
+
<IconX size={16} stroke={1.8} />
|
|
173
|
+
</button>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<div className={cn('px-2 pb-3', desktopHidden && 'md:hidden')}>
|
|
177
|
+
<button
|
|
178
|
+
type="button"
|
|
179
|
+
onClick={onNewChat}
|
|
180
|
+
title="New chat"
|
|
181
|
+
className={cn(
|
|
182
|
+
'border-border/70 text-foreground hover:bg-surface/50 flex h-9 w-full cursor-pointer items-center gap-2 rounded-xl border px-2.5 text-left text-xs transition-colors',
|
|
183
|
+
)}
|
|
184
|
+
>
|
|
185
|
+
<IconPlus size={16} stroke={1.8} aria-hidden="true" />
|
|
186
|
+
<span>New chat</span>
|
|
187
|
+
</button>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<nav aria-label="Chat history" className={cn('[scrollbar-width:none] [&::-webkit-scrollbar]:hidden min-h-0 flex-1 overflow-y-auto overscroll-contain px-2 pb-3', desktopHidden && 'md:hidden')}>
|
|
191
|
+
{pinnedItems.length ? (
|
|
192
|
+
<section className="mb-3">
|
|
193
|
+
<h3 className="text-muted px-2 pb-1.5 pt-1 font-mono text-[9px] tracking-[0.14em] uppercase">Pinned</h3>
|
|
194
|
+
<ul className="space-y-0.5">{pinnedItems.map(renderItem)}</ul>
|
|
195
|
+
</section>
|
|
196
|
+
) : null}
|
|
197
|
+
<section>
|
|
198
|
+
<h3 className="text-muted px-2 pb-1.5 pt-1 font-mono text-[9px] tracking-[0.14em] uppercase">Recent chats</h3>
|
|
199
|
+
<ul className="space-y-0.5">{recentItems.map(renderItem)}</ul>
|
|
200
|
+
</section>
|
|
201
|
+
{archivedItems.length ? (
|
|
202
|
+
<section className="mt-3">
|
|
203
|
+
<button type="button" aria-expanded={showArchived} onClick={() => setShowArchived((show) => !show)} className="text-muted hover:text-foreground flex h-8 w-full cursor-pointer items-center gap-2 px-2 text-left font-mono text-[9px] tracking-[0.14em] uppercase">
|
|
204
|
+
<IconArchive size={14} aria-hidden="true" />
|
|
205
|
+
<span>Archived · {archivedItems.length}</span>
|
|
206
|
+
</button>
|
|
207
|
+
{showArchived ? <ul className="space-y-0.5">{archivedItems.map(renderItem)}</ul> : null}
|
|
208
|
+
</section>
|
|
209
|
+
) : null}
|
|
210
|
+
</nav>
|
|
211
|
+
|
|
212
|
+
<div className={cn('border-border/60 mt-auto flex min-h-14 items-center gap-2.5 border-t px-3 py-2.5', desktopHidden && 'md:justify-center md:px-1')}>
|
|
213
|
+
<span className="border-border/60 bg-background relative flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full border">
|
|
214
|
+
{userAvatar ?? <ChatUserAvatar />}
|
|
215
|
+
</span>
|
|
216
|
+
<span className={cn('min-w-0 flex-1', desktopHidden && 'md:hidden')}>
|
|
217
|
+
<span className="text-foreground block truncate text-xs font-medium">{userName}</span>
|
|
218
|
+
<span className="text-muted mt-0.5 block truncate text-[10px]">Preview account</span>
|
|
219
|
+
</span>
|
|
220
|
+
</div>
|
|
221
|
+
</aside>
|
|
222
|
+
{typeof document !== 'undefined' ? createPortal(
|
|
223
|
+
<AnimatePresence>
|
|
224
|
+
{deleteTarget ? (
|
|
225
|
+
<motion.div
|
|
226
|
+
className="fixed inset-0 z-[600] flex items-center justify-center p-4"
|
|
227
|
+
initial={{ opacity: 0 }}
|
|
228
|
+
animate={{ opacity: 1 }}
|
|
229
|
+
exit={{ opacity: 0 }}
|
|
230
|
+
transition={{ duration: reduceMotion ? 0 : 0.16 }}
|
|
231
|
+
onMouseDown={(event) => {
|
|
232
|
+
if (event.target === event.currentTarget) setDeleteTarget(null)
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
<div className="absolute inset-0 bg-black/65 backdrop-blur-sm" aria-hidden="true" />
|
|
236
|
+
<motion.section
|
|
237
|
+
role="alertdialog"
|
|
238
|
+
aria-modal="true"
|
|
239
|
+
aria-labelledby="delete-chat-title"
|
|
240
|
+
aria-describedby="delete-chat-description"
|
|
241
|
+
className="border-border/70 bg-background relative z-10 w-full max-w-sm rounded-2xl border p-5 shadow-2xl"
|
|
242
|
+
initial={reduceMotion ? { scale: 1 } : { opacity: 0, y: 10, scale: 0.97 }}
|
|
243
|
+
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
244
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 6, scale: 0.98 }}
|
|
245
|
+
transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 380, damping: 30 }}
|
|
246
|
+
>
|
|
247
|
+
<h2 id="delete-chat-title" className="font-display text-base font-semibold">Delete this chat?</h2>
|
|
248
|
+
<p id="delete-chat-description" className="text-muted mt-2 text-sm leading-5">
|
|
249
|
+
“{deleteTarget.title}” will be permanently deleted. This can’t be undone.
|
|
250
|
+
</p>
|
|
251
|
+
<div className="mt-5 flex justify-end gap-2">
|
|
252
|
+
<button type="button" onClick={() => setDeleteTarget(null)} className="border-border/70 text-muted hover:bg-surface hover:text-foreground h-9 cursor-pointer rounded-lg border px-3 text-xs font-medium transition-colors">Cancel</button>
|
|
253
|
+
<button
|
|
254
|
+
ref={confirmDeleteRef}
|
|
255
|
+
type="button"
|
|
256
|
+
onClick={() => {
|
|
257
|
+
onDelete(deleteTarget.id)
|
|
258
|
+
setDeleteTarget(null)
|
|
259
|
+
}}
|
|
260
|
+
className="bg-rose-500 text-white hover:bg-rose-400 h-9 cursor-pointer rounded-lg px-3 text-xs font-semibold transition-colors"
|
|
261
|
+
>
|
|
262
|
+
Delete chat
|
|
263
|
+
</button>
|
|
264
|
+
</div>
|
|
265
|
+
</motion.section>
|
|
266
|
+
</motion.div>
|
|
267
|
+
) : null}
|
|
268
|
+
</AnimatePresence>,
|
|
269
|
+
document.body,
|
|
270
|
+
) : null}
|
|
271
|
+
</>
|
|
272
|
+
)
|
|
273
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IconUser } from '@tabler/icons-react'
|
|
2
|
-
|
|
3
|
-
export default function ChatUserAvatar({ className = '' }: { className?: string }) {
|
|
4
|
-
return (
|
|
5
|
-
<span className={`bg-surface text-muted relative inline-flex size-full shrink-0 items-center justify-center overflow-hidden rounded-full ${className}`}>
|
|
6
|
-
<IconUser size={15} stroke={1.7} aria-hidden="true" />
|
|
7
|
-
</span>
|
|
8
|
-
)
|
|
9
|
-
}
|
|
1
|
+
import { IconUser } from '@tabler/icons-react'
|
|
2
|
+
|
|
3
|
+
export default function ChatUserAvatar({ className = '' }: { className?: string }) {
|
|
4
|
+
return (
|
|
5
|
+
<span className={`bg-surface text-muted relative inline-flex size-full shrink-0 items-center justify-center overflow-hidden rounded-full ${className}`}>
|
|
6
|
+
<IconUser size={15} stroke={1.7} aria-hidden="true" />
|
|
7
|
+
</span>
|
|
8
|
+
)
|
|
9
|
+
}
|