Skip to content

Commit d281040

Browse files
committed
refactor: uploadProgress renamed to Progress and moved outside of message composer
1 parent 50c8b11 commit d281040

File tree

18 files changed

+78
-75
lines changed

18 files changed

+78
-75
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
3+
import { useTranslationContext } from '../../context/TranslationContext';
4+
5+
const RING_RADIUS = 12;
6+
const RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;
7+
8+
export type ProgressIndicatorProps = {
9+
/** Clamped 0–100 completion. */
10+
percent: number;
11+
};
12+
13+
/** Circular progress indicator with input from 0 to 100. */
14+
export const ProgressIndicator = ({ percent }: ProgressIndicatorProps) => {
15+
const { t } = useTranslationContext('ProgressIndicator');
16+
const dashOffset = RING_CIRCUMFERENCE * (1 - percent / 100);
17+
18+
return (
19+
<div className='str-chat__upload-progress'>
20+
<svg
21+
aria-label={t('aria/Progress', { percent })}
22+
aria-valuemax={100}
23+
aria-valuemin={0}
24+
aria-valuenow={percent}
25+
data-testid='progress-ring'
26+
height='100%'
27+
role='progressbar'
28+
viewBox='0 0 32 32'
29+
width='100%'
30+
xmlns='http://www.w3.org/2000/svg'
31+
>
32+
<circle
33+
cx='16'
34+
cy='16'
35+
fill='none'
36+
r={RING_RADIUS}
37+
stroke='currentColor'
38+
strokeOpacity={0.35}
39+
strokeWidth='2.5'
40+
/>
41+
<circle
42+
cx='16'
43+
cy='16'
44+
fill='none'
45+
r={RING_RADIUS}
46+
stroke='currentColor'
47+
strokeDasharray={RING_CIRCUMFERENCE}
48+
strokeDashoffset={dashOffset}
49+
strokeLinecap='round'
50+
strokeWidth='2.5'
51+
transform='rotate(-90 16 16)'
52+
/>
53+
</svg>
54+
</div>
55+
);
56+
};

src/components/Loading/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './LoadingChannel';
22
export * from './LoadingChannels';
33
export * from './LoadingErrorIndicator';
44
export * from './LoadingIndicator';
5+
export * from './ProgressIndicator';

src/components/MessageComposer/AttachmentPreviewList/AttachmentUploadProgressIndicator.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import clsx from 'clsx';
22
import React, { type ReactNode } from 'react';
33

4+
import { ProgressIndicator as DefaultProgressIndicator } from '../../Loading';
45
import { useComponentContext } from '../../../context';
5-
import { UploadProgress as DefaultUploadProgress, LoadingIndicatorIcon } from '../icons';
6+
import { LoadingIndicatorIcon } from '../icons';
67
import { clampUploadPercent } from './utils/uploadProgress';
78

89
export type AttachmentUploadProgressVariant = 'inline' | 'overlay';
@@ -21,7 +22,7 @@ export const AttachmentUploadProgressIndicator = ({
2122
uploadProgress,
2223
variant,
2324
}: AttachmentUploadProgressIndicatorProps) => {
24-
const { UploadProgress = DefaultUploadProgress } = useComponentContext(
25+
const { ProgressIndicator = DefaultProgressIndicator } = useComponentContext(
2526
'AttachmentUploadProgressIndicator',
2627
);
2728

@@ -39,7 +40,7 @@ export const AttachmentUploadProgressIndicator = ({
3940
className,
4041
)}
4142
>
42-
<UploadProgress percent={percent} />
43+
<ProgressIndicator percent={percent} />
4344
</div>
4445
);
4546
};

src/components/MessageComposer/__tests__/AttachmentPreviewList.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,7 @@ describe('AttachmentPreviewList', () => {
338338
});
339339

340340
expect(screen.getByTestId(LOADING_INDICATOR_TEST_ID)).toBeInTheDocument();
341-
expect(
342-
screen.queryByTestId('attachment-upload-progress-ring'),
343-
).not.toBeInTheDocument();
341+
expect(screen.queryByTestId('progress-ring')).not.toBeInTheDocument();
344342
});
345343

346344
it('shows ring while uploading when uploadProgress is numeric', async () => {
@@ -357,7 +355,7 @@ describe('AttachmentPreviewList', () => {
357355
],
358356
});
359357

360-
expect(screen.getByTestId('attachment-upload-progress-ring')).toBeInTheDocument();
358+
expect(screen.getByTestId('progress-ring')).toBeInTheDocument();
361359
expect(screen.queryByTestId(LOADING_INDICATOR_TEST_ID)).not.toBeInTheDocument();
362360
});
363361

src/components/MessageComposer/icons.tsx

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,6 @@ import { nanoid } from 'nanoid';
33

44
import { useTranslationContext } from '../../context/TranslationContext';
55

6-
const UPLOAD_RING_RADIUS = 12;
7-
const UPLOAD_RING_CIRCUMFERENCE = 2 * Math.PI * UPLOAD_RING_RADIUS;
8-
9-
export type UploadProgressProps = {
10-
/** Clamped 0–100 upload completion. */
11-
percent: number;
12-
};
13-
14-
/** Determinate circular upload progress ring (not a spinner; uses `str-chat__upload-progress`, not the loading-indicator spinner). */
15-
export const UploadProgress = ({ percent }: UploadProgressProps) => {
16-
const { t } = useTranslationContext('UploadProgress');
17-
const dashOffset = UPLOAD_RING_CIRCUMFERENCE * (1 - percent / 100);
18-
19-
return (
20-
<div className='str-chat__upload-progress'>
21-
<svg
22-
aria-label={t('aria/Upload progress', { percent })}
23-
aria-valuemax={100}
24-
aria-valuemin={0}
25-
aria-valuenow={percent}
26-
data-testid='attachment-upload-progress-ring'
27-
height='100%'
28-
role='progressbar'
29-
viewBox='0 0 32 32'
30-
width='100%'
31-
xmlns='http://www.w3.org/2000/svg'
32-
>
33-
<circle
34-
cx='16'
35-
cy='16'
36-
fill='none'
37-
r={UPLOAD_RING_RADIUS}
38-
stroke='currentColor'
39-
strokeOpacity={0.35}
40-
strokeWidth='2.5'
41-
/>
42-
<circle
43-
cx='16'
44-
cy='16'
45-
fill='none'
46-
r={UPLOAD_RING_RADIUS}
47-
stroke='currentColor'
48-
strokeDasharray={UPLOAD_RING_CIRCUMFERENCE}
49-
strokeDashoffset={dashOffset}
50-
strokeLinecap='round'
51-
strokeWidth='2.5'
52-
transform='rotate(-90 16 16)'
53-
/>
54-
</svg>
55-
</div>
56-
);
57-
};
58-
596
export const LoadingIndicatorIcon = () => {
607
const id = useMemo(() => nanoid(), []);
618

src/context/ComponentContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import type { VideoPlayerProps } from '../components/VideoPlayer';
7272
import type { EditedMessagePreviewProps } from '../components/MessageComposer/EditedMessagePreview';
7373
import type { FileIconProps } from '../components/FileIcon/FileIcon';
7474
import type { CommandChipProps } from '../components/MessageComposer/CommandChip';
75-
import type { UploadProgressProps } from '../components/MessageComposer/icons';
75+
import type { ProgressIndicatorProps } from '../components/Loading/ProgressIndicator';
7676

7777
export type ComponentContextValue = {
7878
/** 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) */
@@ -143,8 +143,8 @@ export type ComponentContextValue = {
143143
LoadingErrorIndicator?: React.ComponentType<LoadingErrorIndicatorProps>;
144144
/** Custom UI component to render while the `MessageList` is loading new messages, defaults to and accepts same props as: [LoadingIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Loading/LoadingIndicator.tsx) */
145145
LoadingIndicator?: React.ComponentType<LoadingIndicatorProps>;
146-
/** Custom UI component for determinate attachment upload progress (0–100) in attachment previews, defaults to and accepts same props as: [UploadProgress](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageComposer/icons.tsx) */
147-
UploadProgress?: React.ComponentType<UploadProgressProps>;
146+
/** Custom UI component for determinate progress (0–100), defaults to and accepts same props as: [ProgressIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Loading/ProgressIndicator.tsx) */
147+
ProgressIndicator?: React.ComponentType<ProgressIndicatorProps>;
148148
/** Custom UI component to display a message in the standard `MessageList`, defaults to and accepts the same props as: [MessageUI](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageUI.tsx) */
149149
Message?: React.ComponentType<MessageUIComponentProps>;
150150
/** Custom UI component for message actions popup, accepts no props, all the defaults are set within [MessageActions (unstable)](https://github.com/GetStream/stream-chat-react/blob/master/src/experimental/MessageActions/MessageActions.tsx) */

src/i18n/de.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"aria/Open Reaction Selector": "Reaktionsauswahl öffnen",
8585
"aria/Open Thread": "Thread öffnen",
8686
"aria/Pin Message": "Nachricht anheften",
87+
"aria/Progress": "{{percent}} Prozent abgeschlossen",
8788
"aria/Quote Message": "Nachricht zitieren",
8889
"aria/Reaction list": "Reaktionsliste",
8990
"aria/Remind Me Message": "Erinnern",
@@ -102,7 +103,6 @@
102103
"aria/Unblock User": "Benutzer entsperren",
103104
"aria/Unmute User": "Stummschaltung aufheben",
104105
"aria/Unpin Message": "Anheftung aufheben",
105-
"aria/Upload progress": "{{percent}} Prozent hochgeladen",
106106
"Ask a question": "Eine Frage stellen",
107107
"Attach": "Anhängen",
108108
"Attach files": "Dateien anhängen",

src/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"aria/Open Reaction Selector": "Open Reaction Selector",
8585
"aria/Open Thread": "Open Thread",
8686
"aria/Pin Message": "Pin Message",
87+
"aria/Progress": "{{percent}} percent complete",
8788
"aria/Quote Message": "Quote Message",
8889
"aria/Reaction list": "Reaction list",
8990
"aria/Remind Me Message": "Remind Me Message",
@@ -102,7 +103,6 @@
102103
"aria/Unblock User": "Unblock User",
103104
"aria/Unmute User": "Unmute User",
104105
"aria/Unpin Message": "Unpin Message",
105-
"aria/Upload progress": "{{percent}} percent uploaded",
106106
"Ask a question": "Ask a Question",
107107
"Attach": "Attach",
108108
"Attach files": "Attach files",

src/i18n/es.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"aria/Open Reaction Selector": "Abrir selector de reacciones",
9393
"aria/Open Thread": "Abrir hilo",
9494
"aria/Pin Message": "Fijar mensaje",
95+
"aria/Progress": "{{percent}} por ciento completado",
9596
"aria/Quote Message": "Citar mensaje",
9697
"aria/Reaction list": "Lista de reacciones",
9798
"aria/Remind Me Message": "Recordarme",
@@ -110,7 +111,6 @@
110111
"aria/Unblock User": "Desbloquear usuario",
111112
"aria/Unmute User": "Activar sonido",
112113
"aria/Unpin Message": "Desfijar mensaje",
113-
"aria/Upload progress": "{{percent}} por ciento cargado",
114114
"Ask a question": "Hacer una pregunta",
115115
"Attach": "Adjuntar",
116116
"Attach files": "Adjuntar archivos",

src/i18n/fr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"aria/Open Reaction Selector": "Ouvrir le sélecteur de réactions",
9393
"aria/Open Thread": "Ouvrir le fil",
9494
"aria/Pin Message": "Épingler le message",
95+
"aria/Progress": "{{percent}} pour cent terminé",
9596
"aria/Quote Message": "Citer le message",
9697
"aria/Reaction list": "Liste des réactions",
9798
"aria/Remind Me Message": "Me rappeler",
@@ -110,7 +111,6 @@
110111
"aria/Unblock User": "Débloquer l'utilisateur",
111112
"aria/Unmute User": "Désactiver muet",
112113
"aria/Unpin Message": "Détacher le message",
113-
"aria/Upload progress": "{{percent}} pour cent téléchargés",
114114
"Ask a question": "Poser une question",
115115
"Attach": "Joindre",
116116
"Attach files": "Joindre des fichiers",

0 commit comments

Comments
 (0)