ChristopherBiscardi / gatsby-mdx

Gatsby+MDX • Transformers, CMS UI Extensions, and Ecosystem Components for ambitious projects
https://gatsby-mdx.netlify.com/
714 stars 100 forks source link

Zoom images #385

Closed pszafer closed 5 years ago

pszafer commented 5 years ago

Hi, I'm trying to add zoom-in/zoom-out feature to my images. I'm configuring gatsby as:

`gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-mdx`,
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: "gatsby-remark-images",
            options: {
              maxWidth: 1035,
              sizeByPixelDensity: true,
              withWebp: true,
              linkImagesToOriginal: true
            }
          }
        ]
      }
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/blog`,
        name: `blog`,
      },
    }
  ],

My attempts:

Do you know any good example or how to do it properly (gatsby way) if I want use features of gatsby-remark-images and add zoom feature?

JulesBlm commented 5 years ago

Hi, you could try this Gatsby remark plug-in: https://github.com/premieroctet/gatsby-remark-images-zoom. I'm not sure if it works with MDX though.

ChristopherBiscardi commented 5 years ago

I haven't implemented zoom myself. Given that there seems to be a plugin that solves this (thanks @JulesBlm) and that this isn't a gatsby-mdx issue I'm going to close it.

You could probably achieve this by taking control of the rendering of gatsby-remark-image's output using MDXProvider (the remark output can look like this https://github.com/gatsbyjs/gatsby/blob/86ee22e6a5cd57ef566f1a427e94e35e33f0fa99/packages/gatsby-remark-images/src/index.js#L196-L216) and you can override picture, source, or img using MDXProvider.

pszafer commented 5 years ago

@JulesBlm medium-zoom is not working with picture tags properly. It is only working with <img>.

@ChristopherBiscardi is it possible with MdxProvider to extract <picture> / <span> from <p> element?

ChristopherBiscardi commented 5 years ago

@pszafer I'm not sure what you mean by extract. You can take control of any renderable element via MDXProvider. Check the docs here: https://mdxjs.com/advanced/components#mdxprovider

pszafer commented 5 years ago

I ended up doing my modal as gatsby plugin, so this is no problem for me anymore https://github.com/pszafer/gatsby-remark-images-modal

But what I meant is that by default <picture> is put in <p> like this:

<p>
  <span ...>
    <picture>...</picture>
  </span>
</p>

I wanted to extract it from <p> so I can put <div> and other DOM elements there.