import { hooks } from 'botframework-webchat'; import { type DirectLineCardAction } from 'botframework-webchat/internal.js'; import cx from 'classnames'; import React, { memo, useCallback, useMemo } from 'react'; import { useRefFrom } from 'use-ref-from'; import { useStyles } from '../../styles/index.js'; import testIds from '../../testIds.js'; import { FluentIcon } from '../icon'; import styles from './StarterPromptsCardAction.module.css'; const { useFocus, useRenderMarkdownAsHTML, useSendBoxValue, useUIState } = hooks; type Props = Readonly<{ className?: string | undefined; messageBackAction?: (DirectLineCardAction & { type: 'messageBack' }) | undefined; }>; const StarterPromptsCardAction = ({ className, messageBackAction }: Props) => { const [_, setSendBoxValue] = useSendBoxValue(); const [uiState] = useUIState(); const classNames = useStyles(styles); const focus = useFocus(); const inputTextRef = useRefFrom(messageBackAction?.displayText || messageBackAction?.text || ''); const renderMarkdownAsHTML = useRenderMarkdownAsHTML('message activity'); const subtitleHTML = useMemo<{ __html: string } | undefined>( () => (renderMarkdownAsHTML ? { __html: renderMarkdownAsHTML(messageBackAction?.text || '') } : undefined), [messageBackAction?.text, renderMarkdownAsHTML] ); const disabled = uiState === 'disabled'; const title = messageBackAction && 'title' in messageBackAction && messageBackAction.title; // Every starter prompt card action must have "title" field. const shouldShowBlueprint = uiState === 'blueprint' || !title; const handleClick = useCallback(() => { setSendBoxValue(inputTextRef.current); // Focus on the send box after the value is "pasted." focus('sendBox'); }, [focus, inputTextRef, setSendBoxValue]); return shouldShowBlueprint ? (
) : ( ); }; StarterPromptsCardAction.displayName = 'StarterPromptsCardAction'; export default memo(StarterPromptsCardAction);