From 04d693aa2fc540b9f90cc641a0b7e6cee5d54f9a Mon Sep 17 00:00:00 2001 From: Rebecca Alpert Date: Sun, 27 Oct 2024 10:42:51 -0400 Subject: [PATCH] chore(docs): Add additional options for buttons MessageBar buttons previously had non-user-configurable props. I added some props so users can pass in custom text for i18n and other Button props. --- .../module/src/MessageBar/AttachButton.tsx | 17 ++++--- packages/module/src/MessageBar/MessageBar.tsx | 45 ++++++++++++++++--- .../src/MessageBar/MicrophoneButton.tsx | 9 ++-- packages/module/src/MessageBar/SendButton.tsx | 13 +++--- packages/module/src/MessageBar/StopButton.tsx | 4 +- 5 files changed, 65 insertions(+), 23 deletions(-) diff --git a/packages/module/src/MessageBar/AttachButton.tsx b/packages/module/src/MessageBar/AttachButton.tsx index 022c7b00..51d8f69b 100644 --- a/packages/module/src/MessageBar/AttachButton.tsx +++ b/packages/module/src/MessageBar/AttachButton.tsx @@ -9,18 +9,20 @@ import { useDropzone } from 'react-dropzone'; import { PaperclipIcon } from '@patternfly/react-icons/dist/esm/icons/paperclip-icon'; export interface AttachButtonProps extends ButtonProps { - /** OnClick Handler for the Attach Button */ - onClick?: ((event: MouseEvent | React.MouseEvent | KeyboardEvent) => void) | undefined; - /** Callback function for attach button when an attachment is made */ + /** Callback for when button is clicked */ + onClick?: (event: React.MouseEvent) => void; + /** Callback function for AttachButton when an attachment is made */ onAttachAccepted?: (data: File[], event: DropEvent) => void; - /** Class Name for the Attach button */ + /** Class name for AttachButton */ className?: string; - /** Props to control is the attach button should be disabled */ + /** Props to control if the AttachButton should be disabled */ isDisabled?: boolean; /** Props to control the PF Tooltip component */ tooltipProps?: TooltipProps; /** Ref applied to AttachButton and used in tooltip */ innerRef?: React.Ref; + /** English text "Attach" used in the tooltip */ + tooltipContent?: string; } const AttachButtonBase: React.FunctionComponent = ({ @@ -30,6 +32,7 @@ const AttachButtonBase: React.FunctionComponent = ({ className, tooltipProps, innerRef, + tooltipContent = 'Attach', ...props }: AttachButtonProps) => { const { open, getInputProps } = useDropzone({ @@ -43,7 +46,7 @@ const AttachButtonBase: React.FunctionComponent = ({ = ({ variant="plain" ref={innerRef} className={`pf-chatbot__button--attach ${className ?? ''}`} - aria-label={props['aria-label'] || 'Attach Button'} + aria-label={props['aria-label'] || 'Attach button'} isDisabled={isDisabled} onClick={onClick ?? open} icon={ diff --git a/packages/module/src/MessageBar/MessageBar.tsx b/packages/module/src/MessageBar/MessageBar.tsx index 88ab46bd..fe69852c 100644 --- a/packages/module/src/MessageBar/MessageBar.tsx +++ b/packages/module/src/MessageBar/MessageBar.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { DropEvent, TextAreaProps } from '@patternfly/react-core'; +import { ButtonProps, DropEvent, TextAreaProps } from '@patternfly/react-core'; import { AutoTextArea } from 'react-textarea-auto-witdth-height'; // Import Chatbot components @@ -44,13 +44,20 @@ export interface MessageBarProps extends TextAreaProps { /** Flag to enable the Stop button, used for streaming content */ hasStopButton?: boolean; /** Callback function for when stop button is clicked */ - handleStopButton?: () => void; + handleStopButton?: (event: React.MouseEvent) => void; /** Callback function for when attach button is used to upload a file */ handleAttach?: (data: File[], event: DropEvent) => void; /** Props to enable a menu that opens when the Attach button is clicked, instead of the attachment window */ attachMenuProps?: MessageBarWithAttachMenuProps; /** Flag to provide manual control over whether send button is disabled */ isSendButtonDisabled?: boolean; + /** Prop to allow passage of additional props to buttons */ + buttonProps?: { + attach: { tooltipContent?: string; props?: ButtonProps }; + stop: { tooltipContent?: string; props?: ButtonProps }; + send: { tooltipContent?: string; props?: ButtonProps }; + microphone: { tooltipContent?: { active: string; inactive: string }; props?: ButtonProps }; + }; } export const MessageBar: React.FunctionComponent = ({ @@ -64,6 +71,7 @@ export const MessageBar: React.FunctionComponent = ({ isSendButtonDisabled, handleStopButton, hasStopButton, + buttonProps, ...props }: MessageBarProps) => { // Text Input @@ -105,25 +113,50 @@ export const MessageBar: React.FunctionComponent = ({ const renderButtons = () => { if (hasStopButton && handleStopButton) { - return ; + return ( + + ); } return ( <> {attachMenuProps && ( - + )} {!attachMenuProps && hasAttachButton && ( - + )} {hasMicrophoneButton && ( )} {(alwayShowSendButton || message) && ( - + )} ); diff --git a/packages/module/src/MessageBar/MicrophoneButton.tsx b/packages/module/src/MessageBar/MicrophoneButton.tsx index 5d5a9d30..931e5f46 100644 --- a/packages/module/src/MessageBar/MicrophoneButton.tsx +++ b/packages/module/src/MessageBar/MicrophoneButton.tsx @@ -12,7 +12,7 @@ import { MicrophoneIcon } from '@patternfly/react-icons/dist/esm/icons/microphon export interface MicrophoneButtonProps extends ButtonProps { /** Boolean check if the browser is listening to speech or not */ isListening: boolean; - /** Class Name for the Microphone button */ + /** Class name for MicrophoneButton */ className?: string; /** Callback to update the value of isListening */ onIsListeningChange: React.Dispatch>; @@ -20,6 +20,8 @@ export interface MicrophoneButtonProps extends ButtonProps { onSpeechRecognition: React.Dispatch>; /** Props to control the PF Tooltip component */ tooltipProps?: TooltipProps; + /** English text "Use microphone" and "Stop listening" used in the tooltip */ + tooltipContent?: { active: string; inactive: string }; } export const MicrophoneButton: React.FunctionComponent = ({ @@ -28,6 +30,7 @@ export const MicrophoneButton: React.FunctionComponent = onSpeechRecognition, className, tooltipProps, + tooltipContent = { active: 'Stop listening', inactive: 'Use microphone' }, ...props }: MicrophoneButtonProps) => { // Microphone @@ -84,7 +87,7 @@ export const MicrophoneButton: React.FunctionComponent = aria="none" aria-live="polite" id="pf-chatbot__tooltip--use-microphone" - content={isListening ? 'Stop listening' : 'Use microphone'} + content={isListening ? tooltipContent.active : tooltipContent.inactive} position={tooltipProps?.position || 'top'} entryDelay={tooltipProps?.entryDelay || 0} exitDelay={tooltipProps?.exitDelay || 0} @@ -95,7 +98,7 @@ export const MicrophoneButton: React.FunctionComponent =