1.5.1 • Published 3 years ago

@stnew/responsive-image v1.5.1

Weekly downloads
16
License
ISC
Repository
github
Last release
3 years ago

@stnew/responsive-image

Responsive Image component that wraps the HTML picture element and handles lazy loading the media.

Props

PropsTypeOptionalDefaultDesc
sourcesSourceProps[]no (unless src is set)n/aObjects defining the media sources and the breakpoints at which they should be used
srcstringno (unless sources is set)n/aCan be used instead of sources to apply a single media source to the component
indexBy'min-width' or 'max-width'yes'min-width'Rule by which breakpoints are decided
indexUnit'px' or 'rem' or 'vw'yes'px'Unit used when parsing breakpoints
lazyTimeoutnumberyesn/aIf defined, this is the number of milliseconds before the image starts to load
lazybooleanyesfalseIf true, the image will load when the intersection-observer marks the element as "in view"
nativeLazybooleanyesfalseIf true, enables native lazy loading
rootMarginstringyes'500px'Root Margin for the intersection-observer
onLoadfunctionyesn/aCallback for when the image is loaded
altstringyesn/avalue for the alt tag for the img element
titlestringyesn/avalue for the title tag for the img element (will be used for alt if alt is not otherwise defined)

SourceProps

PropsTypeOptionalDesc
srcstringnoMedia source string
widthnumberyesScreen width at which to use this media source
isDefaultbooleanyesIf true, this media source will be used as default

Usage

import React from 'react'
import { ResponsiveImage } from '@stnew/responsive-image'

const sources = [
  {
    src: '/assets/stn-new-wide.png',
    width: 1200,
  },
  {
    src: '/assets/stn-new.png',
    width: 960,
    isDefault: true,
  },
  {
    src: '/assets/stn-new-narrow.png',
    width: 600,
  },
];

funtion MultipleSourcesExample() {
	return (
		<ResponsiveImage
      sources={sources}
      alt="something new graphic"
      title="this is something new"
    />
	)
}

funtion SingleSourceExample() {
	return (
		<ResponsiveImage
      src="/assets/stn-new.png"
      alt="something new graphic"
      title="this is something new"
    />
	)
}

intersection-observer: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)

1.5.1

3 years ago

1.5.0

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.0

5 years ago