Skip to content

Commit b56ae7c

Browse files
committed
docs: 完善stepsform文档
1 parent dab5de7 commit b56ae7c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

react/StepsForm/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77

88
```jsx
99
<StepsForm
10-
defaultCurrent={step}
10+
defaultCurrent={0}
1111
onFinish={async (values) => {
1212
console.log("所有步骤完成", values);
1313
}}
1414
>
15-
<StepForm
15+
<StepsForm.StepForm
1616
onFinish={async (values) => {
1717
console.log("第一步完成", "values");
1818
await delay(2000);
1919
return true;
2020
}}
2121
>
2222
第一步表单
23-
</StepForm>
24-
<StepForm
23+
</StepsForm.StepForm>
24+
<StepsForm.StepForm
2525
onFinish={async (values) => {
2626
console.log("第2步完成", "values");
2727
await delay(2000);
28-
return true;
28+
return false; // 返回false则不会进入下一步
2929
}}
3030
>
3131
第二步表单
32-
</StepForm>
32+
</StepsForm.StepForm>
3333

34-
<StepForm>第三步表单</StepForm>
34+
<StepsForm.StepForm>第三步表单</StepsForm.StepForm>
3535
</StepsForm>
3636
```

react/StepsForm/SetpForm.tsx renamed to react/StepsForm/StepForm.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SetpFormProps = {
1515
*/
1616
onFinish?: (values: any) => Promise<boolean>;
1717
} & FormProps;
18+
1819
export const StepForm = ({ children, onFinish, ...props }: SetpFormProps) => {
1920
const {
2021
currentIndex,
@@ -24,6 +25,7 @@ export const StepForm = ({ children, onFinish, ...props }: SetpFormProps) => {
2425
setCurrentIndex,
2526
onLastFinish,
2627
} = useContext(StepsFormContext);
28+
2729
const [loading, setLoading] = useState<boolean>(false);
2830

2931
return (

react/StepsForm/context.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ const StepsFormContext = React.createContext<StepsFormContextType>({
3737
values: undefined,
3838
currentIndex: 0,
3939
})
40+
4041
export const { Provider: StepsFormProvider } = StepsFormContext
42+
4143
export default StepsFormContext

react/StepsForm/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { useEffect, useMemo, useRef, useState, ReactNode } from "react";
22
import styles from "./index.module.scss";
33
import { StepsFormProvider } from "./context";
4-
import StepForm from "./SetpForm";
4+
import StepForm from "./StepForm";
55

66
type StepsFormProps = {
7+
/**
8+
* 表单内容,每个子元素需要时一个StepForm组件
9+
*/
710
children: ReactNode;
811
/**
912
* 默认初始显示第几步

0 commit comments

Comments
 (0)