All files / src/components/Inputs/InputTypes Wysiwyg.tsx

0% Statements 0/4
0% Branches 0/4
0% Functions 0/1
0% Lines 0/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                     
import MDEditor from "@uiw/react-md-editor";
import React from "react";
import rehypeSanitize from "rehype-sanitize";
 
type WsyisygInputTypes = {
  value: string;
  handleChange: any;
  label?: string;
  error?: string;
  disabled?: boolean;
};
 
function Wysiwyg({ value, handleChange, disabled, error }: WsyisygInputTypes) {
  return (
    <div data-color-mode="light">
      {disabled ? (
        <>
          <MDEditor.Markdown
            source={value}
            style={{
              whiteSpace: "pre-wrap",
              maxHeight: "400px",
              overflow: "scroll",
              border: "1px solid black",
              borderRadius: "5px",
              padding: "1rem",
              width: "100%",
            }}
          />
        </>
      ) : (
        <MDEditor
          value={value}
          onChange={handleChange}
          height={200}
          textareaProps={{
            placeholder: "Please enter Markdown text",
          }}
          className={`${error ? "border-red-500" : ""} w-full`}
          preview="live"
          previewOptions={{
            rehypePlugins: [[rehypeSanitize]],
          }}
        />
      )}
    </div>
  );
}
 
export default Wysiwyg;