npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@emd-cloud/react-components

v1.2.0

Published

Use the EMD Cloud components with one package

Downloads

190

Readme

EMD Cloud / React Components

Overview

The EMD Cloud React components provide a set of React components for interacting with the EMD Cloud platform. These components are designed to simplify working with EMD Cloud services in your React applications.

Getting Started

  1. Register on the EMD Cloud platform and create an application at https://console.cloud.emd.one.

  2. Obtain your application’s API token.

  3. Install the npm or yarn package: NPM

    npm install @emd-cloud/react-components

    Yarn

    yarn add @emd-cloud/react-components

That's it! The EMD Cloud React components are now ready to use.

Hooks

Uploader Hooks:

Hook: useUploader

Description:

This hook manages file uploads to the server using the tus-js-client library. It provides the ability to track the upload status and progress of files.

Parameters:

  • options: Uploader options containing:
    • apiUrl (string): API URL for file uploads.
    • app (string): application name.
  • integration (string, optional): integration identifier for uploads.
  • headers (object, optional): headers to be sent with the request.
  • retryDelays (array, optional): an array of delays for retry attempts in milliseconds. Default is [0, 3000, 5000, 10000, 20000].
  • onBeforeUpload (function): callback function called before the upload starts. It should return true if the upload should continue, or false if the upload should be canceled. Defaults to true.
  • onUpdate (function): callback function called when the status of file uploads is updated. Takes an array of files with updated upload status information.

Return Value: Returns an object with two properties:

  • uploadFiles (function): function to upload files. Takes an array of files to upload.
  • isProccess (boolean): flag indicating if there are active uploads in progress.

Example:

import { useUploader } from '@emd-cloud/react-components';

const MyUploaderComponent = () => {
  const { uploadFiles, isProccess } = useUploader({
    options: {
      apiUrl: 'example.com',
      app: 'myApp',
    },
    onUpdate: (files) => {
      console.log('Updated file status:', files);
    },
  });

  const handleUpload = (files) => {
    uploadFiles(files);
  };

  return (
    <div>
      <input type="file" multiple onChange={(e) => handleUpload(e.target.files)} />
      {isProccess && <p>Uploading files...</p>}
    </div>
  );
};

In this example, the useUploader hook is used for uploading files. The upload status can be tracked via onUpdate upon completion of the uploads.

Method: useDropzone

Description:

This hook implements dropzone functionality for uploading files. It allows handling drag-and-drop events and managing the drag state.

Parameters:

  • accept (object, optional): An object defining the acceptable file types for upload. By default, it is { '*': [] }, which means all file types are accepted.

  • onDragOver (function, optional): A drag event handler called when files are dragged over the upload area. Defaults to an empty function.

  • onDragLeave (function, optional): An event handler called when files leave the upload area. Defaults to an empty function.

  • onDrop (function, optional): An event handler called when files are dropped into the upload area. Defaults to an empty function.

  • onDroped (function): An event handler called when files are successfully dropped. Takes an array of uploaded files.

  • multiple (boolean, optional): A flag indicating if multiple file uploads are supported. Defaults to true.

  • disabled (boolean, optional): A flag disabling the ability to upload files. Defaults to false.

Return Value:

Returns an object with several properties:

  • rootProps (object): Properties to apply to the root element of the dropzone. Includes handlers for the onDragOver, onDragLeave, onDrop, and onClick events.

  • inputProps (object): Properties to apply to the <input type="file"> element. Contains settings for file selection.

  • open (function): A function to open the file selection dialog.

  • dragStatus (object): An object containing the drag state, such as isDraggingOver, which indicates whether the mouse pointer is over the dropzone.

Example:

import { useUploader, useDropzone } from '@emd-cloud/react-components';

const MyUploaderComponent = () => {
  const { uploadFiles } = useUploader({
    options: {
      apiUrl: 'example.com',
      app: 'myApp',
    },
    onUpdate: (files) => {
      console.log('Updated file status:', files);
    },
  });

  const { rootProps, inputProps, open } = useDropzone({
    accept: {
      'image/png': ['.png'],
      'image/jpeg': ['.jpg', '.jpeg'],
      'application/pdf': ['.pdf'],
    },
    onDroped: (files) => {
      uploadFiles(files);
    },
  });

  return (
    <div {...rootProps} style={{ border: '2px dashed #ccc', padding: '20px' }}>
      <input {...inputProps} />
      <button type="button" onClick={open}>Select Files</button>
      <p>Drag files here or click the button to upload.</p>
    </div>
  );
};

In this example, the useDropzone hook is used to create a dropzone, and the uploaded files are passed to uploadFiles from the useUploader hook. The user can drag files into the specified area or select files using the button.

Conclusion

This library will simplify the integration and use of EMD Cloud services in your React application.