-
Notifications
You must be signed in to change notification settings - Fork 0
/
RteQuillExample.tsx
56 lines (51 loc) · 1.64 KB
/
RteQuillExample.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
import React, { useState } from "react";
import { useForm, Controller } from "react-hook-form";
import { RteQuill, RichTextEditorProps } from "../../lib/index"; // ensure this is the correct path to your component
export const Example: React.FC = () => {
const [value, setValue] = useState<string>("");
const { control, handleSubmit } = useForm({
defaultValues: {
rteEditor: "helllo world",
},
});
const onSubmit = (data: { rteEditor: string }) => {
console.log("Form Data: ", data);
setValue(data.rteEditor);
};
const dummyRteQuillProps: Omit<RichTextEditorProps, "value" | "onChange"> = {
name: "rteEditor",
label: "Rich Text Editor",
helperText: "Write something impactful!",
sizes: [
{ label: "Small", value: "12px" },
{ label: "Normal", value: "16px" },
{ label: "Large", value: "20px" },
],
customImageUploadAdapter: async (file: File) => {
// Simulate an image upload and return a URL
console.log("Uploading image", file);
return Promise.resolve("https://dummyimage.com/600x400/000/fff");
},
toolbarProps: {}, // Assuming there are additional props you might provide
errorText: "",
};
return (
<>
<p>Click on submit to see suggestion</p>
<form onSubmit={handleSubmit(onSubmit)}>
<Controller
name="rteEditor"
control={control}
render={({ field }) => (
<RteQuill {...dummyRteQuillProps} {...field} />
)}
/>
<input type="submit" value="Submit" />
</form>
<div>
<p>Selected Suggestion: {value}</p>
</div>
</>
);
};
export default Example;