docuservix/widgets/chat: добавлен компонент чата

This commit is contained in:
2026-06-17 19:47:26 +03:00
parent 480029439f
commit f72371e0bb
13 changed files with 444 additions and 1 deletions
+55
View File
@@ -0,0 +1,55 @@
import block from 'bem-css-modules';
import React, { ReactNode, useState } from 'react';
import { PaperPlaneIcon } from './icons';
import styles from './Input.module.css';
const b = block(styles, 'Input');
interface InputProps {
loading?: boolean;
onSend?: (text: string) => void;
}
export function Input({ loading, onSend }: InputProps): ReactNode {
const [input, setInput] = useState('');
const handleSend = () => {
const text = input.trim();
if (!text || loading) {
return;
}
setInput('');
onSend?.(text);
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSend();
}
};
return (
<div className={b()}>
<textarea
className={b('field')}
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={handleKeyDown}
placeholder="Type your message here..."
rows={1}
disabled={loading}
/>
<button
className={b('send')}
onClick={handleSend}
disabled={loading || !input.trim()}
>
<PaperPlaneIcon />
</button>
</div>
);
}