unlayer / react-email-editor

Drag-n-Drop Email Editor Component for React.js
https://unlayer.com/embed
MIT License
4.51k stars 728 forks source link

Set contentWidth to 100% #404

Open KLeo13 opened 2 months ago

KLeo13 commented 2 months ago

Hello,

I'm trying to set the default contentWidth into 100%. According to here, you can set it using the .setBodyValues. It works initially however, when I go to the Body options, it reverts back to 500px (dafault).

I've also tried adding some eventListener on design:updated however, the issue still persist with the only changes is, it returns to 100% once I leave the Body options

Is there a way I can retain the 100% contentWidth even if I'm in Body options?

Here's my code, its in nextjs .tsx

"use client"
import React, { useRef } from 'react';
import EmailEditor, { EditorRef, EmailEditorProps } from 'react-email-editor';

const EmailEditorComponent = () => {
  const emailEditorRef = useRef<EditorRef>(null);

  const onReady: EmailEditorProps['onReady'] = (unlayer) => {
    unlayer.setAppearance({
        theme: 'modern_dark'
    });
    unlayer.setBodyValues({
      contentWidth: '100%'
    })
    unlayer.addEventListener('design:updated', () => {
      unlayer.setBodyValues({
        contentWidth: '100%'
      })
    })
  };

  return (
    <div className='h-full'>
      <EmailEditor ref={emailEditorRef} onReady={onReady} minHeight={'100%'}/>
    </div>
  );
};

export default EmailEditorComponent;

Here are some screenshots image image

Thank you :)

officialbatman commented 2 months ago

I understand you're looking to maintain a 100% content width in the Unlayer Email Editor, specifically when working within the Body options. Can you try to passing the set body values in the onReady event:

const onReady: EmailEditorProps['onReady'] = (unlayer) => {
        unlayer.setBodyValues({
      contentWidth: '100%'
    })
});
KLeo13 commented 2 months ago

Hi @officialbatman, I tried passing only the .setBodyValues on onReady event and I still get the issue

"use client"
import React, { useRef } from 'react';
import EmailEditor, { EditorRef, EmailEditorProps } from 'react-email-editor';

const EmailEditorComponent = () => {
  const emailEditorRef = useRef<EditorRef>(null);

  const onReady: EmailEditorProps['onReady'] = (unlayer) => {
    unlayer.setBodyValues({
      contentWidth: '100%'
    })
  };

  return (
    <div>
      <EmailEditor ref={emailEditorRef} onReady={onReady} minHeight={'100vh'}/>
    </div>
  );
};

export default EmailEditorComponent;

https://github.com/unlayer/react-email-editor/assets/117796702/53bbe3e3-e7e6-4f86-ab3b-e48873fb60f5

KLeo13 commented 2 months ago

I tried clicking the + button and it can only reach up to 900px' when i set thecontentWidth` to 900px. It doesn't revert to 500px even when i go to Body Options.

Was the maximum contentWidth only 900px? Is setting it to 100% not possible yet?

officialbatman commented 2 months ago

Try passing the width for the body value in px. For email mode, 900px is the maximum limit achievable by default. Also, try the correct reference for your function, such as:

Screenshot 2024-05-29 at 11 05 13 AM

Your callback should be:

this.EditorRef.current?.setBodyValues({

crezol2k commented 2 weeks ago

Can you try contentWidth: 'inherit'