Skip to content

Commit

Permalink
fix: fix react quill for Nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafaRoosta74 committed Oct 26, 2022
1 parent 82855e8 commit ceaa98d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable jsx-a11y/control-has-associated-label */
import React from "react";
import { Quill } from "react-quill";
import RedoIcon from "@mui/icons-material/Redo";
import UndoIcon from "@mui/icons-material/Undo";
//
Expand Down Expand Up @@ -44,14 +43,6 @@ export function redoChange() {
this.quill.history.redo();
}

const Size = Quill.import("attributors/style/size");
Size.whitelist = FONT_SIZE;
Quill.register(Size, true);

const Font = Quill.import("attributors/style/font");
Font.whitelist = FONT_FAMILY;
Quill.register(Font, true);

export const formats = [
"align",
"background",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useMemo } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { FormikProps, FormikValues } from "formik";
import { OptionalObjectSchema } from "yup/lib/object";
import ReactQuill from "react-quill";
import { FormHelperText, Grid, InputLabel } from "@mui/material";
import {
checkIsRequired,
Expand Down Expand Up @@ -29,11 +28,14 @@ interface EditorViewProps<T> {
validationSchema: OptionalObjectSchema<any>;
translator: Function;
}

let ReactQuill = (...props: any) => <>a</>;

const EditorView = <T extends FormikValues>(props: EditorViewProps<T>) => {
const { allData, name, formik, loading, validationSchema, translator } =
props;
const { helperText, label, ...editorProps } = allData.editorProps;

const [load, setLoad] = useState(false);
const id = useMemo(() => `minimal-quill-${handleRandomClassNameOrId()}`, []);

const modules = useMemo(
Expand All @@ -59,7 +61,15 @@ const EditorView = <T extends FormikValues>(props: EditorViewProps<T>) => {
[id]
);

if (loading) {
useEffect(() => {
// eslint-disable-next-line global-require
ReactQuill = require("react-quill");
if (document) {
setLoad(true);
}
}, []);

if (loading && !load) {
return (
<Grid item {...allData.layoutProps}>
<TextViewSkeleton height={253} hasHelper={!!helperText} />
Expand Down Expand Up @@ -97,19 +107,13 @@ const EditorView = <T extends FormikValues>(props: EditorViewProps<T>) => {
className={`class-${id}`}
isSimple={allData.editorProps.isToolbarSimple}
/>
{/* @ts-ignore */}
<ReactQuill
className={`class-${id}`}
value={getData({ source: formik.values, key: name })}
// value={editorValue}
modules={modules}
formats={formats}
onChange={(
value: string,
_delta: any,
_source: any,
editor: ReactQuill.UnprivilegedEditor
) => {
onChange={(value: string, _delta: any, _source: any, editor: any) => {
formik.setFieldValue(
name,
editor.getLength() > 1 ? value : formik.initialValues[name]
Expand Down

0 comments on commit ceaa98d

Please sign in to comment.