-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathAttachmentActions.tsx
More file actions
54 lines (47 loc) · 1.8 KB
/
AttachmentActions.tsx
File metadata and controls
54 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import type { Action, Attachment } from 'stream-chat';
import { useTranslationContext } from '../../context';
import type { ActionHandlerReturnType } from '../Message/hooks/useActionHandler';
export type AttachmentActionsProps = Attachment & {
/** A list of actions */
actions: Action[];
/** Unique id for action button key. Key is generated by concatenating this id with action value - {`${id}-${action.value}`} */
id: string;
/** The text for the form input */
text: string;
/** Click event handler */
actionHandler?: ActionHandlerReturnType;
};
const UnMemoizedAttachmentActions = (props: AttachmentActionsProps) => {
const { actionHandler, actions, id, text } = props;
const { t } = useTranslationContext('UnMemoizedAttachmentActions');
const handleActionClick = (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>,
name?: string,
value?: string,
) => actionHandler?.(name, value, event);
return (
<div className='str-chat__message-attachment-actions'>
<div className='str-chat__message-attachment-actions-form'>
<span>{text}</span>
{actions.map((action) => (
<button
className={`str-chat__message-attachment-actions-button str-chat__message-attachment-actions-button--${action.style}`}
data-testid={`${action.name}`}
data-value={action.value}
key={`${id}-${action.value}`}
onClick={(event) => handleActionClick(event, action.name, action.value)}
>
{action.text ? t(action.text) : null}
</button>
))}
</div>
</div>
);
};
/**
* A component for rendering the actions you can take on an attachment.
*/
export const AttachmentActions = React.memo(
UnMemoizedAttachmentActions,
) as typeof UnMemoizedAttachmentActions;