Utils

Pure utility functions for working with steps

The Utils object provides a set of pure functions for working with steps. These functions help you query and traverse step collections without modifying state or requiring stepper context.

Functions

FunctionDescriptionParametersReturns
getAllRetrieves all steps in the stepper.NoneAn array of all steps
getRetrieves a step by its ID.id: The ID of the step to retrieveThe step with the specified ID
getIndexRetrieves the index of a step by its ID.id: The ID of the step to retrieve the index forThe index of the step
getByIndexRetrieves a step by its index.index: The index of the step to retrieveThe step at the specified index
getFirstRetrieves the first step in the stepper.NoneThe first step
getLastRetrieves the last step in the stepper.NoneThe last step
getNextRetrieves the next step after the specified ID.id: The ID of the current stepThe next step
getPrevRetrieves the previous step before the specified ID.id: The ID of the current stepThe previous step
getNeighborsRetrieves the neighboring steps (previous and next) of the specified step.id: The ID of the current stepAn object containing the previous and next steps, or null if they do not exist

Usage Example

Here's a quick example of how you might use the Utils object in a React component:

import * as React from "react";
import {  } from "@stepperize/react";
 
// Define the stepper with the steps
const {  } = (
  { : "step1", : "Step 1" },
  { : "step2", : "Step 2" },
  { : "step3", : "Step 3" },
  { : "step4", : "Step 4" }
);
 
export function () {
  // Fetch all steps
  const  = .(); // Result: Array of all steps
 
  // Fetch the first and last steps
  const  = .(); // Result: { id: 'step1', name: 'Step 1' }
  const  = .(); // Result: { id: 'step4', name: 'Step 4' }
 
  // Get a step by ID
  const  = .("step3"); // Result: { id: 'step3', name: 'Step 3' }
 
  // Get the index of a step by ID
  const  = .("step2"); // Result: 1
 
  // Get a step by its index
  const  = .(2); // Result: { id: 'step3', name: 'Step 3' }
 
  // Get the next and previous steps
  const  = .("step1"); // Result: { id: 'step2', name: 'Step 2' }
  const  = .("step3"); // Result: { id: 'step2', name: 'Step 2' }
 
  // Get neighbors of a step
  const  = .("step2");
  // Result: { prev: { id: 'step1', name: 'Step 1' }, next: { id: 'step3', name: 'Step 3' } }
}
Edit on GitHub

Last updated on

On this page