mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import React, { forwardRef, KeyboardEventHandler, TextareaHTMLAttributes, useCallback } from 'react';
|
|
|
|
import { Textarea } from '~/components/input/Textarea';
|
|
import { useRandomPhrase } from '~/constants/phrases';
|
|
import { useCommentFormContext } from '~/hooks/comments/useCommentFormFormik';
|
|
|
|
interface IProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
isLoading?: boolean;
|
|
}
|
|
|
|
const LocalCommentFormTextarea = forwardRef<HTMLTextAreaElement, IProps>(({ ...rest }, ref) => {
|
|
const { values, handleChange, handleSubmit, isSubmitting } = useCommentFormContext();
|
|
|
|
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(
|
|
({ ctrlKey, key, metaKey }) => {
|
|
if ((ctrlKey || metaKey) && key === 'Enter') handleSubmit(undefined);
|
|
},
|
|
[handleSubmit]
|
|
);
|
|
|
|
const placeholder = useRandomPhrase('SIMPLE');
|
|
|
|
return (
|
|
<Textarea
|
|
{...rest}
|
|
ref={ref}
|
|
value={values.text}
|
|
handler={handleChange('text')}
|
|
onKeyDown={onKeyDown}
|
|
disabled={isSubmitting}
|
|
placeholder={placeholder}
|
|
/>
|
|
);
|
|
});
|
|
|
|
export { LocalCommentFormTextarea };
|