Skip to content

Commit

Permalink
Allow customizable ChatBox placeholder and send button text
Browse files Browse the repository at this point in the history
  • Loading branch information
edspencer committed Aug 28, 2024
1 parent 7efbbac commit 8b87064
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-berries-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inform-ai": minor
---

Allow customization of placeholder and send button text
4 changes: 3 additions & 1 deletion src/ui/ChatBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
export function ChatBox({
autoFocus = false,
placeholder = "Ask me anything...",
sendButtonText = "Send",
onSubmit,
}: {
autoFocus?: boolean;
placeholder?: string | null;
sendButtonText?: string;
onSubmit: (message: string) => Promise<boolean>;
}) {
return (
Expand Down Expand Up @@ -51,7 +53,7 @@ export function ChatBox({
/>
</div>
<button type="submit" className="chatbox-button">
Send
{sendButtonText}
</button>
</form>
);
Expand Down
13 changes: 11 additions & 2 deletions src/ui/ChatWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface ChatWrapperProps {
submitUserMessage: (messages: any[]) => Promise<any>;
messages?: any[];
setMessages: (value: any[] | ((prevState: any[]) => any[])) => void;
placeholder?: string;
sendButtonText?: string;
}

/**
Expand Down Expand Up @@ -80,7 +82,14 @@ export interface ChatWrapperProps {
* @param {function} props.setMessages - A function to update the messages in the chat history. Can be async.
* @return {JSX.Element} The JSX element representing the chat wrapper.
*/
export function ChatWrapper({ className, submitUserMessage, messages = [], setMessages }: ChatWrapperProps) {
export function ChatWrapper({
className,
submitUserMessage,
messages = [],
setMessages,
placeholder,
sendButtonText,
}: ChatWrapperProps) {
const { popRecentMessages } = useInformAIContext();

async function onMessage(message: string) {
Expand Down Expand Up @@ -109,7 +118,7 @@ export function ChatWrapper({ className, submitUserMessage, messages = [], setMe
return (
<div className={clsx("flex flex-col p-1", className)}>
<Messages messages={messages} />
<ChatBox onSubmit={onMessage} />
<ChatBox onSubmit={onMessage} placeholder={placeholder} sendButtonText={sendButtonText} />
</div>
);
}

0 comments on commit 8b87064

Please sign in to comment.