Skip to main content

Rendering Images

Overview

Having a proper set of tools to render images within your application is quite important for many reasons, of which the most obvious are the fact that they can heavily affect the layout, as well as possible performance hit caused by somewhat careless handling of image assets.

Allium provides components to help you soften the impact of using images on both layout and performance levels.

Allium image components

Out of the box, Allium has three components that can be used to render images:

  • Image
  • ResponsiveImage
  • OptimizeImage

Image

Image component is essentially a wrapper around HTML img tag. However, on top of the basic functionality, it also provides some styling features: you can render circular images, as well as images with rounded corners using the rounded prop that can take either circle or corners as the value if defined.

Note that you can also pass 'lazy' via the loading prop to make the image lazy-loading.

Loading...

ResponsiveImage

ResponsiveImage component allows providing different image sources for different screen sizes based on Allium-specific breakpoints.

Loading...

Note that it also accepts the 'lazy' via the loading prop to allow lazy-loading images.

OptimizeImage

OptimizeImage component should be used to optimize Contentful image files based on screen size. Note that you have to provide a Contentful asset URL here for this component to work properly:

Loading...

Other Allium components rendering images

On top of components directly used to render images, Allium also has several components that render images in context of other information.

Cards with full bleed images

First of all, Allium cards (Card, PreviewCard, StoryCard) offer an option to render full bleed images with flexible positioning options:

Loading...

By default, if fullBleedContent prop has src property set, this functionality will be using ResponsiveImage component to render the image, however you can use by passing some JSX in a content property of the fullBleedContent:

Loading...

This feature allows you to use optimized components like NextJS Image in combination with Allium cards in order to provide better user experience.

Testimonial

The purpose of the Testimonial component is displaying a testimonial in a standalone, pre-styled container. As an optional element, testimonial can have an image rendered next to the main text:

Loading...

Similarly to the full bleed content in cards, you can display image content via a custom image component. All you need in this case is to pass some JSX via the image prop:

Loading...

WaffleGrid

WaffleGrid is used to show items in a waffle-like manner with borders surrounding the element:

Loading...

Here as well, you can display image content via a custom image component by passing some JSX via the image prop:

Loading...

Conclusion

Hopefully, this guide provides enough information for you to choose an appropriate way of rendering images within Allium components. If you believe that something is missing here or needs a clarification, feel free to raise an issue on GitHub or open a discussion in the #ds-allium-support Slack channel.