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

n-image

v2.2.3

Published

Next responsive image component

Downloads

6

Readme

n-image Build Status

Bower component for responsive images.

NOTE: This implementation is likely to change as we discover more scenarios that need to be covered by responsive images.

Usage

The image component allows you to specify different size images to be used at different breakpoints. It's essentially a wrapper around the new <picture></picture> element. Currently we're using the latest version of picturefill to polyfill the picture element for older browsers. This will be removed when a picture polyfill is added to the polyfill service in the near future.

The following image object is expected by the component (when used as a bower component) -

{
	url: 'someurl', //This will be passed into the image service
	alt: 'your alt text',
	class: 'any-bespoke-classes you-want-to-add', //Optional added to <picture> element along with n-image
	srcset: {
		fallback: 500, //Optional pixel width for fallback image.
		default: 200, //The default image size. This will be shown if non of the breakpoint sizes are matched or some haven't been specified
		s: 300,
		m: 500,
		l: 700,
		xl: 1000
	}
}

Arguments are passed to the React component (when used as a node package) -

<NImage
    url="https://ak-hdl.buzzfed.com/static/2014-06/6/12/enhanced/webdr08/enhanced-21313-1402070821-11.jpg"
    srcset={{ s: 120, l: 160 }}
    isImgServiceUrl={false}
    imageServiceParams={{ tint: 'FFF1E0' }}
    alt="A Cat"
    picClass="container__picture"
    imgClass="container__image" />

The arguments should be of the following format:

  • {string} url: Image URL
  • {Object} srcset
  • {number} srcset.fallback: Optional pixel width for fallback image.
  • {number} srcset.default: The default image size. This will be shown if non of the breakpoint sizes are matched or some haven't been specified
  • {number} srcset.s
  • {number} srcset.m
  • {number} srcset.l
  • {number} srcset.xl
  • {boolean} [isImgServiceUrl=false]: Boolean value dictates whether url will use image service or not
  • {Object} [imageServiceParams={}]: Params to use with the image services
  • {string} [alt='']: Optional alt text
  • {string} [picClass='']: Any bespoke classes you want to add //Optional added to element along with n-image
  • {string} [imgClass='']: Any bespoke classes you want to add //Optional added to elements along with n-image__img

The s, m, l, xl size match to those used in o-grid and the relevant width images will be loaded.

The fallback property should only be included if the image must be shown in all scenarios. The suggested usage of picturefill is that browsers without picture support or javascript should only show the alt text. Including the fallback will result in a double image download in certain scenarios and so should only be used when required.

A breakpoint definition will always trump the default declaration. For example with the following options -

{
	url: 'someurl', //This will be passed into the image service
	alt: 'your alt text',
	srcset: {
		default: 400,
		l: 700
	}
}

A 400px image will be shown until you hit the l breakpoint. At which point a 700px image will be shown.

In certain scenarios, images may only be required for larger breakpoint sizes. In this case you can drop the default and s options. You will still need to display:none the picture element at the s breakpoint but it means no image will be requested.

###Installing

make install

###Using

####JS:

	require('n-image');

####SCSS: @import 'n-image/main';

####HTML:

{{>n-image/templates/image}}

Testing

Use the Next Styleguide Demoer to test, by bower link-ing this component into it and updating the data json file with any extra variants.