@kelvininc/ui-components
Version:
Kelvin UI Components
43 lines (42 loc) • 2.32 kB
JavaScript
import { isEmpty, isNil } from "lodash-es";
import { EStepState } from "./wizard.types";
export const buildHeaderConfig = (steps, currentStep) => {
if (isEmpty(steps) || isNil(currentStep) || currentStep < 0 || currentStep > steps.length - 1) {
return null;
}
return {
label: `Step ${currentStep + 1}`,
description: steps[currentStep].title,
tip: steps[currentStep].tip
};
};
export const buildFooterConfig = (steps, currentStep, currentStepState, disabled = false) => {
var _a, _b;
if (isEmpty(steps) || isNil(currentStep) || currentStep < 0 || currentStep > steps.length - 1) {
return null;
}
const stepsConfig = steps.map((step, index) => {
return {
stepKey: step.title,
enabled: !disabled && ((index === currentStep + 1 && (currentStepState === null || currentStepState === void 0 ? void 0 : currentStepState.state) === EStepState.Success) || (index < currentStep && steps[index + 1].allowGoBack)),
active: index <= currentStep,
hasError: index === currentStep && (currentStepState === null || currentStepState === void 0 ? void 0 : currentStepState.state) === EStepState.Error
};
});
return {
steps: stepsConfig,
currentStep,
hasError: false,
showPrevBtn: (_a = steps[currentStep].allowGoBack) !== null && _a !== void 0 ? _a : false,
prevEnabled: !disabled && currentStep > 0,
showNextBtn: currentStep < steps.length - 1,
nextEnabled: !disabled && (currentStepState === null || currentStepState === void 0 ? void 0 : currentStepState.state) === EStepState.Success,
nextTooltip: currentStepState === null || currentStepState === void 0 ? void 0 : currentStepState.error,
showCancelBtn: (_b = steps[currentStep].cancelable) !== null && _b !== void 0 ? _b : false,
cancelEnabled: true,
showCompleteBtn: currentStep === steps.length - 1,
completeEnabled: !disabled && (currentStepState === null || currentStepState === void 0 ? void 0 : currentStepState.state) === EStepState.Success,
completeTooltip: currentStepState === null || currentStepState === void 0 ? void 0 : currentStepState.error,
progressPercentage: currentStep * (100 / (steps.length - 1))
};
};