ImageLoader
Notes
An all-purpose image component. Provides "lazy-loading", graceful image fade-in, and flexible sizing. Most of its functionality can be toggled off or worked around via its many props.
To see many of ImageLoader's performance functionality (such as lazy loading and graceful fade-in) you may need to enable network throttling or hard-refresh the browser so the cached images are cleared.
Image loads as follows:
Props
- alt
string
Required if image conveys information to the user.
- height
string
Set as an attribute on the rendered
<img />
tag. Note, since this may be ignored due to height:auto being set in our pattern library global css, a maxHeight style property will also be generated. - role
string
Role should be set to 'presentation' if image does not convey useful information to the user; do not pass a role if the image is not presenational/decorative.
- src
string
Image source
- width
string
Set as an attribute on the rendered
<img />
tag - constrainWidth
bool
Set to true for images that are known to be smaller than the parent column. Used to hold space with a set width and height div before image has come into viewport.
- className
string
Applied to the image itself. If
includeFallback
is enabled, also applies to the fallback. - imageOnlyClassName
string
Styles the image only when visible.
- imageWhenHiddenClassName
string
Styles the image only when hidden (either loading or behind fallback if
includeFallback
is enabled) - lazyLoadshape {enabled
bool
True by default. Wraps image in ViewportChecker. If the image lives "above the fold" and never should check the viewport, but should load automatically, set to false. See ViewportChecker documentation for more information.
xThresholdnumber
Pixel value threshold for triggering
hasBeenInViewport
on x-axis. Set to 300 pixels by default. If you set this value, make sure lazyLoad.enabled is set to true. See ViewportChecker for more information.}yThresholdnumber
Pixel value threshold for triggering
hasBeenInViewport
on y-axis. Set to 500 pixels by default. If you set this value, make sure lazyLoad.enabled is set to true. See ViewportChecker for more information. - placeholdershape {alt
string
Provide an alt for the placeholder if it conveys meaningful information to users
}srcstring
src attribute for the placeholder image
Props for an optional placeholder image to be used while true image loads. While
lazyLoad.enabled
is true, it saves space for the image as it comes into viewport. IfincludeFallback.enabled
is true, image will fade in from the placeholder instead of the grey fallback div. - wrapInFlexshape {enabled
bool
Wrap the image in a FlexEmbed component to prevent the page from jumping around as it renders. Defaults to a 1:1 ratio unless you provide flexHeight and flexWidth to create a custom ratio. See the FlexEmbed documentation for more information.
constrainWidthbool
For images that are known to be smaller than the parent column, set to true to create a max-width for FlexEmbed parent.
heightnumber
Passed through to underlying FlexEmbed components. In combination with width, this provides a ratio to preserve the right amount of flexible space for the image in the layout. See the FlexEmbed documentation for more information.
widthnumber
Passed through to underlying FlexEmbed components. In combination with height, this provides a ratio to preserve the right amount of flexible space for the image in the layout. See FlexEmbed documentation for more information.
}flexEmbedWrapperClassNamestring
If
wrapInFlex.enabled
is set to true, use this className to style the grandest-parent of the image. See FlexEmbed for more information on how to style. - includeFallbackshape {enabled
bool
Wraps the image in a relatively positioned div, and absolutely positions the image with its fallback (grey div or
placeholder
).fallbackClassNamestring
Class applied to fallback div or placeholder image.
}wrapperClassNamestring
Applied to the div surrounding the image and its fallback. This wrapper is automatically positioned relatively, so that the absolute image and fallback can travel together.