1.0.1 โ€ข Published 5 months ago

@aniruddha1806/progress-tracker v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

React Progress Tracker

A flexible, customizable progress tracker component for React applications with TypeScript support. Perfect for multi-step forms, onboarding flows, checkout processes, and any step-by-step user journey.

Installation

npm install @aniruddha1806/progress-tracker

Features

  • ๐ŸŽจ Extensive customization options (colors, sizes, styles)
  • ๐Ÿ“ฑ Responsive design with multiple size options
  • ๐Ÿ”ง Custom step rendering support
  • ๐ŸŽญ Built-in icons and labels with sublabels
  • ๐Ÿ“Š Visual state management (active, completed, inactive)
  • ๐ŸŽจ CSS class and inline style support
  • ๐Ÿ“ TypeScript support with full type definitions
  • โ™ฟ Accessibility-friendly structure
  • ๐Ÿชถ Zero dependencies and lightweight

Quick Start

import ProgressTracker from '@aniruddha1806/progress-tracker';

function App() {
  const steps = [
    { 
      label: 'Account', 
      sublabel: 'Create your account',
      icon: '๐Ÿ‘ค' 
    },
    { 
      label: 'Profile', 
      sublabel: 'Complete your profile',
      icon: '๐Ÿ“' 
    },
    { 
      label: 'Verification', 
      sublabel: 'Verify your email',
      icon: 'โœ‰๏ธ' 
    },
    { 
      label: 'Complete', 
      sublabel: 'All done!',
      icon: 'โœ…' 
    }
  ];

  return (
    <ProgressTracker
      steps={steps}
      currentStep={1} // 0-indexed (step 2 is active)
    />
  );
}

Props

ProgressTrackerProps

PropTypeDefaultDescription
stepsStep[]requiredArray of step objects
currentStepnumberrequiredCurrent active step (0-indexed)
classNamestring""CSS class for container
stepClassNamestring""CSS class for step elements
labelClassNamestring""CSS class for step labels
sublabelClassNamestring""CSS class for step sublabels
iconClassNamestring""CSS class for step icons
connectorClassNamestring""CSS class for connectors
activeConnectorClassNamestring""CSS class for active connectors
inactiveConnectorClassNamestring""CSS class for inactive connectors
activeColorstring"#0074D9"Color for active/completed steps
inactiveColorstring"#E1E8ED"Color for inactive steps
showLabelsbooleantrueShow step labels
showConnectorsbooleantrueShow connectors between steps
size"small" \| "medium" \| "large""medium"Overall component size
renderCustomStepfunctionundefinedCustom step render function

Step Interface

interface Step {
  label: string;           // Step title
  sublabel?: string;       // Optional subtitle
  icon: React.ReactNode;   // Icon (emoji, SVG, component)
}

Examples

Basic Horizontal Progress

Simple horizontal progress tracker:

import ProgressTracker from '@aniruddha1806/progress-tracker';

function BasicExample() {
  const steps = [
    { label: 'Start', icon: '๐Ÿš€' },
    { label: 'Progress', icon: 'โšก' },
    { label: 'Complete', icon: '๐ŸŽ‰' }
  ];

  return (
    <ProgressTracker
      steps={steps}
      currentStep={1}
    />
  );
}

Custom Colors and Styling

Customize appearance with colors and CSS classes:

import ProgressTracker from '@aniruddha1806/progress-tracker';
import './custom-progress.css'; // Your custom CSS

function CustomStyledExample() {
  const steps = [
    { label: 'Design', icon: '๐ŸŽจ' },
    { label: 'Develop', icon: '๐Ÿ’ป' },
    { label: 'Test', icon: '๐Ÿงช' },
    { label: 'Deploy', icon: '๐Ÿš€' }
  ];

  return (
    <ProgressTracker
      steps={steps}
      currentStep={2}
      activeColor="#28a745"
      inactiveColor="#f8f9fa"
      size="large"
      connectorStyle="dashed"
      className="custom-progress"
      stepClassName="custom-step"
      labelClassName="custom-label"
    />
  );
}

CSS file (custom-progress.css):

.custom-progress {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 24px;
}

.custom-step {
  transition: transform 0.2s ease;
}

.custom-step:hover {
  transform: scale(1.05);
}

.custom-label {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  color: white;
}

With React Icons

Use popular icon libraries:

import ProgressTracker from '@aniruddha1806/progress-tracker';
import { 
  FaUser, 
  FaCreditCard, 
  FaShippingFast, 
  FaCheckCircle 
} from 'react-icons/fa';

function IconExample() {
  const steps = [
    { 
      label: 'Account', 
      sublabel: 'Sign up or login',
      icon: <FaUser /> 
    },
    { 
      label: 'Payment', 
      sublabel: 'Enter payment details',
      icon: <FaCreditCard /> 
    },
    { 
      label: 'Shipping', 
      sublabel: 'Choose delivery option',
      icon: <FaShippingFast /> 
    },
    { 
      label: 'Confirmation', 
      sublabel: 'Order complete',
      icon: <FaCheckCircle /> 
    }
  ];

  return (
    <ProgressTracker
      steps={steps}
      currentStep={1}
      activeColor="#007bff"
      size="large"
    />
  );
}

Different Sizes

Show all available sizes:

import ProgressTracker from '@aniruddha1806/progress-tracker';

function SizesExample() {
  const steps = [
    { label: 'Start', icon: '๐Ÿš€' },
    { label: 'Middle', icon: 'โšก' },
    { label: 'End', icon: '๐ŸŽ‰' }
  ];

  return (
    <div style={{ padding: '20px' }}>
      <h3>Small Size</h3>
      <ProgressTracker
        steps={steps}
        currentStep={1}
        size="small"
        activeColor="#dc3545"
      />
      
      <h3 style={{ marginTop: '40px' }}>Medium Size (Default)</h3>
      <ProgressTracker
        steps={steps}
        currentStep={1}
        size="medium"
        activeColor="#ffc107"
      />
      
      <h3 style={{ marginTop: '40px' }}>Large Size</h3>
      <ProgressTracker
        steps={steps}
        currentStep={1}
        size="large"
        activeColor="#28a745"
      />
    </div>
  );
}

TypeScript Usage

The component provides full TypeScript support:

import ProgressTracker, { Step, ProgressTrackerProps } from '@aniruddha1806/progress-tracker';
import { ReactNode } from 'react';

interface CustomStep extends Step {
  id: string;
  duration?: number;
  isOptional?: boolean;
}

interface WizardProps {
  steps: CustomStep[];
  onStepChange: (stepIndex: number) => void;
}

const CustomWizard: React.FC<WizardProps> = ({ steps, onStepChange }) => {
  const [currentStep, setCurrentStep] = useState<number>(0);

  const handleStepClick = (stepIndex: number): void => {
    setCurrentStep(stepIndex);
    onStepChange(stepIndex);
  };

  const renderCustomStep = (
    step: Step, 
    index: number, 
    isCompleted: boolean, 
    isActive: boolean
  ): ReactNode => {
    const customStep = step as CustomStep;
    
    return (
      <div
        key={customStep.id}
        onClick={() => handleStepClick(index)}
        style={{
          cursor: 'pointer',
          opacity: customStep.isOptional && !isCompleted ? 0.6 : 1
        }}
      >
        {/* Custom step rendering */}
      </div>
    );
  };

  const progressProps: ProgressTrackerProps = {
    steps,
    currentStep,
    renderCustomStep,
    activeColor: '#6366f1',
    size: 'large'
  };

  return <ProgressTracker {...progressProps} />;
};
1.0.1

5 months ago

1.0.0

7 months ago