
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
bpk-component-image
Advanced tools
Backpack image component.
npm install bpk-component-image --save-dev
import React from 'react';
import BpkImage from 'bpk-component-image';
import { breakpointDesktop, breakpointTablet } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
export default () => (
<BpkImage
altText="image description"
aspectRatio={816 / 544}
src="./path/to/image_1640.jpg"
/>
);
withLazyLoading
is a HOC which adds an inView
prop to components.
This boolean prop can be used to determine if the component has been brought into view within a user's browser window.
The BpkImage
component will only load images if inView
is true.
Using this HOC can make pages load faster and prevent data being used to display images which are never seen by the user.
import BpkImage, { withLazyLoading, withLoadingBehavior } from 'bpk-component-image';
import { breakpointDesktop, breakpointTablet } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
// Support for SSR
const documentIfExists = typeof window !== 'undefined' ? document : null;
// withLazyLoading will not use document when rendered server side so it's safe
// pass null.
const LazyLoadedImage = withLazyLoading(BpkImage, documentIfExists);
export default () => (
<LazyLoadedImage
altText="image description"
aspectRatio={816 / 544}
src="./path/to/image_1640.jpg"
/>
);
withLoadingBehavior
is a HOC which provides loading
state for BpkImage
. This allows the component to have different behaviour before and after loading completes.
When the loading
prop is set true, a spinner will be displayed. When this changes to false, the spinner will fade away and the loaded image and content will fade into view.
import BpkImage, { BpkBackgroundImage, withLazyLoading, withLoadingBehavior } from 'bpk-component-image';
import { breakpointDesktop, breakpointTablet } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
const FadingImage = withLoadingBehavior(BpkImage);
const FadingBackgroundImage = withLoadingBehavior(BpkBackgroundImage);
export default () => (
<div>
<FadingImage
altText="image description"
aspectRatio={816 / 544}
src="./path/to/image_1640.jpg"
/>
<FadingBackgroundImage
altText="image description"
aspectRatio={816 / 544}
src="./path/to/image_1640.jpg"
imageStyle={{
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
backgroundPosition: '50% 50%',
}}
/>
</div>
);
Combining withLazyLoading
and withLoadingBehavior
gives us a lazily loaded image that will show a spinner while the image loads.
import BpkImage, { withLazyLoading, withLoadingBehavior } from 'bpk-component-image';
import { breakpointDesktop, breakpointTablet } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
const documentIfExists = typeof window !== 'undefined' ? document : null;
const FadingLazyLoadedImage = withLoadingBehavior(withLazyLoading(BpkImage, documentIfExists));
export default () => (
<FadingLazyLoadedImage
altText="image description"
aspectRatio={816 / 544}
src="./path/to/image_1640.jpg"
/>
);
Property | PropType | Required | Default Value |
---|---|---|---|
altText | string | true | - |
src | string | true | - |
aspectRatio | number | true | - |
borderRadiusStyle | oneOf(BORDER_RADIUS_STYLES) | false | BORDER_RADIUS_STYLES.none |
className | string | false | null |
inView | bool | false | true |
loading | bool | false | false |
onLoad | func | false | null |
style | object | false | {} |
suppressHydrationWarnings | bool | false | false |
Note: The aspectRatio
prop should be calculated as width/height
of the original src image. It is used by the component to preserve space on screen while the image loads.
Note: All standard img
attributes including srcSet
are also supported.
The background image component is useful for setting background images in CSS that can then contain other elements. It supports the same HOCs as BpkImage
.
Property | PropType | Required | Default Value |
---|---|---|---|
src | string | true | - |
aspectRatio | number | true | - |
className | string | false | null |
inView | bool | false | true |
loading | bool | false | false |
onLoad | func | false | null |
style | object | false | {} |
imageStyle | object | false | {} |
FAQs
Backpack image component.
The npm package bpk-component-image receives a total of 63 weekly downloads. As such, bpk-component-image popularity was classified as not popular.
We found that bpk-component-image demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.