Skip to content

Commit 0a8d65d

Browse files
committed
feat: make AttachmentUploadProgressIndicator and AttachmentUploadProgressIndicator overridable
1 parent 77ba34c commit 0a8d65d

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

‎src/components/MessageComposer/AttachmentPreviewList/AudioAttachmentPreview.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
type LocalAudioAttachment,
55
type LocalVoiceRecordingAttachment,
66
} from 'stream-chat';
7-
import { useTranslationContext } from '../../../context';
7+
import { useComponentContext, useTranslationContext } from '../../../context';
88
import React, { useEffect } from 'react';
99
import clsx from 'clsx';
10-
import { AttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
10+
import { AttachmentUploadProgressIndicator as DefaultAttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
1111
import { RemoveAttachmentPreviewButton } from '../RemoveAttachmentPreviewButton';
1212
import { AttachmentPreviewRoot } from './utils/AttachmentPreviewRoot';
1313
import { IconExclamationMark, IconExclamationTriangleFill } from '../../Icons';
@@ -20,7 +20,7 @@ import {
2020
} from '../../AudioPlayback';
2121
import { useAudioPlayer } from '../../AudioPlayback/WithAudioPlayback';
2222
import { useStateStore } from '../../../store';
23-
import { AttachmentUploadedSizeIndicator } from './AttachmentUploadedSizeIndicator';
23+
import { AttachmentUploadedSizeIndicator as DefaultAttachmentUploadedSizeIndicator } from './AttachmentUploadedSizeIndicator';
2424

2525
export type AudioAttachmentPreviewProps<CustomLocalMetadata = Record<string, unknown>> =
2626
UploadAttachmentPreviewProps<
@@ -42,6 +42,10 @@ export const AudioAttachmentPreview = ({
4242
removeAttachments,
4343
}: AudioAttachmentPreviewProps) => {
4444
const { t } = useTranslationContext();
45+
const {
46+
AttachmentUploadedSizeIndicator = DefaultAttachmentUploadedSizeIndicator,
47+
AttachmentUploadProgressIndicator = DefaultAttachmentUploadProgressIndicator,
48+
} = useComponentContext();
4549
const { id, previewUri, uploadPermissionCheck, uploadProgress, uploadState } =
4650
attachment.localMetadata ?? {};
4751
const url = attachment.asset_url || previewUri;

‎src/components/MessageComposer/AttachmentPreviewList/FileAttachmentPreview.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
2-
import { useTranslationContext } from '../../../context';
2+
import { useComponentContext, useTranslationContext } from '../../../context';
33
import { FileIcon } from '../../FileIcon';
4-
import { AttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
5-
import { AttachmentUploadedSizeIndicator } from './AttachmentUploadedSizeIndicator';
4+
import { AttachmentUploadProgressIndicator as DefaultAttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
5+
import { AttachmentUploadedSizeIndicator as DefaultAttachmentUploadedSizeIndicator } from './AttachmentUploadedSizeIndicator';
66
import type { LocalAudioAttachment, LocalFileAttachment } from 'stream-chat';
77
import type { UploadAttachmentPreviewProps } from './types';
88
import { RemoveAttachmentPreviewButton } from '../RemoveAttachmentPreviewButton';
@@ -20,6 +20,10 @@ export const FileAttachmentPreview = ({
2020
removeAttachments,
2121
}: FileAttachmentPreviewProps) => {
2222
const { t } = useTranslationContext('FilePreview');
23+
const {
24+
AttachmentUploadedSizeIndicator = DefaultAttachmentUploadedSizeIndicator,
25+
AttachmentUploadProgressIndicator = DefaultAttachmentUploadProgressIndicator,
26+
} = useComponentContext();
2327
const { id, uploadPermissionCheck, uploadProgress, uploadState } =
2428
attachment.localMetadata ?? {};
2529

‎src/components/MessageComposer/AttachmentPreviewList/MediaAttachmentPreview.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import clsx from 'clsx';
1717
import { IconExclamationMark, IconRetry, IconVideoFill } from '../../Icons';
1818
import { RemoveAttachmentPreviewButton } from '../RemoveAttachmentPreviewButton';
1919
import { Button } from '../../Button';
20-
import { AttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
20+
import { AttachmentUploadProgressIndicator as DefaultAttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
2121
import { AttachmentPreviewRoot } from './utils/AttachmentPreviewRoot';
2222
import { LoadingIndicator as DefaultLoadingIndicator } from '../../Loading';
2323

@@ -35,8 +35,11 @@ export const MediaAttachmentPreview = ({
3535
removeAttachments,
3636
}: MediaAttachmentPreviewProps) => {
3737
const { t } = useTranslationContext();
38-
const { BaseImage = DefaultBaseImage, LoadingIndicator = DefaultLoadingIndicator } =
39-
useComponentContext();
38+
const {
39+
AttachmentUploadProgressIndicator = DefaultAttachmentUploadProgressIndicator,
40+
BaseImage = DefaultBaseImage,
41+
LoadingIndicator = DefaultLoadingIndicator,
42+
} = useComponentContext();
4043
const [thumbnailPreviewError, setThumbnailPreviewError] = useState(false);
4144

4245
const { id, uploadPermissionCheck, uploadProgress, uploadState } =

‎src/context/ComponentContext.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import type { EditedMessagePreviewProps } from '../components/MessageComposer/Ed
7575
import type { FileIconProps } from '../components/FileIcon/FileIcon';
7676
import type { CommandChipProps } from '../components/MessageComposer/CommandChip';
7777
import type { CircularProgressIndicatorProps } from '../components/Loading/CircularProgressIndicator';
78+
import type { AttachmentUploadProgressIndicatorProps } from '../components/MessageComposer/AttachmentPreviewList/AttachmentUploadProgressIndicator';
79+
import type { AttachmentUploadedSizeIndicatorProps } from '../components/MessageComposer/AttachmentPreviewList/AttachmentUploadedSizeIndicator';
7880

7981
export type ComponentContextValue = {
8082
/** Custom UI component to display additional message composer action buttons left to the textarea, defaults to and accepts same props as: [AdditionalMessageComposerActions](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageComposer/MessageComposerActions.tsx) */
@@ -87,6 +89,10 @@ export type ComponentContextValue = {
8789
AttachmentPreviewList?: React.ComponentType<AttachmentPreviewListProps>;
8890
/** Custom UI component to control adding attachments to MessageComposer, defaults to and accepts same props as: [AttachmentSelector](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageComposer/AttachmentSelector.tsx) */
8991
AttachmentSelector?: React.ComponentType;
92+
/** Custom UI component for upload progress on attachment previews in MessageComposer, defaults to and accepts same props as: [AttachmentUploadProgressIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageComposer/AttachmentPreviewList/AttachmentUploadProgressIndicator.tsx) */
93+
AttachmentUploadProgressIndicator?: React.ComponentType<AttachmentUploadProgressIndicatorProps>;
94+
/** Custom UI component for uploaded/total size on attachment previews in MessageComposer, defaults to and accepts same props as: [AttachmentUploadedSizeIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageComposer/AttachmentPreviewList/AttachmentUploadedSizeIndicator.tsx) */
95+
AttachmentUploadedSizeIndicator?: React.ComponentType<AttachmentUploadedSizeIndicatorProps>;
9096
/** Custom UI component for the dedicated voice recording preview slot above composer attachments (REACT-794), defaults to and accepts same props as: [VoiceRecordingPreviewSlot](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageComposer/AttachmentPreviewList/VoiceRecordingPreviewSlot.tsx) */
9197
VoiceRecordingPreviewSlot?: React.ComponentType<VoiceRecordingPreviewSlotProps>;
9298
/** Custom UI component for contents of attachment selector initiation button */

0 commit comments

Comments
 (0)