Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/module/src/MessageBar/AttachButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,8 @@ describe('Attach button', () => {
expect(validator).toHaveBeenCalledWith(file);
expect(onAttachRejected).toHaveBeenCalled();
});
it('should handle icon prop', () => {
render(<AttachButton icon={<img alt="" src="" />} />);
expect(screen.getByRole('img')).toBeVisible();
});
});
5 changes: 4 additions & 1 deletion packages/module/src/MessageBar/AttachButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface AttachButtonProps extends ButtonProps {
validator?: <T extends File>(file: T) => FileError | readonly FileError[] | null;
/** Additional props passed to react-dropzone */
dropzoneProps?: DropzoneOptions;
/** Icon displayed in attach button */
icon?: React.ReactNode;
}

const AttachButtonBase: FunctionComponent<AttachButtonProps> = ({
Expand All @@ -72,6 +74,7 @@ const AttachButtonBase: FunctionComponent<AttachButtonProps> = ({
onAttachRejected,
validator,
dropzoneProps,
icon = <PaperclipIcon />,
...props
}: AttachButtonProps) => {
const { open, getInputProps } = useDropzone({
Expand Down Expand Up @@ -113,7 +116,7 @@ const AttachButtonBase: FunctionComponent<AttachButtonProps> = ({
onClick={onClick ?? open}
icon={
<Icon iconSize={isCompact ? 'lg' : 'xl'} isInline>
<PaperclipIcon />
{icon}
</Icon>
}
size={isCompact ? 'sm' : undefined}
Expand Down
14 changes: 14 additions & 0 deletions packages/module/src/MessageBar/MessageBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ describe('Message bar', () => {
);
await userEvent.click(screen.getByRole('button', { name: 'Test' }));
});
it('can change attach button icon', () => {
render(
<MessageBar
onSendMessage={jest.fn}
hasAttachButton
buttonProps={{
attach: {
icon: <img alt="" src="" />
}
}}
/>
);
expect(screen.getByRole('img')).toBeVisible();
});

// Stop button
// --------------------------------------------------------------------------
Expand Down
12 changes: 4 additions & 8 deletions packages/module/src/MessageBar/MessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
// Import Chatbot components
import SendButton from './SendButton';
import MicrophoneButton from './MicrophoneButton';
import { AttachButton } from './AttachButton';
import { AttachButton, AttachButtonProps } from './AttachButton';
import AttachMenu from '../AttachMenu';
import StopButton from './StopButton';
import { ChatbotDisplayMode } from '../Chatbot';
Expand Down Expand Up @@ -95,12 +95,7 @@ export interface MessageBarProps extends Omit<TextAreaProps, 'innerRef'> {
isSendButtonDisabled?: boolean;
/** Prop to allow passage of additional props to buttons */
buttonProps?: {
attach?: {
tooltipContent?: string;
props?: ButtonProps;
inputTestId?: string;
tooltipProps?: Omit<TooltipProps, 'content'>;
};
attach?: AttachButtonProps & { props?: ButtonProps };
stop?: { tooltipContent?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'> };
send?: { tooltipContent?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'> };
microphone?: {
Expand Down Expand Up @@ -376,7 +371,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
onAttachRejected={onAttachRejected}
validator={validator}
dropzoneProps={dropzoneProps}
{...buttonProps?.attach?.props}
{...buttonProps?.attach}
/>
)}
{!attachMenuProps && hasAttachButton && (
Expand All @@ -396,6 +391,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
onAttachRejected={onAttachRejected}
validator={validator}
dropzoneProps={dropzoneProps}
{...buttonProps?.attach}
{...buttonProps?.attach?.props}
/>
)}
Expand Down
Loading