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

Simplify <Image /> component #102

Merged
merged 1 commit into from Apr 3, 2024
Merged

Simplify <Image /> component #102

merged 1 commit into from Apr 3, 2024

Conversation

stefanoverna
Copy link
Member

@stefanoverna stefanoverna commented Apr 1, 2024

Now that both loading=lazy and aspect-ratio are broadly supported (> 93% of browsers) we can avoid complex JS to achieve lazy-loaded images with placeholders!

<datocms-naked-image /> is a new component that achieves that.

  • Placeholder is set up with a CSS background on the <picture> element
  • Lazy loading is achieved with loading=lazy
  • Sizing before the image load is ensured with aspect-ratio and width: 100%
  • alt during image loading is hidden with color: transparent

Changes to <datocms-image>:

  • removed lazy-load: lazy loading is automatically disabled for images using priority
  • removed root-style: you can simply use style to style the root element
  • removed explicit-width
  • added load event
  • added rootRef and imageRef as public properties
  • fixed minor bugs in styling

All the examples have been consolidated into a single SPA React application to ensure a straightforward maintenance process.

Copy link

vercel bot commented Apr 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue-datocms-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2024 7:15am

@stefanoverna stefanoverna self-assigned this Apr 3, 2024
@stefanoverna stefanoverna merged commit 4904841 into master Apr 3, 2024
5 checks passed
@stefanoverna stefanoverna deleted the native-image branch April 3, 2024 07:16
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

Successfully merging this pull request may close these issues.

None yet

1 participant