Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-image): Add gatsby-image/withIEPolyfill export with objec…
…t-fit/position support (#12681) ## Description This PR will allow users who want `object-fit/object-position` support in IE to simply `import Img from "gatsby-image/withIEPolyfill"` instead of importing directly from `"gatsby-image"`. Please feel free to review the PR and let me know if the implementation can be improved. The `/withIEPolyfill` version of `gatsby-image` currently does the following: 1. Checks if the browser supports the `object-fit/position` CSS properties. a. If yes, no polyfill is loaded. b. If no, the `object-fit-images` polyfill is imported and called. 2. Wraps `gatsby-image` in a component that passes the new `objectFit` and `objectPosition` prop values to the polyfill implementation (which requires a weird `font-family` hack). ### New props To make the implementation simple, I've added new `objectFit` and `objectPosition` props that will needed to be used to pass the corresponding values to the polyfill. This is to avoid a scenario where a user attempts to set these values in a way we can't pass to the polyfill (e.g. via an external CSS stylesheet) and doesn't understand why the polyfill isn't working. Let me know if this API can be improved. ### Loading polyfill in /withIEPolyfill/index.js I opted to load the `object-fit-images` polyfill directly in `withIEPolyfill/index.js` rather than in `gatsby-browser.js`. If anyone knows of a better way to approach this, please let me know and feel free to make improvements. ### Polyfill repo has been archived I was surprised to see that the `object-fit-images` [repo](https://github.com/bfred-it/object-fit-images) has recently been archived by its owner. It still works, but if anyone is concerned about this or knows of a reliable alternative polyfill, please let me know. ### Docs to be updated once implementation is finalized Once we've settled on the API for this `/withIEPolyfills` component, a brief explanation will need to be added to the `gatsby-image` docs. I held off on adding one for now in case we end up changing the API. ## Related Issues Fixes #4021. Co-authored-by: Ward Peeters <[email protected]>
- Loading branch information