Skip to content

Commit 7e060cf

Browse files
authored
refactor(message)!: remove legacy attachment display components and align examples/docs (#162)
* chore(examples): update `message` example * refactor(message)!: remove legacy attachment display components * docs: update `message`
1 parent 24cc84a commit 7e060cf

File tree

5 files changed

+24
-315
lines changed

5 files changed

+24
-315
lines changed

apps/www/content/3.components/1.chatbot/message.md

Lines changed: 3 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -437,124 +437,6 @@ const md = computed(() => (slotContent.value ?? props.content ?? '') as string)
437437
</template>
438438
```
439439

440-
```vue [MessageAttachments.vue]
441-
<script setup lang="ts">
442-
import type { HTMLAttributes } from 'vue'
443-
import { cn } from '@repo/shadcn-vue/lib/utils'
444-
445-
interface Props {
446-
class?: HTMLAttributes['class']
447-
}
448-
449-
const props = defineProps<Props>()
450-
</script>
451-
452-
<template>
453-
<div
454-
v-if="$slots.default"
455-
:class="
456-
cn(
457-
'ml-auto flex w-fit flex-wrap items-start gap-2',
458-
props.class,
459-
)
460-
"
461-
v-bind="$attrs"
462-
>
463-
<slot />
464-
</div>
465-
</template>
466-
```
467-
468-
```vue [MessageAttachment.vue]
469-
<script setup lang="ts">
470-
import type { FileUIPart } from 'ai'
471-
import type { HTMLAttributes } from 'vue'
472-
import { Button } from '@repo/shadcn-vue/components/ui/button'
473-
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@repo/shadcn-vue/components/ui/tooltip'
474-
import { cn } from '@repo/shadcn-vue/lib/utils'
475-
import { PaperclipIcon, XIcon } from 'lucide-vue-next'
476-
import { computed } from 'vue'
477-
478-
interface Props {
479-
data: FileUIPart
480-
class?: HTMLAttributes['class']
481-
}
482-
const props = defineProps<Props>()
483-
484-
const emits = defineEmits<{
485-
(e: 'remove'): void
486-
}>()
487-
488-
const filename = computed(() => props.data.filename || '')
489-
const mediaType = computed(() =>
490-
props.data.mediaType?.startsWith('image/') && props.data.url ? 'image' : 'file',
491-
)
492-
const isImage = computed(() => mediaType.value === 'image')
493-
const attachmentLabel = computed(() =>
494-
filename.value || (isImage.value ? 'Image' : 'Attachment'),
495-
)
496-
</script>
497-
498-
<template>
499-
<div
500-
:class="
501-
cn(
502-
'group relative size-24 overflow-hidden rounded-lg',
503-
props.class,
504-
)
505-
"
506-
v-bind="$attrs"
507-
>
508-
<template v-if="isImage">
509-
<img
510-
:src="props.data.url"
511-
:alt="filename || 'attachment'"
512-
class="size-full object-cover"
513-
height="100"
514-
width="100"
515-
>
516-
<Button
517-
aria-label="Remove attachment"
518-
class="absolute top-2 right-2 size-6 rounded-full bg-background/80 p-0 opacity-0 backdrop-blur-sm transition-opacity hover:bg-background group-hover:opacity-100 [&>svg]:size-3"
519-
type="button"
520-
variant="ghost"
521-
@click.stop="emits('remove')"
522-
>
523-
<XIcon />
524-
<span class="sr-only">Remove</span>
525-
</Button>
526-
</template>
527-
528-
<template v-else>
529-
<TooltipProvider>
530-
<Tooltip>
531-
<TooltipTrigger as-child>
532-
<div
533-
class="flex size-full shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground"
534-
>
535-
<PaperclipIcon class="size-4" />
536-
</div>
537-
</TooltipTrigger>
538-
<TooltipContent>
539-
<p>{{ attachmentLabel }}</p>
540-
</TooltipContent>
541-
</Tooltip>
542-
</TooltipProvider>
543-
<Button
544-
aria-label="Remove attachment"
545-
class="size-6 shrink-0 rounded-full p-0 opacity-0 transition-opacity hover:bg-accent group-hover:opacity-100 [&>svg]:size-3"
546-
type="button"
547-
variant="ghost"
548-
@click.stop="emits('remove')"
549-
>
550-
<XIcon />
551-
<span class="sr-only">Remove</span>
552-
</Button>
553-
</template>
554-
</div>
555-
</template>
556-
```
557-
558440
```vue [MessageToolbar.vue]
559441
<script setup lang="ts">
560442
import type { HTMLAttributes } from 'vue'
@@ -611,8 +493,6 @@ export function useMessageBranchContext(): MessageBranchContextType {
611493
export { default as Message } from './Message.vue'
612494
export { default as MessageAction } from './MessageAction.vue'
613495
export { default as MessageActions } from './MessageActions.vue'
614-
export { default as MessageAttachment } from './MessageAttachment.vue'
615-
export { default as MessageAttachments } from './MessageAttachments.vue'
616496
export { default as MessageAvatar } from './MessageAvatar.vue'
617497
export { default as MessageBranch } from './MessageBranch.vue'
618498
export { default as MessageBranchContent } from './MessageBranchContent.vue'
@@ -959,59 +839,17 @@ function copyToClipboard(text: string) {
959839
::
960840
::
961841

962-
### `<MessageAttachments />`
963-
964-
::field-group
965-
::field{name="class" type="string" defaultValue="''"}
966-
Additional classes applied to the component.
967-
::
968-
::
969-
970-
**Example:**
971-
972-
```vue
973-
<MessageAttachments class="mb-2">
974-
<MessageAttachment
975-
v-for="attachment in files"
976-
:key="attachment.url"
977-
:data="attachment"
978-
/>
979-
</MessageAttachments>
980-
```
981-
982-
### `<MessageAttachment />`
842+
### `<MessageToolbar />`
983843

984844
::field-group
985-
::field{name="data" type="FileUIPart" required}
986-
The file data to display. Must include url and mediaType.
987-
::
988-
989845
::field{name="class" type="string" defaultValue="''"}
990846
Additional classes applied to the component.
991847
::
992848
::
993849

994-
**Example:**
995-
996-
```vue
997-
<MessageAttachment
998-
data="{
999-
type: 'file',
1000-
url: 'https://example.com/image.jpg',
1001-
mediaType: 'image/jpeg',
1002-
filename: 'image.jpg'
1003-
}"
1004-
@remove="() => console.log('Remove clicked')"
1005-
/>
1006-
```
850+
### Attachments
1007851

1008-
### `<MessageToolbar />`
1009-
1010-
::field-group
1011-
::field{name="class" type="string" defaultValue="''"}
1012-
Additional classes applied to the component.
1013-
::
1014-
::
852+
Attachment components have been moved to a separate module. See the [Attachments](/components/chatbot/attachments) component documentation for details on `<Attachments />`, `<Attachment />`, `<AttachmentPreview />`, and `<AttachmentInfo />`.
1015853

1016854
## Emits
1017855

@@ -1022,11 +860,3 @@ function copyToClipboard(text: string) {
1022860
Emitted when the branch changes.
1023861
::
1024862
::
1025-
1026-
### `<MessageAttachment />`
1027-
1028-
::field-group
1029-
::field{name="remove" type="function" }
1030-
Emitted when the attachment is removed.
1031-
::
1032-
::

packages/elements/src/message/MessageAttachment.vue

Lines changed: 0 additions & 87 deletions
This file was deleted.

packages/elements/src/message/MessageAttachments.vue

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/elements/src/message/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
export { default as Message } from './Message.vue'
22
export { default as MessageAction } from './MessageAction.vue'
33
export { default as MessageActions } from './MessageActions.vue'
4-
export { default as MessageAttachment } from './MessageAttachment.vue'
5-
export { default as MessageAttachments } from './MessageAttachments.vue'
64
export { default as MessageAvatar } from './MessageAvatar.vue'
75
export { default as MessageBranch } from './MessageBranch.vue'
86
export { default as MessageBranchContent } from './MessageBranchContent.vue'

0 commit comments

Comments
 (0)