@leitware/composables 0.1.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 (209) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +387 -0
  3. package/dist/presets/brutalist.css +298 -0
  4. package/dist/presets/default.css +298 -0
  5. package/dist/presets/signal-pop.css +369 -0
  6. package/dist/styles.css +2 -0
  7. package/package.json +216 -0
  8. package/rules/composables.md +244 -0
  9. package/src/_internal/accordion.tsx +93 -0
  10. package/src/_internal/ai-elements/attachments.tsx +385 -0
  11. package/src/_internal/ai-elements/chain-of-thought.tsx +197 -0
  12. package/src/_internal/ai-elements/code-block.tsx +516 -0
  13. package/src/_internal/ai-elements/confirmation.tsx +150 -0
  14. package/src/_internal/ai-elements/conversation.tsx +148 -0
  15. package/src/_internal/ai-elements/inline-citation.tsx +248 -0
  16. package/src/_internal/ai-elements/message.tsx +292 -0
  17. package/src/_internal/ai-elements/plan.tsx +126 -0
  18. package/src/_internal/ai-elements/prompt-input.tsx +1285 -0
  19. package/src/_internal/ai-elements/reasoning.tsx +208 -0
  20. package/src/_internal/ai-elements/shimmer.tsx +72 -0
  21. package/src/_internal/ai-elements/sources.tsx +53 -0
  22. package/src/_internal/ai-elements/suggestion.tsx +48 -0
  23. package/src/_internal/ai-elements/task.tsx +64 -0
  24. package/src/_internal/ai-elements/tool.tsx +156 -0
  25. package/src/_internal/alert-dialog.tsx +159 -0
  26. package/src/_internal/alert.tsx +88 -0
  27. package/src/_internal/aspect-ratio.tsx +23 -0
  28. package/src/_internal/avatar.tsx +58 -0
  29. package/src/_internal/badge.tsx +60 -0
  30. package/src/_internal/breadcrumb.tsx +104 -0
  31. package/src/_internal/bubble.tsx +125 -0
  32. package/src/_internal/button-group.tsx +78 -0
  33. package/src/_internal/button.tsx +62 -0
  34. package/src/_internal/calendar.tsx +179 -0
  35. package/src/_internal/card.tsx +83 -0
  36. package/src/_internal/carousel.tsx +215 -0
  37. package/src/_internal/checkbox.tsx +26 -0
  38. package/src/_internal/code-block.tsx +53 -0
  39. package/src/_internal/collapsible.tsx +15 -0
  40. package/src/_internal/combobox.tsx +264 -0
  41. package/src/_internal/command.tsx +155 -0
  42. package/src/_internal/container.tsx +35 -0
  43. package/src/_internal/dialog.tsx +132 -0
  44. package/src/_internal/direction.tsx +12 -0
  45. package/src/_internal/divider.tsx +162 -0
  46. package/src/_internal/dropdown-menu.tsx +247 -0
  47. package/src/_internal/dropzone.tsx +481 -0
  48. package/src/_internal/empty.tsx +94 -0
  49. package/src/_internal/field.tsx +221 -0
  50. package/src/_internal/grid-overlay.tsx +48 -0
  51. package/src/_internal/grid.tsx +109 -0
  52. package/src/_internal/hover-card.tsx +47 -0
  53. package/src/_internal/icon.tsx +45 -0
  54. package/src/_internal/input-group.tsx +146 -0
  55. package/src/_internal/input.tsx +24 -0
  56. package/src/_internal/item.tsx +187 -0
  57. package/src/_internal/kbd.tsx +28 -0
  58. package/src/_internal/label.tsx +18 -0
  59. package/src/_internal/layout-bento.tsx +386 -0
  60. package/src/_internal/layout.tsx +174 -0
  61. package/src/_internal/marker.tsx +66 -0
  62. package/src/_internal/message.tsx +85 -0
  63. package/src/_internal/native-select.tsx +50 -0
  64. package/src/_internal/pagination.tsx +108 -0
  65. package/src/_internal/popover.tsx +83 -0
  66. package/src/_internal/progress.tsx +59 -0
  67. package/src/_internal/radio-group.tsx +36 -0
  68. package/src/_internal/resizable.tsx +44 -0
  69. package/src/_internal/scroll-area.tsx +48 -0
  70. package/src/_internal/select.tsx +187 -0
  71. package/src/_internal/separator.tsx +19 -0
  72. package/src/_internal/sheet.tsx +122 -0
  73. package/src/_internal/sidebar.tsx +687 -0
  74. package/src/_internal/skeleton.tsx +13 -0
  75. package/src/_internal/slider.tsx +60 -0
  76. package/src/_internal/sonner.tsx +51 -0
  77. package/src/_internal/spacer.tsx +42 -0
  78. package/src/_internal/spinner.tsx +16 -0
  79. package/src/_internal/stack.tsx +78 -0
  80. package/src/_internal/switch.tsx +31 -0
  81. package/src/_internal/table.tsx +84 -0
  82. package/src/_internal/tabs.tsx +74 -0
  83. package/src/_internal/textarea.tsx +19 -0
  84. package/src/_internal/toggle-group.tsx +99 -0
  85. package/src/_internal/toggle.tsx +42 -0
  86. package/src/_internal/tooltip.tsx +55 -0
  87. package/src/_internal/typography.tsx +129 -0
  88. package/src/hooks/use-mobile.ts +19 -0
  89. package/src/hooks/use-numeric-input.ts +119 -0
  90. package/src/index.ts +443 -0
  91. package/src/lib/numeric-input.ts +88 -0
  92. package/src/lib/utils.ts +39 -0
  93. package/src/opinionated/accordion.tsx +92 -0
  94. package/src/opinionated/ai/attachments.tsx +27 -0
  95. package/src/opinionated/ai/chain-of-thought.tsx +16 -0
  96. package/src/opinionated/ai/code-block.tsx +22 -0
  97. package/src/opinionated/ai/confirmation.tsx +16 -0
  98. package/src/opinionated/ai/conversation.tsx +13 -0
  99. package/src/opinionated/ai/index.ts +15 -0
  100. package/src/opinionated/ai/inline-citation.tsx +30 -0
  101. package/src/opinionated/ai/message.tsx +26 -0
  102. package/src/opinionated/ai/plan.tsx +18 -0
  103. package/src/opinionated/ai/prompt-input.tsx +29 -0
  104. package/src/opinionated/ai/reasoning.tsx +9 -0
  105. package/src/opinionated/ai/shimmer.tsx +4 -0
  106. package/src/opinionated/ai/sources.tsx +10 -0
  107. package/src/opinionated/ai/suggestion.tsx +6 -0
  108. package/src/opinionated/ai/task.tsx +12 -0
  109. package/src/opinionated/ai/tool.tsx +14 -0
  110. package/src/opinionated/alert-dialog.tsx +143 -0
  111. package/src/opinionated/alert.tsx +99 -0
  112. package/src/opinionated/aspect-ratio.tsx +12 -0
  113. package/src/opinionated/avatar.tsx +59 -0
  114. package/src/opinionated/badge.tsx +33 -0
  115. package/src/opinionated/breadcrumb.tsx +99 -0
  116. package/src/opinionated/bubble.tsx +9 -0
  117. package/src/opinionated/button.tsx +59 -0
  118. package/src/opinionated/calendar.tsx +20 -0
  119. package/src/opinionated/card.tsx +83 -0
  120. package/src/opinionated/carousel.tsx +99 -0
  121. package/src/opinionated/checkbox.tsx +11 -0
  122. package/src/opinionated/code-block.tsx +12 -0
  123. package/src/opinionated/collapsible.tsx +123 -0
  124. package/src/opinionated/combobox.tsx +123 -0
  125. package/src/opinionated/container.tsx +12 -0
  126. package/src/opinionated/dialog.tsx +124 -0
  127. package/src/opinionated/direction.tsx +6 -0
  128. package/src/opinionated/divider.tsx +13 -0
  129. package/src/opinionated/dropdown-menu.tsx +131 -0
  130. package/src/opinionated/dropzone.tsx +39 -0
  131. package/src/opinionated/empty.tsx +191 -0
  132. package/src/opinionated/field.tsx +26 -0
  133. package/src/opinionated/form-calendar-popover.tsx +138 -0
  134. package/src/opinionated/form-checkbox.tsx +107 -0
  135. package/src/opinionated/form-combobox.tsx +181 -0
  136. package/src/opinionated/form-date-of-birth.tsx +193 -0
  137. package/src/opinionated/form-dropzone.tsx +126 -0
  138. package/src/opinionated/form-input-group.tsx +184 -0
  139. package/src/opinionated/form-input.tsx +118 -0
  140. package/src/opinionated/form-multi-combobox.tsx +213 -0
  141. package/src/opinionated/form-multi-dropzone.tsx +141 -0
  142. package/src/opinionated/form-radiogroup.tsx +116 -0
  143. package/src/opinionated/form-select.tsx +176 -0
  144. package/src/opinionated/form-slider.tsx +100 -0
  145. package/src/opinionated/form-switch.tsx +117 -0
  146. package/src/opinionated/form-textarea.tsx +79 -0
  147. package/src/opinionated/grid-overlay.tsx +11 -0
  148. package/src/opinionated/grid.tsx +14 -0
  149. package/src/opinionated/hover-card.tsx +59 -0
  150. package/src/opinionated/icon.tsx +14 -0
  151. package/src/opinionated/input-group.tsx +20 -0
  152. package/src/opinionated/input.tsx +11 -0
  153. package/src/opinionated/item.tsx +182 -0
  154. package/src/opinionated/kbd.tsx +16 -0
  155. package/src/opinionated/label.tsx +11 -0
  156. package/src/opinionated/layout-bento.tsx +29 -0
  157. package/src/opinionated/layout.tsx +26 -0
  158. package/src/opinionated/list.tsx +94 -0
  159. package/src/opinionated/marker.tsx +7 -0
  160. package/src/opinionated/message.tsx +8 -0
  161. package/src/opinionated/native-select.tsx +51 -0
  162. package/src/opinionated/pagination.tsx +204 -0
  163. package/src/opinionated/popover.tsx +68 -0
  164. package/src/opinionated/progress.tsx +48 -0
  165. package/src/opinionated/radio-group.tsx +13 -0
  166. package/src/opinionated/resizable.tsx +2 -0
  167. package/src/opinionated/scroll-area.tsx +82 -0
  168. package/src/opinionated/select.tsx +101 -0
  169. package/src/opinionated/separator.tsx +11 -0
  170. package/src/opinionated/sheet.tsx +120 -0
  171. package/src/opinionated/sidebar.tsx +68 -0
  172. package/src/opinionated/skeleton.tsx +246 -0
  173. package/src/opinionated/slider.tsx +11 -0
  174. package/src/opinionated/sonner.tsx +15 -0
  175. package/src/opinionated/spacer.tsx +11 -0
  176. package/src/opinionated/stack.tsx +18 -0
  177. package/src/opinionated/switch.tsx +11 -0
  178. package/src/opinionated/table.tsx +11 -0
  179. package/src/opinionated/tabs.tsx +68 -0
  180. package/src/opinionated/textarea.tsx +11 -0
  181. package/src/opinionated/theme-injector.tsx +31 -0
  182. package/src/opinionated/toggle-group.tsx +63 -0
  183. package/src/opinionated/toggle.tsx +75 -0
  184. package/src/opinionated/token-config-panel/color-editor.tsx +85 -0
  185. package/src/opinionated/token-config-panel/helpers.ts +31 -0
  186. package/src/opinionated/token-config-panel/index.tsx +398 -0
  187. package/src/opinionated/token-config-panel/json-import-export.tsx +89 -0
  188. package/src/opinionated/token-config-panel/preset-manager.ts +31 -0
  189. package/src/opinionated/token-config-panel/presets-data.ts +23 -0
  190. package/src/opinionated/token-config-panel/spacing-editor.tsx +325 -0
  191. package/src/opinionated/token-config-panel/types.ts +39 -0
  192. package/src/opinionated/token-config-panel/typography-editor.tsx +145 -0
  193. package/src/opinionated/tooltip.tsx +62 -0
  194. package/src/opinionated/typography.tsx +7 -0
  195. package/src/scripts/lint-no-arbitrary.ts +155 -0
  196. package/src/styles/composable.css +68 -0
  197. package/src/styles/presets/brutalist.css +298 -0
  198. package/src/styles/presets/default.css +298 -0
  199. package/src/styles/presets/signal-pop.css +369 -0
  200. package/src/styles/presets-data/brutalist.ts +325 -0
  201. package/src/styles/presets-data/default.ts +315 -0
  202. package/src/styles/presets-data/index.ts +45 -0
  203. package/src/styles/presets-data/signal-pop.ts +393 -0
  204. package/src/styles/tokens/base.css +71 -0
  205. package/src/styles/tokens/components.css +150 -0
  206. package/src/styles/tokens/palette.css +795 -0
  207. package/src/styles/tokens/registry.ts +324 -0
  208. package/src/styles/tokens/semantic.css +266 -0
  209. package/src/styles/tokens/tailwind-theme.css +247 -0
@@ -0,0 +1,385 @@
1
+ 'use client'
2
+
3
+ import { Button } from '../button'
4
+ import { HoverCard, HoverCardContent, HoverCardTrigger } from '../hover-card'
5
+ import { cn } from '../../lib/utils'
6
+ import type { FileUIPart, SourceDocumentUIPart } from 'ai'
7
+ import {
8
+ FileTextIcon,
9
+ GlobeIcon,
10
+ ImageIcon,
11
+ Music2Icon,
12
+ PaperclipIcon,
13
+ VideoIcon,
14
+ XIcon,
15
+ } from 'lucide-react'
16
+ import type { ComponentProps, HTMLAttributes, ReactNode } from 'react'
17
+ import { createContext, useCallback, useContext, useMemo } from 'react'
18
+
19
+ // ============================================================================
20
+ // Types
21
+ // ============================================================================
22
+
23
+ export type AttachmentData = (FileUIPart & { id: string }) | (SourceDocumentUIPart & { id: string })
24
+
25
+ export type AttachmentMediaCategory =
26
+ | 'image'
27
+ | 'video'
28
+ | 'audio'
29
+ | 'document'
30
+ | 'source'
31
+ | 'unknown'
32
+
33
+ export type AttachmentVariant = 'grid' | 'inline' | 'list'
34
+
35
+ const mediaCategoryIcons: Record<AttachmentMediaCategory, typeof ImageIcon> = {
36
+ audio: Music2Icon,
37
+ document: FileTextIcon,
38
+ image: ImageIcon,
39
+ source: GlobeIcon,
40
+ unknown: PaperclipIcon,
41
+ video: VideoIcon,
42
+ }
43
+
44
+ // ============================================================================
45
+ // Utility Functions
46
+ // ============================================================================
47
+
48
+ export const getMediaCategory = (data: AttachmentData): AttachmentMediaCategory => {
49
+ if (data.type === 'source-document') {
50
+ return 'source'
51
+ }
52
+
53
+ const mediaType = data.mediaType ?? ''
54
+
55
+ if (mediaType.startsWith('image/')) {
56
+ return 'image'
57
+ }
58
+ if (mediaType.startsWith('video/')) {
59
+ return 'video'
60
+ }
61
+ if (mediaType.startsWith('audio/')) {
62
+ return 'audio'
63
+ }
64
+ if (mediaType.startsWith('application/') || mediaType.startsWith('text/')) {
65
+ return 'document'
66
+ }
67
+
68
+ return 'unknown'
69
+ }
70
+
71
+ export const getAttachmentLabel = (data: AttachmentData): string => {
72
+ if (data.type === 'source-document') {
73
+ return data.title || data.filename || 'Source'
74
+ }
75
+
76
+ const category = getMediaCategory(data)
77
+ return data.filename || (category === 'image' ? 'Image' : 'Attachment')
78
+ }
79
+
80
+ const renderAttachmentImage = (url: string, filename: string | undefined, isGrid: boolean) =>
81
+ isGrid ? (
82
+ <img
83
+ alt={filename || 'Image'}
84
+ className="size-full object-cover"
85
+ height={96}
86
+ src={url}
87
+ width={96}
88
+ />
89
+ ) : (
90
+ <img
91
+ alt={filename || 'Image'}
92
+ className="size-full rounded object-cover"
93
+ height={20}
94
+ src={url}
95
+ width={20}
96
+ />
97
+ )
98
+
99
+ // ============================================================================
100
+ // Contexts
101
+ // ============================================================================
102
+
103
+ interface AttachmentsContextValue {
104
+ variant: AttachmentVariant
105
+ }
106
+
107
+ const AttachmentsContext = createContext<AttachmentsContextValue | null>(null)
108
+
109
+ interface AttachmentContextValue {
110
+ data: AttachmentData
111
+ mediaCategory: AttachmentMediaCategory
112
+ onRemove?: () => void
113
+ variant: AttachmentVariant
114
+ }
115
+
116
+ const AttachmentContext = createContext<AttachmentContextValue | null>(null)
117
+
118
+ // ============================================================================
119
+ // Hooks
120
+ // ============================================================================
121
+
122
+ export const useAttachmentsContext = () =>
123
+ useContext(AttachmentsContext) ?? { variant: 'grid' as const }
124
+
125
+ export const useAttachmentContext = () => {
126
+ const ctx = useContext(AttachmentContext)
127
+ if (!ctx) {
128
+ throw new Error('Attachment components must be used within <Attachment>')
129
+ }
130
+ return ctx
131
+ }
132
+
133
+ // ============================================================================
134
+ // Attachments - Container
135
+ // ============================================================================
136
+
137
+ export type AttachmentsProps = HTMLAttributes<HTMLDivElement> & {
138
+ variant?: AttachmentVariant
139
+ }
140
+
141
+ export const Attachments = ({
142
+ variant = 'grid',
143
+ className,
144
+ children,
145
+ ...props
146
+ }: AttachmentsProps) => {
147
+ const contextValue = useMemo(() => ({ variant }), [variant])
148
+
149
+ return (
150
+ <AttachmentsContext.Provider value={contextValue}>
151
+ <div
152
+ className={cn(
153
+ 'flex items-start',
154
+ variant === 'list' ? 'flex-col gap-2' : 'flex-wrap gap-2',
155
+ variant === 'grid' && 'ml-auto w-fit',
156
+ className,
157
+ )}
158
+ {...props}
159
+ >
160
+ {children}
161
+ </div>
162
+ </AttachmentsContext.Provider>
163
+ )
164
+ }
165
+
166
+ // ============================================================================
167
+ // Attachment - Item
168
+ // ============================================================================
169
+
170
+ export type AttachmentProps = HTMLAttributes<HTMLDivElement> & {
171
+ data: AttachmentData
172
+ onRemove?: () => void
173
+ }
174
+
175
+ export const Attachment = ({ data, onRemove, className, children, ...props }: AttachmentProps) => {
176
+ const { variant } = useAttachmentsContext()
177
+ const mediaCategory = getMediaCategory(data)
178
+
179
+ const contextValue = useMemo<AttachmentContextValue>(
180
+ () => ({ data, mediaCategory, onRemove, variant }),
181
+ [data, mediaCategory, onRemove, variant],
182
+ )
183
+
184
+ return (
185
+ <AttachmentContext.Provider value={contextValue}>
186
+ <div
187
+ className={cn(
188
+ 'group relative',
189
+ variant === 'grid' && 'size-24 overflow-hidden rounded-lg',
190
+ variant === 'inline' && [
191
+ 'flex h-8 cursor-pointer select-none items-center gap-1.5',
192
+ 'rounded-md border border-stroke px-1.5',
193
+ 'font-medium text-sm transition-all',
194
+ 'hover:bg-muted hover:text-foreground dark:hover:bg-muted/50',
195
+ ],
196
+ variant === 'list' && [
197
+ 'flex w-full items-center gap-3 rounded-lg border p-3',
198
+ 'hover:bg-muted/50',
199
+ ],
200
+ className,
201
+ )}
202
+ {...props}
203
+ >
204
+ {children}
205
+ </div>
206
+ </AttachmentContext.Provider>
207
+ )
208
+ }
209
+
210
+ // ============================================================================
211
+ // AttachmentPreview - Media preview
212
+ // ============================================================================
213
+
214
+ export type AttachmentPreviewProps = HTMLAttributes<HTMLDivElement> & {
215
+ fallbackIcon?: ReactNode
216
+ }
217
+
218
+ export const AttachmentPreview = ({
219
+ fallbackIcon,
220
+ className,
221
+ ...props
222
+ }: AttachmentPreviewProps) => {
223
+ const { data, mediaCategory, variant } = useAttachmentContext()
224
+
225
+ const iconSize = variant === 'inline' ? 'size-3' : 'size-4'
226
+
227
+ const renderIcon = (Icon: typeof ImageIcon) => (
228
+ <Icon className={cn(iconSize, 'text-muted-foreground')} />
229
+ )
230
+
231
+ const renderContent = () => {
232
+ if (mediaCategory === 'image' && data.type === 'file' && data.url) {
233
+ return renderAttachmentImage(data.url, data.filename, variant === 'grid')
234
+ }
235
+
236
+ if (mediaCategory === 'video' && data.type === 'file' && data.url) {
237
+ return <video className="size-full object-cover" muted src={data.url} />
238
+ }
239
+
240
+ const Icon = mediaCategoryIcons[mediaCategory]
241
+ return fallbackIcon ?? renderIcon(Icon)
242
+ }
243
+
244
+ return (
245
+ <div
246
+ className={cn(
247
+ 'flex shrink-0 items-center justify-center overflow-hidden',
248
+ variant === 'grid' && 'size-full bg-muted',
249
+ variant === 'inline' && 'size-5 rounded bg-page',
250
+ variant === 'list' && 'size-12 rounded bg-muted',
251
+ className,
252
+ )}
253
+ {...props}
254
+ >
255
+ {renderContent()}
256
+ </div>
257
+ )
258
+ }
259
+
260
+ // ============================================================================
261
+ // AttachmentInfo - Name and type display
262
+ // ============================================================================
263
+
264
+ export type AttachmentInfoProps = HTMLAttributes<HTMLDivElement> & {
265
+ showMediaType?: boolean
266
+ }
267
+
268
+ export const AttachmentInfo = ({
269
+ showMediaType = false,
270
+ className,
271
+ ...props
272
+ }: AttachmentInfoProps) => {
273
+ const { data, variant } = useAttachmentContext()
274
+ const label = getAttachmentLabel(data)
275
+
276
+ if (variant === 'grid') {
277
+ return null
278
+ }
279
+
280
+ return (
281
+ <div className={cn('min-w-0 flex-1', className)} {...props}>
282
+ <span className="block truncate">{label}</span>
283
+ {showMediaType && data.mediaType && (
284
+ <span className="block truncate text-muted-foreground text-xs">{data.mediaType}</span>
285
+ )}
286
+ </div>
287
+ )
288
+ }
289
+
290
+ // ============================================================================
291
+ // AttachmentRemove - Remove button
292
+ // ============================================================================
293
+
294
+ export type AttachmentRemoveProps = ComponentProps<typeof Button> & {
295
+ label?: string
296
+ }
297
+
298
+ export const AttachmentRemove = ({
299
+ label = 'Remove',
300
+ className,
301
+ children,
302
+ ...props
303
+ }: AttachmentRemoveProps) => {
304
+ const { onRemove, variant } = useAttachmentContext()
305
+
306
+ const handleClick = useCallback(
307
+ (e: React.MouseEvent) => {
308
+ e.stopPropagation()
309
+ onRemove?.()
310
+ },
311
+ [onRemove],
312
+ )
313
+
314
+ if (!onRemove) {
315
+ return null
316
+ }
317
+
318
+ return (
319
+ <Button
320
+ aria-label={label}
321
+ className={cn(
322
+ variant === 'grid' && [
323
+ 'absolute top-2 right-2 size-6 rounded-full p-0',
324
+ 'bg-page/80 backdrop-blur-sm',
325
+ 'opacity-0 transition-opacity group-hover:opacity-100',
326
+ 'hover:bg-page',
327
+ '[&>svg]:size-3',
328
+ ],
329
+ variant === 'inline' && [
330
+ 'size-5 rounded p-0',
331
+ 'opacity-0 transition-opacity group-hover:opacity-100',
332
+ '[&>svg]:size-2.5',
333
+ ],
334
+ variant === 'list' && ['size-8 shrink-0 rounded p-0', '[&>svg]:size-4'],
335
+ className,
336
+ )}
337
+ onClick={handleClick}
338
+ type="button"
339
+ variant="ghost"
340
+ {...props}
341
+ >
342
+ {children ?? <XIcon />}
343
+ <span className="sr-only">{label}</span>
344
+ </Button>
345
+ )
346
+ }
347
+
348
+ // ============================================================================
349
+ // AttachmentHoverCard - Hover preview
350
+ // ============================================================================
351
+
352
+ export type AttachmentHoverCardProps = ComponentProps<typeof HoverCard>
353
+
354
+ export const AttachmentHoverCard = (props: AttachmentHoverCardProps) => <HoverCard {...props} />
355
+
356
+ export type AttachmentHoverCardTriggerProps = ComponentProps<typeof HoverCardTrigger>
357
+
358
+ export const AttachmentHoverCardTrigger = (props: AttachmentHoverCardTriggerProps) => (
359
+ <HoverCardTrigger {...props} />
360
+ )
361
+
362
+ export type AttachmentHoverCardContentProps = ComponentProps<typeof HoverCardContent>
363
+
364
+ export const AttachmentHoverCardContent = ({
365
+ align = 'start',
366
+ className,
367
+ ...props
368
+ }: AttachmentHoverCardContentProps) => (
369
+ <HoverCardContent align={align} className={cn('w-auto p-2', className)} {...props} />
370
+ )
371
+
372
+ // ============================================================================
373
+ // AttachmentEmpty - Empty state
374
+ // ============================================================================
375
+
376
+ export type AttachmentEmptyProps = HTMLAttributes<HTMLDivElement>
377
+
378
+ export const AttachmentEmpty = ({ className, children, ...props }: AttachmentEmptyProps) => (
379
+ <div
380
+ className={cn('flex items-center justify-center p-4 text-muted-foreground text-sm', className)}
381
+ {...props}
382
+ >
383
+ {children ?? 'No attachments'}
384
+ </div>
385
+ )
@@ -0,0 +1,197 @@
1
+ 'use client'
2
+
3
+ import { useControllableState } from '@radix-ui/react-use-controllable-state'
4
+ import { Badge } from '../badge'
5
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../collapsible'
6
+ import { cn } from '../../lib/utils'
7
+ import type { LucideIcon } from 'lucide-react'
8
+ import { BrainIcon, ChevronDownIcon, DotIcon } from 'lucide-react'
9
+ import type { ComponentProps, ReactNode } from 'react'
10
+ import { createContext, memo, useContext, useMemo } from 'react'
11
+
12
+ interface ChainOfThoughtContextValue {
13
+ isOpen: boolean
14
+ setIsOpen: (open: boolean) => void
15
+ }
16
+
17
+ const ChainOfThoughtContext = createContext<ChainOfThoughtContextValue | null>(null)
18
+
19
+ const useChainOfThought = () => {
20
+ const context = useContext(ChainOfThoughtContext)
21
+ if (!context) {
22
+ throw new Error('ChainOfThought components must be used within ChainOfThought')
23
+ }
24
+ return context
25
+ }
26
+
27
+ export type ChainOfThoughtProps = ComponentProps<'div'> & {
28
+ open?: boolean
29
+ defaultOpen?: boolean
30
+ onOpenChange?: (open: boolean) => void
31
+ }
32
+
33
+ export const ChainOfThought = memo(
34
+ ({
35
+ className,
36
+ open,
37
+ defaultOpen = false,
38
+ onOpenChange,
39
+ children,
40
+ ...props
41
+ }: ChainOfThoughtProps) => {
42
+ const [isOpen, setIsOpen] = useControllableState({
43
+ defaultProp: defaultOpen,
44
+ onChange: onOpenChange,
45
+ prop: open,
46
+ })
47
+
48
+ const chainOfThoughtContext = useMemo(() => ({ isOpen, setIsOpen }), [isOpen, setIsOpen])
49
+
50
+ return (
51
+ <ChainOfThoughtContext.Provider value={chainOfThoughtContext}>
52
+ <div className={cn('not-prose w-full space-y-4', className)} {...props}>
53
+ {children}
54
+ </div>
55
+ </ChainOfThoughtContext.Provider>
56
+ )
57
+ },
58
+ )
59
+
60
+ export type ChainOfThoughtHeaderProps = ComponentProps<typeof CollapsibleTrigger>
61
+
62
+ export const ChainOfThoughtHeader = memo(
63
+ ({ className, children, ...props }: ChainOfThoughtHeaderProps) => {
64
+ const { isOpen, setIsOpen } = useChainOfThought()
65
+
66
+ return (
67
+ <Collapsible onOpenChange={setIsOpen} open={isOpen}>
68
+ <CollapsibleTrigger
69
+ className={cn(
70
+ 'flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground',
71
+ className,
72
+ )}
73
+ {...props}
74
+ >
75
+ <BrainIcon className="size-4" />
76
+ <span className="flex-1 text-left">{children ?? 'Chain of Thought'}</span>
77
+ <ChevronDownIcon
78
+ className={cn('size-4 transition-transform', isOpen ? 'rotate-180' : 'rotate-0')}
79
+ />
80
+ </CollapsibleTrigger>
81
+ </Collapsible>
82
+ )
83
+ },
84
+ )
85
+
86
+ export type ChainOfThoughtStepProps = ComponentProps<'div'> & {
87
+ icon?: LucideIcon
88
+ label: ReactNode
89
+ description?: ReactNode
90
+ status?: 'complete' | 'active' | 'pending'
91
+ }
92
+
93
+ const stepStatusStyles = {
94
+ active: 'text-foreground',
95
+ complete: 'text-muted-foreground',
96
+ pending: 'text-muted-foreground/50',
97
+ }
98
+
99
+ export const ChainOfThoughtStep = memo(
100
+ ({
101
+ className,
102
+ icon: Icon = DotIcon,
103
+ label,
104
+ description,
105
+ status = 'complete',
106
+ children,
107
+ ...props
108
+ }: ChainOfThoughtStepProps) => (
109
+ <div
110
+ className={cn(
111
+ 'flex gap-2 text-sm',
112
+ stepStatusStyles[status],
113
+ 'fade-in-0 slide-in-from-top-2 animate-in',
114
+ className,
115
+ )}
116
+ {...props}
117
+ >
118
+ <div className="relative mt-0.5">
119
+ <Icon className="size-4" />
120
+ <div className="absolute top-7 bottom-0 left-1/2 -mx-px w-px bg-border" />
121
+ </div>
122
+ <div className="flex-1 space-y-2 overflow-hidden">
123
+ <div>{label}</div>
124
+ {description && <div className="text-muted-foreground text-xs">{description}</div>}
125
+ {children}
126
+ </div>
127
+ </div>
128
+ ),
129
+ )
130
+
131
+ export type ChainOfThoughtSearchResultsProps = ComponentProps<'div'>
132
+
133
+ export const ChainOfThoughtSearchResults = memo(
134
+ ({ className, ...props }: ChainOfThoughtSearchResultsProps) => (
135
+ <div className={cn('flex flex-wrap items-center gap-2', className)} {...props} />
136
+ ),
137
+ )
138
+
139
+ export type ChainOfThoughtSearchResultProps = ComponentProps<typeof Badge>
140
+
141
+ export const ChainOfThoughtSearchResult = memo(
142
+ ({ className, children, ...props }: ChainOfThoughtSearchResultProps) => (
143
+ <Badge
144
+ className={cn('gap-1 px-2 py-0.5 font-normal text-xs', className)}
145
+ variant="secondary"
146
+ {...props}
147
+ >
148
+ {children}
149
+ </Badge>
150
+ ),
151
+ )
152
+
153
+ export type ChainOfThoughtContentProps = ComponentProps<typeof CollapsibleContent>
154
+
155
+ export const ChainOfThoughtContent = memo(
156
+ ({ className, children, ...props }: ChainOfThoughtContentProps) => {
157
+ const { isOpen } = useChainOfThought()
158
+
159
+ return (
160
+ <Collapsible open={isOpen}>
161
+ <CollapsibleContent
162
+ className={cn(
163
+ 'mt-2 space-y-3',
164
+ 'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
165
+ className,
166
+ )}
167
+ {...props}
168
+ >
169
+ {children}
170
+ </CollapsibleContent>
171
+ </Collapsible>
172
+ )
173
+ },
174
+ )
175
+
176
+ export type ChainOfThoughtImageProps = ComponentProps<'div'> & {
177
+ caption?: string
178
+ }
179
+
180
+ export const ChainOfThoughtImage = memo(
181
+ ({ className, children, caption, ...props }: ChainOfThoughtImageProps) => (
182
+ <div className={cn('mt-2 space-y-2', className)} {...props}>
183
+ <div className="relative flex max-h-[22rem] items-center justify-center overflow-hidden rounded-lg bg-muted p-3">
184
+ {children}
185
+ </div>
186
+ {caption && <p className="text-muted-foreground text-xs">{caption}</p>}
187
+ </div>
188
+ ),
189
+ )
190
+
191
+ ChainOfThought.displayName = 'ChainOfThought'
192
+ ChainOfThoughtHeader.displayName = 'ChainOfThoughtHeader'
193
+ ChainOfThoughtStep.displayName = 'ChainOfThoughtStep'
194
+ ChainOfThoughtSearchResults.displayName = 'ChainOfThoughtSearchResults'
195
+ ChainOfThoughtSearchResult.displayName = 'ChainOfThoughtSearchResult'
196
+ ChainOfThoughtContent.displayName = 'ChainOfThoughtContent'
197
+ ChainOfThoughtImage.displayName = 'ChainOfThoughtImage'