### Quick Start ink-stepper Example Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/index.md A minimal example demonstrating how to use the ink-stepper component to create a three-step wizard. It utilizes React, Ink, and the Stepper and Step components. ```tsx import React from 'react'; import { render, Text } from 'ink'; import { Stepper, Step } from 'ink-stepper'; function App() { return ( console.log('All done!')} onCancel={() => console.log('Cancelled.')} > Welcome to the wizard! Press Enter to continue. This is step 2. Ready to submit? Press Enter to finish. ); } render(); ``` -------------------------------- ### Install ink-stepper using npm, jsr, pnpm, or bun Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Provides commands for installing the ink-stepper package using various package managers like npm, jsr, pnpm, and bun. Ensure you have the respective package manager installed. ```bash # npm npm install ink-stepper # jsr npx jsr add @archcorsair/ink-stepper # pnpm pnpm add ink-stepper # bun bun add ink-stepper ``` -------------------------------- ### Install ink-stepper with NPM Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/index.md Installs the ink-stepper package using various package managers. Supported managers include npm, pnpm, yarn, bun, and deno. ```bash npm install ink-stepper ``` ```bash pnpm add ink-stepper ``` ```bash yarn add ink-stepper ``` ```bash bun add ink-stepper ``` ```bash deno add npm:ink-stepper ``` -------------------------------- ### Basic Stepper Setup with Ink-Stepper Source: https://context7.com/archcorsair/ink-stepper/llms.txt Demonstrates a simple multi-step wizard using ink-stepper with automatic progress tracking and keyboard navigation. It requires the 'ink-stepper' and 'ink' libraries. The wizard progresses through defined steps and handles completion or cancellation events. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box } from "ink"; import { render } from "ink"; function App() { return ( { console.log("Wizard completed!"); process.exit(0); }} onCancel={() => { console.log("Wizard cancelled"); process.exit(1); }} > Welcome to the setup wizard! Press Enter to continue Configure your settings here Review your selections ); } render(); ``` -------------------------------- ### Install ink-stepper with JSR Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/index.md Installs the ink-stepper package from JSR using various package managers. Supported managers include npm, pnpm, yarn, bun, and deno. ```bash npx jsr add @archcorsair/ink-stepper ``` ```bash pnpm i jsr:@archcorsair/ink-stepper ``` ```bash yarn add jsr:@archcorsair/ink-stepper ``` ```bash bunx jsr add @archcorsair/ink-stepper ``` ```bash deno add jsr:@archcorsair/ink-stepper ``` -------------------------------- ### Example Usage of Step Component in React Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/components.md Demonstrates how to use the `` component to define a single step within a stepper. It shows how to provide a name, content, and a condition to control step progression using the `canProceed` prop. ```tsx Please verify your identity. ``` -------------------------------- ### Dynamic Step Rendering with Ink-Stepper (React/TSX) Source: https://context7.com/archcorsair/ink-stepper/llms.txt This example demonstrates how to create a dynamic stepper where steps are conditionally rendered based on user selection or state. It utilizes React's useState hook to manage the visibility of steps and the 'ink-stepper' library for the Stepper and Step components. The example includes a wrapper component for grouping steps, conditional steps based on a boolean state, and dynamic steps based on an array of features. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box } from "ink"; import { useState } from "react"; function DynamicWizard() { const [needsAdvanced, setNeedsAdvanced] = useState(false); const [features, setFeatures] = useState([]); // Wrapper component for grouping steps const StepGroup = ({ children }: { children: React.ReactNode }) => { return <>{children}; }; return ( console.log({ features, needsAdvanced })}> Welcome! Let's get started. {({ goNext }) => ( Select installation mode: { setNeedsAdvanced(false); goNext(); }} > [ Basic ] { setNeedsAdvanced(true); goNext(); }} > [ Advanced ] )} {/* Conditional step - only shown for advanced mode */} {needsAdvanced && ( Advanced configuration options... )} {/* Dynamic steps based on feature selection */} {features.includes("database") && ( Configure database settings )} {features.includes("api") && ( Configure API endpoints )} Review your selections: Mode: {needsAdvanced ? "Advanced" : "Basic"} Features: {features.join(", ") || "None"} ); } ``` -------------------------------- ### Lifecycle Hooks with Ink Stepper Source: https://context7.com/archcorsair/ink-stepper/llms.txt Utilize `onEnterStep` and `onExitStep` callbacks to execute logic during step transitions. This example demonstrates tracking analytics when entering a step and potentially saving drafts or showing confirmation dialogues when exiting a step. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text } from "ink"; import { useState } from "react"; function LifecycleExample() { const [drafts, setDrafts] = useState>({}); const [analytics, setAnalytics] = useState([]); const saveDraft = async (step: number) => { // Simulate saving draft data setDrafts(prev => ({ ...prev, [step]: { timestamp: Date.now() } })); await new Promise(resolve => setTimeout(resolve, 500)); }; const trackEvent = (step: number) => { setAnalytics(prev => [...prev, `entered_step_${step}`]); }; const confirmLeaveWithChanges = async (step: number): Promise => { // In real app, show confirmation dialog const hasUnsavedChanges = Math.random() > 0.5; if (hasUnsavedChanges) { console.log("Saving changes before leaving..."); await saveDraft(step); } return true; // Allow navigation }; return ( console.log("Complete!", { drafts, analytics })} onEnterStep={trackEvent} onExitStep={confirmLeaveWithChanges} onStepChange={(step) => console.log("Step changed to:", step)} > First page with auto-save Second page with tracking Third page ); } ``` -------------------------------- ### Synchronous Validation with canProceed in ink-stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Shows how to implement synchronous validation for step navigation using the `canProceed` prop in ink-stepper. The example demonstrates disabling advancement until a condition (e.g., input field not empty) is met. ```tsx import { useState } from "react"; import { Stepper, Step } from "ink-stepper"; function App() { const [isValid, setIsValid] = useState(false); return ( {(ctx) => ( setIsValid(value.length > 0)} onSubmit={ctx.goNext} /> )} ); } ``` -------------------------------- ### Stepper Component for Wizard Flow Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/basic-usage.md The Stepper component orchestrates the wizard flow. It requires an onComplete callback that triggers when the user finishes the last step, and an onCancel callback for when the user cancels on the first step. An optional initialStep prop can set the starting step. ```tsx process.exit(0)} onCancel={() => process.exit(1)} > {/* Steps go here */} ``` -------------------------------- ### Synchronous Validation with Ink Stepper Source: https://context7.com/archcorsair/ink-stepper/llms.txt Implement synchronous validation to control step progression using the `canProceed` prop. This example uses `ink-stepper` and `ink-text-input` to validate user input for name and email before allowing the user to proceed. It ensures that required fields are filled and email format is valid. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box } from "ink"; import { useState } from "react"; import TextInput from "ink-text-input"; function UserInput() { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const isValidEmail = (email: string) => { return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); }; return ( console.log({ name, email })}> 0}> {({ goNext }) => ( Enter your name: {name.length === 0 && ( Name is required )} )} {({ goNext }) => ( Enter your email: {email && !isValidEmail(email) && ( Invalid email format )} )} Name: {name} Email: {email} ); } ``` -------------------------------- ### Asynchronous Validation with Ink Stepper Source: https://context7.com/archcorsair/ink-stepper/llms.txt Handle asynchronous validation, such as server-side checks, with loading states using the `canProceed` prop and `isValidating` state. This example demonstrates how to check username availability with a simulated API call, showing a loading indicator during the check. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box, Spinner } from "ink"; import { useState } from "react"; import TextInput from "ink-text-input"; function AsyncValidation() { const [username, setUsername] = useState(""); const checkUsernameAvailable = async () => { // Simulate API call await new Promise(resolve => setTimeout(resolve, 1500)); const taken = ["admin", "root", "user"]; return !taken.includes(username.toLowerCase()); }; return ( console.log("Username:", username)}> 0 ? checkUsernameAvailable : false} > {({ goNext, isValidating }) => ( Choose a username: {isValidating && ( Checking availability... )} {!isValidating && username.length === 0 && ( Username cannot be empty )} )} Username "{username}" is available! ); } ``` -------------------------------- ### Execute logic on entering a step using onEnterStep in React Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/lifecycle.md The `onEnterStep` callback is triggered when the active step in the `Stepper` component changes. It receives the index of the new step and is useful for tracking navigation or triggering step-specific actions. This example logs the navigation and tracks a view in an analytics service. ```tsx { console.log(`Navigated to step ${stepIndex}`); analytics.trackView(`step_${stepIndex}`); }} > {/* ... */} ``` -------------------------------- ### Controlled Stepper Mode with External State Management in Ink Source: https://context7.com/archcorsair/ink-stepper/llms.txt This example demonstrates how to use the controlled mode of `ink-stepper` to manage the stepper's current step externally. This is useful for integrating with external state management solutions or routing. The `step` prop controls the active step, and `onStepChange` allows the parent component to react to step changes. External buttons are provided to jump to specific steps and reset the stepper. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box } from "ink"; import { useState, useEffect } from "react"; function ControlledStepper() { const [currentStep, setCurrentStep] = useState(0); const [history, setHistory] = useState([0]); useEffect(() => { // Log step changes console.log("Current step:", currentStep); }, [currentStep]); const handleStepChange = (step: number) => { setCurrentStep(step); setHistory(prev => [...prev, step]); }; // External navigation controls const jumpToReview = () => setCurrentStep(2); const resetToStart = () => setCurrentStep(0); return ( [Skip to Review] " [Reset] console.log("History:", history)} > Introduction (externally controlled) Setup configuration Review and finish Navigation history: {history.join(" → ")} ); } ``` -------------------------------- ### Control Ink Stepper State with `step` Prop (React) Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/controlled-mode.md This React example demonstrates how to use the `step` prop to control the active step in the Ink Stepper component and the `onStepChange` callback to update the external state. It requires React's `useState` hook and the `Stepper` and `Step` components from 'ink-stepper'. The input is the current step index and the output is the updated step index via the callback. ```tsx import { useState } from 'react'; import { Stepper, Step } from 'ink-stepper'; function App() { const [currentStep, setCurrentStep] = useState(0); return ( { // You can intercept or modify the change here if needed setCurrentStep(newStep); }} onComplete={() => console.log('Done')} > Step A Step B Step C ); } ``` -------------------------------- ### Coordinate Input with Ink Stepper in React (TypeScript) Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/input-coordination.md This example demonstrates using the `useStepperInput` hook from `ink-stepper` within a custom component to disable Stepper navigation when the component has focus. This prevents accidental step changes when interacting with elements like `TextInput`. It uses `onFocus` to call `disableNavigation` and `onBlur` to call `enableNavigation`. ```tsx import { useStepperInput } from 'ink-stepper'; import { TextInput } from 'ink-text-input'; // hypothetically import { useState } from 'react'; function MyInput() { const { disableNavigation, enableNavigation } = useStepperInput(); const [value, setValue] = useState(''); return ( { // Handle submission logic here // Then potentially manually trigger goNext() }} /> ); } ``` -------------------------------- ### Prevent navigation by returning false from onExitStep in React Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/lifecycle.md Navigation can be cancelled by returning `false` from the `onExitStep` callback. This is useful for implementing validation checks, ensuring that a user cannot proceed to the next step until certain conditions are met. The example shows how to prevent navigation from step 0 if a form is not valid. ```tsx { if (step === 0 && !formIsValid) { console.log('Cannot leave step 0 yet!'); return false; } return true; }} > {/* ... */} ``` -------------------------------- ### Basic Usage of ink-stepper Component in React Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Demonstrates the fundamental usage of the Stepper and Step components from ink-stepper within a React application. It shows how to define steps, their names, and associated content, along with navigation callbacks. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text } from "ink"; function App() { return ( process.exit(0)} onCancel={() => process.exit(1)}> {(ctx) => ( )} {(ctx) => ( )} ); } ``` -------------------------------- ### Step Context and Manual Navigation in Ink-Stepper Source: https://context7.com/archcorsair/ink-stepper/llms.txt Illustrates how to use the render prop pattern within ink-stepper to access step context, including navigation functions (goNext, goBack) and step metadata (currentStep, totalSteps, isFirst, isLast). This allows for custom navigation logic and dynamic UI updates based on the wizard's state. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box } from "ink"; import { useState } from "react"; function ThemeSelector() { const [theme, setTheme] = useState("dark"); return ( process.exit(0)}> {({ goNext, goBack, currentStep, totalSteps, isFirst, isLast }) => ( Step {currentStep + 1} of {totalSteps} Select theme: {theme} setTheme("dark")} > [ Dark ] setTheme("light")} > [ Light ] {!isFirst && ( < Back )} {isLast ? "Finish" : "Next >"} )} {({ goBack }) => ( You selected: {theme} < Back to change )} ); } ``` -------------------------------- ### Step Context for Manual Navigation Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/basic-usage.md The Step component supports a function-as-child pattern to access StepContext, enabling programmatic control over navigation. This context provides functions like goNext, goBack, and goTo, along with status flags like isLast. ```tsx {({ goNext, goBack, isLast, }) => ( Custom controls: [ Next > ] )} ``` -------------------------------- ### Accessing Stepper Context with useStepperContext Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Demonstrates advanced usage by accessing the full stepper context using the `useStepperContext` hook. This provides access to `stepContext` and `currentStepId` for custom step content implementations. ```tsx import { useStepperContext } from "ink-stepper"; function CustomStepContent() { const { stepContext, currentStepId } = useStepperContext(); return ( Step {stepContext.currentStep + 1} ); } ``` -------------------------------- ### Lifecycle Hooks in Ink-Stepper (onEnterStep, onExitStep) Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Illustrates the usage of `onEnterStep` and `onExitStep` lifecycle hooks in Ink-Stepper. These hooks allow executing logic when a user enters or exits a step, with `onExitStep` supporting asynchronous operations and navigation cancellation. ```tsx { analytics.track(`entered_step_${step}`); }} onExitStep={async (step) => { // Save draft before leaving await saveDraft(step); return true; // Allow navigation }} > ... ``` ```tsx { if (hasUnsavedChanges) { return confirm("Discard changes?"); } return true; }} > ... ``` -------------------------------- ### Ink-Stepper Exports: Components, Hooks, and Types Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Lists the main exports from the 'ink-stepper' library, including components (`Stepper`, `Step`), hooks (`useStepperContext`, `useStepperInput`), and various TypeScript types for props and context values. ```tsx // Components export { Stepper, Step } from "ink-stepper"; // Hooks export { useStepperContext, useStepperInput } from "ink-stepper"; // Types export type { StepperProps, StepProps, StepContext, ProgressContext, StepperMarkers, StepperContextValue, RegisteredStep, UseStepperInputReturn, } from "ink-stepper"; ``` -------------------------------- ### StepContext Interface for ink-stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Illustrates the StepContext interface provided by ink-stepper, detailing the available methods and properties for interacting with the current step. This context is passed to step content when using the render function pattern. ```typescript interface StepContext { goNext: () => void; // Navigate to next step (respects canProceed) goBack: () => void; // Navigate to previous step goTo: (step: number) => void; // Jump to specific step (zero-based) cancel: () => void; // Cancel the wizard currentStep: number; // Current step index (zero-based) totalSteps: number; // Total number of steps isFirst: boolean; // Whether this is the first step isLast: boolean; // Whether this is the last step isValidating: boolean; // Whether async validation is in progress } ``` -------------------------------- ### Step Component Definition Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/basic-usage.md The Step component defines individual pages within the stepper wizard. Each step must have a unique 'name' prop, which is displayed in the progress bar. Content for the step is placed as children of the Step component. ```tsx Step content goes here. ``` -------------------------------- ### Customize Ink Stepper Progress Bar Rendering Source: https://context7.com/archcorsair/ink-stepper/llms.txt Allows for custom visualization of stepper progress. Includes options for custom markers, a completely custom progress renderer function, or hiding the progress bar entirely. Dependencies include 'ink-stepper' and 'ink'. ```tsx import { Stepper, Step } from "ink-stepper"; import { Text, Box } from "ink"; import type { ProgressContext } from "ink-stepper"; // Example 1: Custom markers function CustomMarkersExample() { return ( process.exit(0)} markers={{ completed: "[✓]", current: "[→]", pending: "[ ]" }} > Installing dependencies... Configuring settings... Building project... ); } // Example 2: Completely custom progress renderer function CustomProgressExample() { const renderProgress = ({ currentStep, steps }: ProgressContext) => { return ( Progress: {currentStep + 1}/{steps.length} {steps.map((step, idx) => ( {step.completed && ✓ {step.name}} {step.current && → {step.name}} {!step.completed && !step.current && ( {step.name} )} ))} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ); }; return ( process.exit(0)} renderProgress={renderProgress} > Getting started... Processing... Finishing up... ); } // Example 3: Hide progress bar entirely function NoProgressExample() { return ( process.exit(0)} showProgress={false} > No progress bar shown Clean interface ); } ``` -------------------------------- ### Async Validation in Ink-Stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Demonstrates how to use asynchronous functions for server-side validation within a stepper step. The `isValidating` flag from `StepContext` is utilized to display loading states during validation. ```tsx function App() { const validateEmail = async () => { const response = await fetch(`/api/validate?email=${email}`); return response.ok; }; return ( {( { goNext, isValidating } ) => ( {isValidating && Validating...} )} ); } ``` -------------------------------- ### Input Coordination with useStepperInput Hook Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Shows how to use the `useStepperInput` hook to prevent keyboard conflicts with stepper navigation. This is useful when inputs like `TextInput` are focused, disabling default navigation keys like Enter or Escape. ```tsx import { useStepperInput } from "ink-stepper"; function EmailInput() { const { disableNavigation, enableNavigation } = useStepperInput(); const [value, setValue] = useState(""); return ( ); } ``` -------------------------------- ### Integrate Custom Components with Ink Stepper Context Source: https://context7.com/archcorsair/ink-stepper/llms.txt Enables building custom components that interact with the stepper's internal state, such as navigation buttons or step indicators. Utilizes the `useStepperContext` hook. Requires 'ink-stepper' and 'ink'. ```tsx import { Stepper, Step, useStepperContext } from "ink-stepper"; import { Text, Box } from "ink"; function CustomNavigationButtons() { const { stepContext, currentStepId } = useStepperContext(); if (!stepContext) return null; return ( ← Previous | {stepContext.isLast ? "Finish" : "Next →"} | Cancel ); } function StepIndicator() { const { stepContext } = useStepperContext(); if (!stepContext) return null; return ( Step {stepContext.currentStep + 1} of {stepContext.totalSteps} {stepContext.isValidating && " (validating...)"} ); } function App() { return ( console.log("Done!")} keyboardNav={false} // Disable default keyboard nav > Content for page 1 Content for page 2 Final page ); } ``` -------------------------------- ### Controlled Mode with Step Prop Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Demonstrates how to control the stepper's current step externally using the `step` prop and update it via `onStepChange`. This is useful for integrating with external state management solutions. ```tsx function App() { const [currentStep, setCurrentStep] = useState(0); return ( ... ... ); } ``` -------------------------------- ### Wrapped and Nested Steps in Ink-Stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Illustrates how `Step` components can be wrapped in custom components, fragments, or conditionally rendered. This allows for flexible structuring of stepper content. ```tsx const StepGroup = ({ children }) => <>{children}; This works! {showOptional && ( Conditional step )} ``` -------------------------------- ### ProgressContext Interface for ink-stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Defines the ProgressContext interface used by ink-stepper for custom progress bar rendering. It provides information about the current step and the status of all steps. ```typescript interface ProgressContext { currentStep: number; steps: Array<{ name: string; completed: boolean; current: boolean; }>; } ``` -------------------------------- ### useStepperContext Hook Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/hooks.md The `useStepperContext` hook provides access to the internal Stepper context. This is particularly useful for creating deeply nested components that require control over the wizard's state. ```APIDOC ## `useStepperContext` Hook ### Description A hook to access the internal Stepper context. Useful for building deeply nested components that need to control the wizard. ### Usage ```tsx import { useStepperContext } from 'ink-stepper'; const { stepContext, currentStepId } = useStepperContext(); ``` ### Returns - `StepperContextValue` - An object containing the Stepper's internal context and current step ID. (Refer to Types for detailed structure). ``` -------------------------------- ### useStepperInput Hook Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/hooks.md The `useStepperInput` hook is designed to coordinate input focus with Stepper keyboard navigation. It is recommended for use within custom input components to avoid potential keyboard conflicts. ```APIDOC ## `useStepperInput` Hook ### Description A hook for coordinating input focus with Stepper keyboard navigation. Use this in custom input components to prevent keyboard conflicts. ### Usage ```tsx import { useStepperInput } from 'ink-stepper'; const { disableNavigation, enableNavigation, isNavigationDisabled } = useStepperInput(); ``` ### Returns - **`disableNavigation`** (`() => void`) - Disables global Stepper navigation (Enter/Escape). - **`enableNavigation`** (`() => void`) - Re-enables global Stepper navigation. - **`isNavigationDisabled`** (`boolean`) - Current status of navigation. ``` -------------------------------- ### StepContext Interface in TypeScript Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/types.md Defines the context object passed to the render function of a `` component or accessible via `useStepperContext().stepContext`. It provides methods for navigating steps (goNext, goBack, goTo, cancel) and properties for the current step's state (currentStep, totalSteps, isFirst, isLast, isValidating). ```typescript interface StepContext { /** Navigate to the next step (respects canProceed) */ goNext: () => void; /** Navigate to the previous step */ goBack: () => void; /** Jump to a specific step by index (zero-based) */ goTo: (step: number) => void; /** Cancel the wizard (calls onCancel) */ cancel: () => void; /** Current step index (zero-based) */ currentStep: number; /** Total number of steps */ totalSteps: number; /** Whether this is the first step */ isFirst: boolean; /** Whether this is the last step */ isLast: boolean; /** Whether async validation is in progress */ isValidating: boolean; } ``` -------------------------------- ### useStepperContext Hook for Stepper State Access Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/hooks.md The useStepperContext hook provides access to the internal Stepper context, which is valuable for creating deeply nested components that require control over the wizard's state. It returns the step context and the ID of the current step. ```tsx import { useStepperContext } from 'ink-stepper'; const { stepContext, currentStepId } = useStepperContext(); ``` -------------------------------- ### ProgressContext Interface in TypeScript Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/types.md Defines the context object passed to the `renderProgress` function. It includes the current step index and an array of step metadata, where each step indicates its name, completion status, and whether it's the current step. ```typescript interface ProgressContext { /** Current step index (zero-based) */ currentStep: number; /** Array of step metadata */ steps: Array<{ name: string; completed: boolean; current: boolean; }>; } ``` -------------------------------- ### Customizing Step Markers in Ink Stepper (React) Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/customization.md Allows customization of symbols for completed, current, and pending steps using the `markers` prop. Defaults are provided if not explicitly set. This prop accepts an object with `completed`, `current`, and `pending` keys. ```tsx {/* ... */} ``` -------------------------------- ### Perform actions before exiting a step using onExitStep in React Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/lifecycle.md The `onExitStep` callback is executed just before leaving the current step. It's ideal for tasks like data validation, saving state, or performing cleanup operations. The callback receives the index of the step being exited and can return a boolean to control navigation. ```tsx { console.log(`Leaving step ${stepIndex}`); // Perform cleanup or save await saveData(stepIndex); // Return true to allow navigation, false to cancel return true; }} > {/* ... */} ``` -------------------------------- ### useStepperInput Hook for Input Focus Coordination Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/hooks.md The useStepperInput hook is designed to coordinate input focus with Stepper keyboard navigation. It should be used within custom input components to prevent conflicts with the Stepper's global navigation keys (Enter/Escape). It returns functions to disable/enable navigation and a boolean indicating the current navigation state. ```tsx import { useStepperInput } from 'ink-stepper'; const { disableNavigation, enableNavigation, isNavigationDisabled } = useStepperInput(); ``` -------------------------------- ### Synchronous Validation with Boolean Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/validation.md Implement synchronous validation by passing a boolean value to the `canProceed` prop of the `` component. This immediately determines if the user can proceed, and navigation is blocked if the condition is false. ```tsx function NameStep() { const [name, setName] = useState(''); return ( 0}> Enter your name: {name.length === 0 && Name is required} ); } ``` -------------------------------- ### Custom Progress Rendering in Ink Stepper (React) Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/customization.md Provides complete control over the progress bar's appearance by replacing the default renderer with a custom function via the `renderProgress` prop. This function receives a `ProgressContext` object containing the current step and all steps' completion status. ```tsx ( Step {currentStep + 1} of {steps.length} {steps.map(s => s.completed ? '■' : '□').join(' ')} )} onComplete={handleComplete}> {/* ... */} ``` -------------------------------- ### Custom Progress Bar Renderer in Ink-Stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Provides full control over the progress bar's rendering by supplying a custom `renderProgress` function. This function receives `currentStep` and `steps` information to display custom progress information. ```tsx ( Step {currentStep + 1} of {steps.length}: {steps[currentStep].name} )} > ... ``` -------------------------------- ### Asynchronous Validation with Promise Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/validation.md Enable asynchronous validation by providing a function to `canProceed` that returns a `Promise`. This is ideal for server-side checks or simulating network requests. During validation, `isValidating` is set to true, and navigation is temporarily disabled. ```tsx const checkServer = async () => { // simulate delay await new Promise(r => setTimeout(r, 1000)); return true; }; {({ isValidating }) => ( Checking server status... {isValidating && } )} ``` -------------------------------- ### Custom Progress Bar Markers in Ink-Stepper Source: https://github.com/archcorsair/ink-stepper/blob/main/README.md Shows how to customize the progress bar markers (completed, current, pending) without replacing the entire progress bar component. Default markers are `✓`, `●`, and `○`. ```tsx ]", pending: "[ ]" }} > ... ``` -------------------------------- ### StepperMarkers Interface in TypeScript Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/api/types.md Defines the configuration object for customizing the default progress bar markers in the Ink Stepper. It allows setting custom strings for completed, current, and pending steps, with default values provided. ```typescript interface StepperMarkers { /** Marker for completed steps (default: ' ✓ ') */ completed?: string; /** Marker for current step (default: '●') */ current?: string; /** Marker for pending steps (default: '○') */ pending?: string; } ``` -------------------------------- ### Prevent Input Conflicts with useStepperInput in Ink Stepper Source: https://context7.com/archcorsair/ink-stepper/llms.txt This snippet shows how to use the `useStepperInput` hook to disable stepper navigation when an interactive input element within a step is focused. This prevents accidental navigation (e.g., pressing Enter or Escape) while the user is typing. It requires the `ink-stepper` and `ink-text-input` libraries. ```tsx import { Stepper, Step, useStepperInput } from "ink-stepper"; import { Text, Box } from "ink"; import { useState } from "react"; import TextInput from "ink-text-input"; function EmailStep() { const { disableNavigation, enableNavigation } = useStepperInput(); const [email, setEmail] = useState(""); return ( Enter your email: Type your email and press Enter ); } function App() { return ( process.exit(0)}> Thank you! ); } ``` -------------------------------- ### Hiding Progress Bar in Ink Stepper (React) Source: https://github.com/archcorsair/ink-stepper/blob/main/docs/guide/customization.md Allows the complete hiding of the progress bar by setting the `showProgress` prop to `false`. This is useful when a visual progress indicator is not desired. ```tsx {/* ... */} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.