import { useWizard, Step, useStepForm, Field } from 'graneet-form';
interface WizardData {
personal: {
firstName: string;
lastName: string;
};
contact: {
email: string;
phone: string;
};
}
function PersonalInfoStep() {
const { form } = useStepForm<WizardData, 'personal'>();
return (
<Step name="personal" title="Personal Information">
<Field
name="firstName"
render={({ value, onChange, onBlur, onFocus }) => (
<input
placeholder="First Name"
value={value || ''}
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
onFocus={onFocus}
/>
)}
/>
<Field
name="lastName"
render={({ value, onChange, onBlur, onFocus }) => (
<input
placeholder="Last Name"
value={value || ''}
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
onFocus={onFocus}
/>
)}
/>
</Step>
);
}
function ContactInfoStep() {
const { form } = useStepForm<WizardData, 'contact'>();
return (
<Step name="contact" title="Contact Information">
<Field
name="email"
render={({ value, onChange, onBlur, onFocus }) => (
<input
type="email"
placeholder="Email"
value={value || ''}
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
onFocus={onFocus}
/>
)}
/>
<Field
name="phone"
render={({ value, onChange, onBlur, onFocus }) => (
<input
placeholder="Phone"
value={value || ''}
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
onFocus={onFocus}
/>
)}
/>
</Step>
);
}
function MyWizard() {
const wizard = useWizard<WizardData>(
(wizardValues) => {
console.log('Wizard completed:', wizardValues);
},
() => {
console.log('Wizard cancelled');
}
);
return (
<WizardContext.Provider value={wizard}>
<PersonalInfoStep />
<ContactInfoStep />
</WizardContext.Provider>
);
}