>
)}
);
}
```
--------------------------------
### Full Example: Custom Step Indicator
Source: https://stepperize.vercel.app/docs/react/examples/basic
A comprehensive example demonstrating how to implement custom step indicators using render props within `Stepper.Indicator` for enhanced visual feedback.
```javascript
import { Stepper } from "stepperize";
const steps = [
{ id: "details", label: "Details" },
{ id: "plan", label: "Plan" },
{ id: "payment", label: "Payment" },
];
function CustomIndicatorStepper() {
return (
{ (step) => (
{ (state) => (
{state.index + 1}
) }
{step.label}
) }
Enter your details here.
Choose your plan.
Enter your payment information.
);
}
```
--------------------------------
### Complete Stepper Example
Source: https://stepperize.vercel.app/docs/react/api-references/primitives
This example demonstrates how to use the Stepper primitives to build a complete checkout stepper UI. It includes the list of steps, content for each step, and navigation actions. Ensure Stepper.Root is used to provide the stepper state.
```jsx
import React from "react"
import { defineStepper } from "@stepperize/react"
const { Stepper } = defineStepper(
{ id: "shipping", title: "Shipping" },
{ id: "payment", title: "Payment" },
{ id: "confirmation", title: "Confirmation" }
);
function CheckoutStepper() {
return (
{({ stepper }) => (
<>
{stepper.state.all.map((step) => (
{step.title}
))}
Shipping form here
Payment form here
Confirmation here
PreviousNext
>
)}
);
}
```
--------------------------------
### Install TanStack Form with Zod
Source: https://stepperize.vercel.app/docs/react/examples/forms
Install TanStack Form and Zod for form handling and validation.
```bash
pnpm add @tanstack/react-form zod
```
--------------------------------
### Install @stepperize/react with Bun
Source: https://stepperize.vercel.app/docs/react/installation
Use this command to add @stepperize/react to your project if you are using Bun as your package manager.
```bash
bun add @stepperize/react
```
--------------------------------
### Scoped Component - Props
Source: https://stepperize.vercel.app/docs/react/api-references/scoped
Details the available props for the Scoped component, including `initialStep` for setting the starting step and `initialMetadata` for pre-populating step-specific data. It also shows how to use these props in a practical example.
```APIDOC
## Scoped Component - Props
### Description
The `Scoped` component accepts several props to configure the initial state of the stepper.
### Props
Name| Type| Description
---|---|---
`initialStep`| `Get.Id`| Initial active step ID
`initialMetadata`| `Partial, Metadata>>`| Initial metadata per step
`children`| `React.ReactNode`| Content to render
### Usage with Props
```jsx
import React from "react";
import { defineStepper } from "@stepperize/react";
const { Scoped, useStepper } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" },
{ id: "last", title: "Last" }
);
export const MyScopedStepper = () => (
);
const StepContent = () => {
const stepper = useStepper();
return
Current: {stepper.state.current.data.title}
;
};
```
```
--------------------------------
### Full Example: Horizontal Stepper
Source: https://stepperize.vercel.app/docs/react/examples/basic
A complete example of a horizontal stepper, integrating all the necessary components for step definition, navigation, and content display.
```javascript
import { Stepper } from "stepperize";
const steps = [
{ id: "details", label: "Details" },
{ id: "plan", label: "Plan" },
{ id: "payment", label: "Payment" },
];
function HorizontalStepper() {
return (
{ (step) => (
{step.label}
) }
Enter your details here.
Choose your plan.
Enter your payment information.
);
}
```
--------------------------------
### Full Example: Vertical Stepper
Source: https://stepperize.vercel.app/docs/react/examples/basic
A complete example of a vertical stepper, demonstrating the use of the `orientation='vertical'` prop for a different layout.
```javascript
import { Stepper } from "stepperize";
const steps = [
{ id: "details", label: "Details" },
{ id: "plan", label: "Plan" },
{ id: "payment", label: "Payment" },
];
function VerticalStepper() {
return (
{ (step) => (
{step.label}
) }
Enter your details here.
Choose your plan.
Enter your payment information.
);
}
```
--------------------------------
### Install @stepperize/react with PNPM
Source: https://stepperize.vercel.app/docs/react/installation
Use this command to add @stepperize/react to your project if you are using PNPM as your package manager.
```bash
pnpm install @stepperize/react
```
--------------------------------
### Install @stepperize/react with NPM
Source: https://stepperize.vercel.app/docs/react/installation
Use this command to add @stepperize/react to your project if you are using NPM as your package manager.
```bash
npm install @stepperize/react
```
--------------------------------
### Install React Hook Form with Zod
Source: https://stepperize.vercel.app/docs/react/examples/forms
Install React Hook Form and the Zod resolver for validation.
```bash
pnpm add react-hook-form @hookform/resolvers zod
```
--------------------------------
### Install @stepperize/react with Yarn
Source: https://stepperize.vercel.app/docs/react/installation
Use this command to add @stepperize/react to your project if you are using Yarn as your package manager.
```bash
yarn add @stepperize/react
```
--------------------------------
### Stepper State and Navigation Example
Source: https://stepperize.vercel.app/docs/react/api-references/hook
Demonstrates accessing stepper state properties like `current`, `isFirst`, and `isLast`, and utilizing navigation methods such as `next()`, `prev()`, `goTo(id)`, and `reset()`.
```javascript
import React from "react";
import { defineStepper } from "@stepperize/react";
const { useStepper } = defineStepper(
{ id: "info", title: "Info" },
{ id: "review", title: "Review" },
{ id: "done", title: "Done" }
);
function NavExample() {
const stepper = useStepper();
return (
>
)}
);
}
```
--------------------------------
### Add Navigation Controls (next / prev / reset)
Source: https://stepperize.vercel.app/docs/react/examples/scoped
Implement navigation buttons using `stepper.state.isFirst`, `stepper.state.isLast`, and `stepper.navigation.next()`, `prev()`, `reset()`. This example shows conditional rendering for 'Back', 'Next', and 'Reset' buttons.
```javascript
import React from "react";
import { defineStepper } from "@stepperize/react";
const { Scoped, useStepper } = defineStepper(
{ id: "info", title: "Info" },
{ id: "review", title: "Review" },
{ id: "done", title: "Done" }
);
function StepNavigation() {
const stepper = useStepper();
return (
{stepper.state.isLast ? (
) : (
{!stepper.state.isFirst && (
)}
)}
);
}
```
--------------------------------
### Implement onBeforeTransition Hook
Source: https://stepperize.vercel.app/docs/react/api-references/hook
Use `stepper.lifecycle.onBeforeTransition` to run logic before a step transition. Return `false` to cancel the transition. This example shows a confirmation dialog before navigating back.
```javascript
import React from "react";
import { defineStepper } from "@stepperize/react";
const { useStepper } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" }
);
function MyStepper() {
const stepper = useStepper();
React.useEffect(() => {
const unsub = stepper.lifecycle.onBeforeTransition(async (ctx) => {
if (ctx.direction === "prev" && !window.confirm("Go back?")) return false;
});
return () => unsub();
}, [stepper]);
return (
);
}
```
--------------------------------
### Define and Use a Complete Stepper Component
Source: https://stepperize.vercel.app/docs/react/api-references/primitives
This example demonstrates how to define a fully-typed stepper component using `defineStepper` and render it with a list, content, and navigation controls. It includes imports for React and the `defineStepper` function.
```jsx
import React from "react"
import { defineStepper } from "@stepperize/react"
const { Stepper, useStepper } = defineStepper(
{ id: "account", title: "Account", description: "Create your account" },
{ id: "profile", title: "Profile", description: "Set up your profile" },
{ id: "complete", title: "Complete", description: "All done!" }
);
function OnboardingStepper() {
return (
{({ stepper }) => (
{/* Step list */}
{stepper.state.all.map((step) => (
);
}
export function ConformStepperForm() {
return (
);
}
```
--------------------------------
### Stepper.Root Component
Source: https://stepperize.vercel.app/docs/react/api-references/scoped
Explains `Stepper.Root` as a convenience wrapper that internally uses `Scoped` and provides access to the stepper instance via a render prop. It simplifies initial state setup using `initialStep` and `initialMetadata`.
```APIDOC
## Stepper.Root Component
### Description
`Stepper.Root` is a component that wraps your stepper content and provides the stepper instance through a render prop. It internally utilizes the `Scoped` component and accepts `initialStep` and `initialMetadata` props to configure the initial state.
### Usage
```jsx
import React from "react";
import { defineStepper } from "@stepperize/react";
const { Stepper, useStepper } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" }
);
export const MyStepper = () => (
{({ stepper }) => (
Current: {stepper.state.current.data.title}
)}
);
```
```
--------------------------------
### Scoped Stepper with Initial State
Source: https://stepperize.vercel.app/docs/react/api-references/scoped
Configure the initial step and metadata for a stepper using the `initialStep` and `initialMetadata` props on the Scoped component. This sets the starting point and pre-defined states for your stepper.
```jsx
import React from "react";
import { defineStepper } from "@stepperize/react";
const { Scoped, useStepper } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" },
{ id: "last", title: "Last" }
);
export const MyScopedStepper = () => (
);
const StepContent = () => {
const stepper = useStepper();
return
Current: {stepper.state.current.data.title}
;
};
```
--------------------------------
### Manage Step Metadata with set, get, and reset
Source: https://stepperize.vercel.app/docs/react/api-references/hook
Use `stepper.metadata.set(id, values)` to save metadata for a specific step, `stepper.metadata.get(id)` to retrieve it, and `stepper.metadata.reset(keepInitialMetadata?)` to clear it. You can also manage metadata for the current step directly.
```javascript
import React from "react";
import { defineStepper } from "@stepperize/react";
const { useStepper } = defineStepper(
{ id: "first", title: "First step" },
{ id: "second", title: "Second step" },
{ id: "last", title: "Last step" }
);
const MyStepperComponent = () => {
const stepper = useStepper();
const handleSave = () => {
stepper.metadata.set("first", { value: "saved" });
};
const meta = stepper.metadata.get("first");
return (
First step: {meta?.value}
);
};
```
--------------------------------
### Add Stepper with Description (Base UI)
Source: https://stepperize.vercel.app/docs/react/shadcn
Use this command to add a stepper component that includes descriptions for each step, using Base UI.
```bash
npx shadcn add https://stepperize.vercel.app/r/base-ui/stepper-with-description.json
```
--------------------------------
### Get Namespace Type Utilities
Source: https://stepperize.vercel.app/docs/react/api-references/types
Illustrates how to use the Get namespace for type inference of step IDs and step types based on a Steps array.
```typescript
import { defineStepper, Get } from "@stepperize/react";
const { steps } = defineStepper(
{ id: "shipping", title: "Shipping" },
{ id: "payment", title: "Payment" }
);
type StepId = Get.Id; // "shipping" | "payment"
type ShippingStep = Get.StepById; // { id: "shipping"; title: string }
```
--------------------------------
### Use Stepper with Initial Configuration (v5)
Source: https://stepperize.vercel.app/docs/react/migration/migrating-to-v5
When migrating to v5, the `useStepper` hook now expects an object with an `initial` property for configuration. This object includes `step`, `metadata`, and `statuses` for the initial state.
```javascript
const methods = useStepper({
initial: {
step: "first", // The ID of the initial step to display
metadata: { ... }, // The initial metadata for each step
statuses: { ... }, // The initial status for each step
}
});
```
--------------------------------
### Add Stepper with Description (Radix UI)
Source: https://stepperize.vercel.app/docs/react/shadcn
Use this command to add a stepper component that includes descriptions for each step, using Radix UI.
```bash
npx shadcn add https://stepperize.vercel.app/r/radix-ui/stepper-with-description.json
```
--------------------------------
### Wrap with Stepper.Root
Source: https://stepperize.vercel.app/docs/react/examples/basic
Use Stepper.Root to initialize the stepper component with the defined steps.
```javascript
{/* ... stepper content ... */}
```
--------------------------------
### Get Namespace Types
Source: https://stepperize.vercel.app/docs/react/api-references/types
Utility types for inferring information about steps based on their IDs and the overall Steps type.
```APIDOC
## Get namespace
Type| Description
---|---
`Get.Id`| Union of step IDs
`Get.StepById`| Step type for given ID
`Get.StepSansId`| Union of steps that are not `Id`
`Get.Switch`| Object type for `flow.switch` handlers: `{ [Id in Get.Id]?: (step: Get.StepById) => R }`
```typescript
import { defineStepper, Get } from "@stepperize/react";
const { steps } = defineStepper(
{ id: "shipping", title: "Shipping" },
{ id: "payment", title: "Payment" }
);
type StepId = Get.Id; // "shipping" | "payment"
type ShippingStep = Get.StepById; // { id: "shipping"; title: string }
```
```
--------------------------------
### useStepper Configuration: Initial State (v5 vs v6)
Source: https://stepperize.vercel.app/docs/react/migration/migrating-to-v6
v5 used a nested `initial` object for step, metadata, and statuses. v6 uses top-level `initialStep` and `initialMetadata`, and statuses are derived.
```javascript
useStepper({
initial: {
step: "second",
metadata: { first: { saved: true } },
statuses: { ... },
},
});
```
```javascript
useStepper({
initialStep: "second",
initialMetadata: { first: { saved: true } },
});
```
--------------------------------
### Custom Step Indicator with Step Index
Source: https://stepperize.vercel.app/docs/react/examples/basic
Customize the indicator for each step by providing a render prop to `Stepper.Indicator`. This example shows how to display the step index.
```javascript
{({ index }) => {index + 1}}
{step.label}
```
--------------------------------
### Add Stepper with Icons (Base UI)
Source: https://stepperize.vercel.app/docs/react/shadcn
Use this command to add a stepper component that includes icons for each step, using Base UI.
```bash
npx shadcn add https://stepperize.vercel.app/r/base-ui/stepper-with-icon.json
```
--------------------------------
### Use Stepper Hook
Source: https://stepperize.vercel.app/docs/react/api-references/hook
Use the useStepper hook to access the stepper instance and its API for state management and navigation. This example shows basic usage within a component.
```javascript
import React from "react";
import { defineStepper } from "@stepperize/react";
const { useStepper } = defineStepper(
{ id: "first", title: "First step" },
{ id: "second", title: "Second step" }
);
const MyStepperComponent = () => {
const stepper = useStepper();
return (
{stepper.state.current.data.title}
);
};
```
--------------------------------
### Stepper.Next Button Examples
Source: https://stepperize.vercel.app/docs/react/api-references/primitives
Use Stepper.Next for navigating to the next step. It's automatically disabled on the last step. Dynamic labels and custom click handlers with validation are supported.
```jsx
{/* Default behavior */}
Next
```
```jsx
{/* Dynamic label */}
{stepper.state.isLast ? "Finish" : "Next"}
```
```jsx
{/* Custom click with validation */}
{
const isValid = await validateCurrentStep();
if (isValid) {
stepper.navigation.next();
}
}}>
Continue
```
--------------------------------
### Stepper Separator with Dynamic Rendering
Source: https://stepperize.vercel.app/docs/react/api-references/primitives
Implement Stepper.Separator to visually divide steps. This example shows how to conditionally render the separator between items in a Stepper.List, ensuring the last separator is not displayed.
```jsx
{stepper.state.all.map((step, index) => (
...
{index < stepper.state.all.length - 1 && }
))}
```
--------------------------------
### Configure Initial Step and Metadata
Source: https://stepperize.vercel.app/docs/react/examples/scoped
Set the initial step and initial metadata for a stepper by passing `initialStep` and `initialMetadata` props to the `Scoped` component. This allows pre-populating state for specific steps.
```javascript
import React from "react";
import { defineStepper } from "@stepperize/react";
const { Scoped, useStepper } = defineStepper(
{ id: "info", title: "Info" },
{ id: "review", title: "Review" },
{ id: "done", title: "Done" }
);
function StepContent() {
const stepper = useStepper();
return
{/* content per step */}
;
}
function StepNavigation() {
const stepper = useStepper();
return
{/* buttons */}
;
}
function Example() {
return (
);
}
```
--------------------------------
### Add Stepper with Icons (Radix UI)
Source: https://stepperize.vercel.app/docs/react/shadcn
Use this command to add a stepper component that includes icons for each step, using Radix UI.
```bash
npx shadcn add https://stepperize.vercel.app/r/radix-ui/stepper-with-icon.json
```
--------------------------------
### Stepper.Root for Context Provision
Source: https://stepperize.vercel.app/docs/react/api-references/scoped
Utilize `Stepper.Root` as a convenient wrapper that internally uses `Scoped` to provide stepper context. It accepts `initialStep` and `initialMetadata` for setting initial state, offering an alternative to directly using `Scoped`.
```jsx
import React from "react";
import { defineStepper } from "@stepperize/react";
const { Stepper, useStepper } = defineStepper(
{ id: "first", title: "First" },
{ id: "second", title: "Second" }
);
export const MyStepper = () => (
{({ stepper }) => (