Skip to content

Commit b81ec17

Browse files
feat(AttachButton): Allow custom icon (#751)
1 parent b3a49bd commit b81ec17

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

packages/module/src/MessageBar/AttachButton.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,8 @@ describe('Attach button', () => {
173173
expect(validator).toHaveBeenCalledWith(file);
174174
expect(onAttachRejected).toHaveBeenCalled();
175175
});
176+
it('should handle icon prop', () => {
177+
render(<AttachButton icon={<img alt="" src="" />} />);
178+
expect(screen.getByRole('img')).toBeVisible();
179+
});
176180
});

packages/module/src/MessageBar/AttachButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export interface AttachButtonProps extends ButtonProps {
5151
validator?: <T extends File>(file: T) => FileError | readonly FileError[] | null;
5252
/** Additional props passed to react-dropzone */
5353
dropzoneProps?: DropzoneOptions;
54+
/** Icon displayed in attach button */
55+
icon?: React.ReactNode;
5456
}
5557

5658
const AttachButtonBase: FunctionComponent<AttachButtonProps> = ({
@@ -72,6 +74,7 @@ const AttachButtonBase: FunctionComponent<AttachButtonProps> = ({
7274
onAttachRejected,
7375
validator,
7476
dropzoneProps,
77+
icon = <PaperclipIcon />,
7578
...props
7679
}: AttachButtonProps) => {
7780
const { open, getInputProps } = useDropzone({
@@ -113,7 +116,7 @@ const AttachButtonBase: FunctionComponent<AttachButtonProps> = ({
113116
onClick={onClick ?? open}
114117
icon={
115118
<Icon iconSize={isCompact ? 'lg' : 'xl'} isInline>
116-
<PaperclipIcon />
119+
{icon}
117120
</Icon>
118121
}
119122
size={isCompact ? 'sm' : undefined}

packages/module/src/MessageBar/MessageBar.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ describe('Message bar', () => {
325325
);
326326
await userEvent.click(screen.getByRole('button', { name: 'Test' }));
327327
});
328+
it('can change attach button icon', () => {
329+
render(
330+
<MessageBar
331+
onSendMessage={jest.fn}
332+
hasAttachButton
333+
buttonProps={{
334+
attach: {
335+
icon: <img alt="" src="" />
336+
}
337+
}}
338+
/>
339+
);
340+
expect(screen.getByRole('img')).toBeVisible();
341+
});
328342

329343
// Stop button
330344
// --------------------------------------------------------------------------

packages/module/src/MessageBar/MessageBar.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
// Import Chatbot components
1515
import SendButton from './SendButton';
1616
import MicrophoneButton from './MicrophoneButton';
17-
import { AttachButton } from './AttachButton';
17+
import { AttachButton, AttachButtonProps } from './AttachButton';
1818
import AttachMenu from '../AttachMenu';
1919
import StopButton from './StopButton';
2020
import { ChatbotDisplayMode } from '../Chatbot';
@@ -95,12 +95,7 @@ export interface MessageBarProps extends Omit<TextAreaProps, 'innerRef'> {
9595
isSendButtonDisabled?: boolean;
9696
/** Prop to allow passage of additional props to buttons */
9797
buttonProps?: {
98-
attach?: {
99-
tooltipContent?: string;
100-
props?: ButtonProps;
101-
inputTestId?: string;
102-
tooltipProps?: Omit<TooltipProps, 'content'>;
103-
};
98+
attach?: AttachButtonProps & { props?: ButtonProps };
10499
stop?: { tooltipContent?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'> };
105100
send?: { tooltipContent?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'> };
106101
microphone?: {
@@ -376,7 +371,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
376371
onAttachRejected={onAttachRejected}
377372
validator={validator}
378373
dropzoneProps={dropzoneProps}
379-
{...buttonProps?.attach?.props}
374+
{...buttonProps?.attach}
380375
/>
381376
)}
382377
{!attachMenuProps && hasAttachButton && (
@@ -396,6 +391,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
396391
onAttachRejected={onAttachRejected}
397392
validator={validator}
398393
dropzoneProps={dropzoneProps}
394+
{...buttonProps?.attach}
399395
{...buttonProps?.attach?.props}
400396
/>
401397
)}

0 commit comments

Comments
 (0)