0.6.4 • Published 2 years ago

svelte-datocms v0.6.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Svelte-datocms

Progressive/responsive image component

<Image /> is a Svelte component specially designed to work seamlessly with DatoCMS’s responsiveImage GraphQL query that optimizes image loading for your sites.

This is a port to Svelte from react version.

Props

proptyperequireddescriptiondefault
dataResponsiveImage object:white_check_mark:The actual response you get from a DatoCMS responsiveImage GraphQL query.
fadeInDurationinteger:x:Duration (in ms) of the fade-in transition effect upoad image loading500
intersectionThresholdfloat:x:Indicate at what percentage of the placeholder visibility the loading of the image should be triggered. A value of 0 means that as soon as even one pixel is visible, the callback will be run. A value of 1.0 means that the threshold isn't0
lazyLoadBoolean:x:Wheter enable lazy loading or nottrue
explicitWidthBoolean:x:Wheter the image wrapper should explicitely declare the width of the image or keep it fluidfalse

The ResponsiveImage object

The data prop expects an object with the same shape as the one returned by responsiveImage GraphQL call. It's up to you to make a GraphQL query that will return the properties you need for a specific use of the <Image> component.

  • The minimum required properties for data are: aspectRatio, width, sizes, srcSet and src;
  • alt and title, while not mandatory, are all highly suggested, so remember to use them!
  • You either want to add the webpSrcSet field or specify { auto: format } in your imgixParams, to automatically use WebP images in browsers that support the format;
  • If you provide both the bgColor and base64 property, the latter will take precedence, so just avoiding querying both fields at the same time, it will only make the response bigger :wink:

Here's a complete recap of what responsiveImage offers:

propertytyperequireddescription
aspectRatiofloat:white_check_mark:The aspect ratio (width/height) of the image
widthinteger:white_check_mark:The width of the image
heightinteger:white_check_mark:The height of the image
sizesstring:white_check_mark:The HTML5 sizes attribute for the image
srcSetstring:white_check_mark:The HTML5 srcSet attribute for the image
srcstring:white_check_mark:The fallback src attribute for the image
webpSrcSetstring:x:The HTML5 srcSet attribute for the image in WebP format, for browsers that support the format
altstring:x:Alternate text (alt) for the image
titlestring:x:Title attribute (title) for the image
bgColorstring:x:The background color for the image placeholder
base64string:x:A base64-encoded thumbnail to offer during image loading

Blurhash Component

<Blurhash/> is a Svelte component to display an image placeholder from blurhash string.

Props

proptyperequireddescriptiondefault
hashstring:white_check_mark:blurhash string of the image
widthnumber:x:x resolution of the drawed canvas32
heightnumber:x:x resolution of the drawed canvas32
punchnumber:x:punch is intesivity of the color effect after decoding1

More coming soon...

Contributing

Contributions are always welcome!

0.6.4

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.1

3 years ago

0.5.7

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.4-a

3 years ago

0.5.4

3 years ago

0.5.3-a

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago