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

react-file-uploader-widget

v1.0.5

Published

React file uploader

Downloads

10

Readme

eGov upload widget

installation

npm install egov-upload-widget

import style

import 'egov-upload-widget/styles';

Avatar Uploader Component

Avatar Image Avatar Image Avatar Image

The Avatar Uploader component allows users to upload and display avatars in your React application.

Parameters

  • project: (string) Name of the project.
  • name: (string) Name of the component.
  • value: (string) Image URL of the avatar.
  • maxFileSize: (number) Maximum file size in bytes allowed for avatar uploads.
  • onChange: (function) Function called when the value of the component changes.
  • onDelete: (function) Delete Function trigger when delete icon clicked.
  • onClick: (function) Click Function to get current data.
  • customRender: (React component) Custom React component for rendering the avatar.
  • disabled: (function) disabled upload and delete.

Usage

import Avatar from 'egov-upload-widget/avatar';
//or
import Avatar from 'egov-upload-widget/avatar-circle';

<Avatar
  project="project_name"
  name="avatar"
  value="https://example.com/avatar.jpg"
  maxFileSize={1048576} // 1MB
  onChange={(e) => console.log(e.target.value)}
  onDelete={() => {}}
  customRender={<CustomAvatarComponent />}
/>
import React, { useState } from 'react';
import Avatar from 'egov-upload-widget/avatar';

const App = () => {
  const [value, setValue] = useState('');

  const onHandleChange = (e) => {
    setValue(e.target.value.url);
  };

  return (
    <div>
      <Avatar
        project="project_name"
        name="avatar"
        value={value}
        maxFileSize={5242880} // 5MB
        onchange={onHandleChange}
      />
    </div>
  );
};

export default App;

customRender Prop

The customRender prop allows you to specify a custom React component for rendering the avatar. This gives you full control over the appearance and behavior of the avatar component. The custom component will receive the following props:

  • onToggleMenu: (function) A function to toggle the menu display.
  • data: (any) Additional data to pass to the custom component.
  • progressPercentage: (number) Progress percentage of the avatar upload (0 to 100).
  • error: (string) Error message if avatar upload fails.
  • isShowMenu: (boolean) Flag indicating whether the menu is currently shown.
  • setIsShowMenu: (function) A function to toggle the menu display.
  • onHandleDelete: (function) A function to handle the deletion of the avatar.
  • MenuComponent: (React component) The menu component to be rendered alongside the avatar.

Example Usage

import React from 'react';

const CustomAvatarComponent = ({
  onToggleMenu,
  data,
  progressPercentage,
  error,
  isShowMenu,
  setIsShowMenu,
  onHandleDelete,
  MenuComponent
}) => {
  return (
    ...
  )
}

const App = () => {
  
  return (
    <Avatar
      project="project_name"
      name="avatar"
      value={avatarUrl}
      maxFileSize={5242880} // 5MB
      onchange={onHandleChange}
      customRender={(props) => (
        <CustomAvatarComponent />
      )}
    />
  );
};

export default App;

Single File Uploader Component

Avatar Image Avatar Image Avatar Image

The Single File Uploader component allows users to upload and display file in your React application.

Parameters

  • project: (string) Name of the project.
  • name: (string) Name of the component.
  • value: (object) data value for component.
  • maxFileSize: (number) Maximum file size in bytes allowed for file uploads.
  • onchange: (function) Function called when the value of the component changes.
  • onDelete: (function) Delete Function trigger when delete icon clicked.
  • onClick: (function) Click Function to get current data.
  • fileTypes: (function) Allowed mime types | default to all
  • customRender: (React component) Custom React component for rendering the file.
  • disabled: (function) disabled upload and delete.

value

  • url: (string) Url of file.
  • mime_type: (string) mime type of file.
  • file_name: (string) file name of file.
  • file_size: (string) file size of file.

Usage

import File from 'egov-upload-widget/file';

<File
  project="project_name"
  name="file"
  value={{
    file_name: 'file.jpg',
    url: 'https://example.com/file.jpg',
    mime_type: 'application/jpeg'
  }}
  maxFileSize={1048576} // 1MB
  onchange={(e) => console.log(e.target.value.url)}
  customRender={<CustomAvatarComponent />}
/>
import React, { useState } from 'react';
import File from 'egov-upload-widget/file';

const App = () => {
  const [value, setValue] = useState('');

  const onHandleChange = (e) => {
    setValue(e.target.value);
  };

  return (
    <div>
      <File
        project="project_name"
        name="file"
        value={value}
        maxFileSize={5242880} // 5MB
        onchange={onHandleChange}
      />
    </div>
  );
};

export default App;

customRender Prop

The customRender prop allows you to specify a custom React component for rendering the file. This gives you full control over the appearance and behavior of the file component. The custom component will receive the following props:

  • onToggleMenu: (function) A function to toggle the menu display.
  • data: (any) Additional data to pass to the custom component.
  • progressPercentage: (number) Progress percentage of the file upload (0 to 100).
  • error: (string) Error message if file upload fails.
  • isShowMenu: (boolean) Flag indicating whether the menu is currently shown.
  • setIsShowMenu: (function) A function to toggle the menu display.
  • onHandleDelete: (function) A function to handle the deletion of the file.
  • MenuComponent: (React component) The menu component to be rendered alongside the file.

Example Usage

import React from 'react';

const CustomFileComponent = ({
  onToggleMenu,
  data,
  progressPercentage,
  error,
  isShowMenu,
  setIsShowMenu,
  onHandleDelete,
  MenuComponent
}) => {
  return (
    ...
  )
}

const App = () => {
  
  return (
    <File
      project="project_name"
      name="file"
      value={value}
      maxFileSize={5242880} // 5MB
      onchange={onHandleChange}
      customRender={(props) => (
        <CustomFileComponent />
      )}
    />
  );
};

export default App;

Multiple File Uploader Component

Avatar Image Avatar Image Avatar Image

The Multiple File Uploader component allows users to upload and display files in your React application.

Parameters

  • project: (string) Name of the project.
  • name: (string) Name of the component.
  • value: (array) array of file object .
  • maxFileSize: (number) Maximum file size in bytes allowed for file uploads.
  • onchange: (function) Function called when the value of the component changes.
  • onDeleteItem: (function) Delete Function trigger when click delete icon clicked.
  • onClickItem: (function) Click Function trigger when content click and get current data and index.
  • fileTypes: (function) Allowed mime types | default to all
  • customRender: (React component) Custom React component for rendering the file.
  • disabled: (function) disabled upload and delete.
  • disabledOnDeleteItem: (function) disabled onDelete only.

value

  • url: (string) Url of file.
  • mime_type: (string) mime type of file.
  • file_name: (string) file name of file.
  • file_size: (string) file size of file.

Usage

import Files from 'egov-upload-widget/files';

<Files
  project="project_name"
  name="files"
  value={[
    {
      file_name: 'file.jpg',
      url: 'https://example.com/file.jpg',
      mime_type: 'application/jpeg'
    },
    {
      file_name: 'file2.jpg',
      url: 'https://example.com/file2.jpg',
      mime_type: 'application/jpeg'
    },
    {
      file_name: 'file3.pdf',
      url: 'https://example.com/file3.jpg',
      mime_type: 'application/pdf'
    }
  ]}
  maxFileSize={1048576} // 1MB
  onchange={(e) => {
    //array of files
    console.log(e.target.value)
  }}
  customRender={<CustomAvatarComponent />}
/>
import React, { useState } from 'react';
import Files from 'egov-upload-widget/files';

const App = () => {
  const [value, setValue] = useState('');

  const onHandleChange = (e) => {
    //array of files
    setValue(e.target.value);
  };

  return (
    <div>
      <Files
        project="project_name"
        name="files"
        value={value}
        maxFileSize={5242880} // 5MB
        onchange={onHandleChange}
      />
    </div>
  );
};

export default App;

customRender Prop

The customRender prop allows you to specify a custom React component for rendering the file. This gives you full control over the appearance and behavior of the file component. The custom component will receive the following props:

  • onToggleMenu: (function) A function to toggle the menu display.
  • data: (array) Additional data to pass to the custom component.
  • tmpData: (array) Additional temp data to pass to the custom component to indicate incoming file upload.
  • progressPercentage: (number) Progress percentage of the file upload (0 to 100).
  • error: (array) Error message if file upload fails.
  • isShowMenu: (boolean) Flag indicating whether the menu is currently shown.
  • setIsShowMenu: (function) A function to toggle the menu display.
  • onHandleDelete: (function) A function to handle the deletion of the file.
  • MenuComponent: (React component) The menu component to be rendered alongside the file.

Example Usage

import React from 'react';

const CustomFileComponent = ({
  onToggleMenu,
  data,
  progressPercentage,
  error,
  isShowMenu,
  setIsShowMenu,
  onHandleDelete,
  MenuComponent
}) => {
  return (
    ...
  )
}

const App = () => {
  
  return (
    <Files
      project="project_name"
      name="files"
      value={value}
      maxFileSize={5242880} // 5MB
      onchange={onHandleChange}
      customRender={(props) => (
        <CustomFileComponent />
      )}
    />
  );
};

export default App;