Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@crystallize/react-image

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crystallize/react-image

Modern and responsive images based on the source variations from Crystallize

  • 7.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

alt text

React Srcset Images for Crystallize

A React package to output an img tag with different source variations from Crystallize using srcset. Use this to easily build responsive images powered by the Crystallize headless commerce service.

And don't forget: react image sizes attribute for fast ecommerce.

Demo

Demo

Install

yarn add @crystallize/react-image

Use

import { Image } from '@crystallize/react-image';

const imageFromCrystallize = {
    url: '...',
    variants: [...]
}

<Image
    {...imageFromCrystallize}
    sizes="(max-width: 700px) 90vw, 700px"
/>

Render child function

const imageFromCrystallize = {
    url: '...',
    variants: [...],
    altText: ''
}

<Image
    {...imageFromCrystallize}
    sizes="(max-width: 700px) 90vw, 700px"
>
  {({
      src,
      srcSet,
      srcSetWebp,
      useAvif,
      useWebP,
      sizes,
      width,
      height,
      loading,
      alt,
      originalFileExtension,
      ...rest
    }) => {
      // Roll your own render
      return (
          <picture {...rest}>
            {useAvif && (
                <source srcSet={srcSetAvif} type="image/avif" sizes={sizes} />
            )}
            {useWebP && (
                <source srcSet={srcSetWebp} type="image/webp" sizes={sizes} />
            )}
            {srcSet.length > 0 && (
                <source
                    srcSet={srcSet.join(", ")}
                    src={std[0].url}
                    type={`image/${originalFileExtension}`}
                    sizes={sizes}
                />
            )}

            <img src={src} width={width} height={height} loading={loading} alt={alt} />
        </picture>
      )
  }}
</Image>

Keywords

FAQs

Package last updated on 03 Nov 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc