Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Fix snippet to use a custom progress bar in WizardForm #9163

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions docs/WizardForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,37 +173,36 @@ You can also customize the progress stepper by passing a custom component in the
```tsx
import React from 'react';
import { Create, TextInput, required } from 'react-admin';
import { WizardForm, WizardForm.Step } from '@react-admin/ra-form-layout';
import { WizardForm, WizardFormProgressProps, useWizardFormContext } from '@react-admin/ra-form-layout';

const MyProgress = ({ currentStep, onStepClick, steps }) => (
<ul>
{steps.map((step, index) => {
const label = React.cloneElement(step, { intent: 'label' });

return (
<li key={`step_${index}`}>
{!onStepClick ? (
const MyProgress = (props: WizardFormProgressProps) => {
const { currentStep, steps } = useWizardFormContext(props);
return (
<ul>
{steps.map((step, index) => {
const label = React.cloneElement(step, { intent: 'label' });
return (
<li key={`step_${index}`}>
<span
className={
currentStep === index ? 'active' : undefined
}
style={{
textDecoration:
currentStep === index
? 'underline'
: undefined,
}}
>
{label}
</span>
) : (
<button onClick={() => onStepClick(index)}>
{label}
</button>
)}
</li>
);
})}
</ul>
);
</li>
);
})}
</ul>
);
};

const PostCreate = () => (
<Create>
<WizardForm progress={MyProgress}>
<WizardForm progress={<MyProgress />}>
<WizardForm.Step label="First step">
<TextInput source="title" validate={required()} />
</WizardForm.Step>
Expand Down
Loading