A flexible and customizable multi-step dialog component for React applications, built with TypeScript and Material-UI.
- 🚀 TypeScript Support - Fully typed with comprehensive type definitions
- 🎨 Customizable - Flexible styling and layout options
- 📱 Responsive - Works seamlessly across different screen sizes
- 🔧 Form Integration - Built-in React Hook Form integration with validation
- 🎯 Type-Safe - Strongly typed step definitions and form schemas
- 🌟 Material-UI - Built on top of MUI components
npm install steps-dialog
# or
yarn add steps-dialog
# or
pnpm add steps-dialogMake sure you have the following peer dependencies installed:
npm install react react-dom @mui/material @emotion/react @emotion/styled react-hook-form @hookform/resolvers zod lodashimport { StepDialog, useStepDialog } from 'steps-dialog';
// Define your step schema
const steps = z.object({
name: z.string().min(1, "Name is required"),
age: z.number().min(18, "Must be 18 or older"),
});
// Create step definitions
const stepDefinitions = [
{
key: "step1",
schema: z.object({ name: z.string().min(1) }),
Layout: YourFirstStepComponent,
},
{
key: "step2",
schema: z.object({ age: z.number().min(18) }),
Layout: YourSecondStepComponent,
}
];
function App() {
const dialog = useStepDialog();
return (
<div>
<button onClick={dialog.openDialog}>
Open Step Dialog
</button>
<StepDialog
steps={stepDefinitions}
{...dialog.dialogProps}
/>
</div>
);
}Main dialog component that renders the multi-step interface.
Props:
steps- Array of step definitionsopen- Boolean to control dialog visibilityonClose- Callback when dialog closesonSubmit- Callback when all steps are completed
Each step should implement the StepLayoutProps interface:
interface StepLayoutProps {
onNext: () => void;
onPrevious: () => void;
onCancel: () => void;
onSubmit: () => void;
stepIndex: number;
stepsAmount: number;
formMeta: FormMeta;
}Hook for managing dialog state.
Returns:
openDialog()- Function to open the dialogdialogProps- Props to spread on<StepDialog>
Hook for form management within steps.
Returns React Hook Form utilities:
control- Form control objectgetValues()- Get current form valuesvalidateFields()- Validate current stepformState- Form state including errorswatch()- Watch form fields
<ControlledField>- Pre-configured form field component<Header>- Step header component<Footer>- Step footer with navigation buttons<Title>- Dialog title component
See the /example folder in the repository for a complete working example.
# Install dependencies
pnpm install
# Run example in development
pnpm dev
# Build the library
pnpm build
# Run example build
pnpm build:exampleMIT