This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
website/components/Application/Messages/Message/EditMessage/EditMessage.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

import useTranslation from "next-translate/useTranslation"
import TextareaAutosize from "react-textarea-autosize"
2022-08-31 21:44:33 +02:00
import type { MessageProps } from "../Message"
2022-08-31 21:44:33 +02:00
export interface EditMessageProps extends MessageProps {
handleEdit: () => Promise<void>
handleKeyDown: React.KeyboardEventHandler<HTMLFormElement>
textareaRef: React.RefObject<HTMLTextAreaElement>
}
export const EditMessage: React.FC<
React.PropsWithChildren<EditMessageProps>
> = ({ handleEdit, handleKeyDown, textareaRef, message }) => {
const { t } = useTranslation()
const handleEditSubmit: React.FormEventHandler<HTMLFormElement> = async (
event,
2022-08-31 21:44:33 +02:00
) => {
event.preventDefault()
await handleEdit()
}
return (
<form
className="flex h-full w-full items-center"
2022-08-31 21:44:33 +02:00
onSubmit={handleEditSubmit}
onKeyDown={handleKeyDown}
>
<TextareaAutosize
className="scrollbar-firefox-support w-full resize-none bg-transparent p-2 tracking-wide outline-none"
placeholder={t("application:write-a-message")}
wrap="soft"
2022-08-31 21:44:33 +02:00
maxRows={6}
name="message"
2022-08-31 21:44:33 +02:00
defaultValue={message.value}
ref={textareaRef}
autoFocus
onFocus={(event) => {
event.currentTarget.setSelectionRange(
event.currentTarget.value.length,
event.currentTarget.value.length,
2022-08-31 21:44:33 +02:00
)
}}
/>
</form>
)
}