-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow custom attachments (#2383)
- Loading branch information
1 parent
6a3a7f8
commit c751670
Showing
52 changed files
with
2,035 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
docusaurus/docs/React/guides/message-input/attachment-previews.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
id: attachment_previews | ||
title: Attachment Previews in Message Input | ||
--- | ||
|
||
In this section we will focus on how to customize attachment previews display in `MessageInput` component. The attachment previews are rendered by [`AttachmentPreviewList` component](../../../components/message-input-components/ui_components#attachmentpreviewlist). | ||
|
||
## Customize the rendering of default attachment previews | ||
|
||
The default attachment types recognized by `AttachmentPreviewList` are: | ||
|
||
- `audio` | ||
- `video` | ||
- `image` | ||
- `voiceRecording` | ||
- `file` | ||
|
||
If the attachment object has property `og_scrape_url` or `title_link`, then it is rendered by [`LinkPreviewList` component](#linkpreviewlist-props) and not `AttachmentPreviewList`. | ||
|
||
To customize attachment previews we need to override `AttachmentsPreviewList` component. | ||
|
||
```jsx | ||
import { VideoAttachmentPreview } from './AttachmentPreviews'; | ||
|
||
const CustomAttachmentPreviewList = () => ( | ||
<AttachmentPreviewList VideoAttachmentPreview={VideoAttachmentPreview} /> | ||
); | ||
``` | ||
|
||
And pass it to `Channel` component. | ||
|
||
```jsx | ||
<Channel AttachmentPreviewList={CustomAttachmentPreviewList} /> | ||
``` | ||
|
||
We can customize the following preview components: | ||
|
||
- `AudioAttachmentPreview` | ||
- `FileAttachmentPreview` | ||
- `ImageAttachmentPreview` | ||
- `UnsupportedAttachmentPreview` | ||
- `VideoAttachmentPreview` | ||
- `VoiceRecordingPreview` | ||
|
||
## Customize the rendering of custom attachment previews | ||
|
||
It is possible to add custom attachments (objects) to composed messages via [`upsertAttachments` function](../../../components/contexts/message-input-context#upsertattachments) provided by `MessageInputContext`. | ||
|
||
The custom attachments are not recognized by `AttachmentPreviewList` component and therefore rendered via `UnsupportedAttachmentPreview` component within `AttachmentPreviewList`. The component `UnsupportedAttachmentPreview` can be customized and handle all the custom attachment objects added to the message attachments. | ||
|
||
```tsx | ||
import { GeolocationPreview } from './GeolocationAttachmentPreview'; | ||
import type { UnsupportedAttachmentPreviewProps } from 'stream-chat-react'; | ||
|
||
const CustomAttachmentsPreview = (props: UnsupportedAttachmentPreviewProps) => { | ||
const { attachment } = props; | ||
if (attachment.type === 'geolocation') { | ||
return <GeolocationPreview {...props} />; | ||
} | ||
// more conditions follow... | ||
}; | ||
``` | ||
|
||
The custom component is then passed to custom `AttachmentsPreviewList` component which purpose is just to specify the custom `UnsupportedAttachmentPreview` component. | ||
|
||
```jsx | ||
import { CustomAttachmentsPreview } from './AttachmentPreviewList'; | ||
const CustomAttachmentPreviewList = () => ( | ||
<AttachmentPreviewList UnsupportedAttachmentPreview={CustomAttachmentsPreview} /> | ||
); | ||
``` | ||
|
||
```jsx | ||
<Channel AttachmentPreviewList={CustomAttachmentPreviewList} /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.