CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mantine--nprogress

Navigation progress bar component for React applications with Mantine UI framework integration

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

imperative-progress-control.mddocs/

Imperative Progress Control

The imperative progress control API provides functions for programmatic control of progress state, enabling integration with routing libraries, async operations, and custom navigation flows.

Capabilities

Start Progress

Begins automatic progress increments with variable speed based on current progress value.

/**
 * Starts automatic progress increments using intervals
 * Progress speed varies: fast initially (10), then slower as it approaches completion
 */
function startNavigationProgress(): void;

Usage Examples:

import { startNavigationProgress } from "@mantine/nprogress";

// Start progress on navigation
function handleRouteChange() {
  startNavigationProgress();
}

// Integration with Next.js router
import { useRouter } from "next/router";

function useProgressOnRouteChange() {
  const router = useRouter();
  
  useEffect(() => {
    const handleStart = () => startNavigationProgress();
    router.events.on('routeChangeStart', handleStart);
    
    return () => router.events.off('routeChangeStart', handleStart);
  }, [router]);
}

Stop Progress

Stops automatic progress increments without changing current progress value.

/**
 * Stops automatic progress increments by clearing the interval
 * Progress value remains at current position
 */
function stopNavigationProgress(): void;

Usage Examples:

import { stopNavigationProgress } from "@mantine/nprogress";

// Stop progress on user action
function handleUserPause() {
  stopNavigationProgress();
}

// Conditional stopping
function handleConditionalStop(shouldStop: boolean) {
  if (shouldStop) {
    stopNavigationProgress();
  }
}

Set Progress Value

Sets progress to a specific value between 0 and 100.

/**
 * Sets progress to a specific value and makes progress bar visible
 * @param value - Progress value (automatically clamped to 0-100 range)
 */
function setNavigationProgress(value: number): void;

Usage Examples:

import { setNavigationProgress } from "@mantine/nprogress";

// Set specific progress value
setNavigationProgress(45);

// Track upload progress
function handleUploadProgress(progressEvent: ProgressEvent) {
  const percentComplete = (progressEvent.loaded / progressEvent.total) * 100;
  setNavigationProgress(percentComplete);
}

// Step-by-step progress
const steps = ['Loading', 'Processing', 'Finalizing'];
function updateStepProgress(currentStep: number) {
  const progress = ((currentStep + 1) / steps.length) * 100;
  setNavigationProgress(progress);
}

Increment Progress

Increases progress by the current step amount.

/**
 * Increases progress by the step amount (default 1)
 * Automatically handles completion and reset when reaching 100%
 */
function incrementNavigationProgress(): void;

Usage Examples:

import { incrementNavigationProgress } from "@mantine/nprogress";

// Manual progress increments
function handleTaskCompletion() {
  incrementNavigationProgress();
}

// Batch processing progress
async function processBatch(items: any[]) {
  for (const item of items) {
    await processItem(item);
    incrementNavigationProgress();
  }
}

Decrement Progress

Decreases progress by the current step amount.

/**
 * Decreases progress by the step amount, minimum value is 0
 */
function decrementNavigationProgress(): void;

Usage Examples:

import { decrementNavigationProgress } from "@mantine/nprogress";

// Handle progress reversal
function handleUndo() {
  decrementNavigationProgress();
}

// Error handling with progress rollback
function handleProcessingError() {
  decrementNavigationProgress();
  console.log("Process failed, rolling back progress");
}

Complete Progress

Completes progress with smooth animation and automatic cleanup.

/**
 * Sets progress to 100%, waits briefly, then hides and resets
 * Includes automatic cleanup of intervals and timeouts
 */
function completeNavigationProgress(): void;

Usage Examples:

import { completeNavigationProgress } from "@mantine/nprogress";

// Complete progress on successful navigation
function handleRouteChangeComplete() {
  completeNavigationProgress();
}

// Complete progress after async operation
async function handleAsyncOperation() {
  try {
    await performOperation();
    completeNavigationProgress();
  } catch (error) {
    resetNavigationProgress();
  }
}

// Integration with fetch requests
async function handleApiRequest() {
  startNavigationProgress();
  
  try {
    const response = await fetch('/api/data');
    const data = await response.json();
    completeNavigationProgress();
    return data;
  } catch (error) {
    resetNavigationProgress();
    throw error;
  }
}

Reset Progress

Immediately resets progress to 0 and hides the progress bar.

/**
 * Immediately resets progress to 0, hides progress bar, and cleans up
 * Clears all active intervals and timeouts
 */
function resetNavigationProgress(): void;

Usage Examples:

import { resetNavigationProgress } from "@mantine/nprogress";

// Reset on navigation error
function handleNavigationError() {
  resetNavigationProgress();
}

// Reset on component unmount
useEffect(() => {
  return () => resetNavigationProgress();
}, []);

Cleanup Resources

Clears all active intervals and timeouts without changing progress state.

/**
 * Clears active intervals and timeouts for resource cleanup
 * Progress value and visibility state remain unchanged
 */
function cleanupNavigationProgress(): void;

Usage Examples:

import { cleanupNavigationProgress } from "@mantine/nprogress";

// Manual cleanup before component unmount
function handleComponentCleanup() {
  cleanupNavigationProgress();
}

// Cleanup before starting new progress sequence
function handleNewSequence() {
  cleanupNavigationProgress();
  startNavigationProgress();
}

Usage Patterns

Router Integration

import { 
  startNavigationProgress, 
  completeNavigationProgress, 
  resetNavigationProgress 
} from "@mantine/nprogress";

// Next.js integration
router.events.on('routeChangeStart', startNavigationProgress);
router.events.on('routeChangeComplete', completeNavigationProgress);
router.events.on('routeChangeError', resetNavigationProgress);

// React Router integration (with history)
history.listen(() => {
  startNavigationProgress();
  // Complete when component loads
  setTimeout(completeNavigationProgress, 100);
});

Async Operation Tracking

async function trackAsyncOperation<T>(operation: () => Promise<T>): Promise<T> {
  startNavigationProgress();
  
  try {
    const result = await operation();
    completeNavigationProgress();
    return result;
  } catch (error) {
    resetNavigationProgress();
    throw error;
  }
}

// Usage
await trackAsyncOperation(async () => {
  const data = await fetchUserData();
  await processUserData(data);
  return data;
});

Manual Progress Control

// Step-by-step progress tracking
const totalSteps = 5;
let currentStep = 0;

function nextStep() {
  currentStep++;
  const progress = (currentStep / totalSteps) * 100;
  setNavigationProgress(progress);
  
  if (currentStep === totalSteps) {
    setTimeout(completeNavigationProgress, 500);
  }
}

docs

custom-store-creation.md

imperative-progress-control.md

index.md

navigation-progress-component.md

progress-state-management.md

tile.json