Command palette

@yasinsensoy/native

React Native · Components

Stepper

Progress indicator for multi-step flows (checkout, sign-up, wizard).

15 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Create your account

If you type “[email protected]”, server validation fails.

Code

import { Wizard, TextField, RadioField, SwitchField, Summary, toast } from "@yasinsensoy/native";

<Wizard
  onComplete={async (data) => { await save(data); toast.success("Account created"); }}
  steps={[
    {
      label: "Account",
      title: "Create your account",
      content: <>
        <TextField label="Email" name="email" type="email" required />
        <TextField label="Password" name="password" type="password" minLength={8} required />
      </>,
      // Runs once the browser rules pass; returns errors by field name.
      validate: async (data) =>
        (await isRegistered(data.get("email"))) ? { email: "This email is already registered" } : undefined,
    },
    { label: "Profile", content: <><TextField label="Full name" name="name" required /> …</> },
    { label: "Plan", content: <RadioField label="Plan" name="plan" variant="card" … /> },
    { label: "Newsletter", optional: true, content: <SwitchField label="Monthly newsletter" name="newsletter" /> },
    { label: "Review", content: ({ data }) => <Summary data={data} /> },
  ]} />

Events

  1. Events appear here when you interact with the preview.

Server action: jumps to the step of the field that returned an error by itself

Username

If you type “admin”, the server returns an error on the last step.

Import

import { Stepper, Wizard, resolveStepStatus, useWizard } from "@yasinsensoy/native";

Stepper

component

Progress indicator for multi-step flows (checkout, sign-up, wizard). On phones (below 640 px) horizontal steps switch to a compact view by default: "Step 2 / 5", the step's name and a segmented bar; it always fits the screen. States (error, warning, loading, skipped) and navigation rules are the same as web.

Stepper({ items, value: valueProp, defaultValue, onValueChange, navigation, orientation, variant: variantProp, effect, labelPlacement: labelPlacementProp, mobile, size, label, style, }: StepperProps): JSX.Element

Examples

<Stepper value={step} onValueChange={setStep} items={[
  { label: "Cart" }, { label: "Address" }, { label: "Payment" }, { label: "Confirm" },
]} />
<Stepper orientation="vertical" items={steps} />

Wizard

component

A form that progresses step by step (same API as the web Wizard): step indicator, the step's fields, Back / Next / Complete buttons and per-step validation in one component. All steps are a single Form; entries are not lost when going back, and all values are submitted together on the last step.

  • Pressing Next validates only that step's fields against the schema; errors show under the fields and the first invalid field is focused. Then the step's validate function (may be async) runs, if any.
  • When a server error arrives (state.errors or setErrors) it goes to the step of the invalid field. Invalid steps are red in the indicator, skipped ones dashed.
  • The Android back button returns to the previous step; on step change the screen reader reads the new step's title; the transition slides by direction (none when reduce motion is on).
Wizard(props: WizardProps<Schema>): JSX.Element

Examples

<Wizard schema={SignUp} onComplete={save} steps={[
  { label: "Account", content: <><TextField name="email" label="Email" /><TextField name="password" label="Password" type="password" /></> },
  { label: "Newsletter", optional: true, content: <Switch name="newsletter" label="Subscribe" /> },
  { label: "Confirm", content: ({ data }) => <Summary values={data} /> },
]} />

State of a step from its order and the manually given state (same as web).

resolveStepStatus(item: StepItem, index: number, current: number): StepStatus

useWizard

function

State and navigation functions of the nearest Wizard; for writing your own buttons or showing a summary inside a step.

useWizard(): WizardContextValue

Examples

const { next } = useWizard();
<Button onPress={next}>Continue with this plan</Button>

Step state; computed from the order if omitted.

type StepStatus = "complete" | "current" | "upcoming" | "error" | "warning" | "loading" | "skipped"

StepItem

interface

A step inside Stepper.

NameTypeDescription
labelReactNodeIts name.
description?ReactNodeDescription under the name.
icon?IconPropIcon instead of the number.
status?StepStatusManually given state (error, warning, loading, skipped).
optional?boolean | ReactNodeOptional step: shows "İsteğe bağlı" (optional) or the given text.
disabled?booleanCannot be selected.
content?ReactNodeContent shown under the step while selected, in the vertical layout.

Appearance: numbered circle, dot or segmented bar.

type StepperVariant = "circle" | "dot" | "bar"

Appearance of horizontal steps on narrow screens (below 640 px).

type StepperMobile = "compact" | "scroll" | "full"

Which steps can be reached by tapping.

type StepperNavigation = "none" | "completed" | "all"

StepperProps

interface

Stepper props.

NameTypeDefaultDescription
itemsreadonly StepItem[]Steps.
value?numberIndex of the current step (controlled, starting at 0).
defaultValue?number0Initial step.
onValueChange?(index: number) => voidWhen the step changes.
navigation?StepperNavigation"completed"` with `onValueChange`, otherwise `"none"Navigation by tapping.
orientation?"horizontal" | "vertical""horizontal"Orientation.
variant?StepperVariant | (string & {})"circle"Appearance.
effect?EffectPropEffect of the step indicators ("pulse", "glow", "bounce"…); stays on for the current step. Defaults to appearance.defaults.stepper.effect. See BuiltinEffect.
labelPlacement?"end" | "bottom""end"In horizontal layout the name sits beside or below the indicator; always below on narrow screens with mobile="full".
mobile?StepperMobile"compact"Narrow screen appearance.
size?Size"md"Size.
label?string{@link UIProvider} `steps` textScreen reader name.
style?StyleProp<ViewStyle>Container style.

Return value of a step's validate function (same as web).

  • undefined / true: valid, proceeds.
  • false: does not proceed.
  • Text: shown in an error box above the step.
  • { fieldName: "message" }: messages are shown under the fields with matching names; names not in the step fall into the error box.
type WizardValidateResult = undefined | null | boolean | string | Readonly<Record<string, string | null | undefined>>

Value received by useWizard and function-form step content.

NameTypeDescription
stepnumberIndex of the current step (from 0).
countnumberNumber of steps.
isFirstbooleanOn the first step?
isLastbooleanOn the last step?
busybooleanIs a validation or submission running?
next() => Promise<boolean>Validates the step and moves to the next; true if it moved. Completes on the last step.
back() => voidReturns to the previous step (no validation).
goTo(index: number) => Promise<boolean>Goes to a step; when moving forward (in a linear flow) the steps in between are validated.
skip() => voidSkips an optional step without validation; its fields are not submitted.
dataRecord<string, unknown> | nullForm values at the moment the step was entered (for a summary step). On native this is a values object instead of FormData.
getData() => Record<string, unknown>Current values of the form.

WizardStep

interface

A step inside Wizard.

NameTypeDescription
labelReactNodeName in the step indicator.
description?ReactNodeShort description under the name.
icon?IconPropIcon instead of the number.
title?ReactNodeTitle above the content. If omitted, screen readers read only label.
contentReactNode | ((wizard: WizardContextValue) => ReactNode)The step's fields; a function receives the wizard's state.
validate?(values: Record<string, unknown>, wizard: WizardContextValue) => WizardValidateResult | Promise<WizardValidateResult>Extra validation run after the schema rules pass (can be a Promise; the Next button shows loading meanwhile). See WizardValidateResult.
optional?booleanOptional: a "Skip" button appears; the skipped step's fields are neither submitted nor validated.
disabled?booleanThe step is skipped and cannot be navigated to.

WizardLabels

interface

Texts of the Wizard buttons.

NameTypeDefaultDescription
back?ReactNode"Geri"
next?ReactNode"İleri"
finish?ReactNode"Tamamla"
skip?ReactNode"Atla"

WizardProps

interface

Wizard props (same names as web).

Extends: Omit<FormProps<Schema>, "children" | "onValidSubmit">

NameTypeDefaultDescription
stepsreadonly WizardStep[]Steps.
step?numberCurrent step in controlled use.
defaultStep?number0Initial step.
onStepChange?(index: number) => voidWhen the step changes.
linear?booleantrueLinear flow: the next step cannot be reached before passing a step.
onComplete?(data: FormValues<Schema>, values: Record<string, unknown>) => unknownOn the last step, if all steps are valid, called with the schema output and the raw values. If it returns a Promise the Complete button shows loading until it settles.
variant?StepperVariant"circle"Indicator style.
effect?EffectPropIndicator effects.
labelPlacement?"end" | "bottom""end"Position of the name in the horizontal indicator.
mobile?StepperMobile"compact"Indicator appearance on narrow screens.
size?Size"md"Indicator size.
labels?WizardLabelsButton texts.
footer?ReactNodeExtra content in the bottom bar, left of the buttons.
backButton?booleantrueThe Android back button returns to the previous step.