ar-design 0.4.40 → 0.4.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,10 +3,14 @@ import { IChildren } from "../../../libs/types/IGlobalProps";
|
|
|
3
3
|
interface IProps<TData extends object> extends IChildren {
|
|
4
4
|
name: string;
|
|
5
5
|
steps: StepProps[];
|
|
6
|
+
currentStep?: number;
|
|
6
7
|
onChange: (currentStep: number) => void;
|
|
7
8
|
validation?: {
|
|
8
9
|
data: TData;
|
|
9
10
|
rules: ValidationProperties<TData>[];
|
|
10
11
|
};
|
|
12
|
+
config?: {
|
|
13
|
+
isAutomatic?: boolean;
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
16
|
export default IProps;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import IProps from "./IProps";
|
|
3
3
|
import "../../../assets/css/components/navigation/steps/styles.css";
|
|
4
|
-
declare const Steps: <T extends object>({ children, name, steps, onChange, validation }: IProps<T>) => React.JSX.Element;
|
|
4
|
+
declare const Steps: <T extends object>({ children, name, steps, currentStep, onChange, validation, config, }: IProps<T>) => React.JSX.Element;
|
|
5
5
|
export default Steps;
|
|
@@ -5,11 +5,11 @@ import Typography from "../../data-display/typography";
|
|
|
5
5
|
import Button from "../../form/button";
|
|
6
6
|
import { useValidation } from "../../../libs/core/application/hooks";
|
|
7
7
|
const { Title } = Typography;
|
|
8
|
-
const Steps = function ({ children, name, steps = [], onChange, validation }) {
|
|
8
|
+
const Steps = function ({ children, name, steps = [], currentStep, onChange, validation, config, }) {
|
|
9
9
|
// states
|
|
10
|
-
const [
|
|
10
|
+
const [_currentStep, setCurrentStep] = useState(0);
|
|
11
11
|
// hooks
|
|
12
|
-
const { errors, onSubmit, setSubmit } = useValidation(validation?.data, validation?.rules,
|
|
12
|
+
const { errors, onSubmit, setSubmit } = useValidation(validation?.data, validation?.rules, _currentStep + 1);
|
|
13
13
|
// methods
|
|
14
14
|
const getStepIconStatus = (currentStep, index) => {
|
|
15
15
|
if (currentStep < index)
|
|
@@ -20,17 +20,24 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
|
|
|
20
20
|
};
|
|
21
21
|
// useEffects
|
|
22
22
|
useEffect(() => {
|
|
23
|
+
setCurrentStep(currentStep ?? 0);
|
|
24
|
+
}, [currentStep]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (config?.isAutomatic)
|
|
27
|
+
return;
|
|
23
28
|
const key = `${window.location.pathname}::${name}`;
|
|
24
29
|
const stored = sessionStorage.getItem(key);
|
|
25
|
-
setCurrentStep(stored !== null ? Number(stored) : 0);
|
|
26
|
-
onChange?.(stored !== null ? Number(stored) : 0);
|
|
30
|
+
setCurrentStep(stored !== null ? Number(stored) : (currentStep ?? 0));
|
|
31
|
+
onChange?.(stored !== null ? Number(stored) : (currentStep ?? 0));
|
|
27
32
|
}, []);
|
|
28
33
|
return (React.createElement("div", { className: "ar-steps" },
|
|
29
34
|
React.createElement("div", { className: "steps" }, steps.length > 0 &&
|
|
30
35
|
steps.map((step, index) => {
|
|
31
36
|
let itemIcon = ["item-icon"];
|
|
32
|
-
itemIcon.push(getStepIconStatus(
|
|
37
|
+
itemIcon.push(getStepIconStatus(_currentStep, index));
|
|
33
38
|
return (React.createElement("div", { key: step.title || index, className: "item", onClick: () => {
|
|
39
|
+
if (config?.isAutomatic)
|
|
40
|
+
return;
|
|
34
41
|
if (validation) {
|
|
35
42
|
onSubmit((result) => {
|
|
36
43
|
if (!result)
|
|
@@ -48,7 +55,7 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
|
|
|
48
55
|
sessionStorage.setItem(key, String(index));
|
|
49
56
|
} },
|
|
50
57
|
React.createElement("div", { className: itemIcon.map((c) => c).join(" ") },
|
|
51
|
-
React.createElement("span", { className: getStepIconStatus(
|
|
58
|
+
React.createElement("span", { className: getStepIconStatus(_currentStep, index) })),
|
|
52
59
|
React.createElement("div", { className: "item-informations" },
|
|
53
60
|
React.createElement("span", { className: "step" },
|
|
54
61
|
"STEP ",
|
|
@@ -58,7 +65,7 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
|
|
|
58
65
|
React.createElement("div", { className: "content" },
|
|
59
66
|
steps.map((step, stepIndex) => {
|
|
60
67
|
return (React.createElement("div", { key: stepIndex }, React.Children.map(step.content, (child) => {
|
|
61
|
-
if (React.isValidElement(child) && stepIndex ===
|
|
68
|
+
if (React.isValidElement(child) && stepIndex === _currentStep) {
|
|
62
69
|
return validation
|
|
63
70
|
? React.cloneElement(child, {
|
|
64
71
|
errors: errors,
|
|
@@ -68,28 +75,28 @@ const Steps = function ({ children, name, steps = [], onChange, validation }) {
|
|
|
68
75
|
return null;
|
|
69
76
|
})));
|
|
70
77
|
}),
|
|
71
|
-
React.createElement("div", { className: "buttons" },
|
|
72
|
-
|
|
78
|
+
!config?.isAutomatic && (React.createElement("div", { className: "buttons" },
|
|
79
|
+
_currentStep > 0 && (React.createElement(Button, { color: "blue", onClick: () => {
|
|
73
80
|
setCurrentStep((prev) => prev - 1);
|
|
74
|
-
onChange(
|
|
81
|
+
onChange(_currentStep - 1);
|
|
75
82
|
} }, "Geri")),
|
|
76
83
|
children && children,
|
|
77
|
-
|
|
84
|
+
_currentStep < steps.length - 1 && (React.createElement(Button, { color: "blue", onClick: () => {
|
|
78
85
|
if (validation) {
|
|
79
86
|
onSubmit((result) => {
|
|
80
87
|
if (!result)
|
|
81
88
|
return;
|
|
82
89
|
setCurrentStep((prev) => prev + 1);
|
|
83
|
-
onChange(
|
|
90
|
+
onChange(_currentStep + 1);
|
|
84
91
|
setSubmit(false);
|
|
85
92
|
});
|
|
86
93
|
}
|
|
87
94
|
else {
|
|
88
95
|
setCurrentStep((prev) => prev + 1);
|
|
89
|
-
onChange(
|
|
96
|
+
onChange(_currentStep + 1);
|
|
90
97
|
}
|
|
91
98
|
const key = `${window.location.pathname}::${name}`;
|
|
92
|
-
sessionStorage.setItem(key, String(
|
|
93
|
-
} }, "\u0130leri"))))));
|
|
99
|
+
sessionStorage.setItem(key, String(_currentStep + 1));
|
|
100
|
+
} }, "\u0130leri")))))));
|
|
94
101
|
};
|
|
95
102
|
export default Steps;
|