Skip to content

Commit

Permalink
Merge pull request #85 from BitteProtocol/add-extra-input-btn
Browse files Browse the repository at this point in the history
feat: add extra input button for mobile
  • Loading branch information
sainthiago authored Feb 13, 2025
2 parents 0d129c4 + 31686dc commit a722207
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ interface BitteAiChatProps {
chatId?: string; // Custom chat ID
};
welcomeMessageComponent?: JSX.Element; // Custom Welcome Message to be displayed when the chat loads
mobileInputExtraButton?: JSX.Element // Custom Button to add in mobile next to 'Send'
}
```

Expand Down
2 changes: 2 additions & 0 deletions src/components/BitteAiChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const BitteAiChat = ({
agentId,
options,
welcomeMessageComponent,
mobileInputExtraButton,
}: BitteAiChatProps) => {
const [loadedData, setLoadedData] = useState({
agentIdLoaded: "",
Expand Down Expand Up @@ -59,6 +60,7 @@ export const BitteAiChat = ({
localAgent: options?.localAgent,
}}
welcomeMessageComponent={welcomeMessageComponent}
mobileInputExtraButton={mobileInputExtraButton}
/>
</AccountProvider>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/chat/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ChatContent = ({
options,
messages: initialMessages,
welcomeMessageComponent,
mobileInputExtraButton
}: BitteAiChatProps) => {
const chatId = useRef(options?.chatId || generateId()).current;
const [isAtBottom, setIsAtBottom] = useState(true);
Expand Down Expand Up @@ -285,6 +286,7 @@ export const ChatContent = ({
textColor={textColor!}
backgroundColor={generalBackground!}
agentName={options?.agentName}
mobileInputExtraButton={mobileInputExtraButton}
/>
</div>
</div>
Expand Down
31 changes: 19 additions & 12 deletions src/components/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface SmartActionsInputProps {
borderColor: string;
textColor: string;
backgroundColor: string;
mobileInputExtraButton?: JSX.Element;
}

export const SmartActionsInput = ({
Expand All @@ -26,6 +27,7 @@ export const SmartActionsInput = ({
borderColor,
textColor,
backgroundColor,
mobileInputExtraButton,
}: SmartActionsInputProps) => {
const agentNameRef = useRef<HTMLDivElement>(null);
const [paddingLeft, setPaddingLeft] = useState<number>(125);
Expand All @@ -47,11 +49,11 @@ export const SmartActionsInput = ({

return (
<form
className="bitte-relative bitte-mb-0 bitte-flex bitte-w-full bitte-items-center bitte-justify-center bitte-gap-4 max-lg:bitte-flex-wrap"
className='bitte-relative bitte-mb-0 bitte-flex bitte-w-full bitte-items-center bitte-justify-center bitte-gap-4 max-lg:bitte-flex-wrap'
style={{ color: textColor }}
onSubmit={handleSubmit}
>
<div className="bitte-w-full bitte-relative">
<div className='bitte-w-full bitte-relative'>
<AgentPill name={agentName || previousAgentName} ref={agentNameRef} />

<Textarea
Expand All @@ -61,7 +63,7 @@ export const SmartActionsInput = ({
background: backgroundColor,
borderColor: borderColor,
}}
className="bitte-h-[42px] bitte-w-full bitte-resize-none bitte-min-h-0 textarea-chat"
className='bitte-h-[42px] bitte-w-full bitte-resize-none bitte-min-h-0 textarea-chat'
onChange={handleChange}
onKeyDown={(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey) {
Expand All @@ -72,15 +74,20 @@ export const SmartActionsInput = ({
value={input}
/>
</div>
<Button
type='submit'
disabled={!input || isLoading}
className="bitte-h-[42px] bitte-w-full lg:bitte-w-[42px] bitte-p-0 disabled:bitte-opacity-20"
style={{ backgroundColor: buttonColor, color: textColor }}
>
<ArrowUp className="bitte-h-[16px] bitte-w-[16px] bitte-hidden lg:bitte-block" />
<span className="lg:bitte-hidden">Send</span>
</Button>
<div className='bitte-flex bitte-gap-2 bitte-w-full lg:bitte-contents'>
{mobileInputExtraButton ? (
<div className='bitte-w-full lg:bitte-hidden'>{mobileInputExtraButton}</div>
) : null}
<Button
type='submit'
disabled={!input || isLoading}
className='bitte-h-[42px] bitte-w-full lg:bitte-w-[42px] bitte-p-0 disabled:bitte-opacity-20'
style={{ backgroundColor: buttonColor, color: textColor }}
>
<ArrowUp className='bitte-h-[16px] bitte-w-[16px] bitte-hidden lg:bitte-block' />
<span className='lg:bitte-hidden'>Send</span>
</Button>
</div>
</form>
);
};
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export interface BitteAiChatProps {
};
};
welcomeMessageComponent?: JSX.Element;
mobileInputExtraButton?: JSX.Element;
}

/**
Expand Down

0 comments on commit a722207

Please sign in to comment.