docuservix/widgets/chat: добавлен компонент чата
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user