01 Software

Components

Image

Image component with LQIP/palette placeholder

Image

An image component with LQIP (blur-up) or palette color placeholder support. Provides automatic srcSet generation and fade transition on load.

Basic Usage

import { Image } from '@01.software/sdk/components'

function ProductCard({ product }) {
  return (
    <Image
      image={product.thumbnail}
      placeholder="blur"
      sizes="(max-width: 768px) 100vw, 50vw"
    />
  )
}

Props

PropTypeDefaultDescription
imageImageDataPayload image document (required)
widthnumberCSS pixel width
dprnumber1Device pixel ratio
placeholder'blur' | 'color' | 'none''blur'Placeholder strategy
classNamestringContainer CSS class
styleCSSPropertiesContainer style
imgClassNamestring<img> CSS class
imgStyleCSSProperties<img> style
sizesstringHTML sizes attribute
loading'lazy' | 'eager''lazy'Loading strategy
onLoad() => voidImage load complete callback
objectFit'cover' | 'contain' | 'fill' | 'none' | 'scale-down''cover'object-fit

Placeholder Strategies

  • blur: Overlays a blurred LQIP image, fades out on load. Falls back to palette color if LQIP is unavailable.
  • color: Uses palette color as background.
  • none: No placeholder.

Image Utilities

Utility functions for image processing. Can be used independently without the Image component.

import {
  getImageUrl,
  getImageSrcSet,
  getImageLqip,
  getImagePalette,
  getImagePlaceholderStyle,
  IMAGE_SIZES,
} from '@01.software/sdk'
FunctionReturnsDescription
getImageUrl(image, displayWidth, dpr?)stringSelect optimal image URL for display width
getImageSrcSet(image)stringGenerate HTML srcset attribute string
getImageLqip(image)string | undefinedLQIP data URL
getImagePalette(image)ImagePalette | undefined6-color palette (vibrant, muted, darkVibrant, darkMuted, lightVibrant, lightMuted)
getImagePlaceholderStyle(image, options?)CSSPropertiesInline CSS styles for placeholder
IMAGE_SIZES[384, 768, 1536]Pre-generated image size breakpoints

Usage Example

// Select optimal URL
const url = getImageUrl(product.thumbnail, 400, 2) // 400px @ 2x

// Custom <img> tag
<img
  src={getImageUrl(image, 768)}
  srcSet={getImageSrcSet(image)}
  sizes="(max-width: 768px) 100vw, 50vw"
  style={getImagePlaceholderStyle(image, { type: 'color' })}
/>

On this page