1.0.5 • Published 6 years ago

react-picture-component v1.0.5

Weekly downloads
16
License
MIT
Repository
-
Last release
6 years ago

react-picture-component

npm package

Simple abstraction for <picture /> for use in React applications. It imports the polyfill picturefill to support older browsers.

Install

  • npm install react-picture-component -S
  • or yarn add react-picture-component

Usage

import Picture from 'react-picture-component';
import React from 'react';

const images = {
  700: './images/cat-700.jpg',
  300: './images/cat-300.jpg',
  1200: './images/cat-1200.jpg',
};

export function MyApp() {
  return (
    <div>
      <Picture images={images} />
    </div>
  );
}

Props

  • images: Object with keys for the image size, and values for the image source.
  • alt: String
  • renderImage: optional render-prop Function to render a custom image component.

Usage with styled-components

You may want to leverage a styled component to render your img element. This can be achieved like so:

import Picture from 'react-picture-component';
import React from 'react';
import styled from 'styled-components';

const images = { ... };

const MyImage = styled.img`
  border: 2px solid gold;
  // etc...
`;

export function MyApp() {
  return (
    <div>
      <Picture
        images={images}
        renderImage={({src, alt }) => (
          <MyImage src={src} alt={alt} />
        )}
      />
    </div>
  );
}
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago