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

librephotos-react-pig

v1.0.0

Published

Arrange images in a responsive, progressive-loading grid managed in JavaScript using CSS transforms.

Downloads

8

Readme

react-pig

Arrange images in a responsive, progressive-loading grid managed in JavaScript using CSS transforms.

View Demo

NPM npm bundle size JavaScript Style Guide

A re-implementation of @schlosser's pig.js in React.

Instead of hosting images locally I've used Cloudinary - an image hosting provider, which adds the benefit of on-the-fly image resizing. So we don't need to worry about managing/generating multiple versions of an image at different resolutions. Like the original version of Pig.js we still need to provide an array of objects containing metadata about each image. I've created a node script upload.js to do this for us, see below section on upload.js.

In addition each image is now clickable and will expand to the center of the screen. It uses React Spring to handle the transition.

React-pig-utils

React Pig requires that a specific JSON format be supplied. So this project comes with a companion repo which provides utilities for doing that. Check it out here react-pig-utils.

Example usage of react-pig

yarn add react-pig
# or
npm i react-pig
import Pig from 'react-pig'
import imageData from './imageData.json' // the file generated by using react-pig-utils

class App extends Component {
  render() {
    return (
      <Pig
        imageData={imageData} // Array. Required.
        numberOfItems={500} // Number. Optional, set the number of Items if you only partially loaded the data
        updateItems=(visibleItem) => {} // Function. Optional. Returns the visible Items / items in buffer for dynamically fetching items.
        scaleOfImage={3} // Number. Show more or less images. This value would show 3x more images
        groupByDate // Boolean. Optional. Groups images by 'date' value. And uses the first 'location' in the group for the heading text.
        updateGroups=(visibleGroups) => {} // Function. Optional. Returns the visible groups / groups in buffer to dynamically fetch data for them
        gridGap={10} // Integer. Optional. Defaults to 8
        expandedSize={1600} // Integer. Optional. Expanded image will be loaded in that size. Defaults to 1000
        thumbnailSize={25} // Integer. Optional. Thumbnail image will be loaded in that size. Defaults to 10
        sortFunc={(a, b) => a.imageOrder > b.imageOrder} // Function. Optional. Used for sorting images f.ex. if you add custom fields to the json file
        bgColor="#fff" // String. Optional. Used for outlines when image is expanded, and for group headings
        getUrl={(url, pxHeight) => {
          // Pig calls this function every time it needs to fetch an image.
          // The url arg will be provided as is from imageData
          // Assuming the imageData was generated using upload.js, the url string will contain {{HEIGHT}}
          // The purpose of this function is to replace {{HEIGHT}} value with a dynamic value (which is passed in with pxHeight)
          // Eg this:
          // http://res.cloudinary.com/cloudinaryusername/image/upload/h_{{HEIGHT}}/v12345678/cloudinaryfolder/image.jpg
          // Becomes this:
          // http://res.cloudinary.com/cloudinaryusername/image/upload/h_800/v12345678/cloudinaryfolder/image.jpg
          // This gives you flexibility to define what the url looks like in case you're using something other than Cloudinary.
          // getUrl is optional.
          // If you omit this prop completely, Pig will do exactly this;
        }}
        handleClick={(event, item) => {}} // Allows for a custom click handler
        selectable={true} // If true, it will add a selection to the top left corner
        handleSelection={(item) =>{}} // Allows for a custom selection handler
        selectedItems={selectedItems} // Array. Makes it possible to change the state of the selected tiles
        toprightoverlay={component} // Add a component to the top right corner as an overlay
        bottomleftoverlay={component} // Add a component to the bottom left corner as an overlay
      />
    )
  }
}

export default App

Development

You have to install yarn:

npm install --global yarn

Use the yarn commands to install and continuously build react-pig:

yarn install
yarn run build
yarn start

To test your changes to the component, build and serve the example:

cd /example
yarn install
yarn start

You should now be able to see the website, with the changed component, at localhost:3000

This React library was packaged with https://github.com/transitive-bullshit/create-react-library

License

MIT © nickmcmillan