1.3.2 • Published 10 months ago

egov-upload-widget v1.3.2

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

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;
1.3.2

10 months ago

1.3.1

10 months ago

1.3.0

10 months ago

1.2.0

10 months ago

1.1.9

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.12

11 months ago

1.1.11

11 months ago

1.1.10

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.26

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.24

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.23

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago