npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pixboost-react

v2.2.1

Published

React library to integrate with pixboost api

Downloads

1,229

Readme

pixboost-react

Node.js CI codecov

Library for integrating Pixboost API into the React applications.

Table of Contents:

Installation

To install the library:

npm install --save pixboost-react

There are 3 components that library provides:

  • HiDpiPicture and Picture for responsive images.
  • Image for images that don't need to change size depending on the device.

Library supports React version 14+.

Examples

You can find examples of how to use components in the example application.

Example application is also deployed at http://www.midday.coffee/react-demo/index.html

Responsive images

There are two types of responsive images components available in the library. Both implementations are using <picture> tag for high dpi screens optimisation.

  • HiDpiPicture - Using combination of srcset and sizes attributes, so browser can pick the most suitable one.
  • Picture - Displays fixed sizes images on defined media breakpoints

Which one to use?

HiDpiPicture is preferred for large images because any up-scaling artifacts will be more visible to the user on the screens with DPI > 1. Examples are hero banners, product images, zoom-in images.

Note that you would also need original images to be in a good quality and at least 3x of intended viewports size. For instance, if your product image takes up to 1000px then the original image should be at least 3000px wide.

Picture and Image are a good choice for small images like thumbnails, icons, etc.

HiDpiPicture

HiDpiPicture is a modern way of implementing responsive images using srcset and sizes attributes where we provide browser with variants of the image and visual size constraints to display. The browser then will make hard work for us and pick the best option to load and display.

Example:

    // Reusable configuration
    const pixboostConfig = {
        apiKey: 'MTg4MjMxMzM3MA__',
        domain: 'pixboost.com',
        breakpoints: {
            lg: {media: '(min-width: 990px)'},
            md: {media: '(min-width: 640px)'},
            sm: {}
        }
    };

    function YourComponent() {
      return (
              <HiDpiPicture alt="YO"
                            config={testConfig}
                            breakpoints={{ // operation for each breakpoint width {WIDTH} and {HEIGHT} values replaced with generated width and specified height if any
                              sm: {op: 'fit?size={WIDTH}x{HEIGHT}', height: 600}, // operation and optional fixed height
                              md: {op: 'resize?size={WIDTH}'},
                              lg: {op: 'resize?size={WIDTH}'}
                            }}
                            sizes={{ // image width for each breakpoint
                              sm: '100vw',
                              md: '640px',
                              lg: '1500px'
                            }}
                            minWidth={300}  // minimum visible size of the image
                            maxWidth={3000} // maximum visible size of the image
                            src="//here.com/logo.png"
              />
      )
    }

Properties (mandatory properties marked with *):

| Property | Type | Default | Description | |--------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| | src* | String | | Source url or path with alias to the source image. | | breakpoints* | Object | | Object that sets an option for each visual breakpoint. You can use only breakpoints that you specified in the configuration property | | breakpoints.op* | String | | Operation to perform. By default is optimise. You can use {WIDTH} and {HEIGHT} placeholders. | | breakpoints.height | Number | | Setting the fixed height for the image on the given breakpoint | | sizes* | Object | | Object that specifies width of the image for the particular breakpoint. See More Info. | | minWidth* | Number | | | | maxWidth* | Number | | | | config* | Object | | Configuration | | alt* | String | | alt text for an image | | lazy | Boolean | false | If true, then will enable lazy loading for the image. | | imgProps | Object | | Pass through props to <img> tag. |

Picture

Picture component renders different sizes of the image for different visual breakpoints.

Below is a simple example:

    //This is a reusable configuration
    const pixboostConfig = {
        apiKey: 'MTg4MjMxMzM3MA__',
        domain: 'pixboost.com',
        breakpoints: {
            lg: {media: '(min-width: 990px)'},
            md: {media: '(min-width: 640px)'},
            sm: {}
        }
    };

    class YourComponent extends Component {
        render() {
            return (
                <Picture alt={"gadgets"} breakpoints={
                    {
                        lg: {
                            //Will optimise image by default
                            src: 'https://cdn.pixabay.com/photo/2015/01/21/14/14/apple-606761_960_720.jpg'
                        },
                        md: {
                            src: 'https://cdn.pixabay.com/photo/2015/02/02/15/28/bar-621033_960_720.jpg',
                            op: 'fit?size=300x300'
                        },
                        sm: {
                            //We can hide image for certain breakpoints
                            hide: true
                        }
                    }
                } config={pixboostConfig}/>
            )
        }
    }

Properties (mandatory properties marked with *):

| Property | Type | Default | Description | |------------------|---------|----------|--------------------------------------------------------------------------------------------------------------------------------------| | breakpoints* | Object | | Object that sets an option for each visual breakpoint. You can use only breakpoints that you specified in the configuration property | | breakpoints.src* | String | | URL of the original image | | breakpoints.op | String | optimise | Operation to perform. By default is optimise. | | breakpoints.hide | Boolean | false | If true then will hide image on the breakpoint. | | config* | Object | | Configuration | | alt | String | | alt text for an image | | lazy | Boolean | true | If true, then will enable lazy loading for the picture. | | imgProps | Object | | Pass through props to <img> tag. |

Non-responsive images

An Image component will be rendered the same on all screen sizes.

Example:

    //This is a reusable configuration
    const pixboostConfig = {
        apiKey: 'MTg4MjMxMzM3MA__',
        domain: 'pixboost.com'
    };

    class YourComponent extends Component {
        render() {
            return (
                <Image src={'https://cdn.pixabay.com/photo/2016/05/10/15/29/bear-1383980_960_720.jpg'}
                       alt={'lazy bear'}
                       config={pixboostConfig}
                       op={'resize?size=200'}
                />
            )
        }
    }

Properties (mandatory properties marked with *):

| Property | Type | Default | Description | |----------|---------|---------|-------------------------------------------------------| | src* | String | | URL of the original image | | config* | Object | | Configuration | | alt | String | | alt text for an image | | lazy | Boolean | true | If true, then will enable lazy loading for the image. |

Configuration

| Property | Type | Default | Description | |-------------------|--------|---------|------------------------------------------------------------------------| | apiKey* | String | | Pixboost API key | | domain* | String | | Custom domain name that you setup or pixboost.com | | breakpoints | Object | | Key-Value pair of breakpoints that you are using for responsive images | | breakpoints.media | String | | Media query for the breakpoint |

Browsers Support

The library supports all major browsers including Chrome, Chromium based (including IE), Firefox, Safari.

Build

To build from sources:

npm install
npm run build

Result will be generated into the lib/ folder.