chatvrm_for_desh / src /components /messageInput.tsx
ratalai's picture
Deploy ChatVRM with all binary files in Git LFS
af60542
Raw History Blame Contribute Delete
3.56 kB
import { IconButton } from "./iconButton";
import { useTranslation } from 'react-i18next';
import { useState, useEffect, useCallback } from "react";
type Props = {
userMessage: string;
isMicRecording: boolean;
isChatProcessing: boolean;
onChangeUserMessage: (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => void;
onClickSendButton: (event: React.MouseEvent<HTMLButtonElement>) => void;
onClickTestVoiceButton: (event: React.MouseEvent<HTMLButtonElement>) => void;
onClickMicButton: (event: React.MouseEvent<HTMLButtonElement>) => void;
onClickLangButton: (event: React.MouseEvent<HTMLButtonElement>) => void;
};
export const MessageInput = ({
userMessage,
isMicRecording,
isChatProcessing,
onChangeUserMessage,
onClickMicButton,
onClickSendButton,
onClickTestVoiceButton,
}: Props) => {
const { t } = useTranslation();
const handleKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter") {
onClickSendButton(event as unknown as React.MouseEvent<HTMLButtonElement>);
}
},[onClickSendButton]);
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Shift') {
const inputElement = document.querySelector('input');
if (inputElement) {
inputElement.focus();
}
}
};
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
}, []);
return (
<div className="absolute bottom-0 z-20 w-screen">
<div className="bg-base text-black">
<div className="mx-auto max-w-4xl p-16">
<div className="grid grid-flow-col gap-[8px] grid-cols-[min-content_1fr_min-content_min-content]">
<IconButton
iconName="24/Microphone"
className="bg-secondary hover:bg-secondary-hover active:bg-secondary-press disabled:bg-secondary-disabled"
isProcessing={isMicRecording}
disabled={isChatProcessing}
onClick={onClickMicButton}
/>
<input
type="text"
placeholder={t('EnterYourQuestion')}
onChange={onChangeUserMessage}
onKeyDown={handleKeyDown} // enter key
disabled={isChatProcessing}
className="bg-surface1 hover:bg-surface1-hover focus:bg-surface1 disabled:bg-surface1-disabled disabled:text-primary-disabled rounded-16 w-full px-16 text-text-primary typography-16 font-bold disabled"
value={userMessage}
></input>
<IconButton
iconName="24/Send"
className="bg-secondary hover:bg-secondary-hover active:bg-secondary-press disabled:bg-secondary-disabled"
isProcessing={isChatProcessing}
disabled={isChatProcessing || !userMessage}
onClick={onClickSendButton}
/>
<IconButton
iconName="24/Play"
className="bg-[#10a37f] hover:bg-[#0d8f6f] active:bg-[#0a7a5e] disabled:bg-surface1-disabled"
isProcessing={false}
disabled={isChatProcessing || !userMessage}
onClick={onClickTestVoiceButton}
title="測試語音 (不經過 LLM)"
/>
</div>
</div>
<div className="py-4 bg-[#413D43] text-center text-white font-Montserrat">
powered by VRoid, VITS API, Anthropic API
</div>
</div>
</div>
);
};