0.1.1 ā€¢ Published 5 years ago

filejet-react v0.1.1

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

FileJet - React integration

React library which provides an easy drop-in solution for your images.

Installation

npm install filejet-react --save

Example

import { FilejetProvider, Img } from 'filejet-react';
import React from 'react';

const filejetConfig = { storageId: 'abc123' };

function App() {
  return (
    <FilejetProvider config={filejetConfig}>
      <Img src="https://example.com/img.jpg" width={200} height={200} alt="..." />
    </FilejetProvider>
  );
}

Components

<FilejetProvider>

All components require <FilejetProvider> with the necessary config:

  • storageId: your storage ID (required)
  • maxDPR: maximum DPR, which srcsets should support (defaults to 2)

Example

<FilejetProvider config={{ storageId: 'abc123', maxDPR: 4 }}>
  <div>...</div>
</FilejetProvider>

<Img>

Use <Img> to render FileJet image.

Optionally, provide width or height or both to fetch the image of the right size. Source sets for high DPI devices will be generated automatically.

Properties

NameDescriptiontypeexample
srcfile ID or absolute path to external filestring, required"80c1ae98f9d020a80c1ae98f9dd4020a"
widthexpected width in pixelsnumber, optional200
heightexpected height in pixelsnumber, optional200
srcMutationcustom mutation - ignores width/heightstring, optionalresize_300x300,crop_200x200_10_10
srcSetMutationcustom srcset mutation - ignores width/heightobject, optional{ '200w': 'resize_200x200' }

šŸ’” Component also accepts all <img> attributes (alt, sizes, etc.) except srcset.

Example

<Img src="80c1ae98f9d020a80c1ae98f9dd4020a" width={200}>
<Img src="80c1ae98f9d020a80c1ae98f9dd4020a" height={200}>
<Img src="80c1ae98f9d020a80c1ae98f9dd4020a" width={200} height={200}>
<Img src="80c1ae98f9d020a80c1ae98f9dd4020a" srcMutation="fit_200x200">
<Img src="https://example.com/image.jpg" srcSetMutation={{ '1x': 'resize_10x10', '2x': 'crop_20x20'}}>

šŸš€ Powered by FileJet!