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

@bbc/psammead-image

v3.1.3

Published

React styled components for an Image

Downloads

207

Readme

psammead-image - Known Vulnerabilities Dependency Status peerDependencies Status Storybook GitHub license npm version PRs Welcome

Description

The psammead-image component has two images available. The default is a styled img element that uses Styled Components.

There is an alternative AMP Image which can be used. It is a React component returning an amp-img element.

When to use this component

This component can be used at any point on a page.

Installation

npm install @bbc/psammead-image

Usage

Img

Importing the standard Image component renders an <img /> tag.

import Image from '@bbc/psammead-image';

const WrappingContainer = ({ alt, src, height, width, sizes }) => (
  <Img alt={alt} src={src} height={height} width={width} sizes={sizes} fade />
);

AmpImg

If you're to use the AmpImg component, please read the AMP documentation here for further details.

The Amp Image component renders an <amp-img> tag.

Example:

import { AmpImg } from '@bbc/psammead-image';

const WrappingContainer = ({ alt, src, height, width, sizes }) => (
  <AmpImg
    alt={alt}
    layout="responsive"
    sizes={sizes}
    src={src}
    height={height}
    width={width}
  />
);

Props

Img

| Prop | Type | Required | Default | Example | |:-----|:-----|:---------|:--------|:--------| | alt | string | Yes | - | "A picture of a cat" | | height | number/string | No | null | 450 | | sizes | string | No | null | "100vw" | | src | string | Yes | - | "https://bbc.com/300/cat.jpg" | | srcset | string | No | null | "https://bbc.com/300/cat.jpg.webp 300w, https://bbc.com/450/cat.jpg.webp 450w, https://bbc.com/600/cat.jpg.webp 600w" | | fallbackSrcset | string | No | null | "https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w" | | primaryMimeType | string | No | null | "image/webp" | | fallbackMimeType | string | No | null | "image/jpeg" | | width | number/string | No | null | 600 | | fade | boolean | No | false | true |

The height and width props are optional, in some cases to preserve the image ratio you might specify either height or width and let the browser scale the image accordingly.

However when not specified the browser will not be able to determine the size of the image, the browser will therefore build the page twice or more depending on the number of images you have. First paint is for the browser to display all the text and once the image is downloaded and size determined a second paint to wrap the texts around the image.

Specifying the width and height allows the browser to reserve space for the image which prevent content moving around while the image is being loaded.

The srcset prop is optional since some projects might not want to use the srcset attribute on images.

The sizes prop is optional since some projects might not want to use the sizes attribute on images.

The fade prop is optional and set to false by default. It's been used to apply a fade-in animation effect on the Img component.

AmpImg

| Prop | Type | Required | Default | Example | |:-----|:-----|:---------|:--------|:--------| | alt | string | Yes | - | "A picture of a cat" | | attribution | string | No | '' | "Getty Images" | | height | number/string | Yes | null | 450 | | layout | string | Yes | - | "responsive" | | sizes | string | No | null | "100vw" | | src | string | Yes | - | "https://bbc.com/300/cat.jpg" | | srcset | string | No | null | "https://bbc.com/300/cat.jpg.webp 300w, https://bbc.com/450/cat.jpg.webp 450w, https://bbc.com/600/cat.jpg.webp 600w" | | fallbackSrcset | string | No | null | "https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w" | | width | number/string | Yes | - | 600 |

The attribution prop is available to pass in strings to include the image source. For further details, please refer to the amp-img attribute docs. The layout prop can be one of several, including responsive, fixed, intrinsic etc. We recommend using responsive for most use-cases, with height and width props passed in, so the AMP can use the correct ratio for scaling the image. For further details, please refer to the AMP docs. The srcset prop is a string with comma separated string of image URLs with varying sizes. For further details, please refer to the MDN docs. The sizes prop is string containing a list of comma separated strings indicating a set of source sizes. For further details, please refer to the MDN docs.

Accessibility notes

This component requires an alt property to describe the image. This alt text is crucial for users of Assistive Technology, and by any user whose internet connection is so slow the browser decides to render the text instead of the image.

Some images are purely presentational - in these cases, an alt attribute must still be passed, but the value would be an empty string: "".

Contributing

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead respository.

Code of Conduct

We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.

License

Psammead is Apache 2.0 licensed.