mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
#34 added LocalCommentForm
This commit is contained in:
parent
d42a98957d
commit
8ae2dc02f0
6 changed files with 226 additions and 49 deletions
36
src/components/comment/LocalCommentFormTextarea/index.tsx
Normal file
36
src/components/comment/LocalCommentFormTextarea/index.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import React, { FC, KeyboardEventHandler, useCallback } from 'react';
|
||||
import { Textarea } from '~/components/input/Textarea';
|
||||
import { useCommentFormContext } from '~/utils/hooks/useCommentFormFormik';
|
||||
import { useRandomPhrase } from '~/constants/phrases';
|
||||
|
||||
interface IProps {
|
||||
isLoading?: boolean;
|
||||
setRef?: (r: HTMLTextAreaElement) => void;
|
||||
}
|
||||
|
||||
const LocalCommentFormTextarea: FC<IProps> = ({ isLoading, setRef }) => {
|
||||
const { values, handleChange, handleSubmit } = useCommentFormContext();
|
||||
|
||||
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(
|
||||
({ ctrlKey, key }) => {
|
||||
if (!!ctrlKey && key === 'Enter') handleSubmit(null);
|
||||
},
|
||||
[handleSubmit]
|
||||
);
|
||||
|
||||
const placeholder = useRandomPhrase('SIMPLE');
|
||||
|
||||
return (
|
||||
<Textarea
|
||||
value={values.text}
|
||||
handler={handleChange('text')}
|
||||
onKeyDown={onKeyDown}
|
||||
disabled={isLoading}
|
||||
placeholder={placeholder}
|
||||
minRows={2}
|
||||
setRef={setRef}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export { LocalCommentFormTextarea };
|
Loading…
Add table
Add a link
Reference in a new issue