tiptap icon indicating copy to clipboard operation
tiptap copied to clipboard

Responsive design YouTube Extension

Open joppehoekstra opened this issue 2 years ago • 2 comments

What problem are you facing?

The current YouTube extension provides users with the option to provide the size of the iframe. However, this is not a great experience on differently sized screens, because that causes the dimensions to change. Since the dimensions of YouTube videos stay the same, the dimensions of the iframe should stay the same too.

What’s the solution you would like to see?

For example, add a class to the div around the iframe, which can be styled to make the dimensions stay the same (and add an example to the documentation). This leaves it up to the developer what solution fits best in their application.

<div class="responsive-video">
  <iframe width="100%" height="100%" src="https://www.youtube.com/embed/XYZ" title="YouTube video player"></iframe>
</div>
<style>
.responsive-video{
position: relative;
padding-bottom: 56.25%;
height: 0;
}
</style>

What alternatives did you consider?

Allow the user to select a dimension, so that the right class is automatically applied.

Anything to add? (optional)

No response

Are you sponsoring us?

  • [ ] Yes, I’m a sponsor. 💖

joppehoekstra avatar Jun 22 '22 09:06 joppehoekstra

Good idea!

bdbch avatar Jun 22 '22 11:06 bdbch

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Aug 07 '22 00:08 github-actions[bot]

hello, any solution for this plesase?!

beocaca avatar Aug 30 '22 10:08 beocaca

adding a tailwind Aspect Ratio classes will be nice w-full aspect-video md:aspect-square

or allow to add custom class to the iframe itself

tarek-89 avatar Sep 26 '22 17:09 tarek-89

adding a tailwind Aspect Ratio classes will be nice w-full aspect-video md:aspect-square

or allow to add custom class to the iframe itself

Yeah that would be nice. Currently I did it this way:

div[data-youtube-video] > iframe {
  aspect-ratio: 16 / 9;
  width: 100%;
}

philmetzger avatar Oct 25 '22 06:10 philmetzger

allowing to input string as width is a good idea. my case is showing the embedded video on mobile apps, which have so many width and aspect ratio, so manually set the output is the only way. just in case there is people need a way like me

   if (editorHtml.includes('iframe') && !editorHtml.includes('style')) {
            editorHtml = editorHtml.replace(
                /<iframe/g,
                '<iframe style="width: 100%;aspect-ratio: 16 / 9"',
            );
        }

hi-reeve avatar Nov 03 '22 03:11 hi-reeve

You can define the class / other attributes on the HTML elements.

Youtube.configure({
  HTMLAttributes: {
      class: 'my-iframe-class',
  },
})

bdbch avatar Nov 04 '22 16:11 bdbch

For anyone who cares, this is the solution that worked best for me.

I didn't touch the jsx, but added the following code in my TipTap.css

I don't remember, what the recommended or default CSS was, but the key here that solved my problem was a simple max-height in some @media screens that I added. This worked on pretty much every test screen size I tried. I think it should work for most other use cases as well with some slight adjustments to the numbers.

iframe {
    border: 8px solid #000;
    border-radius: 4px;
    min-width: 200px;
    min-height: 200px;
    display: block;
    outline: 0px solid transparent;
  }

  div[data-youtube-video] > iframe {
    cursor: move;
    aspect-ratio: 16 / 9;
    width: 100%;
  }

  .ProseMirror-selectednode iframe {
    transition: outline 0.15s;
    outline: 6px solid #fbbf24;
  }

  @media only screen and (max-width: 480px) {
    div[data-youtube-video] > iframe {
      max-height: 50px;
    }
  }

  @media only screen and (max-width: 720px) {
    div[data-youtube-video] > iframe {
      max-height: 100px;
    }
  }

LazAustin avatar Nov 22 '22 16:11 LazAustin