import dynamic from 'next/dynamic';
import 'react-quill/dist/quill.snow.css';
import * as Quill from 'quill';
import { ReactNode } from 'react';
const ReactQuill = dynamic(
import('react-quill'),
{ ssr: false }
);
export interface UnprivilegedEditor {
getLength(): number;
getText(index?: number, length?: number): string;
getHTML(): string;
getBounds(index: number, length?: number): Quill.BoundsStatic;
getSelection(focus?: boolean): Quill.RangeStatic;
getContents(index?: number, length?: number): Quill.DeltaStatic;
}
export interface ComponentProps {
id?: string;
className?: string;
style?: React.CSSProperties;
readOnly?: boolean;
value?: string | Quill.Delta;
defaultValue?: string | Quill.Delta;
placeholder?: string;
tabIndex?: number;
bounds?: string | HTMLElement;
scrollingContainer?: string | HTMLElement;
onChange?: (
content: string,
delta: Quill.Delta,
source: Quill.Sources,
editor: UnprivilegedEditor
) => void;
onChangeSelection?: (
range: Quill.RangeStatic,
source: Quill.Sources,
editor: UnprivilegedEditor
) => void;
onFocus?: (
range: Quill.RangeStatic,
source: Quill.Sources,
editor: UnprivilegedEditor
) => void;
onBlur?: (
previousRange: Quill.RangeStatic,
source: Quill.Sources,
editor: UnprivilegedEditor
) => void;
onKeyPress?: React.EventHandler<React.KeyboardEvent>;
onKeyDown?: React.EventHandler<React.KeyboardEvent>;
onKeyUp?: React.EventHandler<React.KeyboardEvent>;
formats?: string[];
children?: ReactNode;
preserveWhitespace?: boolean;
toolbar?: never;
styles?: never;
pollInterval?: never;
}
export default function RichEditor({ value, onChange, defaultValue }: ComponentProps) {
const toolbarOptions = [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] as string[] }, { 'background': [] as string[] }],
[{ 'font': [] as string[] }],
[{ 'align': [] as string[] }],
['clean'],
['image', 'code-block']
];
return <div className='cls001'>
<ReactQuill defaultValue={defaultValue} value={value} theme="snow" modules={{ toolbar: toolbarOptions }} onChange={onChange}></ReactQuill>
<style jsx>{`
.cls001{
margin: 50px;
}
`}</style>
</div>;
}