1.1.15 • Published 9 months ago

@fuseloader/lite v1.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

FuseLoader

FuseLoader is a versatile and customizable file upload and processing component for React applications. It provides an easy-to-use interface for uploading and processing CSV, Excel, and other file types.

Installation

npm install @fuseloader/lite

Screenshot

FuseLoader Screenshot

Configuration Parameters

The FuseLoader component accepts the following configuration parameters:

ParameterTypeDefaultDescription
onFileUploadFunctionRequiredCallback function called when a file is successfully uploaded and processed. Receives (file, sheetData) as arguments.
onCloseFunctionOptionalCallback function called when the close button is clicked.
headerTemplateObjectOptionalTemplate for mapping CSV headers to specific keys.
formatValidationFunctionOptionalCustom function for additional file format validation.
onNotificationFunctionOptionalCustom function for handling notifications. Receives (message, type) as arguments.
allowedTypesArray['csv']Array of allowed file types. Options: 'csv', 'excel', 'xml', 'ods', 'any'.
maxSizenumber10 * 1024 * 1024Maximum allowed file size in bytes (default is 10MB).
themestring'light'Theme of the component. Options: 'light', 'dark'.
animationsObjectSee belowConfiguration for animations.
labelsObjectSee belowCustom labels for various elements.
brandColorsObjectSee belowCustom brand colors.
notificationOptionsObjectSee belowOptions for notifications.
showCloseIconbooleantrueWhether to show the close icon.
useCardStylebooleantrueWhether to use card styling.
templateObjectOptionalConfiguration for template download.
customCSSObjectOptionalCustom CSS styles for buttons and labels.
returnNotificationStringbooleanfalseWhether to return notification as a string instead of displaying it.
analyticsObjectOptionalConfiguration for analytics integration.

Animations Object

PropertyTypeDefaultDescription
dropZonebooleantrueEnable/disable drop zone animations.
processProgressbooleantrueEnable/disable process progress animations.
filePreviewbooleantrueEnable/disable file preview animations.

Labels Object

PropertyTypeDefaultDescription
titlestring'File Processor'Title of the component.
dropZoneTextstring'Drag and drop your file here'Text displayed in the drop zone.
browseTextstring'browse'Text for the browse file action.
maxSizeTextstring'Maximum file size: {size}'Text for maximum file size information.
processingTextstring'Processing your file...'Text displayed during file processing.
processButtonTextstring'Process File'Text for the process button.
downloadTemplateTextstring'Download Template'Text for the download template action.

Brand Colors Object

PropertyTypeDefaultDescription
primarystring'#3498db'Primary brand color.
secondarystring'#2ecc71'Secondary brand color.
accentstring'#e74c3c'Accent brand color.

Notification Options Object

PropertyTypeDefaultDescription
positionstring'bottom-right'Position of the notification. Options: 'top-right', 'top-left', 'bottom-right', 'bottom-left'.
durationnumber2000Duration of the notification in milliseconds.

Template Object

PropertyTypeDefaultDescription
enabledbooleanfalse
urlstring''URL of the template file.
filenamestring'template.csv'Filename for the downloaded template.

Analytics Object

PropertyTypeDefaultDescription
enabledbooleanfalseEnable/disable analytics tracking.
trackingIdstring''Google Analytics tracking ID.
  1. When using the FuseLoader component, users can enable Google Analytics by passing the configuration:
import { FuseLoader } from '@fuseloader/lite';

const App = () => {
  return (
    <FuseLoader
      onFileUpload={handleFileUpload}
      allowedTypes={['csv', 'excel']}
      maxSize={5 * 1024 * 1024}
      googleAnalytics={{
        enabled: true,
        trackingId: 'G-XXXXXXXXXX' // Replace with actual Google Analytics 4 Measurement ID
      }}
    />
  );
};
  1. With this configuration, the FuseLoader component will automatically track the following events:

  2. File Upload (Success and Error)

  3. File Processing (Success and Error)
  1. These events will appear in the Google Analytics 4 dashboard under the "Events" section.
  2. Users can create custom reports and analyze the data to gain insights into how their file upload component is being used.

Remember to remind users to replace 'G-XXXXXXXXXX' with their actual Google Analytics 4 Measurement ID.

Advanced Usage

More complex examples and use cases will be documented here. Here a sample of implementation

import React from 'react';
import { FuseLoader, SheetRow, FuseLoaderConfig } from '@fuseloader/lite';

function App() {
  const handleFileUpload = (file: File, sheetData: SheetRow[]) => {
    console.log('File uploaded:', file);
    console.log('Sheet data:', sheetData);
  };

  const handleNotification = (message: string, type: 'success' | 'error' | 'warning' | 'info') => {
    console.log(`Custom notification - ${type}: ${message}`);
  };

  const handleClose = () => {
    console.log('FuseLoader closed');
    // Implement your desired close behavior here
  };

  const customConfig: FuseLoaderConfig = {
    allowedTypes: ['csv', 'excel'],
    maxSize: 5 * 1024 * 1024, // 5MB
    theme: 'dark',
    animations: {
      dropZone: true,
      processProgress: true,
      filePreview: true,
    },
    labels: {
      title: "Custom File Upload",
      dropZoneText: "Drop your file here",
      browseText: "choose file",
      maxSizeText: "Max size: {size}",
      processingText: "Processing your file...",
      processButtonText: "Upload File",
      downloadTemplateText: "Download Template"
    },
    brandColors: {
      primary: '#9b59b6',
      secondary: '#f1c40f',
      accent: '#1abc9c',
    },
    notificationOptions: {
      position: 'top-right',
      duration: 100,
    },
    showCloseIcon: true,
    useCardStyle: true,
    template: {
      enabled: true,
      url: 'https://example.com/template.csv',
      filename: 'custom_template.csv'
    },
    customCSS: {
      button: {
        fontFamily: 'Arial, sans-serif',
        fontSize: '14px',
        letterSpacing: '0.5px',
      },
      labels: {
        fontSize: '14px',
        fontFamily: 'Roboto, sans-serif',
        lineHeight: '1.5',
      },
    },
    returnNotificationString: true,
  };

  return (
    <div className="min-h-screen p-4 space-y-8">
      <div className="flex flex-col items-center gap-8 max-w-3xl mx-auto">
        <FuseLoader
          onFileUpload={handleFileUpload}
          showCloseIcon={false}
          useCardStyle={false}
          allowedTypes={['csv']}
          maxSize={1 * 1024 * 1024} // 1MB
        />

        <FuseLoader
          onFileUpload={handleFileUpload}
          {...customConfig}
          onNotification={handleNotification}
          onClose={handleClose}
          formatValidation={(file: File) => {
            // Custom format validation logic
            return new Promise((resolve, reject) => {
              if (file.size > 1024 * 1024) { // 1MB
                reject(new Error('File size must be less than 1MB'));
              } else {
                resolve(true);
              }
            });
          }}
        />
      </div>
    </div>
  );
}

export default App;