Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for size prop in Editor and EditorContent components. #1250

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ export const COMBINED_REGEX = new RegExp(
]).join("|"),
"g"
);

export const EDITOR_SIZES = { MEDIUM: "medium", LARGE: "large" };
5 changes: 4 additions & 1 deletion src/components/Editor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { forwardRef, useImperativeHandle, useState, useRef, memo } from "react";
import { EditorView } from "@tiptap/pm/view";
import { useEditor, EditorContent, useEditorState } from "@tiptap/react";
import classnames from "classnames";
import { EDITOR_OPTIONS } from "common/constants";
import { EDITOR_OPTIONS, EDITOR_SIZES } from "common/constants";
import { noop, slugify } from "neetocist";
import { useFuncDebounce } from "neetocommons/react-utils";
import { Label } from "neetoui";
Expand Down Expand Up @@ -69,6 +69,7 @@ const Editor = (
openLinkInNewTab = true,
collaborationProvider = null,
enableReactNodeViewOptimization = false,
size = EDITOR_SIZES.MEDIUM,
...otherProps
},
ref
Expand Down Expand Up @@ -130,6 +131,8 @@ const Editor = (
"bubble-menu-active": isBubbleMenuActive,
"placeholder-active": isPlaceholderActive,
"attachments-active": isAttachmentsActive,
"neeto-editor--size-large": size === EDITOR_SIZES.LARGE,
"neeto-editor--size-medium": size === EDITOR_SIZES.MEDIUM,
[contentClassName]: contentClassName,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/EditorContent/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { lowlight } from "lowlight";

export const EDITOR_CONTENT_CLASSNAME = "neeto-editor-content";
export const EDITOR_CONTENT_CLASS_NAME = "neeto-editor-content";

export const SANITIZE_OPTIONS = {
ADD_TAGS: ["iframe"],
Expand Down
11 changes: 7 additions & 4 deletions src/components/EditorContent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import CopyToClipboardButton from "neetomolecules/CopyToClipboardButton";
import { isNil } from "ramda";
import { createRoot } from "react-dom/client";

import { EDITOR_SIZES } from "src/common/constants";
import "src/styles/editor/editor-content.scss";

import { EDITOR_CONTENT_CLASSNAME, SANITIZE_OPTIONS } from "./constants";
import { EDITOR_CONTENT_CLASS_NAME, SANITIZE_OPTIONS } from "./constants";
import ImagePreview from "./ImagePreview";
import {
highlightCode,
Expand All @@ -20,6 +21,7 @@ const EditorContent = ({
content = "",
variables = [],
className,
size = EDITOR_SIZES.MEDIUM,
...otherProps
}) => {
const [imagePreviewDetails, setImagePreviewDetails] = useState(null);
Expand All @@ -30,7 +32,7 @@ const EditorContent = ({

const injectCopyButtonToCodeBlocks = () => {
const preTags = editorContentRef.current?.querySelectorAll(
`.${EDITOR_CONTENT_CLASSNAME} pre`
`.${EDITOR_CONTENT_CLASS_NAME} pre`
);

preTags.forEach(preTag => {
Expand All @@ -50,7 +52,7 @@ const EditorContent = ({

const bindImageClickListener = () => {
const figureTags = editorContentRef.current?.querySelectorAll(
`.${EDITOR_CONTENT_CLASSNAME} figure`
`.${EDITOR_CONTENT_CLASS_NAME} figure`
);

figureTags.forEach(figureTag => {
Expand All @@ -77,8 +79,9 @@ const EditorContent = ({
<div
data-cy="neeto-editor-content"
ref={editorContentRef}
className={classnames(EDITOR_CONTENT_CLASSNAME, {
className={classnames(EDITOR_CONTENT_CLASS_NAME, {
[className]: className,
[`${EDITOR_CONTENT_CLASS_NAME}--size-${size}`]: true,
})}
dangerouslySetInnerHTML={{
__html: sanitize(htmlContent, SANITIZE_OPTIONS),
Expand Down
2 changes: 2 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ interface EditorProps {
openImageInNewTab?: boolean;
openLinkInNewTab?: boolean;
enableReactNodeViewOptimization?: boolean;
size?: "large" | "medium";
[otherProps: string]: any;
}

Expand Down Expand Up @@ -158,6 +159,7 @@ export function EditorContent(props: {
content?: string;
className?: string;
variables?: (VariableCategory | Variable)[];
size?: "large" | "medium";
[otherProps: string]: any;
}): JSX.Element;

Expand Down
Loading