Skip to content

Wizard

A task in a few steps, one screen each: where you are, what is left, Back and Next. The last button says what happens.

import { Wizard } from '@sypnia/ui/react'

On this page
  1. Connect a database
  2. When to use it
  3. For everyone
  4. Props

Connect a database

Press Next without choosing.

  1. Choose the source
  2. Where it is
  3. Review

Choose the source

Code
import { useState } from 'react';
import { Field, Input, KeyValue, RadioGroup, toast, Toaster, Wizard } from '@sypnia/ui/react';

// Press Next without choosing: it says what is missing. Back keeps what was written.
export default function Connect() {
  const [source, setSource] = useState('');
  const [host, setHost] = useState('');
  return (
    <>
      <Wizard label="Connect a database" finishLabel="Connect" onFinish={() => new Promise<void>((r) => setTimeout(() => { r(); toast('Connected', { tone: 'ok' }); }, 1200))} steps={[
        { id: 'source', title: 'Choose the source', validate: () => (source ? undefined : 'Choose where the data comes from.'),
          content: <RadioGroup aria-label="Source" value={source} onChange={setSource} options={[{ value: 'postgres', label: 'Postgres' }, { value: 'mysql', label: 'MySQL' }, { value: 'csv', label: 'A CSV file' }]} /> },
        { id: 'where', title: 'Where it is', validate: () => (host ? undefined : 'Write the address of the server.'),
          content: <Field label="Host" hint="For example db.northwind.io"><Input machine value={host} onChange={(e) => setHost(e.target.value)} /></Field> },
        { id: 'review', title: 'Review', content: <KeyValue items={[['Source', source || '—'], ['Host', host || '—']]} /> },
      ]} />
      <Toaster />
    </>
  );
}

When to use it

Use it when

  • Tasks that need answers in order: connect a database, create a project.
  • Check each step with validate and say what is missing.

Do not use it when

  • Forms that fit on one screen.
  • More than five steps: split the task.

For everyone

  • The Stepper says where you are; the focus moves to the title of each new step.
  • What is missing is said in an alert above the buttons.

Props

WizardTypeDefault
finishLabelrequired

What the last button does: «Connect the database».

string
labelrequired string
onFinishrequired () => void | Promise<void>
stepsrequired WizardStep[]
busy boolean
onCancel (() => void)
  1. Connect a database
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms