Skip to content

Commit

Permalink
fix: remove unused dependency and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Feb 21, 2024
1 parent 59165fa commit 7e364f3
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @jest-environment jsdom
*/
import { render } from "@testing-library/react";
import { RichTextLexicalRenderer } from "~/index";
import React from "react";
import {
defaultHeadingValue,
Expand All @@ -13,7 +12,8 @@ import {
notCorrectValue
} from "./lexical-content";
import { emptyEditorContent, LexicalCmsInputRender } from "./lexical-render";
import theme from "theme/theme";
import theme from "./theme";
import { RichTextLexicalRenderer } from "~/index";

describe("Test Rich Lexical Renderer", () => {
it("Paragraph string value type is rendered", async () => {
Expand Down Expand Up @@ -68,6 +68,7 @@ describe("Test Rich Lexical Renderer", () => {
expect(container.innerHTML.includes("editor")).toBeTruthy();
// emotion produced css classes are here
expect(container.innerHTML.includes("css-")).toBeTruthy();
expect(container.innerHTML.includes("-lx")).toBeTruthy();
// `css-99wy28` is a class generated for `paragraph1` styles defined in the `theme`.
expect(container.innerHTML.includes("css-99wy28")).toBeTruthy();
});
});
178 changes: 178 additions & 0 deletions packages/react-rich-text-lexical-renderer/__tests__/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import { createTheme } from "@webiny/app-theme";
import { CSSObject } from "@emotion/react";

// Breakpoints (desktop, tablet, mobile).
export const breakpoints = {
desktop: "@media (max-width: 4000px)",
tablet: "@media (max-width: 991px)",
"mobile-landscape": "@media (max-width: 767px)",
"mobile-portrait": "@media (max-width: 478px)"
};

// Colors.
export const colors = {
color1: "#fa5723", // Primary.
color2: "#00ccb0", // Secondary.
color3: "#0a0a0a", // Text primary.
color4: "#616161", // Text secondary.
color5: "#eaecec", // Background.
color6: "#ffffff" // White background.
};

// Fonts.
export const fonts = {
font1: "'IBM Plex Sans', sans-serif;", // Primary.
font2: "'Lato', sans-serif;" // Secondary.
};

// Border radius.
export const borderRadius = 4;

// Typography.
const headings = {
fontFamily: fonts.font2,
color: colors.color3,
WebkitFontSmoothing: "antialiased",
lineHeight: "150%"
};

const paragraphs = {
fontFamily: fonts.font1,
color: colors.color3,
fontWeight: 400,
lineHeight: 1.35,
WebkitFontSmoothing: "antialiased"
};

// Buttons.
const buttons = (overrides: CSSObject) => ({
a: { textDecoration: "none" },
".button-body": {
borderRadius,
border: 0,
padding: "14px 20px",
fontFamily: fonts.font1,
textTransform: "uppercase",
display: "flex",
alignItems: "center",
fontSize: "14px",
fontWeight: 600,
justifyContent: "center",
textAlign: "center",
cursor: "pointer",
transition: "all .2s",
"&:hover": {
boxShadow: "0 7px 14px rgb(50 50 93 / 10%), 0 3px 6px rgb(0 0 0 / 8%)",
transform: "translateY(-1px)"
},
...overrides
}
});

export const typography = {
headings: [
{
id: "heading1",
name: "Heading 1",
tag: "h1",
styles: { ...headings, fontWeight: "bold", fontSize: 48 }
},
{
id: "heading2",
name: "Heading 2",
tag: "h2",
styles: { ...headings, fontSize: 36 }
},
{
id: "heading3",
name: "Heading 3",
tag: "h3",
styles: { ...headings, fontSize: 30 }
},
{
id: "heading4",
name: "Heading 4",
tag: "h4",
styles: { ...headings, fontSize: 24 }
},
{
id: "heading5",
name: "Heading 5",
tag: "h5",
styles: { ...headings, fontSize: 20 }
},
{
id: "heading6",
name: "Heading 6",
tag: "h6",
styles: { ...headings, fontSize: 18, lineHeight: "1.75rem" }
}
],
paragraphs: [
{
id: "paragraph1",
name: "Paragraph 1",
tag: "p",
styles: { ...paragraphs, fontSize: 22 }
},
{
id: "paragraph2",
name: "Paragraph 2",
tag: "p",
styles: {
...paragraphs,
fontSize: 12.5,
letterSpacing: "0.45px",
lineHeight: "19px"
}
}
],
quotes: [
{
id: "quote",
name: "Quote",
tag: "quoteblock",
styles: {
...paragraphs,
fontWeight: "bold",
fontSize: 22
}
}
],
lists: [{ id: "list", name: "List 1", tag: "ul", styles: { ...paragraphs, fontSize: 17 } }]
} as const; // https://github.com/emotion-js/emotion/issues/1373#issuecomment-498059774 ;

// Theme object.
const theme = createTheme({
breakpoints,
styles: {
colors,
typography,
elements: {
document: {
a: { color: colors.color1 },
b: { fontWeight: "bold" },
i: { fontStyle: "italic" }
},
button: {
default: buttons({ background: colors.color5, color: colors.color3 }),
primary: buttons({ background: colors.color1, color: colors.color6 }),
secondary: buttons({ background: colors.color2, color: colors.color6 }),
outlinePrimary: buttons({
border: `2px solid ${colors.color1}`,
color: colors.color1
}),
outlineSecondary: buttons({
border: `2px solid ${colors.color2}`,
color: colors.color2
}),
simple: buttons({
color: colors.color1,
"&:hover": { transform: "translateY(-1px)" }
})
}
}
}
});

export default theme;
5 changes: 3 additions & 2 deletions packages/react-rich-text-lexical-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"react": "17.0.2"
},
"devDependencies": {
"@emotion/react": "^11.10.6",
"@testing-library/react": "^12.1.5",
"@webiny/app-theme": "0.0.0",
"@webiny/cli": "0.0.0",
"@webiny/project-utils": "0.0.0",
"@webiny/react-composition": "0.0.0",
"identity-obj-proxy": "^3.0.0",
"prettier": "^2.8.3",
"theme": "0.0.0"
"prettier": "^2.8.3"
},
"publishConfig": {
"access": "public",
Expand Down

0 comments on commit 7e364f3

Please sign in to comment.