| 1 |
import { DynamicTextarea } from '@help-center/components/ai-chat/DynamicTextarea'; |
| 2 |
import { send } from '@help-center/components/ai-chat/icons'; |
| 3 |
import { useRef, useState } from '@wordpress/element'; |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
import { Icon } from '@wordpress/icons'; |
| 6 |
|
| 7 |
export const Question = ({ onSubmit }) => { |
| 8 |
const [inputValue, setInputValue] = useState(''); |
| 9 |
const formRef = useRef(null); |
| 10 |
|
| 11 |
const handleInputChange = (e) => { |
| 12 |
setInputValue(e.target.value); |
| 13 |
}; |
| 14 |
|
| 15 |
const handleKeyDown = (e) => { |
| 16 |
if (e.key === 'Enter' && !e.shiftKey) { |
| 17 |
formRef?.current?.requestSubmit(); |
| 18 |
} |
| 19 |
}; |
| 20 |
|
| 21 |
return ( |
| 22 |
<form onSubmit={onSubmit} ref={formRef} className="rtl:w-full"> |
| 23 |
<p className="m-0 mb-1 text-lg font-medium opacity-80"> |
| 24 |
{__('Hi there!', 'extendify-local')} |
| 25 |
</p> |
| 26 |
<p className="m-0 mb-6 text-2xl font-medium"> |
| 27 |
{__('Ask me any questions about WordPress.', 'extendify-local')} |
| 28 |
</p> |
| 29 |
<div className="relative rounded-sm border border-gray-300 bg-white shadow"> |
| 30 |
<DynamicTextarea |
| 31 |
value={inputValue} |
| 32 |
className="rtl:pl-auto h-full w-full flex-1 resize-none py-4 pl-3 pr-10 placeholder-gray-600 rtl:py-2.5 rtl:pr-2" |
| 33 |
placeholder={__('Ask your WordPress question…', 'extendify-local')} |
| 34 |
onChange={handleInputChange} |
| 35 |
onKeyDown={handleKeyDown} |
| 36 |
/> |
| 37 |
<button |
| 38 |
type="submit" |
| 39 |
className="absolute bottom-3.5 right-2.5 flex h-6 items-center border-none bg-transparent fill-current text-gray-700 hover:text-gray-900 rtl:bottom-2 rtl:left-2.5 rtl:right-auto" |
| 40 |
disabled={!inputValue} |
| 41 |
> |
| 42 |
<Icon icon={send} className="h-4 w-4" /> |
| 43 |
</button> |
| 44 |
</div> |
| 45 |
</form> |
| 46 |
); |
| 47 |
}; |
| 48 |
|