我正在尝试构建一个多步骤表单,用户在按下下一步按钮时可以选择步骤。通过添加我想要的设计的屏幕截图,我在这里清楚地说明了这一点。 请参阅我标记整个圆圈的图像。当用户单击继续时,会像这样弹出 sub-steeper
为了实现这一点,我正在尝试使用 Kendo React UI 步进器组件。这是我的代码,
import * as React from "react";
import { Form, FormElement } from "@progress/kendo-react-form";
import { Button } from "@progress/kendo-react-buttons";
import { Stepper } from "@progress/kendo-react-layout";
import { AccountDetails } from "./Forms/account-details";
// import { PersonalDetails } from './personal-details';
// import { PaymentDetails } from './payment-details';
const stepPages = [
AccountDetails,
// PersonalDetails,
// PaymentDetails
];
const s=0;
export const Main = () => {
const [step, setStep] = React.useState(0);
const [formState, setFormState] = React.useState({});
const [steps, setSteps] = React.useState([
{ label: "Step 1", isValid: undefined },
{ label: "Personal Details", isValid: undefined },
{ label: "Payment Details", isValid: undefined },
]);
const lastStepIndex = steps.length - 1;
const isLastStep = lastStepIndex === step;
const isPreviousStepsValid =
steps
.slice(0, step)
.findIndex((currentStep) => currentStep.isValid === false) === -1;
const onStepSubmit = React.useCallback(
(event) => {
const { isValid, values } = event;
const currentSteps = steps.map((currentStep, index) => ({
...currentStep,
isValid: index === step ? isValid : currentStep.isValid,
}));
setSteps(currentSteps);
setStep(() => Math.min(step + 1, lastStepIndex));
setFormState(values);
if (isLastStep && isPreviousStepsValid && isValid) {
alert(JSON.stringify(values));
}
},
[
step,
steps,
setSteps,
setStep,
setFormState,
isLastStep,
isPreviousStepsValid,
]
);
const onPrevClick = React.useCallback(
(event) => {
event.preventDefault();
setStep(() => Math.max(step - 1, 0));
},
[step, setStep]
);
return (
<div
style={{
display: "flex",
flexDirection: "column",
justifyContent: "center",
}}
>
<div style={{paddingTop:"100px",paddingLeft:"100px"}}>
<Stepper value={step} items={steps} orientation="vertical" />
</div>
<Form
initialValues={formState}
onSubmitClick={onStepSubmit}
render={(formRenderProps) => (
<div style={{ alignSelf: "center" }}>
<FormElement style={{ width: 480 }}>
{stepPages[step]}
<span
style={{ marginTop: "40px" }}
className={"k-form-separator"}
/>
<div
style={{
justifyContent: "space-between",
alignContent: "center",
}}
className={"k-form-buttons k-buttons-end"}
>
<span style={{ alignSelf: "center" }}>
Step {step + 1} of 3
</span>
<div>
{step !== 0 ? (
<Button
style={{ marginRight: "16px" }}
onClick={onPrevClick}
>
Previous
</Button>
) : undefined}
<Button
primary={true}
disabled={isLastStep ? !isPreviousStepsValid : false}
onClick={formRenderProps.onSubmit}
>
{isLastStep ? "Submit" : "Continue"}
</Button>
</div>
</div>
</FormElement>
</div>
)}
/>
</div>
);
};
export default Main;
只是帮助在那里实施这些子步骤。提前致谢。