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

Fonts aren't displayed #205

Open
amartya-dev opened this issue Jul 19, 2021 · 5 comments
Open

Fonts aren't displayed #205

amartya-dev opened this issue Jul 19, 2021 · 5 comments

Comments

@amartya-dev
Copy link

I am trying to embed the EmailEditor via React, everything seems to work fine except the fonts section, the dropdown which is supposed to contain the list of fonts, shows nothing and even the font size selection is a bit off:

the_editor_font_problem_1
the_editor_font_problem_2

Is it a bug with the editor itself? or am I doing something wrong:

Code:

import {
  Button,
  Box,
  Container,
  Grid,
  Hidden,
  Typography,
  AppBar,
} from "@material-ui/core";
import clsx from "clsx";
import React, { useRef } from "react";
import EmailEditor from "react-email-editor";
import { useSelector } from "react-redux";
import { useStyles } from "./emailBuilder.css";

import { selectOpen } from "../../redux/utils";
import { TemplatesNav } from "./TemplatesNav";
import Component from "react-email-editor";

export function EmailBuilder() {
  const emailEditorRef = useRef<Component>(null);

  const onLoad = () => {
    // you can load your template here;
    // const templateJson = {};
    // emailEditorRef.current.editor.loadDesign(templateJson);
  };

  const classes = useStyles();

  const drawerOpen = useSelector(selectOpen);

  const [templatesNavOpen, setTemplatesNavOpen] =
    React.useState<boolean>(false);
  const openTemplatesNav =
    () => (event: React.KeyboardEvent | React.MouseEvent) => {
      console.log(templatesNavOpen);
      setTemplatesNavOpen(true);
    };

  const exportHtml = async () => {
    emailEditorRef.current!.exportHtml(
      (data: { design: Object; html: String }) => {
        const { design, html } = data;
        console.log("exportHtml", html);
        console.log("Design JSON", design);
      }
    );
  };

  return (
    <Container maxWidth="xl">
      <Hidden mdDown>
        <AppBar
          position="fixed"
          className={clsx(classes.appBarStyle, {
            [classes.shiftedAppBarStyle]: drawerOpen,
          })}
          elevation={0}
        >
          <Box display="flex" m={1} p={1}>
            <Box p={1} flexGrow={1}>
              <Button
                onClick={openTemplatesNav()}
                color="primary"
                variant="contained"
              >
                Templates
              </Button>
            </Box>
            <Box p={1}>
              <Button color="primary" variant="contained">
                Preview
              </Button>
            </Box>
            <Box p={1}>
              <Button color="primary" variant="contained" onClick={exportHtml}>
                Save
              </Button>
            </Box>
          </Box>
        </AppBar>
        <TemplatesNav
          drawerOpen={templatesNavOpen}
          setDrawerOpen={setTemplatesNavOpen}
        />
        <Grid container className={classes.container}>
          <EmailEditor ref={emailEditorRef} onLoad={onLoad} />
        </Grid>
      </Hidden>
      <Hidden mdUp>
        <Typography variant="h5">
          Shoot !! We do not support designing on mobiles yet
        </Typography>
      </Hidden>
    </Container>
  );
}
@talovicnedim
Copy link

@amartya-dev
Did you figure out something? I have the same issue.

@amartya-dev
Copy link
Author

@talovicnedim nope,
I am thinking of moving away from this

@eMuonTau
Copy link

@amartya-dev @talovicnedim
Can you try to set projectId property of EmailEditor to some number? I don't know why but if projectId is not defined fonts are broken.

@lf-devs
Copy link

lf-devs commented Dec 2, 2021

@amartya-dev here is the solution for fonts

<EmailEditor
                            ref={emailEditorRef}
                            exportHtml={exportHtml}
                            options={{
                                appearance: {
                                    theme: "dark",
                                },
                                features: {
                                    textEditor: {
                                        fontSizes: ["70px", "60px", "50px"],
                                    },
                                },
                                fonts: {
                                    showDefaultFonts: false,
                                    customFonts: [
                                        {
                                            label: "Comic Sans",
                                            value: "'Comic Sans MS', cursive, sans-serif",
                                        },
                                        {
                                            label: "DotGothic16",
                                            value: "'DotGothic16',cursive",
                                            url: "https://fonts.googleapis.com/css?family=DotGothic16",
                                        },
                                    ],
                                },
                            }}
                            onLoad={onLoad}
                            onReady={onReady} />
                            ```

@fedotxxl
Copy link

same issuer on Ubuntu, fixed with showDefaultFonts: false, not sure is it correct solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants