@progress/kendo-react-conversational-ui
Version:
React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components
825 lines (776 loc) • 24 kB
TypeScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import { BaseEvent } from '@progress/kendo-react-common';
import { ButtonProps } from '@progress/kendo-react-buttons';
import { CustomComponent } from '@progress/kendo-react-common';
import { default as default_2 } from 'prop-types';
import { default as default_3 } from 'react';
import { JSX as JSX_2 } from 'react/jsx-runtime';
import * as React_2 from 'react';
import { SVGIcon } from '@progress/kendo-svg-icons';
import { SVGIcon as SVGIcon_2 } from '@progress/kendo-react-common';
import { TextAreaProps } from '@progress/kendo-react-inputs';
/**
* Defines a quick action for a message.
* The value is interpreted according to the specified action type.
*/
export declare interface Action {
/**
* A predefined or custom (string) type for the action.
*/
type: ActionType;
/**
* The value which is associated with the action.
*/
value: any;
/**
* An optional title for the quick action.
* If omitted, the Chat displays the value instead.
*/
title?: string;
}
/**
* The button type of the quick action
* ([see examples]({% slug suggested_actions_chat %})).
*
* * `openUrl`—Opens a new browser window with the specified URL.
* * `reply`—Sends the action value as a reply in the Chat.
* * `call`—Treats a value as a phone number.
* Similar to clicking a [telephone link](https://css-tricks.com/the-current-state-of-telephone-links/).
* * other—
* Handled by user code in the [`ExecuteActionEvent`]({% slug api_conversational-ui_chatactionexecuteevent %}).
*/
export declare type ActionType = 'openUrl' | 'reply' | 'call' | any;
/**
* Represents the KendoReact AIPrompt component.
*/
export declare const AIPrompt: (props: AIPromptProps) => JSX_2.Element;
/**
* The fields of the AIPromptOutputView card prop.
*/
declare interface AIPromptCardInterface {
/**
* Custom template for AIPromptCard header.
*/
header?: (props: AIPromptOutputInterface) => default_3.ReactNode;
/**
* Custom template for AIPromptCard body.
*/
body?: (props: AIPromptOutputInterface) => default_3.ReactNode;
/**
* Custom template for AIPromptCard actions.
*/
actions?: (props: AIPromptOutputInterface) => default_3.ReactNode;
}
/**
* The props of the AIPromptCommandsView component.
*/
export declare const AIPromptCommandsView: (props: AIPromptCommandsViewProps) => JSX_2.Element;
/**
* The props of the AIPromptCommandsView component.
*/
declare interface AIPromptCommandsViewProps {
/**
* The collection of commands that will be rendered in the Command view.
*/
commands?: CommandInterface[];
/**
* Fires each time the user clicks over a Command view command. Exposes the selected command as event data.
*/
onCommandExecute?: (command: CommandItemInterface) => void;
}
/**
* Represents the KendoReact AIPromptContent component.
*/
export declare const AIPromptContent: default_3.ForwardRefExoticComponent<AIPromptContentProps & default_3.RefAttributes<HTMLDivElement>>;
/**
* The props of the AIPromptContent component.
*/
declare interface AIPromptContentProps {
/**
* Specifies the AIPromptContent children elements.
*/
children?: default_3.ReactNode;
}
/**
* Represents the KendoReact AIPromptFooter component.
*/
export declare const AIPromptFooter: (props: AIPromptFooterProps) => JSX_2.Element;
/**
* The props of the AIPromptFooter component.
*/
declare interface AIPromptFooterProps {
/**
* Specifies the AIPromptFooter children elements.
*/
children?: default_3.ReactNode;
}
/**
* @hidden
*/
declare interface AIPromptHeaderProps {
activeView: string;
toolbarItems: (AIPromptToolbarItemInterface | default_3.ReactNode)[];
activeViewChange?: (viewName: string) => void;
}
export declare interface AIPromptOutputInterface {
/**
* The unique identifier of the command.
*/
id: string | number;
/**
* An optional custom title for the prompt output.
*/
title?: string;
/**
* An optional custom sub title for the prompt output.
*/
subTitle?: string;
/**
* The prompt that initiated the output generation.
*/
prompt?: string;
/**
* The text content of the prompt output.
*/
responseContent: string;
/**
* Specifies if the prompt generation was initiated via the retry button.
*/
isRetry?: boolean;
/**
* The prompt output rating.
*/
ratingType?: string;
/**
* Optionally specifies a command, if the prompt generation was triggered via a command.
*/
command?: CommandInterface;
}
/**
* Represents the KendoReact AIPromptOutputView component.
*/
export declare const AIPromptOutputView: (props: AIPromptOutputViewProps) => JSX_2.Element;
/**
* The props of the AIPromptOutputView component.
*/
declare interface AIPromptOutputViewProps {
/**
* The collection of generated prompt outputs that will be rendered in the Output view.
*/
outputs?: AIPromptOutputInterface[];
/**
* Represents a template that allows you to define custom Card fields for:
* header
* body
* actions
* The custom fields will override the default one.
*/
outputCard?: AIPromptCardInterface;
/**
* Specifies if the rating buttons in each card will be rendered.
* By default, rating buttons are not rendered.
*
* @default false
*/
showOutputRating?: boolean;
onRetry?: (value: any) => void;
/**
* Fires each time the user clicks Copy button in the card.
*/
onCopy?: () => void;
/**
* Fires each time the user clicks a rating button in the card.
*/
onOutputRating?: () => void;
}
/**
* The props of the AIPrompt component.
*/
export declare interface AIPromptProps extends default_3.HTMLAttributes<HTMLElement> {
/**
* The styles that are applied to the component.
*/
style?: default_3.CSSProperties;
/**
* Name of the active view.
*/
activeView: typeof promptViewDefaults.name | typeof outputViewDefaults.name | typeof commandsViewDefaults.name | string;
/**
* Collection with items that will override the default Toolbar items.
*/
toolbarItems?: (AIPromptToolbarItemInterface | default_3.ReactNode)[];
/**
* The collection of generated prompt outputs that will be rendered in the Output view.
*/
outputs?: AIPromptOutputInterface[];
/**
* Specifies the AIPrompt children elements.
*/
children?: default_3.ReactNode;
/**
* The placeholder text for the Prompt view textarea.
*/
promptPlaceholder?: string;
/**
* Represents the `dir` HTML attribute.
*/
dir?: string;
/**
* The onActiveViewChange event handler of the KendoReact AIPrompt component.
* Fires when active view is changed. Exposes the name of the new active view as event data.
*/
onActiveViewChange?: (name: string) => void;
/**
* The onCommandExecute event handler of the KendoReact AIPrompt component.
* Fires each time the user clicks a command in the Command view. Exposes the selected command as event data.
*/
onCommandExecute?: (command: CommandInterface) => void;
/**
* The onPromptRequest event handler of the KendoReact AIPrompt component.
* Fires when user clicks the `Generate` button in the Prompt view.
*/
onPromptRequest?: (prompt?: string, outputItem?: AIPromptOutputInterface) => void;
}
/**
* An interface for the AIPromptToolbarItem.
*/
export declare interface AIPromptToolbarItemInterface {
/**
* Defines the name of the view witch is related to.
*/
name: string;
/**
* Defines the svgIcon used in the Toolbar button.
*/
buttonIcon?: SVGIcon;
/**
* Defines the text used in the Toolbar button.
*/
buttonText?: string;
}
/**
* The props of the AIPromptCommandsView component.
*/
export declare const AIPromptView: (props: AIPromptViewProps) => JSX_2.Element;
/**
* The properties of the AIPromptView component.
*/
export declare interface AIPromptViewProps {
/**
* Accepts a custom component that can be used to render the prompt input. See example [here]({% slug customization_aiprompt %}).
*/
promptInput?: CustomComponent<TextAreaProps>;
/**
* Accepts a custom component that can be used to render the generate button. See example [here]({% slug customization_aiprompt %}).
*/
generateButton?: CustomComponent<ButtonProps>;
/**
* The value of the prompt input.
*/
promptValue?: string;
/**
* The suggestions that will be displayed in the prompt view. See example [here]({% slug suggestions_aiprompt %}).
*/
promptSuggestions?: string[];
}
/**
* Represents the KendoReact AIPromptViewRender component.
*/
export declare const AIPromptViewRender: (props: AIPromptViewRenderProps) => default_3.ReactNode;
/**
* The props of the AIPromptViewRender component.
*/
declare interface AIPromptViewRenderProps {
/**
* Specifies the name of the view.
*/
name: string;
/**
* Specifies the AIPromptViewRender children elements.
*/
children: default_3.ReactNode;
}
/**
* Represents a message attachment
* ([see examples]({% slug attachments_chat %})).
*
*/
export declare interface Attachment {
/**
* The content type identifier for the attachment.
* Typically a MIME type. Can also be any string.
*/
contentType: string;
/**
* The content of the attachment.
*/
content: any;
/**
* (Optional) The title of the attachment.
*/
title?: string;
/**
* (Optional) The subtitle of the attachment.
*/
subtitle?: string;
}
/**
* Specifies the layout for the message attachments.
*
* The supported values are:
* * `"list"`—A vertical list.
* * `"carousel"`—A horizontal, scrollable list. Also called a card deck.
*/
export declare type AttachmentLayout = 'list' | 'carousel';
/**
* Represents the [KendoReact Chat component]({% slug overview_convui %}).
*/
export declare class Chat extends React_2.Component<ChatProps, ChatState> {
/**
* @hidden
*/
static propTypes: {
messages: default_2.Requireable<(object | null | undefined)[]>;
user: default_2.Requireable<object>;
messageTemplate: default_2.Requireable<any>;
attachmentTemplate: default_2.Requireable<any>;
width: default_2.Requireable<NonNullable<string | number | null | undefined>>;
onMessageSend: default_2.Requireable<(...args: any[]) => any>;
onActionExecute: default_2.Requireable<(...args: any[]) => any>;
dir: default_2.Requireable<string>;
messageBox: default_2.Requireable<any>;
};
/**
* @hidden
*/
static defaultProps: {
messages: never[];
dateFormat: string;
message: typeof ChatMessage;
};
/**
* @hidden
*/
readonly state: ChatState;
private chatWrapperEl;
private viewItemsWrapperEl;
private newMsgComp;
private timeoutIdForChatLosingFocus;
private nextTickId;
private viewItems;
private isDirectionRightToLeft;
private scrollToBottomOnLoadingData;
private readonly showLicenseWatermark;
constructor(props: ChatProps);
/**
* @hidden
*/
render(): JSX_2.Element;
/**
* @hidden
*/
componentDidMount(): void;
/**
* @hidden
*/
componentWillUnmount(): void;
/**
* @hidden
*/
componentDidUpdate(prevProps: ChatProps): void;
private getClassNames;
private checkIsDirectionRightToLeft;
private onFocus;
private onBlur;
private onSelectionRequested;
private onKeyDown;
private renderViewItems;
private onMessageSend;
private onActionExecute;
private scrollViewItemsToBottom;
private getViewItemsFromMsgs;
}
/**
* The arguments for the `actionexecute` event of the Chat.
*/
export declare interface ChatActionExecuteEvent extends BaseEvent<Chat> {
/**
* The executed action.
*/
action: Action;
}
/**
* Represents the ChatMessage component.
*/
export declare class ChatMessage extends FocusableUponSelection<ChatMessageProps, {}> {
/**
* @hidden
*/
static defaultProps: {
dateFormat: string;
tabIndex: number;
};
/**
* @hidden
*/
render(): JSX_2.Element;
private getMainView;
private getTimestampView;
private getStatusView;
private getClassNames;
}
/**
* Represents a Chat message box.
*/
export declare interface ChatMessageBoxProps {
/**
* Sets the input message of the Chat component.
*/
messageInput: JSX.Element;
/**
* Sets the toolbar button of the Chat component.
*/
toolbarButton: JSX.Element;
/**
* Sets the send button of the Chat component.
*/
sendButton: JSX.Element;
}
/**
* Represents the properties of [ChatMessage] (% slug api_conversational-ui_chatmessage %) component.
*/
export declare interface ChatMessageProps extends FocusableUponSelectionProps {
/**
* Represents the data item of the `Message`.
*/
item: MessageModel;
/**
* Represents the React Component rendered inside the `Message`.
*/
template?: React_2.ComponentType<ChatMessageTemplateProps>;
/**
* @hidden
*/
onRequestSelection: any;
/**
* Represents the tab index attribute.
*/
tabIndex?: number;
/**
* @hidden
*/
isFirstItemInGroup: boolean;
/**
* @hidden
*/
isLastItemInGroup: boolean;
/**
* @hidden
*/
isOnlyItemInGroup: boolean;
/**
* Represents the date format of the message date.
*/
dateFormat?: string;
}
/**
* The arguments for the `messagesend` event of the Chat.
*/
export declare interface ChatMessageSendEvent extends BaseEvent<Chat> {
/**
* The new message.
*/
message: Message;
}
/**
* Represents the properties available to the `messageTemplate` custom component.
*
* For more information, refer to the [Message Template]({% slug message_templates_chat %}) article.
*/
export declare interface ChatMessageTemplateProps {
item: MessageModel;
}
export declare interface ChatProps {
/**
* Sets a class of the Chat DOM element.
*/
className?: string;
/**
* Sets the messages of the Chat.
*/
messages: Message[];
/**
* Sets the [`User`]({% slug api_conversational-ui %}) instance for the local user. The User ID identifies messages that are authored by the local user.
*/
user: User;
/**
* A React functional or class component which is used as a message template. The corresponding [`message`]({% slug api_conversational-ui_message %}) is passed to the component as a property by the name `item`.
*/
messageTemplate?: React.ComponentType<ChatMessageTemplateProps>;
/**
* A React functional or class component which is used as an attachment template ([see example]({% slug attachments_chat %}#toc-attachment-templates)). The corresponding [`attachment`]({% slug api_conversational-ui_attachment %}) is passed to the component as a property by the name `item`.
*/
attachmentTemplate?: any;
/**
* Sets the width of the Chat.
*/
width?: string | number;
/**
* Determines if the toolbar will be rendered.
*/
showToolbar?: any;
/**
* Renders a toolbar inside the Chat.
*/
toolbar?: any;
/**
* Fires when the user types a message and clicks the **Send** button or presses **Enter**. Emits the [`MessageSendEvent`]({% slug api_conversational-ui_chatmessagesendevent %}).
*
* > The Chat is not automatically updated with the new message.
*/
onMessageSend?: (event: ChatMessageSendEvent) => void;
/**
* Fires when the user clicks a quick action button. The Chat internally handles the `reply`, `openUrl`, and `call` [known actions]({% slug api_conversational-ui_actiontype %}). Emits the [`ExecuteActionEvent`]({% slug api_conversational-ui_chatactionexecuteevent %}). The event is preventable. If `preventDefault` is called, the built-in action will be suppressed.
*/
onActionExecute?: (event: ChatActionExecuteEvent) => void;
/**
* Fires when the user clicks the button to show or hide the toolbar.
*/
onToolbarActionExecute?: (event: ChatToolbarActionExecuteEvent) => void;
/**
* Sets the direction of the Chat component.
*/
dir?: string;
/**
* The text which is visible inside the new message input when the message input is empty.
*/
placeholder?: string;
/**
* Enables the customization or the override of the default message box item in the Conversational UI
* ([see example]({% slug custom-rendering_chat %})).
*/
messageBox?: React.ComponentType<ChatMessageBoxProps>;
/**
* Represents the ChatMessage component.
*/
message?: React.ComponentType<ChatMessageProps>;
}
/**
* @hidden
*/
export declare interface ChatState {
selectedItemIndex: number | null;
isFirstRender: boolean;
}
/**
* The arguments for the `toolbaractionexecute` event of the Chat.
*/
export declare interface ChatToolbarActionExecuteEvent extends BaseEvent<Chat> {
/**
* The new toolbarShow value.
*/
show: boolean;
}
/**
* An interface for the command in the Command view.
*/
export declare interface CommandInterface extends CommandItemInterface {
/**
* Collection with nested commands.
*/
children?: CommandItemInterface[];
}
/**
* An interface for the command item.
*/
export declare interface CommandItemInterface {
/**
* The unique identifier of the command.
*/
id: string;
/**
* Specifies the command text.
*/
text: string;
/**
* Specifies the name of the SVG icon that will be rendered for the command.
*/
svgIcon?: SVGIcon_2;
}
/**
* Specifies the default values for Commands view Toolbar.
*/
export declare const commandsViewDefaults: AIPromptToolbarItemInterface;
/**
* @hidden
*/
declare abstract class FocusableUponSelection<P extends FocusableUponSelectionProps, S = {}> extends React_2.Component<P, S> {
protected elementToFocus: any;
/**
* @hidden
*/
componentDidUpdate(prevProps: any): void;
}
/**
* @hidden
*/
declare interface FocusableUponSelectionProps {
/**
* Sets the `selected` state of the component.
*/
selected: boolean;
}
/**
* Represents a Hero Card component. Hero cards host a single large image and action buttons with text content.
*/
export declare class HeroCard extends React_2.Component<HeroCardProps, {}> {
/**
* @hidden
*/
render(): JSX_2.Element;
private onBtnClick;
private getActionsView;
private getTitleView;
private getSubtitleView;
}
/**
* The arguments for the `actionexecute` event of the hero card.
*/
export declare interface HeroCardActionExecuteEvent extends BaseEvent<HeroCard> {
/**
* The executed action.
*/
action: Action;
}
export declare interface HeroCardProps {
/**
* The URL of the hero card image.
*/
imageUrl: string;
/**
* The title of the hero card.
*/
title: string;
/**
* The subtitle of the hero card.
*/
subtitle: string;
/**
* An array with the possible quick actions for this hero card.
*/
actions: Action[];
/**
* Fires when the user clicks a button.
*/
onActionExecute?: (event: HeroCardActionExecuteEvent) => void;
/**
* Max width of the card image.
*/
imageMaxWidth?: string | number;
}
/**
* Represents a Chat message.
*
* > * You are required to provide the `author` field.
* > * [Local users]({% slug api_conversational-ui_chatprops %}#toc-user) are displayed to the
* right in left-to-right languages and to the left in right-to-left languages.
* > * If `typing` is set to `true`, the Chat displays a typing indicator instead of text.
*/
export declare interface Message {
/**
* The author of the message.
*/
author: User;
/**
* The layout that will be used for displaying message attachments, if any
* ([see example]({% slug attachments_chat %}#toc-display-modes)).
*/
attachmentLayout?: AttachmentLayout;
/**
* (Optional) The message attachments
* ([see example]({% slug attachments_chat %})).
*/
attachments?: Attachment[];
/**
* The suggested quick actions that will be displayed below this message
* ([see example]({% slug suggested_actions_chat %}#toc-defining-quick-actions)).
*
* > Suggested actions are displayed only for the last message in the conversation.
*/
suggestedActions?: Action[];
/**
* An optional status string for the message.
* The status is displayed when the message is selected—either
* by clicking on it or by using the keyboard navigation shortcuts.
*/
status?: string;
/**
* (Optional) The text for the message.
* For example, certain messages can contain
* only attachments or quick actions.
*/
text?: string;
/**
* The time at which the message was composed.
*
*/
timestamp?: Date;
/**
* A Boolean value which indicates if the message is still being typed by the user.
* If set to `true`, the Chat displays a typing indicator instead of the actual message.
*/
typing?: boolean;
}
/**
* Represents the data item of a single `Message`.
*/
export declare interface MessageModel extends Message, Selectable {
}
/**
* Specifies the default values for Output view Toolbar.
*/
export declare const outputViewDefaults: AIPromptToolbarItemInterface;
/**
* @hidden
*/
export declare const PromptHeader: (props: AIPromptHeaderProps) => JSX_2.Element;
/**
* Specifies the default values for Prompt view Toolbar.
*/
export declare const promptViewDefaults: AIPromptToolbarItemInterface;
/**
* @hidden
*/
declare interface Selectable {
selectionIndex: number;
}
/**
* Represents a participant in a Chat conversation.
*/
export declare interface User {
/**
* A unique ID for this user.
* Typically, the ID is a number.
* Can also be a string or an object.
*/
id: any;
/**
* (Optional) The displayed name for the user.
*/
name?: string;
/**
* (Optional) An avatar image for the user.
*/
avatarUrl?: string;
/**
* (Optional) An avatar image alt text for the user.
*/
avatarAltText?: string;
}
export { }