-
Notifications
You must be signed in to change notification settings - Fork 355
/
ReplyCommentForm.tsx
84 lines (78 loc) · 2.49 KB
/
ReplyCommentForm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { CoralRTE } from "@coralproject/rte";
import { Localized } from "@fluent/react/compat";
import { FormApi, FormState } from "final-form";
import React, {
EventHandler,
FunctionComponent,
MouseEvent,
Ref,
useCallback,
} from "react";
import { useViewerEvent } from "coral-framework/lib/events";
import { OnSubmit } from "coral-framework/lib/form";
import { ReplyCommentFocusEvent } from "coral-stream/events";
import { AriaInfo } from "coral-ui/components/v2";
import { PropTypesOf } from "coral-ui/types";
import RTEContainer from "../../RTE";
import CommentForm from "../../Stream/CommentForm";
import ReplyTo from "./ReplyTo";
export interface ReplyCommentFormProps {
id: string;
className?: string;
onSubmit: OnSubmit<any>;
onCancel?: EventHandler<MouseEvent<any>>;
onChange?: (state: FormState<any>, form: FormApi) => void;
initialValues?: any;
rteRef?: Ref<CoralRTE>;
parentUsername: string | null;
min: number | null;
max: number | null;
disabled?: boolean;
siteID: string;
disabledMessage?: React.ReactNode;
rteConfig: PropTypesOf<typeof RTEContainer>["config"];
mediaConfig: PropTypesOf<typeof CommentForm>["mediaConfig"];
}
const ReplyCommentForm: FunctionComponent<ReplyCommentFormProps> = (props) => {
const inputID = `comments-replyCommentForm-rte-${props.id}`;
const emitFocusEvent = useViewerEvent(ReplyCommentFocusEvent);
const onFocus = useCallback(() => {
emitFocusEvent();
}, [emitFocusEvent]);
return (
<div>
<CommentForm
rteRef={props.rteRef}
siteID={props.siteID}
onSubmit={props.onSubmit}
initialValues={props.initialValues}
min={props.min}
max={props.max}
disabled={props.disabled}
classNameRoot="createReplyComment"
disabledMessage={props.disabledMessage}
onFocus={onFocus}
onCancel={props.onCancel}
mediaConfig={props.mediaConfig}
placeHolderId="comments-replyCommentForm-rte"
placeholder="Write a reply"
bodyInputID={inputID}
bodyLabel={
<>
<Localized id="comments-replyCommentForm-rteLabel">
<AriaInfo component="label" htmlFor={inputID}>
Write a reply
</AriaInfo>
</Localized>
{props.parentUsername && (
<ReplyTo username={props.parentUsername} />
)}
</>
}
rteConfig={props.rteConfig}
topBorder={false}
/>
</div>
);
};
export default ReplyCommentForm;