Skip to main content

Chat Components

Introduction

The CMND React SDK provides customizable UI components that allow you to tailor your conversation view's appearance to match your application's theme. This feature is particularly valuable when integrating with existing UI libraries or maintaining consistent design systems.

note

This guide contains information on how to customize input fields, send buttons, and other UI elements of the CMND chatbot in order to create a seamless integration with your application.

Available Components

The SDK supports customization of the following components:

InputField Component

The InputField component allows you to customize the appearance and behavior of the message input area.

Type Definition

TypeScript
interface InputFieldProps {
/** Current input value */
input: string;

/** Function to update input value */
setInput: (input: string) => void;

/** Boolean indicating if message can be sent */
canSendMessage: boolean;

/** Function to handle message sending */
handleSendClick: () => void;
}

Usage Example

TypeScript
// Usage example
import { InputFieldProps } from "@cmnd-ai/chatbot-react";

const CustomInputField = ({
input,
setInput,
canSendMessage,
handleSendClick,
}: InputFieldProps) => {
return (
<div className="custom-input-container">
<input
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Type your message..."
/>
</div>
);
};

Implementation

To use custom components, pass them as props when initializing the chat component:

TypeScript
import { ChatProvider, CmndChatBot } from "@cmnd-ai/chatbot-react";

function App() {
return (
<ChatProvider
baseUrl="<your-cmnd-api-base-url>"
chatbotId="<your-chatbot-id>"
organizationId="<your-organization-id>"
Components={{
InputField: CustomInputField,
SendButton: CustomSendButton,
}}
>
<CmndChatBot />
</ChatProvider>
);
}

Component States

Component States

Each component should handle the following states to provide a complete user experience:

StateDescription
DefaultNormal appearance of the component
HoverVisual feedback when user hovers over component
Active/FocusVisual feedback when component is active or focused
DisabledAppearance when interaction is not allowed
ErrorVisual feedback for error conditions
LoadingVisual indicator for async operations (if applicable)

Best Practices

  • Ensure custom components maintain ARIA attributes and keyboard navigation
  • Provide appropriate visual feedback for different states
  • Use sufficient color contrast for text and interactive elements
TypeScript Integration

The SDK provides full TypeScript support for all component props and interfaces. This ensures type safety and better developer experience when implementing custom components.

Implementation Examples

Below are examples of how to implement custom components using popular UI frameworks:

TypeScript
import {
ChatProvider,
CmndChatBot,
InputFieldProps,
SendButtonProps,
} from "@cmnd-ai/chatbot-react";
import { TextField, Button } from "@mui/material";

const MaterialInputField = ({
input,
setInput,
canSendMessage,
}: InputFieldProps) => (
<TextField
value={input}
onChange={(e) => setInput(e.target.value)}
variant="outlined"
fullWidth
disabled={!canSendMessage}
/>
);

const MaterialSendButton = ({
handleSendClick,
canSendMessage,
}: SendButtonProps) => (
<Button
onClick={handleSendClick}
disabled={!canSendMessage}
variant="contained"
color="primary"
>
Send
</Button>
);

function App() {
return (
<ChatProvider
baseUrl="<your-cmnd-api-base-url>"
chatbotId="<your-chatbot-id>"
organizationId="<your-organization-id>"
Components={{
InputField: MaterialInputField,
SendButton: MaterialSendButton,
}}
>
<CmndChatBot />
</ChatProvider>
);
}
tip

When implementing custom components, consider creating a theme file that defines consistent styles across all your components to maintain visual coherence throughout your application.