Socket
Socket
Sign inDemoInstall

filestack-react

Package Overview
Dependencies
1
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    filestack-react

React component wrapper for filestack-js


Version published
Maintainers
4
Install size
11.4 MB
Created

Changelog

Source

3.0.1 (2019-06-28)

  • Update demo dependencies

Readme

Source

filestack-react

React component which allow you to easily integrate powerful filestack-api into your app.


Table of Contents

Overview

filestack-react is a kind of wrapper on filestack-js sdk which allow you to integrate with filestack service in just a few lines of code. Almost all you can do with filestack-js you can do with this component.

Usage

Install it through NPM

npm install filestack-react

then just insert into your app

import ReactFilestack from 'filestack-react';

<ReactFilestack
  apikey={YOUR_API_KEY}
  onSuccess={(res) => console.log(res)}
/>

Props

KeyTypeRequiredDefaultDescription
apikeyStringtrueFilestack api key
actionStringfalse'pick'A method from Client class. One of 'transform','retrieve','metadata','storeUrl','upload','remove','pick','removeMetadata','preview','logout'
actionOptionsObjectfalseAn action (client method) specific options object eg. PickerOptions, TransformOptions etc.
componentDisplayModeObjectDetermines how will be wrapper component displayed
componentDisplayMode.typeStringfalse'button'It can be 'button', 'link' or 'immediate'
componentDisplayMode.customTextStringfalse'Pick file'If type is 'button' or 'link' you can set text for it
componentDisplayMode.customClassStringfalse'filestack-react'If type is 'button' or 'link' you can set class for it
onSuccessFunctionfalseresult => console.log(result)A function to be called after successful completed action
onErrorFunctionfalseerror => console.error(error)A function to be called when error occurs
clientOptionsObjectFilestack client options used for an every action
clientOptions.cnameStringfalseCheck cname
clientOptions.securitySecurityfalseCheck security
clientOptions.sessionCacheBooleanfalseCheck sessionCache
fileObjectfalseUse it to insert a file object for 'upload' action
sourceStringfalseUse it to pass for some actions handle or external url
customRenderFunctionfalseUse it if you need custom html structure

Examples

Picker with custom designed button

<ReactFilestack
  apikey={YOUR_API_KEY}
  actionOptions={PickerOptions}
  componentDisplayMode={{
      type: 'button',
      customText: 'Click here to open picker',
      customClass: 'some-custom-class'
  }}
  onSuccess={this.yourCallbackFunction}
/>

Picker with custom wrapper

<ReactFilestack
  apikey={YOUR_API_KEY}
  actionOptions={PickerOptions}
  customRender={({ onPick }) => (
    <div>
      <strong>Find an avatar</strong>
      <button onClick={onPick}>Pick</button>
    </div>
  )}
  onSuccess={this.yourCallbackFunction}
/>

Show picker directly after component is mounted

<ReactFilestack
  apikey={YOUR_API_KEY}
  componentDisplayMode={{
    type: 'immediate'
  }}/>

Show picker directly and embed it inside specific container

<ReactFilestack
  apikey={YOUR_API_KEY}
  componentDisplayMode={{
    type: 'immediate'
  }}
  actionOptions={{
    displayMode: "inline",
    container: "embedded"
  }}/>

Transformation of external url with security

<ReactFilestack
  apikey={YOUR_API_KEY}
  componentDisplayMode={{
    type: 'immediate'
  }}
  action='transform'
  actionOptions= {{
    resize: {
      width: 250
    },
    flip: true
  }}
  clientOptions={{
    security: {
      policy: 'YOUR_POLICY',
      signature: 'YOUR_SIGNATURE'
    }
  }}
  source='https://upload.wikimedia.org/wikipedia/commons/c/cf/Pears.jpg'
  onSuccess={(res) => console.log(res)}/>

filestack-js Client

If you need to use Client just try

import ReactFilestack, { client } from 'filestack-react';

SSR

If you need to use filestack-react with SSR project or site generators like Gatsby check some workarounds in this issues
issue57
issue65

Migration from 1.x.x and 2.x.x

One of the changes introduced in the new version are rethinked props that the component accepts, so that the use of the component is as straightforward as possible. Below you will find information about what happened to each of the options available in 2.x.x :

2.x.x3.0.0Comment
apikeyapikey
modeaction
optionsactionOptionsWe want to emphasize that this option is associated with 'action'
preloadN/ANow, component is at default preloading neccessary js assets, styles, images
filefile
onSuccessonSuccess
onErroronError
options.handlesourceHandle or url used by specific action is now stored in separate prop
options.urlsourceHandle or url used by specific action is now stored in separate prop
securityclientOptions.securityOptions used to initialize filestack client are now grouped in ‘clientOptions’
buttonTextcomponentDisplayMode.customTextUse componentDisplayMode option (see examples)
buttonClasscomponentDisplayMode.customClassUse componentDisplayMode option (see examples)
cnameclientOptions.cnameOptions used to initialize filestack client are now grouped in ‘clientOptions’
sessionCacheclientOptions.sessionCacheOptions used to initialize filestack client are now grouped in ‘clientOptions’
rendercustomRender
childrenN/AUse customRender instead

Live demo

Check demo at codepen https://codepen.io/Filestack/pen/KEpVdR

Development

The whole componenst is located inside src/ReactFilestack.jsx

After you add some changes just type

npm run build

Be sure that your change doesn't break existing tests and are compatible with linter

npm run test

npm run lint

Documentation

You can find info about avalaible options for actions (Client class methods) in https://filestack.github.io/filestack-js/

Contribution

Any your contributions or ideas are more than welcome. Please consider that we follow the conventional commits specification to ensure consistent commit messages and changelog formatting.

Future

Current ideas:

  • Better support for SSR, static site generator and isomorphic apps

Keywords

FAQs

Last updated on 28 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc