Skip to content

Commit 3d1db65

Browse files
authored
Merge pull request #9163 from marmelab/doc-fix-use-of-custom-progress-in-wizard-form
[no-ci][Doc] Fix snippet to use a custom progress bar in WizardForm
2 parents de8fbaa + 7ab7094 commit 3d1db65

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

docs/WizardForm.md

+22-23
Original file line numberDiff line numberDiff line change
@@ -173,37 +173,36 @@ You can also customize the progress stepper by passing a custom component in the
173173
```tsx
174174
import React from 'react';
175175
import { Create, TextInput, required } from 'react-admin';
176-
import { WizardForm, WizardForm.Step } from '@react-admin/ra-form-layout';
176+
import { WizardForm, WizardFormProgressProps, useWizardFormContext } from '@react-admin/ra-form-layout';
177177

178-
const MyProgress = ({ currentStep, onStepClick, steps }) => (
179-
<ul>
180-
{steps.map((step, index) => {
181-
const label = React.cloneElement(step, { intent: 'label' });
182-
183-
return (
184-
<li key={`step_${index}`}>
185-
{!onStepClick ? (
178+
const MyProgress = (props: WizardFormProgressProps) => {
179+
const { currentStep, steps } = useWizardFormContext(props);
180+
return (
181+
<ul>
182+
{steps.map((step, index) => {
183+
const label = React.cloneElement(step, { intent: 'label' });
184+
return (
185+
<li key={`step_${index}`}>
186186
<span
187-
className={
188-
currentStep === index ? 'active' : undefined
189-
}
187+
style={{
188+
textDecoration:
189+
currentStep === index
190+
? 'underline'
191+
: undefined,
192+
}}
190193
>
191194
{label}
192195
</span>
193-
) : (
194-
<button onClick={() => onStepClick(index)}>
195-
{label}
196-
</button>
197-
)}
198-
</li>
199-
);
200-
})}
201-
</ul>
202-
);
196+
</li>
197+
);
198+
})}
199+
</ul>
200+
);
201+
};
203202

204203
const PostCreate = () => (
205204
<Create>
206-
<WizardForm progress={MyProgress}>
205+
<WizardForm progress={<MyProgress />}>
207206
<WizardForm.Step label="First step">
208207
<TextInput source="title" validate={required()} />
209208
</WizardForm.Step>

0 commit comments

Comments
 (0)